18

If I have types defined in a module inside a model, and an array of these types also defined in the same model, how can I call a value from this array randomly when defining a new factory?

Thanks!

John

John
  • 12,385
  • 14
  • 49
  • 72

1 Answers1

38

Checkout this answer - use Array#sample:

FactoryGirl.define do
  factory :user do
    name "Foo Bar"
    foo { [:a, :list, :of, :values].sample }
  end
end
Community
  • 1
  • 1
tjwallace
  • 5,368
  • 1
  • 24
  • 15