使用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
这里独一无二的是“品牌”。我有“类别”,“项目”等其他情况。我想知道我是否可以让它更干,而不需要修补FactoryGirl。