FactoryGirl for Deep Nested_form?

时间:2014-07-02 10:30:46

标签: ruby-on-rails ruby rspec factory-bot rspec-rails

我跟着NestedForm  实现了使用4.1.0和ruby2.1.2使用Rspec3.0基本功能。

我使用之后(创建)回调创建工厂(有很多关系)调查问题

after(:create) do |survey|
  survey.questions << FactoryGirl.build(:question, :survey => survey)
end

但现在我想用调查创建工厂,问题答案。这该怎么做 ?帮助我...

有关系的模型

class Survey < ActiveRecord::Base
  has_many :questions, :dependent => :destroy, inverse_of: :survey
  accepts_nested_attributes_for :questions, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true
end

class Question < ActiveRecord::Base
  belongs_to :survey, inverse_of: :questions
  has_many :answers, :dependent => :destroy, inverse_of: :questions
  accepts_nested_attributes_for :answers, :reject_if => lambda { |a| a[:answers].blank? }, :allow_destroy => true,:limit => 2,:update_only => true
end

class Answer < ActiveRecord::Base
  belongs_to :question,inverse_of: :questions
end

0 个答案:

没有答案