What we should test - agentbright/rails-guide GitHub Wiki

Fixtures

  • Create fixtures
  • Keep fixtures up-to-date with models

Model tests

Process:

  1. Setup the data we need
  2. Trigger the item being tested
  3. Assert what we expect

What to test:

  • Validations
  • Collections
  • Public methods

Controller tests

Process:

  1. Setup the application to respond to a request
  2. Fake a request to an action
  3. Make assertions on instance variables, cookies, the session, and the flash
  4. Assert that the application changed or didn't change as expected
  5. Assert that the response is what we expect

What to test:

  • get index
  • :filter
  • get new
  • get show
  • get edit
  • post create
  • put update
  • delete destroy

Mailers

What to test:

  • The mail options (to, from, subject, etc) are set properly
  • The mail body matches keywords or even an entire fixture
  • The mail template renders without errors