steel
steel

Reputation: 12540

Factory Girl: Specify Trait for Parent

I would like a factory to inherit from another factory with a specific trait. How can I specify a parent factory with a specific trait as the parent? I'm looking for something along the lines of how you can declare an association with a specific trait, like this:

  factory :mom do
    trait :smart do
    end
  end

  factory :kiddo, parent: [:mom, :smart] do
    ... #does not work
  end

Upvotes: 1

Views: 833

Answers (1)

Collin Graves
Collin Graves

Reputation: 2267

If I'm not mistaken, this should work:

factory :mom do
    trait :smart do
    end
  end

factory :kiddo, parent: :mom, traits: [:smart] do
end

Upvotes: 2

Related Questions