Today is a big day. I officially transitioned from manually testing by
clicking around in my app, to automated testing with RSpec + Autotest.
Yes RSpec made me find a few weaknesses in my app: while I was writing
specs for one of my models, I discovered that I had forgotten some
validations, that simply I had never tested by my super manual clicking
Also, RSpec made me discover something else: my model has some custom
find methods. Often over time I find myself changing the name of these
custom find methods, e.g: find_all_products -> find_available_products
As some of these finds are used by more than 1 controller, changing the
name of the find_ often breaks code in different places at once. This
was painful to manually test, and it is still a bit painful to have
RSpec test, as I would also have to rename the custom find method in my
Based on this recent article:
“Each controller action only calls one model method other than an
initial find or new.”.
Would this mean that I should change my custom find naming convention to
something more general that would never have to be renamed over time
such as find_for_index, find_for_create, etc?
What are your thoughts on that. Is there a “design pattern” on naming
custom find methods in Rails models? Because I tend to be seeing one.
Also, is it clever to write specs such as:
so that if I break the rule of my naming convention, one of my spec will
quickly bark at me.