我有以下模式:
class SecondaryIabCategory < ApplicationRecord
has_many :sites, foreign_key: :secondary_category_id
belongs_to :primary_iab_category
end以下是有问题的工厂的评论:
factory :primary_category, class: PrimaryIabCategory do
name 'Arts & Entertainment - yaddah'
value 'IAB1-some'
end
factory :another_primary_category, class: PrimaryIabCategory do
name 'Games are cool! - dabbah'
value 'IAB1-other'
end
factory :secondary_category, class: SecondaryIabCategory do
# here is the problem - what's the correct syntax?
primary_iab_category another_primary_category
name 'Test Secondary Cat'
value 'xxyy'
end我得到了错误信息:
NoMethodError: undefined method `another_primary_category=' for #<SecondaryIabCategory:0x00007f925c64e0d8>我已经有几个月没有使用FactoryBot/Girl了,所以我不确定它的语法是什么。有什么想法吗?
发布于 2018-07-11 23:27:10
尝尝这个
factory :secondary_category, class: SecondaryIabCategory do
association :primary_iab_category, factory: :another_primary_category
name 'Test Secondary Cat'
value 'xxyy'
end鲁比多是非常详细的
https://stackoverflow.com/questions/51295286
复制相似问题