Homeschool Fixtures

April 15th, 2007

homeschool_fixtures :posts, :comments, :users
def test_comment
  post :create, :post_id => the_post(:user => some_user).id, :comment => {:text => 'hi'}
  assert_equal last_comment, the_post.comments.last
  assert_equal some_user, last_comment.moderator
end

There are no supporting fixture definitions anywhere. It’s wicked-awesome in practice. Everything is right there.

It was a late innovation on a recent project, so I don’t know much about the performance impact of doing things this way. On the one hand, it’s more dynamic, which is usually means slower, but on the other hand, you don’t have to load anything you don’t need, so it might be faster. To have any chance at good performance, you would want to use this method consistently, turn off the yaml features, and do appropriate DELETE FROMs in between tests (we were using blank yml files to get that effect, but that’s bad).

Sorry, comments are closed for this article.