-
-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathrailtie.rb
37 lines (29 loc) · 890 Bytes
/
railtie.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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