我有以下型号:
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
我无法创建 :activity 工厂,因为我收到验证错误“活动不能为空白”。
我的工厂是这样的:
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)
请帮忙!