Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts

Tuesday, November 10, 2009

Factory.create(:factory_girl, :fixtures => false)

Rails fixtures are a great starting point, but you can't live with them on a large project.
While working on a feature recently I kept breaking other unit tests while working with working in the associated fixtures. The relationship graph between all these objects is quite large, and I quickly decided this wasn't a game I wanted to play anymore.
FactoryGirl isn't new, and I've actually played around with FactoryGirl in the past. It didn't take much effort to add a test/factories.rb, specify a few Factory objects and then bask in the win.
Tests written. New feature added. Existing tests continue to work. Everybody is happy.
Over the last few weeks we have almost entirely replaced fixtures as we've encountered them. At this point in time it is quicker to replace the fixtures than it is to continue repairing fixtures.
Yay, our tests aren't as brittle anymore :)
For everything but the most trivial project, I'll be dropping fixtures at the start of the project.

Monday, September 22, 2008

Rails with NO Fixtures?

I have a Rails project, and I created a Country model. I added the basic details of Norway to the countries.yml fixture.
norway:
 code: NO
 name: Norway
I added a unit test to make sure I could get Norway by it's country code, which is NO
def test_find_by_code
 assert_equal countries(:norway), Country.find_by_code('NO')
end
Agreed, I probably don't need a unit test for this, but this should have worked, but it was failing with the following message.
Country id: 318845244, code: "1", name: "Norway" expected but was
nil
Apparently NO in the yaml file is interpreted as a 0 (zero). To prove the theory I changed the code of norway to YES. The unit test failed, and indicated that the model it expected should have had code: "1". Changing countries.yml to be...
norway:
 code: "NO"
 name: Norway
I personally really like fixtures and the nice features they bring in, but sometimes they can catch you out. I'm sure it's not a bug, I've just never encountered this before. Ever found anything strange in your fixtures?

Thursday, August 14, 2008

Ruby on Rails doesn't scale you say?

You might want to read this how this Bumer Sticker, a Linked-In application, that is serving 1 billion page views per month. From the article... "Ruby on Rails is frequently criticized for lacking the ability to scale. While the road to a billion page views per month has certainly had some potholes, Bumper Sticker has clearly demonstrated that the Rails platform can scale quite well, so as long as the team behind it understands that many of the bottlenecks are exactly those faced by developers on any other database-driven web platform." Joyent also blogged about this. How many Rails application have you developed, then found scaling the app was fast, relatively simple... not to mention cheap? How many Java web applications have you developed, then found scaling the app was difficult, slower, and expensive? You probably aren't even aware of the extra work you're going through here if you've never tried to scale a Rails app. You can take your pick of frameworks, I'm not citing any specific Java web application frameworks here. I'm not directly comparing Rails to Java, but Rails to insert-your-java-framework-here. I've been working with Java for a long time, and it still has it's place. But I think Rails is eating Java's lunch in a lot of areas these days, particularly in the web application and web services area.