spec/mongoid/contextual/atomic_spec.rb in mongoid-7.1.11 vs spec/mongoid/contextual/atomic_spec.rb in mongoid-7.2.0.rc1

- old
+ new

@@ -751,29 +751,16 @@ before do context.set(name: "Recoil") end - shared_examples 'writes as expected' do - it "sets existing fields" do - expect(depeche_mode.reload.name).to eq("Recoil") - end - - it "sets non existent fields" do - expect(smiths.reload.name).to eq("Recoil") - end + it "sets existing fields" do + expect(depeche_mode.reload.name).to eq("Recoil") end - include_examples 'writes as expected' - - context 'when fields being set have been projected out' do - - let(:criteria) do - Band.only(:genres) - end - - include_examples 'writes as expected' + it "sets non existent fields" do + expect(smiths.reload.name).to eq("Recoil") end end describe "#unset" do @@ -799,41 +786,39 @@ before do context.unset(:name) end - 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 + it "unsets the first existing field" do + expect(depeche_mode.reload.name).to 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 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 + it "unsets the first existing field" do + expect(depeche_mode.reload.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: %w[electro dub], years: 10, - likes: 200, rating: 4.3, origin: 'Space') + Band.create(name: "New Order", genres: [ "electro", "dub" ], years: 10) end let(:criteria) do Band.all end @@ -846,68 +831,33 @@ before do context.unset(:name, :genres) end - 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 + it "unsets name field" do + expect(new_order.reload.name).to 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 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 + it "unsets the unaliased field" do + expect(new_order.reload.name).to be_nil end - end - context "when using Hash arguments" do - - before do - context.unset({ years: true, likes: "" }, { rating: false, origin: nil }) + it "unsets the aliased field" do + expect(new_order.reload.years).to be_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' @@ -930,12 +880,10 @@ before do context.unset(:name) end it "unsets the unaliased field" do - depeche_mode.reload - expect(depeche_mode.name).to be_nil - expect(depeche_mode.years).to_not be_nil + expect(depeche_mode.reload.name).to be_nil end end end end