Created
June 18, 2010 06:13
-
-
Save evansagge/443316 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
describe Mongoid::Associations do | |
before do | |
Person.collection.remove | |
end | |
context "embeds_one" do | |
describe "creating associated document" do | |
let(:person) { Person.create!( :ssn => "1234", :pet_attributes => { :name => 'odie' } ) } | |
specify { person.reload.pet.name.should == 'odie' } | |
end | |
describe "updating associated document" do | |
let(:person) { Person.create!( :ssn => "1234", :pet_attributes => { :name => 'garfield' } ) } | |
before { person.update_attributes(:pet_attributes => { :name => 'odie' } ) } | |
specify { person.reload.pet.name.should == 'odie' } | |
end | |
end | |
context "embeds_many" do | |
describe "creating associated document" do | |
let(:person) { Person.create!( :ssn => "1234", :favorites_attributes => { '0' => { :title => 'something' } } ) } | |
specify { person.reload.favorites.first.title.should == 'something' } | |
end | |
describe "updating associated document" do | |
let(:person) { Person.create!( :ssn => "1234", :favorites => { '0' => { :title => 'nothing' } } ) } | |
before { person.update_attributes(:favorites_attributes => { '0' => { :title => 'something' } } ) } | |
specify { person.reload.favorites.first.title.should == 'something' } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment