Ruby on rails 重复类问题:AssociationTypeMismatch

Ruby on rails 重复类问题:AssociationTypeMismatch,ruby-on-rails,ruby-on-rails-3,cucumber,Ruby On Rails,Ruby On Rails 3,Cucumber,当模型回调方法中存在对self的引用时,Cucumber有一个问题 下面的代码示例。 错误如下: Person(#26738680)应为,Get Person(#29003170)(ActiveRecord::AssociationTypeMismatch) 以及失败的步骤: Before do include Authlogic::TestCase activate_authlogic end def valid_person @current_person = Factor

当模型回调方法中存在对self的引用时,Cucumber有一个问题

下面的代码示例。 错误如下: Person(#26738680)应为,Get Person(#29003170)(ActiveRecord::AssociationTypeMismatch)

以及失败的步骤:

Before do
  include Authlogic::TestCase
  activate_authlogic
end

def valid_person
    @current_person = Factory.create(:valid_person, :person_profile => new_person_profile('Kelly','Hope'))
end  

Given /^I am a valid Student$/ do
  valid_student
end
多谢各位
Adam

这并不能直接回答您的问题,但我建议不需要创建后回调。您已经在
Person
模型中为
定义了
接受\u嵌套的\u属性\u——如果目标是在一个步骤中创建
Person
和关联的
PersonProfile
,您应该能够做到(例如):


请向我们展示你失败的情景。
  Scenario: Student logs in for the first time
    Given I am a valid Student
Before do
  include Authlogic::TestCase
  activate_authlogic
end

def valid_person
    @current_person = Factory.create(:valid_person, :person_profile => new_person_profile('Kelly','Hope'))
end  

Given /^I am a valid Student$/ do
  valid_student
end
params = { :person => { :name => "John Smith",  
 :person_profile_attributes => { :some_profile_attribute => "some_value" }}}
@person = Person.create!(params[:person])