Sha256: a168f670a539d16a82ff36265d016587d3a40cc1e95f00135e3bbce731935a45

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require "spec_helper"

describe Mongoid::Persistence::Atomic::Unset do

  describe "#persist" do

    context "when unsetting a field" do

      let(:person) do
        Person.create(age: 100)
      end

      let!(:removed) do
        person.unset(:age)
      end

      it "removes the field" do
        person.age.should be_nil
      end

      it "resets the dirty attributes" do
        person.changes["age"].should be_nil
      end

      it "returns nil" do
        removed.should be_nil
      end
    end


    [[ :age, :score, { safe: true }], [ :age, :score ], [ [:age, :score ]]].each do |args|

      context "when unsetting multiple fields using #{args}" do

        let(:person) do
          Person.create(age: 100, score: 2)
        end

        let!(:removed) do
          person.unset *(args)
        end

        it "removes age field" do
          person.age.should be_nil
        end

        it "removes score field" do
          person.score.should be_nil
        end

        it "resets the age dirty attribute" do
          person.changes["age"].should be_nil
        end

        it "resets the score dirty attribute" do
          person.changes["score"].should be_nil
        end

        it "returns nil" do
          removed.should be_nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-3.1.7 spec/mongoid/persistence/atomic/unset_spec.rb
mongoid-3.1.6 spec/mongoid/persistence/atomic/unset_spec.rb
mongoid-3.1.5 spec/mongoid/persistence/atomic/unset_spec.rb