我有以下型號:我得到驗證錯誤「活動不能爲空」活動工廠:factory_girl的has_many:通過與驗證
class Activity < ActiveRecord::Base
has_many :clientships, :dependent => :destroy
has_many :clients, :through => :clientships
end
class Clientship < ActiveRecord::Base
belongs_to :client
belongs_to :activity
validates_presence_of :client_id
validates_presence_of :activity_id, :unless => :new_record?
end
class Client < ActiveRecord::Base
has_many :clientships
has_many :activities, :through => :clientships
end
我不能創建一個。
我的工廠是這樣的:
Factory.define :activity do |a|
a.association :staff, :factory => :user
a.clientships { |cs| [cs.association :clientship] }
end
Factory.define :clientship do |cs|
cs.association(:client)
end
Factory.define :client do |c|
c.first_name {Factory.next(:name)}
c.last_name {Factory.next(:name)}
end
我得到的錯誤,當我在我的規格運行這個廠: @activity = Factory(:activity)
請幫助!
「客戶」?我會選擇「ClientActivity」......聽起來更自然。 – 2010-09-24 07:11:09