Joh*_*ohn 14 ruby-on-rails factory-bot
如果我在模型中的模块中定义了类型,并且在同一模型中也定义了这些类型的数组,那么在定义新工厂时如何随机调用此数组中的值?
谢谢!
约翰
tjw*_*ace 34
查看此答案 - 使用Array#sample:
FactoryGirl.define do
factory :user do
name "Foo Bar"
foo { [:a, :list, :of, :values].sample }
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3122 次 |
| 最近记录: |