Reputation: 26061
I have a factory for an account that has a relationship with a product. When adding an after create callback it is referring to the product and not the account.
FactoryBot.define do
factory :account do
billing_method { 'monthly' }
workflow_state { 'active' }
end
after :create, &:create_api_credential
end
FactoryBot.define do
factory :product do
...
account
end
end
subject { create(:product) }
it 'has an account' do
subject
assert_not_nil(subject.account)
end
NoMethodError: undefined method `create_api_credential' for #<Product:0x00007fab7cefe2f8>
create_api_credential exist on account not product
Upvotes: 0
Views: 136
Reputation: 2086
Did you try to move:
after :create, &:create_api_credential
to :account
block?
factory :account do
billing_method { 'monthly' }
workflow_state { 'active' }
after :create, &:create_api_credential
end
Upvotes: 1