我正在使用rspec和工厂女孩,并且从工厂获得子类有一个奇怪的问题。我正在创建一个设计器,它是用户的子猫,但是测试仍在接收用户,而不是设计师。
FactoryGirl.define do
factory :user do
factory :designer do
role: "designer"
end
end
end
describe StoreRating do
it "should have a rating" do
user = FactoryGirl.create(:designer)
store = FactoryGirl.create(:store)
StoreRating.create(designer: user, store: store, rating: 5)
end
end
答案 0 :(得分:0)
尝试:
FactoryGirl.define do
factory :user do
factory :designer, class: Designer do
role: "designer"
end
end
end