Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 创建后引用关联的工厂_Ruby On Rails_Ruby_Unit Testing_Factory Bot_Minitest - Fatal编程技术网

Ruby on rails 创建后引用关联的工厂

Ruby on rails 创建后引用关联的工厂,ruby-on-rails,ruby,unit-testing,factory-bot,minitest,Ruby On Rails,Ruby,Unit Testing,Factory Bot,Minitest,我有一个与产品有关系的客户工厂。添加创建后回调时,它指的是产品,而不是帐户 会计工厂 产品厂 测试 错误 NoMethodError:未定义的方法“创建api凭据”# 创建api凭据存在于帐户而非产品上您是否尝试移动: after:create,&:create_api_凭证到:账户块 factory :account do billing_method { 'monthly' } workflow_state { 'active' } after :create, &:

我有一个与产品有关系的客户工厂。添加创建后回调时,它指的是产品,而不是帐户

会计工厂 产品厂 测试 错误
NoMethodError:未定义的方法“创建api凭据”#
创建api凭据存在于帐户而非产品上

您是否尝试移动:
after:create,&:create_api_凭证
:账户

factory :account do
  billing_method { 'monthly' }
  workflow_state { 'active' }

  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>
factory :account do
  billing_method { 'monthly' }
  workflow_state { 'active' }

  after :create, &:create_api_credential
end