1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00
thoughtbot--factory_bot_rails/lib/factory_bot_rails/railtie.rb
Daniel Colson 4e730548cb Introduce definition file path configuration
Fixes #165 and closes #166

Currently the only way to customize the factory definition file
paths is to do it in an initializer right after the
"factory_bot.set_factory_paths" initializer. With this commit,
we can customize factory definition file paths by
setting `config.factory_bot.definition_file_paths`
in config/application.rb or the appropriate environment file.

Once we update the documentation to include this new configuration, we
should be able to close #149 and #180 as well, since using this
configuration can replace the initializer solution for sharing factories
in an engine (the initializer solution will still work, but with the new
configuration you don't need to know anything about the
fbr railtie).

This will also allow us to close #192, since we can use this
configuration with an empty array to disable automatic loading
of factories in development.
2018-09-14 20:09:10 +00:00

37 lines
900 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.find_definitions
end
private
def definition_file_paths
config.factory_bot.definition_file_paths.map do |path|
Rails.root.join(path)
end
end
end
end