Skip to content

Instantly share code, notes, and snippets.

@evansagge
Created June 18, 2010 06:13
Show Gist options
  • Save evansagge/443316 to your computer and use it in GitHub Desktop.
Save evansagge/443316 to your computer and use it in GitHub Desktop.
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