FactoryGirl覆盖父类属性子类

时间:2015-11-13 18:11:37

标签: ruby-on-rails cucumber capybara factory-bot

我想使用子类工厂覆盖父类。例如,我想更改子类的子域,以便它从父类重写它。

campaign.rb文件

FactoryGirl.define do
  factory :campaign do
    subdomain 'thrifty'
  end
end

photo_upload_campaign.rb文件

FactoryGirl.define do
  factory :photo_upload_campaign, parent: :campaign do
    subdomain 'weekender' 
  end
end

步骤定义文件

Given(/^there's a subdomain for a photo upload campaign campaign$/) do
  @campaign = create(:campaign)
  @photo_upload = create(:photo_upload_campaign)
  if !@campaign.subdomain.present?
    fail(ArgumentError.new('Where is the subdomain?'))
  end
end

When(/^I visit the photo upload campaign microsite subdomain url$/) do
  visit_with_subdomain microsite_home_path, subdomain: @photo_upload.subdomain
end

1 个答案:

答案 0 :(得分:0)

我可以创建一个工厂测验广告系列,它会从广告系列

中获取所有属性
FactoryGirl.define do
  factory :quiz_campaign do
    subdomain 'weekender'
  end
end