Skip to content

Commit 2ca94e9

Browse files
committed
Use pathnames to follow factory bot rails conventions
factory bot rails converts the default factory bot directory paths to pathnames based on rails root: https://github.com/thoughtbot/factory_bot_rails/blob/dfdef4c70a76d36058cf77fc1ccd9904a2bf0beb/lib/factory_bot_rails/railtie.rb#L50-L52 * Ensure any duplicate pathnames are removed. * Clarify the rationale for using definition_path_files and reload.
1 parent 49ceb45 commit 2ca94e9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

spec/support/factory_bot_helper.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ def seq_padded_for_sorting(n)
2424

2525
# Also, add factories from provider gems until miq codebase does not use any provider specific factories anymore
2626
Rails::Engine.subclasses.select { |e| e.name.starts_with?("ManageIQ::Providers") }.each do |engine|
27-
FactoryBot.definition_file_paths << File.join(engine.root, 'spec', 'factories')
27+
FactoryBot.definition_file_paths << engine.root.join('spec', 'factories')
2828
end
2929

30-
# find_definitions is not reentrant, so call reload to reset things before it calls find_definitions.
31-
# Other code, such as factory bot rails, may have already registered factories, so we can't assume we're the first to call
32-
# find_definitions.
30+
# Prefer setting the definition_file_paths and call FactoryBot.reload, which will recreate the configuration
31+
# and call find_definitions.
32+
#
33+
# find_definitions is not reentrant, so a second call will lead to loading already registered factories.
34+
# Other code, such as factory bot rails, may have already registered factories, so we can't assume
35+
# we're the first to call find_definitions.
36+
FactoryBot.definition_file_paths = FactoryBot.definition_file_paths.uniq
37+
3338
FactoryBot.reload
3439

3540
FactoryBot.define do

0 commit comments

Comments
 (0)