- If the return value of a method in your tests is totally different from what you see in the source code, chances are 100:1 that you (or your colleague) stubbed it out before the test run
- You can’t set the sequence of validations in ActiveRecord. You just can’t. Don’t add validations that depend on each other, e.g. ensuring the presence of X in one validation and in another that X > Y.
- Be carefull where you use symbols. Something like
belongs_to :preferred_city, :class_name => City, :foreign_key => :city_id
will throw something like
NoMethodError: undefined method `match’ for #
because you must use strings here a la:
belongs_to :preferred_city, :class_name => 'City', :foreign_key => 'city_id'
- If you have trouble saving a model via web interface for no obvious reason double check the log, there’s a good chance that you forgot to use attr_accessble
- Similar to above: If you use nested forms e.g. User has_one profile and your editing user and profile in one form don’t forget
attr_accessible :profile_attributes
in your user model
- When manually constructing links like:
def my_url "/offer/#{city.to_param}" enddon’t forget the leading slash unless you really want a relative path.
- Formtastic is great, but I always forget that it’s
form.input :field, :input_html => ...
and not
form.input :field, :html => ...
and it’s
form.button :commit, :button_html => ...
and not
form.button :commit, :html => ...
- I constantly forget to interpolate strings in regexes, so given
pattern = 'oh no'
I find myself writing
if input =~ /pattern/
instead of
if input =~ /#{pattern}/ - When you pass numeric values to cucumber steps make sure to call to_i, to_f or whatever is appropriate because cucumber passes everything as a string (yes, an easy one, but I forget it every now and then)
-
Recent Posts
Recent Comments
Archives
Categories
Meta