我有这个模型
FactoryGirl.define do
factory :upload, class: Upload do
before :create do |upload|
create(:user_2)
end
end
end
用户工厂:
FactoryGirl.define do
factory :user do
first_name "John"
password "1234567890"
factory :user_2 do
initialize_with {
User.where(id: 2).first_or_create(
id: 2,
first_name: "John",
password: "1234567890",
)
}
end
end
end
这就是错误:
/home/developer/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/factory_girl-4.4.0/lib/factory_girl.rb:73:in `lint': The following factories are invalid: (FactoryGirl::InvalidFactoryError) *upload
我不知道这个错误发生了什么
(更新) 我解决了它,我在需要时直接创建了Upload对象:
@upload = Upload.create(fund_source: @fund_source, user: build(:user), status: 'uploaded',
file: fixture_file_upload('files/HennesseeHedgeFundIndices_UnitTest.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))