spec/mongoid/changeable_spec.rb in mongoid-4.0.2 vs spec/mongoid/changeable_spec.rb in mongoid-5.0.0.beta

- old
+ new

@@ -659,12 +659,30 @@ end it "returns an array of changed field names" do expect(person.changed).to include("title") end + end + context "When the document has changed but changed back to the original" do + + let(:person) do + Person.instantiate(title: "Grand Poobah") + end + + before do + person.title = "Captain Obvious" + person.title = nil + end + + it "returns an array of changed field names" do + expect(person.changed).not_to include("title") + end + + end + context "when the document has not changed" do let(:person) do Person.instantiate({}) end @@ -788,9 +806,61 @@ address.number = 10 end it "returns true" do expect(person).to be_changed + end + end + + context "when changed? has been called before child elements size change" do + + let(:person) do + Person.create + end + + let(:address) do + person.addresses.create(street: "hobrecht") + end + + let!(:location) do + address.locations.create(name: "home") + end + + before do + person.changed? + end + + context "when adding via new" do + + before do + address.locations.new + end + + it "returns true" do + expect(person).to be_changed + end + end + + context "when adding via build" do + + before do + address.locations.build + end + + it "returns true" do + expect(person).to be_changed + end + end + + context "when adding via create" do + + before do + address.locations.create + end + + it "returns false" do + expect(person).to_not be_changed + end end end context "when a deeply embedded child has changed" do