如何在迷你裙工厂创建协会?

时间:2012-09-29 18:35:11

标签: ruby-on-rails factory-bot minitest factories miniskirt

我正在用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

0 个答案:

没有答案