Added preferences for click amount and valid days on digital links. Tests for authorization are now running

This commit is contained in:
Michael Bianco
2012-03-31 11:07:52 -04:00
parent c4a85b71d7
commit e652835a5f
4 changed files with 45 additions and 57 deletions

View File

@@ -38,61 +38,39 @@ describe Spree::DigitalLink do
end
end
#context "authorization" do
# it "should increment the counter using #authorize!" do
# link = Factory(:digital_link)
# link.authorize!
# link.access_counter.should == 1
# end
#
# it "should not be #authorized? when the access_counter is too high" do
# link = Factory(:digital_link)
# link.stub(:access_counter => 2)
# link.authorized?.should be_true
# link.stub(:access_counter => 3)
# link.authorized?.should be_false
# end
#
# it "should not be #authorize! when the access_counter is too high" do
# link = Factory(:digital_link)
# link.stub(:access_counter => 2)
# link.authorize!.should be_true
# link.stub(:access_counter => 3)
# link.authorize!.should be_false
# end
#
# it "should not be #authorized? when the created_at date is too far in the past" do
# link = Factory(:digital_link)
# link.authorized?.should be_true
# link.stub(:created_at => 23.hours.ago)
# link.authorized?.should be_true
# link.stub(:created_at => 25.hours.ago)
# link.authorized?.should be_false
# end
#
# it "should not be #authorize! when the created_at date is too far in the past" do
# link = Factory(:digital_link)
# link.authorize!.should be_true
# link.stub(:created_at => 23.hours.ago)
# link.authorize!.should be_true
# link.stub(:created_at => 25.hours.ago)
# link.authorize!.should be_false
# end
#
# it "should not be #authorized? when both access_counter and created_at are invalid" do
# link = Factory(:digital_link)
# link.authorized?.should be_true
# link.stub(:access_counter => 3, :created_at => 25.hours.ago)
# link.authorized?.should be_false
# end
#
# it "should not be #authorize! when both access_counter and created_at are invalid" do
# link = Factory(:digital_link)
# link.authorize!.should be_true
# link.stub(:access_counter => 3, :created_at => 25.hours.ago)
# link.authorize!.should be_false
# end
#end
context "authorization" do
it "should increment the counter using #authorize!" do
link = Factory(:digital_link)
link.access_counter.should == 0
link.authorize!
link.access_counter.should == 1
end
it "should not be #authorized? when the access_counter is too high" do
link = Factory(:digital_link)
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks] - 1)
link.authorizable?.should be_true
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks])
link.authorizable?.should be_false
end
it "should not be #authorize! when the created_at date is too far in the past" do
link = Factory(:digital_link)
link.authorize!.should be_true
link.stub(:created_at => (Spree::DigitalConfiguration[:authorized_days] * 24 - 1).hours.ago)
link.authorize!.should be_true
link.stub(:created_at => (Spree::DigitalConfiguration[:authorized_days] * 24 + 1).hours.ago)
link.authorize!.should be_false
end
it "should not be #authorized? when both access_counter and created_at are invalid" do
link = Factory(:digital_link)
link.authorizable?.should be_true
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks], :created_at => (Spree::DigitalConfiguration[:authorized_days] * 24 + 1).hours.ago)
link.authorizable?.should be_false
end
end
end