Kees Briggs
Kees Briggs

Reputation: 381

FactoryBot: how to use transient in skip_create factory to specify properties in an internal factory?

I have the following factory, which has _skip_create_ inside, and also calls another factory upon create, upon which I am trying to specify a specific UUID. Example:

FactoryBot.define do
  factory :experiment do

    transient { order nil }

    env_array = %w[prod dev test]
    uuid { SecureRandom.uuid }
    name { 'some name' }

    skip_create
    initialize_with do
      env_array.each_with_index do |env, idx|
        FactoryBot.create(:environment, uuid: 'b5c096d5-479a-4693-ac14-9cea7dfd045c') if order.eql? 'first'
      end
    end
  end
end

The problem is, I cannot get order to be actionable. I get:

ArgumentError: Trait not registered: order

How can I get order to be specifiable when I call the factory?

Upvotes: 0

Views: 1052

Answers (1)

It is because you missed the curly braces {}

FactoryBot.define do
  factory :experiment do
    transient do
      order { nil }
    end
   ....
  end
end

Upvotes: 1

Related Questions