我已尽我所能,按照本网站上的文档和类似问题,没有任何快乐。我试图创建一个仪式,其中有许多邀请:工厂女孩 - 创建相关记录
ceremony.rb
class Ceremony < ApplicationRecord
has_many :invites, dependent: :destroy
end
invite.rb
class Invite < ApplicationRecord
belongs_to :ceremony
end
在我的天赋我“米试图建立与邀请典礼如下:
let(:ceremony) { FactoryGirl.create(:ceremony) }
let(:nom_1) { FactoryGirl.create(:nominee, award: award) }
let(:inv_1) { FactoryGirl.create(:invite, email: nom_1.email, ceremony: ceremony) }
let(:inv_2) { FactoryGirl.create(:invite, ceremony: ceremony) }
let(:inv_3) { FactoryGirl.create(:invite, ceremony: ceremony) }
before do
User.delete_all
end
it 'should return invites not assigned a nominee' do
binding.pry
expect(award.available_nominees).to include(inv_2, inv_3)
end
当测试命中binding.pry和我去探索,我可以看到一个新的ceremo ny已经创建,并有3个新的邀请与该仪式的ID。当我拨打电话
ceremony.invites
我收到一个空关系。当我致电
Invite.where(ceremony: ceremony.id)
我收到[inv_1,inv_2,inv_3]。当我打电话
inv_1.ceremony
我收到了仪式,但再次
ceremony.invites
返回一个空的关系。我不知道为什么邀请是用正确的仪式ID创建的,但是仪式显然没有邀请。任何帮助是极大的赞赏。
当您定义“Invite”工厂时,您是否添加了与仪式的关联? – iskvmk
我不认为我需要,因为我明确指出他们,但是我有 – Mark