Friday, August 11, 2006

Rails Tip : 1 Place To Define Fixtures

This wasn't immediately obvious to me until recently.

You don't need to repeat your list of fixtures in every unit test file. Put your fixture list in the test_helper.rb file. Look for the line that says this, "# Add more helper methods to be used by all tests here..." Put your fixture list right after that, before the "end". So it looks like this:

class Test::Unit::TestCase

# Omitted rest of code in class

# Add more helper methods to be used by all tests here...
fixtures :model1, :model2, :model3

end

4 Comments:

Anonymous John Topley said...

Nice tip, thanks.

Tuesday, August 15, 2006 3:38:00 PM  
Blogger Michael Sica said...

No problem. You're my inspiration for these bit-sized Rails tips!

Tuesday, August 15, 2006 9:10:00 PM  
Anonymous John Topley said...

Ha ha! We'll have to see who can come up with the shortest tip! It think my latest one is pretty concise.

BTW, have you seen this: http://peepcode.com/? Excellent idea.

Wednesday, August 16, 2006 3:03:00 AM  
Blogger Michael Sica said...

That is concise!

That peepcode thing looks cool, but I don't want to drop the $9 on it. Maybe if someone else highly recommends it. (I've been meaning to get up to speed with RJS. My app was started before RJS was around, so I'm kick'n it Rails 1.0 style.)

Wednesday, August 16, 2006 7:20:00 PM  

Post a Comment

<< Home