spec/spec_helpers/examples/model.rb in protector-0.5.3 vs spec/spec_helpers/examples/model.rb in protector-0.5.4

- old
+ new

@@ -99,17 +99,18 @@ end end end it "marks blocked" do - d = dummy.new(string: 'bam', number: 1) - d.restrict!('!').creatable?.should == false + d = dummy.new(string: 'bam', number: 1).restrict!('!') + d.creatable?.should == false end it "marks allowed" do - d = dummy.new(string: 'bam') - d.restrict!('!').creatable?.should == true + d = dummy.new(string: 'bam').restrict!('!') + $debug = true + d.creatable?.should == true end it "invalidates" do d = dummy.new(string: 'bam', number: 1).restrict!('!') d.should invalidate @@ -178,10 +179,40 @@ it "validates" do d = dummy.new(number: 2).restrict!('!') d.should validate end end + + context "by direct values" do + before(:each) do + dummy.instance_eval do + protect do + can :create, number: 5 + end + end + end + + it "marks blocked" do + d = dummy.new(number: 500) + d.restrict!('!').creatable?.should == false + end + + it "marks allowed" do + d = dummy.new(number: 5) + d.restrict!('!').creatable?.should == true + end + + it "invalidates" do + d = dummy.new(number: 500).restrict!('!') + d.should invalidate + end + + it "validates" do + d = dummy.new(number: 5).restrict!('!') + d.should validate + end + end end # # Updating # @@ -302,9 +333,43 @@ end it "validates" do d = dummy.first.restrict!('!') assign!(d, number: 2) + d.should validate + end + end + + context "by direct values" do + before(:each) do + dummy.instance_eval do + protect do + can :update, number: 5 + end + end + end + + it "marks blocked" do + d = dummy.first + assign!(d, number: 500) + d.restrict!('!').updatable?.should == false + end + + it "marks allowed" do + d = dummy.first + assign!(d, number: 5) + d.restrict!('!').updatable?.should == true + end + + it "invalidates" do + d = dummy.first.restrict!('!') + assign!(d, number: 500) + d.should invalidate + end + + it "validates" do + d = dummy.first.restrict!('!') + assign!(d, number: 5) d.should validate end end end \ No newline at end of file