2018-07-16 18:31:25 -04:00
|
|
|
# frozen_string_literal: true
|
2016-12-02 10:25:09 -05:00
|
|
|
|
2018-07-16 18:31:25 -04:00
|
|
|
require "factory_bot"
|
|
|
|
require "factory_bot_rails/generator"
|
|
|
|
require "factory_bot_rails/reloader"
|
|
|
|
require "rails"
|
|
|
|
|
|
|
|
module FactoryBotRails
|
2016-12-02 10:25:09 -05:00
|
|
|
class Railtie < Rails::Railtie
|
2018-09-09 21:44:34 -04:00
|
|
|
config.factory_bot = ActiveSupport::OrderedOptions.new
|
|
|
|
config.factory_bot.definition_file_paths = FactoryBot.definition_file_paths
|
2016-12-02 10:25:09 -05:00
|
|
|
|
|
|
|
initializer "factory_bot.set_fixture_replacement" do
|
2018-07-16 18:31:25 -04:00
|
|
|
Generator.new(config).run
|
2016-12-02 10:25:09 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
initializer "factory_bot.set_factory_paths" do
|
2018-09-09 21:44:34 -04:00
|
|
|
FactoryBot.definition_file_paths = definition_file_paths
|
2016-12-02 10:25:09 -05:00
|
|
|
end
|
|
|
|
|
2018-07-16 18:31:25 -04:00
|
|
|
initializer "factory_bot.register_reloader" do |app|
|
|
|
|
Reloader.new(app, config).run
|
|
|
|
end
|
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
config.after_initialize do
|
|
|
|
FactoryBot.find_definitions
|
|
|
|
end
|
2018-09-09 21:44:34 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def definition_file_paths
|
|
|
|
config.factory_bot.definition_file_paths.map do |path|
|
|
|
|
Rails.root.join(path)
|
|
|
|
end
|
|
|
|
end
|
2016-12-02 10:25:09 -05:00
|
|
|
end
|
|
|
|
end
|