Cancelling the ActiveRecord callback chain
|Cancel later callbacks||Rails 1-4||
|Cancel later callbacks||Rails 5+||
|Rollback the transaction||Rails 1-4||
|Rollback the transaction||Rails 5+||
Take care that your callbacks don't accidentally
return false, since that cancels the chain in Rails 1-4. Since in Ruby the last expression of a method becomes its return value automatically, this can happen accidentally:
before_save :callback def callback call_to_method_that_happens_to_return_false end
If uncertain, return
before_save :callback def callback call_to_method_that_happens_to_return_false true end
Exceptions raised in callbacks always rollback the transaction, but only exceptions that are not
ActiveRecord::Rollback will bubble up to the caller.
Flaky tests are tests that sometimes fail for no obvious reason. They are the plague of many end-to-end (E2E) test suites that automate the browser through tools like Capybara and Selenium.
Join our free training event and learn to fix any flaky test suite, even in large legacy applications.