We’ve gotten a lot of mileage out of the the mantra “skinny controllers, fat models”. It has resulted in huge gains in test speed and maintainability. But many ruby developers who got there via Rails don’t have a high comfort level with pure ruby classes.
I recently gave a talk on this at the monthlyKansas City Ruby meeting. The benefits include much faster tests, dryer code, and a much more organized class structure.
This was a recorded presentation, so a link to the video is coming soon.
This repository has four main branches, for each stage of development as I refactor the app with best practices.
This is the initial application that is unrefactored and more typical of a first-draft Rails app.
In this branch, I abstract the common search_address method into a module that can be mixed into any class that contains the necessary address accessors. I test drive this, and the corresponding specs are now only run once - against the library - instead of being run fully on each address-enable model.
To DRY up the order model, I abstract the shipping methods into a class hierarchy of shipping carriers. Again, this is test-driven so the test suite gets a huge benefit as well.
The test suite for shipping classes are now DRY’d up using RSpec’s shared examples.