Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions spec/factories/miq_region.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
region_remote = MiqRegion.my_region_number

factory :miq_region do
sequence(:region) { |region| region == region_remote ? region + 1 : region }
sequence(:region) do |region|
region == ApplicationRecord.region_number_from_sequence ? region + 1 : region
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worked this out with Joe, and this is effectively the same as before, but done lazily, so this should work.

end
end
end
16 changes: 12 additions & 4 deletions spec/support/factory_bot_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ def seq_padded_for_sorting(n)

require 'factory_bot'

# In case we are running as an engine, the factories are located in the dummy app
FactoryBot.definition_file_paths << 'spec/manageiq/spec/factories'
# In case we are running as an engine, the factories are located in the Rails application
FactoryBot.definition_file_paths << Rails.root.join('spec/factories')

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

FactoryBot.find_definitions
# Prefer setting the definition_file_paths and call FactoryBot.reload, which will recreate the configuration
# and call find_definitions.
#
# find_definitions is not reentrant, so a second call will lead to loading already registered factories.
# Other code, such as factory bot rails, may have already registered factories, so we can't assume
# we're the first to call find_definitions.
FactoryBot.definition_file_paths = FactoryBot.definition_file_paths.uniq

FactoryBot.reload

FactoryBot.define do
trait :other_region do
Expand Down