【发布时间】:2015-07-16 20:49:51
【问题描述】:
我的模型;家庭 has_many :neighbors 和 Neighbor belongs_to :household
每个家庭必须有一个邻居:
validates :neighbors, presence: {message: 'You must enter at least one neighbor']
我正在尝试创建一个工厂
factory :household, class: "Household" do
household_name "Brooke"
neighbor
end
factory :neighbor, class: "Neighbor" do
first_name "Tom"
last_name "Brooke"
end
it "has a valid factory" do
household = create(:household, neighbors: :neighbor)
expect(household).to be_valid
end
这给了我:
undefined method `neighbor=' for #<Household:0x007fd45ec85138>
如何成立Factory Girl来体现协会?
【问题讨论】:
-
另一个任务!!!
标签: ruby-on-rails associations factory-bot