Only reload if cache_classes is disabled, reload_classes_only_on_change enabled#418
Closed
stanhu wants to merge 0 commit intothoughtbot:mainfrom
Closed
Only reload if cache_classes is disabled, reload_classes_only_on_change enabled#418stanhu wants to merge 0 commit intothoughtbot:mainfrom
stanhu wants to merge 0 commit intothoughtbot:mainfrom
Conversation
mathieujobin
reviewed
Aug 9, 2023
Contributor
mathieujobin
left a comment
There was a problem hiding this comment.
interesting, I wonder if this isn't the fix I need for failing to load factories with Rails 7.1
Contributor
|
The test suite passes without this patch on Rails 7.1.0-beta2. If this does fix an issue you're seeing on Rails 7.1, @mathieujobin , I'm interested in hearing more about that so we can write a test to catch it. @stanhu this patch needs a test. I can try to write one later, but maybe you can help write one first. Here's my sketch but I think it needs more finesse: context "when cache_classes is true and reload_classes_only_on_change is true" do
it "does not reload factory definitions" do
Rails.application.config.cache_classes = true
Rails.application.config.reload_classes_only_on_change = true
allow(FactoryBot).to receive(:reload)
reload_rails!
expect(FactoryBot).not_to have_received(:reload)
end
end
context "when cache_classes is true and reload_classes_only_on_change is false" do
it "does not reload factory definitions" do
Rails.application.config.cache_classes = true
Rails.application.config.reload_classes_only_on_change = false
allow(FactoryBot).to receive(:reload)
reload_rails!
expect(FactoryBot).not_to have_received(:reload)
end
end
context "when cache_classes is false and reload_classes_only_on_change is true" do
it "reloads the factory definitions" do
Rails.application.config.cache_classes = false
Rails.application.config.reload_classes_only_on_change = true
allow(FactoryBot).to receive(:reload)
reload_rails!
expect(FactoryBot).to have_received(:reload).at_least(1).times
end
end
context "when cache_classes is false and reload_classes_only_on_change is false" do
it "does not reload factory definitions" do
Rails.application.config.cache_classes = false
Rails.application.config.reload_classes_only_on_change = false
allow(FactoryBot).to receive(:reload)
reload_rails!
expect(FactoryBot).not_to have_received(:reload)
end
end |
Author
|
Reopening as #533. The suggested tests above don't pass because |
This file contains hidden or 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
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.
https://guides.rubyonrails.org/configuring.html#config-reload-classes-only-on-change states:
It was surprising to us that even though
cache_classeswere set to true that factory_bot_rails still instantiated file watchers.