22

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
  • 13,125
  • 14
  • 52
  • 73

1 Answers1

42

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,528
  • 1
  • 26
  • 15