spec/mongoid/contextual/atomic_spec.rb in mongoid-7.3.2 vs spec/mongoid/contextual/atomic_spec.rb in mongoid-7.3.3

- old
+ new

@@ -799,39 +799,41 @@ before do context.unset(:name) end - it "unsets the first existing field" do - expect(depeche_mode.reload.name).to be_nil + it "unsets the fields from all documents" do + depeche_mode.reload + new_order.reload + expect(depeche_mode.name).to be_nil + expect(depeche_mode.years).to_not be_nil + expect(new_order.name).to be_nil + expect(new_order.years).to_not be_nil end - - it "unsets the last existing field" do - expect(new_order.reload.name).to be_nil - end end context "when the field is aliased" do - before do context.unset(:years) end - it "unsets the first existing field" do - expect(depeche_mode.reload.years).to be_nil + it "unsets the fields from all documents" do + depeche_mode.reload + new_order.reload + expect(depeche_mode.name).to_not be_nil + expect(depeche_mode.years).to be_nil + expect(new_order.name).to_not be_nil + expect(new_order.years).to be_nil end - - it "unsets the last existing field" do - expect(new_order.reload.years).to be_nil - end end end context "when unsetting multiple fields" do let!(:new_order) do - Band.create(name: "New Order", genres: [ "electro", "dub" ], years: 10) + Band.create(name: "New Order", genres: %w[electro dub], years: 10, + likes: 200, rating: 4.3, origin: 'Space') end let(:criteria) do Band.all end @@ -844,33 +846,68 @@ before do context.unset(:name, :genres) end - it "unsets name field" do - expect(new_order.reload.name).to be_nil + it "unsets the specified fields" do + new_order.reload + expect(new_order.name).to be_nil + expect(new_order.genres).to be_nil + expect(new_order.years).to_not be_nil + expect(new_order.likes).to_not be_nil + expect(new_order.rating).to_not be_nil end - - it "unsets genres field" do - expect(new_order.reload.genres).to be_nil - end end context "when the field is aliased" do before do context.unset(:name, :years) end - it "unsets the unaliased field" do - expect(new_order.reload.name).to be_nil + it "unsets the specified fields" do + new_order.reload + expect(new_order.name).to be_nil + expect(new_order.genres).to_not be_nil + expect(new_order.years).to be_nil + expect(new_order.likes).to_not be_nil + expect(new_order.rating).to_not be_nil end + end - it "unsets the aliased field" do - expect(new_order.reload.years).to be_nil + context "when using Hash arguments" do + + before do + context.unset({ years: true, likes: "" }, { rating: false, origin: nil }) end + + it "unsets the specified fields" do + new_order.reload + expect(new_order.name).to_not be_nil + expect(new_order.genres).to_not be_nil + expect(new_order.years).to be_nil + expect(new_order.likes).to be_nil + expect(new_order.rating).to be_nil + expect(new_order.origin).to be_nil + end end + + context "when mixing argument types" do + + before do + context.unset(:name, [:years], { likes: "" }, { rating: false }) + end + + it "unsets the specified fields" do + new_order.reload + expect(new_order.name).to be_nil + expect(new_order.genres).to_not be_nil + expect(new_order.years).to be_nil + expect(new_order.likes).to be_nil + expect(new_order.rating).to be_nil + end + end end context 'when the criteria has a collation' do min_server_version '3.4' @@ -893,10 +930,12 @@ before do context.unset(:name) end it "unsets the unaliased field" do - expect(depeche_mode.reload.name).to be_nil + depeche_mode.reload + expect(depeche_mode.name).to be_nil + expect(depeche_mode.years).to_not be_nil end end end end