Sha256: 16073441358b833207db31341abbb2a439f5520bad7d20db522366bbfcd018a9

Contents?: true

Size: 1.21 KB

Versions: 41

Compression:

Stored size: 1.21 KB

Contents

require "spec_helper"

describe Mongoid::Extensions::Hash::Assimilation do

  describe "#assimilate" do

    context "when a type is not provided" do

      before do
        @child = { :first_name => "Hank", :last_name => "Moody" }
        @parent = Person.new(:title => "Mr.")
        @options = Mongoid::Associations::Options.new(:name => :name)
      end

      it "incorporates the hash into the object graph" do
        @child.assimilate(@parent, @options)
        @parent.name.first_name.should == "Hank"
        @parent.name.last_name.should == "Moody"
      end

    end

    context "when a type is provided" do

      before do
        @child = { :speed => 300 }
        @parent = Canvas.new(:name => "web page")
        @options = Mongoid::Associations::Options.new(:name => :writer)
      end

      it "incorporates the hash into the object graph with the supplied type" do
        @child.assimilate(@parent, @options, HtmlWriter)
        @parent.writer.should be_a_kind_of(HtmlWriter)
        @parent.writer.speed.should == 300
      end

      it "adds the _type field to the hash" do
        @child.assimilate(@parent, @options, HtmlWriter)
        @parent.writer._type.should == "HtmlWriter"
      end

    end

  end

end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
mongoid-pre-2.0.0.beta1 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-2.0.0.alpha spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.14 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.13 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.12 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.11 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.10 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.9 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.8 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.7 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-pre-2.0.0.pre spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.6 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.5 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.4 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.3 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.2 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.1 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.2.0 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.1.4 spec/unit/mongoid/extensions/hash/assimilation_spec.rb
mongoid-1.1.3 spec/unit/mongoid/extensions/hash/assimilation_spec.rb