1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00

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
This commit is contained in:
Jacob Frautschi 2019-03-27 10:47:05 -07:00 committed by Daniel Colson
parent 0b24977c34
commit dcfc9f6662
3 changed files with 5 additions and 9 deletions

View file

@ -22,10 +22,6 @@ module FactoryBotRails
Reloader.new(app, config).run Reloader.new(app, config).run
end end
config.after_initialize do
FactoryBot.find_definitions
end
private private
def definition_file_paths def definition_file_paths

View file

@ -31,7 +31,7 @@ module FactoryBotRails
def register_reloader(reloader) def register_reloader(reloader)
config.to_prepare do config.to_prepare do
reloader.execute_if_updated reloader.execute
end end
app.reloaders << reloader app.reloaders << reloader

View file

@ -9,7 +9,7 @@ describe FactoryBotRails::Railtie do
touch("factories.rb") touch("factories.rb")
reload_rails! reload_rails!
expect(FactoryBot).to have_received(:reload) expect(FactoryBot).to have_received(:reload).at_least(1).times
end end
end end
@ -20,17 +20,17 @@ describe FactoryBotRails::Railtie do
touch("factories/definitions.rb") touch("factories/definitions.rb")
reload_rails! reload_rails!
expect(FactoryBot).to have_received(:reload) expect(FactoryBot).to have_received(:reload).at_least(1).times
end end
end end
context "when the factory definitions have NOT been updated" do 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) allow(FactoryBot).to receive(:reload)
reload_rails! reload_rails!
expect(FactoryBot).not_to have_received(:reload) expect(FactoryBot).to have_received(:reload).at_least(1).times
end end
end end