How to user factory girl to create associated lists with a has_many with a validation that requires it on create

后端 未结 3 1546
无人及你
无人及你 2021-02-01 20:45

In a Rails application, given three models User, Article and Reviewer with the following relationships and validations:

class User < ActiveRecord::Base
  has_         


        
3条回答
  •  北海茫月
    2021-02-01 21:40

    The new syntax is:

    before(:create) do |article|
      article.reviewers << FactoryGirl.build(:reviewer, article: article)
    end
    

提交回复
热议问题