Skip to content
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

Always execute a reload when Rails triggers one (instead of just on u… #329

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/factory_bot_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class Railtie < Rails::Railtie
Reloader.new(app, config).run
end

config.after_initialize do
FactoryBot.find_definitions
end

private

def definition_file_paths
Expand Down
2 changes: 1 addition & 1 deletion lib/factory_bot_rails/reloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def reloader_class

def register_reloader(reloader)
config.to_prepare do
reloader.execute_if_updated
reloader.execute
end

app.reloaders << reloader
Expand Down
8 changes: 4 additions & 4 deletions spec/factory_bot_rails/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
touch("factories.rb")
reload_rails!

expect(FactoryBot).to have_received(:reload)
expect(FactoryBot).to have_received(:reload).at_least(1).times
end
end

Expand All @@ -20,17 +20,17 @@
touch("factories/definitions.rb")
reload_rails!

expect(FactoryBot).to have_received(:reload)
expect(FactoryBot).to have_received(:reload).at_least(1).times
end
end

context "when the factory definitions have NOT been updated" do
it "does NOT reload the factory definitions" do
it "reloads the factory definitions" do
allow(FactoryBot).to receive(:reload)

reload_rails!

expect(FactoryBot).not_to have_received(:reload)
expect(FactoryBot).to have_received(:reload).at_least(1).times
end
end

Expand Down