Skip to content

Instantly share code, notes, and snippets.

@notahat
Created June 12, 2010 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notahat/435343 to your computer and use it in GitHub Desktop.
Save notahat/435343 to your computer and use it in GitHub Desktop.
# Here's some more hints at what's coming in Machinist 2.
Machinist::Collection.blueprint(:stuff) do
user
posts 3, :author => user
posts.each do |post|
comments 3, :post => post
end
end
stuff = Machinist::Collection.make(:stuff)
stuff.user.should be_a(User)
stuff.posts.should have(3).elements
stuff.posts.each do |post|
post.should be_a(Post)
post.author.should == stuff.user
end
stuff.comments.should have(9).elements
stuff.comments.each do |comment|
comment.should be_a(Comment)
end
stuff.comments[0..2].each do |comment|
comment.post.should == stuff.posts[0]
end
stuff.comments[3..5].each do |comment|
comment.post.should == stuff.posts[1]
end
stuff.comments[6..8].each do |comment|
comment.post.should == stuff.posts[2]
end
# And yes, that whole collection of stuff will be cached, so it'll only be
# generated once even if you call Machinist::Collection.make(:stuff) in
# multiple tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment