rake db:fixtures:load
rake db:fixtures:load is probably one of the most useful commands I have used recently.
You see, I was meeting some people about some potential work. They wanted to see an example - preferably related to payment systems. I had some code but unfortunately, the service that is part of had been switched off (a number of reasons, none of which connected to my supreme stylings). I had a copy of said code on my machine, but no database and I had no time to prepare.
So how could I demo it? Easy peasy.
cd ~/Source/my_app
rake db:migrate
rake db:fixtures:load
ruby script/server
And then start Camino.
Because the application had been developed test-first I knew that there was a decent set of data within those fixtures. Data designed to show all the edge cases, all the complexities of the application. From users and logins through to payment records and customers.
It is fair to say that when writing your applications, test-first, the fixtures are the hardest thing. It can take ages and it is detailed, painstaking work. Especially if you are trying to build a narrative (:dave logs in, selects a :cucumber, goes to the :checkout, pays with his :expired_credit_card which is rejected).
But the benefit is there. Building a narrative helps you when you come back to the code in six months time. Defining a wide-range of test fixtures helps you when you make changes and need to ensure that it won't break a feature over there. And it helps you demo your code in front of a prospective client when faced with the unexpected.
Data Highway by KLatham.
No comments:
Post a Comment