-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid loading ActiveRecord::Base early #91
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Doing this cause a slew of problems with Rails loading process, causing some configurations not to be applied, etc. Fix: DatabaseCleaner#89 Fix: DatabaseCleaner#90
I confirm that is a good proposal that fix some issue on other gem. |
benoittgt
added a commit
to benoittgt/factory_bot_rails
that referenced
this pull request
Nov 23, 2023
It happens if the AR::Base as already been loaded. For example: DatabaseCleaner/database_cleaner-active_record#91
benoittgt
added a commit
to benoittgt/factory_bot_rails
that referenced
this pull request
Nov 23, 2023
It happens if the AR::Base as already been loaded. For example: DatabaseCleaner/database_cleaner-active_record#91
etagwerker
approved these changes
Nov 23, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@casperisfine Thanks for submitting this patch!
Just waiting for CI to finish before I merge.
neilvcarvalho
pushed a commit
to thoughtbot/factory_bot_rails
that referenced
this pull request
Nov 23, 2023
* CI against Rails 7.1 * Ignore the directory that keeps factory files under the `lib` Some tests put factory files under the `lib`. But since Rails 7.1, Rails loads `lib` directory by default in a new application. https://guides.rubyonrails.org/7_1_release_notes.html#introducing-config-autoload-lib-and-config-autoload-lib-once-for-enhanced-autoloading But factory files don't follow the naming rule of Zeitwerk. So Zeitwerk raises `Zeitwerk::NameError`. To avoid the error, this changed to ignore the directory that puts factory files. * Remove the route that is defined by default Some test code loads the route file twice. This wasn't a problem before Rails 7.0 because we didn't have a route. But, Rails 7.1 has one route by default. So the test application raises the following error during the load. ``` Invalid route name, already in use: 'rails_health_check' (ArgumentError) You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: https://guides.rubyonrails.org/routing.html#restricting-the-routes-created ``` The routing isn't a matter of this gem, so just ignore that for running the test. * Prevent warning about deprecated cache_format_version * Wrap ActiveRecord configuration into initializer `Rails.application` is not available when the railties are collected, so we move the ActiveRecord configuration into the initializer phase. ``` NoMethodError: undefined method `config' for nil:NilClass (NoMethodError) application.config ^^^^^^^ /project/app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.8/lib/rails.rb:47:in `configuration' /project/app/vendor/bundle/ruby/3.2.0/gems/factory_bot_rails-6.4.0/lib/factory_bot_rails/railtie.rb:25:in `block in <class:Railtie>' ``` * Provide non regression feature test when ActiveRecord::Base is loaded It happens if the AR::Base as already been loaded. For example: DatabaseCleaner/database_cleaner-active_record#91 --------- Co-authored-by: Yuji Yaginuma <yuuji.yaginuma@gmail.com> Co-authored-by: Leo Arnold <github@leoarnold.de>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Doing this cause a slew of problems with Rails loading process, causing some configurations not to be applied, etc.
Fix: #89
Fix: #90