Coding conventions

General stuff

  • avoid using return in methods. Use
       def method
         value
       end
       
    instead of
       def method
         return value
       end
       
  • when a method has arguments, always use parenthesis in its declaration
  • when writing models, please follow the following order in your declarations:
    1. relationships (has_many, belongs_to, etc) and applied behaviour (acts_as_*)
    2. virtual attributes, if needed
    3. validations
    4. business logic in general
  • thin controllers, fat models:
    • every time you write a method with more than, say, 5 lines in a controller, consider if some of its logic shouldn't go inside a model class
    • NEVER reference anything but assigned @variables inside templates (.rhtml)
  • indentation is 2 spaces

Testing

  • test every validation that you add to ActiveRecord models
  • add a test to your unit tests that passes all your fixtures through ActiveRecord validation, unless you are using an individual fixture as invalid data on purpose. Name your invalid data fixtures with "invalid_" as prefix.
  • every model must have unit tests
  • every controller must have functional tests. At least one test for each action.
  • every user story must have one or more corresponding integration tests.
  • Rcov reports must present 100% coverage of everything

-- AntonioTerceiro - 09 Jul 2007


Add comment
You need to login to be able to comment.
 

Topic revision: r6 - 07 May 2010 - 22:08:23 - AntonioTerceiro
Anhetegua.CodingConventions moved from Multypass.CodingConventions on 11 Jul 2007 - 18:48 by AntonioTerceiro
 
Copyright © 2007-2010 Noosfero
Colivre - Cooperativa de Tecnologias Livres