Fix instantiating observers on app boot. #65
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When adding support for Rails 4.1, 4.2 and 5.0, the
instantiate_observers
call that happened after boot was erroneously removed.
https://github.com/rails/rails-observers/pull/39/files#diff-9db46e46113d0c2eeb41f5d6f08bcac4L24
This covered a regression in the test suite for the rake integration and
also broke the gem for apps.
The reason the test/rake_test.rb failed was that a require to
active_record/base
had been removed which rails-observers depended on.
rails/rails@9e9793b
Without that we're this circular dependency error:
That's because User loads ActiveRecord::Base which then instantiates
the observers in its on_load hook, finally calling observed_class
which constantizes the very User constant we're loading!
One fix is to add a require to active_record/base manually here, because
we depend on the load hooks having been fired before model constants are
loaded.
(I didn't look into reorganizing the code such that observed_class isn't
needed on observer instantiation.)
This has the added benefit of not breaking the gem should Rails remove
the require's in
console
orrunner
blocks as well.I can reliably reproduce the above circular dependency error by commenting
out the added
require "active_record/base"
. And when it's in the raketask works: