From dcfc9f666239be71a56f0ba4f1ad003d3c8550bf Mon Sep 17 00:00:00 2001 From: Jacob Frautschi Date: Wed, 27 Mar 2019 10:47:05 -0700 Subject: [PATCH] Always execute a reload when Rails triggers one (instead of just on update) to prevent doubly-defined constants errors in factories when using Spring - https://github.com/thoughtbot/factory_bot_rails/issues/323 --- lib/factory_bot_rails/railtie.rb | 4 ---- lib/factory_bot_rails/reloader.rb | 2 +- spec/factory_bot_rails/railtie_spec.rb | 8 ++++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/factory_bot_rails/railtie.rb b/lib/factory_bot_rails/railtie.rb index 6ccfcc2..1f948d1 100644 --- a/lib/factory_bot_rails/railtie.rb +++ b/lib/factory_bot_rails/railtie.rb @@ -22,10 +22,6 @@ module FactoryBotRails Reloader.new(app, config).run end - config.after_initialize do - FactoryBot.find_definitions - end - private def definition_file_paths diff --git a/lib/factory_bot_rails/reloader.rb b/lib/factory_bot_rails/reloader.rb index 329ac26..e3e3d95 100644 --- a/lib/factory_bot_rails/reloader.rb +++ b/lib/factory_bot_rails/reloader.rb @@ -31,7 +31,7 @@ module FactoryBotRails def register_reloader(reloader) config.to_prepare do - reloader.execute_if_updated + reloader.execute end app.reloaders << reloader diff --git a/spec/factory_bot_rails/railtie_spec.rb b/spec/factory_bot_rails/railtie_spec.rb index b03e680..88d8773 100644 --- a/spec/factory_bot_rails/railtie_spec.rb +++ b/spec/factory_bot_rails/railtie_spec.rb @@ -9,7 +9,7 @@ describe FactoryBotRails::Railtie do touch("factories.rb") reload_rails! - expect(FactoryBot).to have_received(:reload) + expect(FactoryBot).to have_received(:reload).at_least(1).times end end @@ -20,17 +20,17 @@ describe FactoryBotRails::Railtie do 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