Sha256: 8587056af0731d3e9f10e24af869a8db8e237e896397710d836be287380bcdc1
Contents?: true
Size: 1.57 KB
Versions: 3
Compression:
Stored size: 1.57 KB
Contents
require "spec_helper" describe Mongoid::Persistence::Atomic::Push do describe "#persist" do context "when the field exists" do let(:person) do Person.create(aliases: [ "007" ]) end let!(:pushed) do person.push(:aliases, "Bond") end let(:reloaded) do person.reload end it "pushes the value onto the array" do person.aliases.should eq([ "007", "Bond" ]) end it "persists the data" do reloaded.aliases.should eq([ "007", "Bond" ]) end it "removes the field from the dirty attributes" do person.changes["aliases"].should be_nil end it "resets the document dirty flag" do person.should_not be_changed end it "returns the new array value" do pushed.should eq([ "007", "Bond" ]) end end context "when the field does not exist" do let(:person) do Person.create end let!(:pushed) do person.push(:aliases, "Bond") end let(:reloaded) do person.reload end it "pushes the value onto the array" do person.aliases.should eq([ "Bond" ]) end it "persists the data" do reloaded.aliases.should eq([ "Bond" ]) end it "removes the field from the dirty attributes" do person.changes["aliases"].should be_nil end it "resets the document dirty flag" do person.should_not be_changed end it "returns the new array value" do pushed.should eq([ "Bond" ]) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mongoid-3.1.7 | spec/mongoid/persistence/atomic/push_spec.rb |
mongoid-3.1.6 | spec/mongoid/persistence/atomic/push_spec.rb |
mongoid-3.1.5 | spec/mongoid/persistence/atomic/push_spec.rb |