Ruby on rails Ruby/Rails:AssociationTypeMitch与正确的关联不匹配,但它需要不同的对象id?什么?
所以,我这里有一个非常奇怪的错误。。。我试着隔离它,但它是准间歇性的。我有点想知道这是否与在javascript驱动程序中使用capybara有关,因为这在我的非capybara测试中没有发生。这是:Ruby on rails Ruby/Rails:AssociationTypeMitch与正确的关联不匹配,但它需要不同的对象id?什么?,ruby-on-rails,activerecord,rspec,capybara,Ruby On Rails,Activerecord,Rspec,Capybara,所以,我这里有一个非常奇怪的错误。。。我试着隔离它,但它是准间歇性的。我有点想知道这是否与在javascript驱动程序中使用capybara有关,因为这在我的非capybara测试中没有发生。这是: Failure/Error: @existing_user, household = create_new_user_and_household ActiveRecord::AssociationTypeMismatch: User(#57141560) expected, got User(#
Failure/Error: @existing_user, household = create_new_user_and_household
ActiveRecord::AssociationTypeMismatch:
User(#57141560) expected, got User(#42098260)
# ./app/models/household.rb:64:in `block in create_new_household'
# ./app/models/household.rb:62:in `new'
# ./app/models/household.rb:62:in `create_new_household'
# ./spec/support/spec_helpers.rb:55:in `create_new_user_and_household'
# ./spec/integration/accepting_an_invitation_spec.rb:21:in `block (4 levels) in <top (required)>'
非常基本,当我在rails控制台中手动操作时,效果很好
我不知道还能告诉你们什么。。。但我很乐意提供更多信息
我在所有测试中都使用了rspec
。因此,正如所指出的,答案是在test.rb
中将缓存类设置为true
这可能与spork冲突,这就是为什么我被告知首先关闭它——因为您希望spork在运行另一个测试时重新加载您的模型等等。解决方案是将cache_classes
设置为true
,但也要将ActiveSupport::Dependencies。清除spork prefork块中的
参考资料:
因此,正如所指出的,答案是在test.rb
中将cache\u类设置为true
这可能与spork冲突,这就是为什么我被告知首先关闭它——因为您希望spork在运行另一个测试时重新加载您的模型等等。解决方案是将cache_classes
设置为true
,但也要将ActiveSupport::Dependencies。清除spork prefork块中的
参考资料:
您是否为测试打开了cache_类?没有,我在test.rbah中关闭了它们,我重新打开了它们,它工作了!我在某个地方读过书,想把它们关掉。。。也许这不再适用了…?您是否为测试打开了cache_类?不,我在test.rbah中关闭了它们,我重新打开了它们,它工作了!我在某个地方读过书,想把它们关掉。。。也许这不再适用。。。?
household = Household.new attributes, do |h|
h.account = user.account || Account.create(user: user)
end