mirror of
https://github.com/thoughtbot/factory_bot_rails.git
synced 2022-11-09 11:49:18 -05:00
c1d0a7887b
We removed the call to `FactoryBot.load_definitions` in the `after_initialize` hook indcfc9f6
because the other changes in that commit were causing us to sometimes call `FactoryBot.load_definitions` after `FactoryBot.reload`. We could have changed `FactoryBot.load_definitions` to `FactoryBot.reload`, which is what this PR does, but it didn't seem necessary at the time since all the tests were still passing. We fixed a problem in9b83f48
that was causing us to watch the root directory of the project. This fix caused a test failure, but I ended up changing the test in2b7bca0
because it seemed like an unlikely scenario. This PR adds back the original test case. Although I do think it unlikely, I would rather not risk making a breaking change in the next patch release.
37 lines
890 B
Ruby
37 lines
890 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "factory_bot"
|
|
require "factory_bot_rails/generator"
|
|
require "factory_bot_rails/reloader"
|
|
require "rails"
|
|
|
|
module FactoryBotRails
|
|
class Railtie < Rails::Railtie
|
|
config.factory_bot = ActiveSupport::OrderedOptions.new
|
|
config.factory_bot.definition_file_paths = FactoryBot.definition_file_paths
|
|
|
|
initializer "factory_bot.set_fixture_replacement" do
|
|
Generator.new(config).run
|
|
end
|
|
|
|
initializer "factory_bot.set_factory_paths" do
|
|
FactoryBot.definition_file_paths = definition_file_paths
|
|
end
|
|
|
|
initializer "factory_bot.register_reloader" do |app|
|
|
Reloader.new(app, config).run
|
|
end
|
|
|
|
config.after_initialize do
|
|
FactoryBot.reload
|
|
end
|
|
|
|
private
|
|
|
|
def definition_file_paths
|
|
config.factory_bot.definition_file_paths.map do |path|
|
|
Rails.root.join(path)
|
|
end
|
|
end
|
|
end
|
|
end
|