O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Really Common Rails Gotchas

The following patterns in Rails lead to relatively silent test failure. I stumble over them all the time.

  • ActiveRecord models not saving when I expect them to. The most common cause is that the creation of the object fails a validation. Often this causes a test failure down the line because a record that was supposed to be found in the database isn’t there—because it didn’t save. Using a factory tool helps with this, as does using save! and create! in test setup to have the failure happen at the point of the code problem and not further down the line.

  • In versions of Rails that use attr_accessible, Rails silently ignores inaccessible parameters in mass assignment. Rails 4 will still ignore parameters not specified ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required