Sha256: 5feb5d95281d0e644c7bfb6933bc3006d36a73d8bb0013e55ef54ec63669aac2

Contents?: true

Size: 1.04 KB

Versions: 33

Compression:

Stored size: 1.04 KB

Contents

require "spec_helper"

describe Mongoid::Extensions::Array::Accessors do

  describe "#update" do

    context "when the attributes exist" do

      before do
        @array = [{ :_id => 1, :name => "James T. Kirk" }]
      end

      it "overwrites with the new attributes" do
        @array.update({ :_id => 1, :name => "Spock" })
        @array.first[:name].should == "Spock"
      end

    end

    context "when the attributes do not exist" do

      before do
        @array = [{ :_id => 1, :name => "James T. Kirk" }]
      end

      it "appends the new attributes" do
        @array.update({ :_id => 2, :name => "Scotty" })
        @array.size.should == 2
        @array.last[:name].should == "Scotty"
      end

    end

    context "when the new attribtues have no id" do

      before do
        @array = [{ :_id => 1, :name => "James T. Kirk" }]
      end

      it "appends the new attributes" do
        @array.update({:name => "Scotty" })
        @array.size.should == 2
        @array.last[:name].should == "Scotty"
      end

    end

  end

end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
mongoid-0.10.4 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.10.3 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.10.2 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.10.1 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.10.0 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.12 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.11 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.10 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.9 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.8 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.7 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.6 spec/unit/mongoid/extensions/array/accessors_spec.rb
mongoid-0.9.5 spec/unit/mongoid/extensions/array/accessors_spec.rb