6407: Route: Change `#calculate_costs!` to `after_commit` callback
Created by: teddywing
Use an after_commit instead of an after_save. The after_save could
cause intermittent problems due to Sidekiq starting before the
record/transaction actually gets committed to the database. In those
cases, the record wouldn't be found and cause an error.
With an after_commit callback, the record is sure to be committed
before Sidekiq takes over.
Additionally, limit the callback to :create and :update because
otherwise it will be active on :destroy by default also. This work
isn't relevant on destroy, so don't do it then.
Update the tests:
- Update labels
- Use
buildinstead ofcreatebecause we're saving the record at the end anyway so we don't need an object that starts out persisted - Use
truncation: truefor these tests because otherwise thecommitcallback doesn't get called due to transactional teardown
Refs #6407