我正在尝试让FactoryGirl创建quiz_question。但它只在测试数据库环境中创建属于工厂(quiz_campaign),而不是有很多工厂(quiz_question)。
quiz_campaign.rb
FactoryGirl.define do
trait :with_quiz_questions do
after_create do |campaign|
FactoryGirl.create(:quiz_question, quiz_campaign: campaign)
end
end
end
factory :quiz_campaign do
subdomain "macy"
end
quiz_question.rb
FactoryGirl.define do
factory :quiz_question do
message "What's your question"
end
end
quiz_home_page.feature
Given(/^there's a subdomain for a quiz campaign$/) do
@quiz_campaign = create(:quiz_campaign)
end
When(/^I visit the quiz campaign microsite subdomain url$/) do
visit_with_subdomain microsite_home_path, subdomain: @quiz_campaign.subdomain
end
答案 0 :(得分:0)
不使用特征解决了这个问题。似乎使用特征会导致比所需更复杂的解决方案