Sha256: 0a54a230b9bfb3902dcdb3a894208d22de5d787058073d0cfeb4c3e58835724d

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), "/../../spec_helper.rb"))

describe Mongoid::Attributes do

  describe "#process" do

    context "when supplied hash has values" do

      before do
        @attributes = {
          :_id => "1",
          :title => "value",
          :age => "30",
          :terms => "true",
          :name => {
            :_id => "2", :first_name => "Test", :last_name => "User"
          },
          :addresses => [
            { :_id => "3", :street => "First Street" },
            { :_id => "4", :street => "Second Street" }
          ]
        }
      end

      it "returns a properly cast the attributes" do
        attrs = Person.new(@attributes).attributes
        attrs[:age].should == 30
        attrs[:terms].should == true
        attrs[:_id].should == "1"
      end

    end

    context "when associations provided in the attributes" do

      before do
        @name = Name.new(:first_name => "Testy")
        @attributes = {
          :name => @name
        }
        @person = Person.new(@attributes)
      end

      it "sets the associations" do
        @person.name.should == @name
      end

    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-0.6.10 spec/unit/mongoid/attributes_spec.rb
mongoid-0.6.9 spec/unit/mongoid/attributes_spec.rb
mongoid-0.6.8 spec/unit/mongoid/attributes_spec.rb