Determine NamespacedClassFinder#finder method after rails config #1336
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.
Hi there!
You're making a great gem, thank you very much.
I've found a bug while profiling a thing in our app.
Formtastic has two modes of finding classes, one is fast and another fetches new files in development. It works in dev mode all the time because
use_const_defined?
is called whenRails.application
is still nil.As a result, finding input classes sometimes takes half of the time Formtastic works.
This PR fixes this by determining the finder method on the first calling, which likely happens after the app initialization.
Bonus: spec for the class tested changed
cache_classes
config value, which, I suppose, was used beforeeager_load
.Testing
I don't know how to make a spec for the case, but here is how I do it manually:
config.eager_load = !!ENV["EAGER_LOAD"] # config/environments/development.rb
EAGER_LOAD=true rails c
For this PR:
Workaround
Just in case the fix won't get to master or will be released only for v4. I've added a workaround to reach the same effect