Archive for September, 2008
Pagination for make_resourceful
Hampton Catlin the creator of make_resourceful has let his thoughts on pagination known and in summary he is not a fan. Hence there is no DRY way to add pagination to m_r without overriding the defaults methods repeatedly.
I am not so anti pagination and often find it mildly useful. But mostly my clients want it regardless. So I have abtracted my pagination solution for m_r into a plugin called funnily enough make_resourceful_with_pagination. Now it may sound like a fork of m_r but it is in fact an “evil-twin” plugin, which is a plugin pattern invented by Chris Wanstrath of GitHub. So basically you need to install both m_r and my plugin.
It works with will_paginate by default but should also work with paginating_find or any pagination that acts on the model. You just need to tweak the global options. It won’t work with classic pagination, but frankly I don’t see the appeal of that anyway.
No commentsmocked_fixtures: reuse fixtures as mocks without the database
For a while I have sitting on this plugin called mocked_fixtures. I wrote most of it a few months ago and added a few things here and there but just hadn’t got round to releasing it.
Basically it loads your fixtures files as mock model objects with the values from the fixture stubbed out on the mock. It saves you having to stub lots of attribute methods on your mocks with values that could have just as happily come from your fixtures. After all if you are still using fixtures then they often have a fair bit of thought behind them. So why not use them again but practice some good test isolation and remove the database from the picture.
I am using it in projects, mostly in controller and view specs to save myself a ton of stubbing code to get a passable mock object to use. Of course you can alter the mock object after you have created it to further customise it, after all it is just a mock.
The problem is I don’t how useful people will find it, given this huge push towards complete fixture replacements with FactoryGirl, model_stubbing , unit-record and the like. Its not an answer to those or even one in the herd since it still relies on fixtures.
Its really for those who like fast tests, test isolation and still use fixtures. I will be interested to see if it gets used.
I am not even going to go in depth here coz the readme does just that. So if you want to have a look then go to the source.
2 comments
