Skip to content

Commit

Permalink
Adding specs to test issue #26 on github
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Mar 12, 2010
1 parent fe03329 commit c5a8533
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/integration/mongoid/associations_spec.rb
Expand Up @@ -49,6 +49,16 @@

end

context "creation of an embedded association on a callback" do

it "allows the use of create!" do
artist = Artist.create!(:name => "Depeche Mode")
artist.songs.size.should == 2
artist.songs.first.title.should == "0"
artist.songs.last.title.should == "1"
end
end

context "criteria on has many embedded associations" do

before do
Expand Down
18 changes: 18 additions & 0 deletions spec/models/callbacks.rb
@@ -0,0 +1,18 @@
class Artist
include Mongoid::Document
field :name
has_many :songs

after_create :create_songs

protected
def create_songs
2.times { |n| songs.create!(:title => "#{n}") }
end
end

class Song
include Mongoid::Document
field :title
belongs_to :artist, :inverse_of => :songs
end

0 comments on commit c5a8533

Please sign in to comment.