spec/spec_helpers/examples/model.rb in protector-0.1.1 vs spec/spec_helpers/examples/model.rb in protector-0.2.1

- old
+ new

@@ -10,11 +10,11 @@ can :create can :update end end - fields = Hash[*%w(id string number text dummy_id created_at updated_at).map{|x| [x, nil]}.flatten] + fields = Hash[*%w(id string number text dummy_id).map{|x| [x, nil]}.flatten] meta = dummy.new.restrict!('!').protector_meta meta.access[:view].should == fields meta.access[:create].should == fields meta.access[:update].should == fields @@ -51,11 +51,11 @@ end d = dummy.first.restrict!('!') d.number.should == nil d[:number].should == nil - d.read_attribute(:number).should_not == nil + read_attribute(d, :number).should_not == nil d.string.should == 'zomgstring' end end # @@ -182,17 +182,17 @@ end end it "marks blocked" do d = dummy.first - d.assign_attributes(string: 'bam', number: 1) + assign!(d, string: 'bam', number: 1) d.restrict!('!').updatable?.should == false end it "invalidates" do d = dummy.first.restrict!('!') - d.assign_attributes(string: 'bam', number: 1) + assign!(d, string: 'bam', number: 1) d.should invalidate end end context "by list of fields" do @@ -204,29 +204,29 @@ end end it "marks blocked" do d = dummy.first - d.assign_attributes(string: 'bam', number: 1) + assign!(d, string: 'bam', number: 1) d.restrict!('!').updatable?.should == false end it "marks allowed" do d = dummy.first - d.assign_attributes(string: 'bam') + assign!(d, string: 'bam') d.restrict!('!').updatable?.should == true end it "invalidates" do d = dummy.first.restrict!('!') - d.assign_attributes(string: 'bam', number: 1) + assign!(d, string: 'bam', number: 1) d.should invalidate end it "validates" do d = dummy.first.restrict!('!') - d.assign_attributes(string: 'bam') + assign!(d, string: 'bam') d.should validate end end context "by lambdas" do @@ -238,29 +238,29 @@ end end it "marks blocked" do d = dummy.first - d.assign_attributes(string: 'bam') + assign!(d, string: 'bam') d.restrict!('!').updatable?.should == false end it "marks allowed" do d = dummy.first - d.assign_attributes(string: '12345') + assign!(d, string: '12345') d.restrict!('!').updatable?.should == true end it "invalidates" do d = dummy.first.restrict!('!') - d.assign_attributes(string: 'bam') + assign!(d, string: 'bam') d.should invalidate end it "validates" do d = dummy.first.restrict!('!') - d.assign_attributes(string: '12345') + assign!(d, string: '12345') d.should validate end end context "by ranges" do @@ -272,29 +272,29 @@ end end it "marks blocked" do d = dummy.first - d.assign_attributes(number: 500) + assign!(d, number: 500) d.restrict!('!').updatable?.should == false end it "marks allowed" do d = dummy.first - d.assign_attributes(number: 2) + assign!(d, number: 2) d.restrict!('!').updatable?.should == true end it "invalidates" do d = dummy.first.restrict!('!') - d.assign_attributes(number: 500) + assign!(d, number: 500) d.should invalidate end it "validates" do d = dummy.first.restrict!('!') - d.assign_attributes(number: 2) + assign!(d, number: 2) d.should validate end end end @@ -321,20 +321,20 @@ it "invalidates" do dummy.instance_eval do protect do; end end - dummy.first.restrict!('!').destroy.should == false + d = dummy.create.restrict!('!') + d.should survive end it "validates" do dummy.instance_eval do protect do; can :destroy; end end - d = dummy.create!.restrict!('!') - d.destroy.should == d - d.destroyed?.should == true + d = dummy.create.restrict!('!') + d.should destroy end end # # Associations \ No newline at end of file