Ruby on rails 3.2 让工厂里的工厂更干燥
在使用FactoryGirl为数据库视图创建工厂时,我有一个循环模式。工厂的外观示例如下:Ruby on rails 3.2 让工厂里的工厂更干燥,ruby-on-rails-3.2,factory-bot,Ruby On Rails 3.2,Factory Bot,在使用FactoryGirl为数据库视图创建工厂时,我有一个循环模式。工厂的外观示例如下: factory :site_brand do brand brand_translation country initialize_with do SiteBrand.where(brand_id: attributes[:brand].id, country_id: attributes[:country].id).first end end 这里唯一独特的是“品牌”。我
factory :site_brand do
brand
brand_translation
country
initialize_with do
SiteBrand.where(brand_id: attributes[:brand].id, country_id: attributes[:country].id).first
end
end
这里唯一独特的是“品牌”。我还有“类别”、“项目”等的其他案例。我想弄清楚我是否可以让它更干燥,而不需要给FactoryGirl打补丁。你试过使用吗?我已经看过了traits,我不确定,但我想我需要把一个参数传递给traits来让它工作,哪些traits不支持。还是我错过了什么?