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
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
Checkout this answer - use Array#sample
:
FactoryGirl.define do
factory :user do
name "Foo Bar"
foo { [:a, :list, :of, :values].sample }
end
end
© 2022 - 2024 — McMap. All rights reserved.