spec/mongoid/attributes/readonly_spec.rb in mongoid-4.0.0.beta2 vs spec/mongoid/attributes/readonly_spec.rb in mongoid-4.0.0.rc1

- old
+ new

@@ -58,15 +58,15 @@ end context "when updating an existing readonly field" do before do - Person.attr_readonly :title, :terms + Person.attr_readonly :title, :terms, :score end let(:person) do - Person.create(title: "sir", terms: true) + Person.create(title: "sir", terms: true, score: 1) end context "when updating via the setter" do before do @@ -78,9 +78,49 @@ expect(person.title).to eq("sir") end it "does not persist the changes" do expect(person.reload.title).to eq("sir") + end + end + + context "when updating via inc" do + + context 'with single field operation' do + it "raises an error " do + expect { + person.inc(score: 1) + }.to raise_error(Mongoid::Errors::ReadonlyAttribute) + end + end + + context 'with multiple fields operation' do + it "raises an error " do + expect { + person.inc(score: 1, age: 1) + }.to raise_error(Mongoid::Errors::ReadonlyAttribute) + end + end + end + + context "when updating via bit" do + + context 'with single field operation' do + it "raises an error " do + expect { + person.bit(score: { or: 13 }) + }.to raise_error(Mongoid::Errors::ReadonlyAttribute) + end + end + + context 'with multiple fields operation' do + it "raises an error " do + expect { + person.bit( + age: { and: 13 }, score: { or: 13 }, inte: { and: 13, or: 10 } + ) + }.to raise_error(Mongoid::Errors::ReadonlyAttribute) + end end end context "when updating via []=" do