我正在用minitest编写测试并尝试使用迷你裙来处理我的rails应用程序中的工厂。我在创建用户模型和其他模型之间的关联时遇到了麻烦。由于迷你裙没有工厂女孩Factory#association
如何创建关联?我正在尝试这个:
Factory.define :user do |f|
f.email "joey@ramones.com"
f.password f.password_confirmation("rockaway")
end
Factory.define :song do |f|
f.title "I Wanna Be Sedated"
f.artist "Ramones"
f.credits "Recorded on February 12-19, 1976 at Plaza Sound, Radio City Music Hall in New York City for Sire Records. All Songs by The Ramones."
f.artwork "name-of-the-file.jpg"
f.user { Factory :user }
end
但是以下测试仍然以Validation failed: User can't be blank
:
require "test_helper"
describe Song do
it "has a valid factory" do
Factory.create :song
end
end