简体   繁体   English

尽管存在关系,但Rspec +应该在accept_nested_attributes_for上进行测试失败

[英]Rspec + shoulda test fails on accept_nested_attributes_for despite relationship

I'm writing a model test for my Applications model, which accepts_nested_attributes_for(:user) . 我正在为我的Applications模型编写模型测试,该模型接受accepts_nested_attributes_for(:user) Here's the test that's failing: 这是失败的测试:

describe UserApplication, "associations" do
  it { should belong_to(:user) }
  it { should accept_nested_attributes_for(:user) }
end

And here's the model: 这是模型:

class UserApplication < ActiveRecord::Base
   #attr_accessible all the fields

   belongs_to :user
   accepts_nested_attributes_for :user
end

I'm using rspec with shoulda-matchers 2.8, and from my research this should all work fine. 我正在将rspec与shoulda-matchers 2.8一起使用,并且从我的研究中来看,这一切都可以正常工作。 No spring or any other weirdness, either. 也没有春天或任何其他怪异。 Here's the error I'm seeing: 这是我看到的错误:

1) UserApplication association 
 Failure/Error: it { should accept_nested_attributes_for(:user) }
 NoMethodError:
   undefined method `accept_nested_attributes_for' for #<RSpec::Core::ExampleGroup::Nested_2:0x007fec5c641a40>
 # ./spec/models/user_application_spec.rb:25:in `block (2 levels) in <top (required)>'

I'm not sure what could be causing this. 我不确定是什么原因造成的。 Could this be some weird gem conflict shenanigans or am I missing something obvious? 这可能是一些怪异的宝石冲突恶作剧,还是我缺少明显的东西?

Okay, so I have to give credit to @PeterAlfvin for giving me the tools to see what was wrong. 好的,所以我必须感谢@PeterAlfvin给我的工具,以查看发生了什么问题。 My gemfile specified gem 'shoulda-matchers' but that was only loading up version 1.0, which didn't have support for accepts_nested_attributes_for . 我的gemfile指定了gem'shoulda gem 'shoulda-matchers' matchers gem 'shoulda-matchers'但它仅加载1.0版,该版本不支持accepts_nested_attributes_for His suggestion, via https://stackoverflow.com/a/2954632/1008891 pointed me in the right direction. 他通过https://stackoverflow.com/a/2954632/1008891提出的建议为我指明了正确的方向。 Specifying 2.8.0 fixed the problem without immediately breaking anything. 指定2.8.0可解决问题,而无需立即中断任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 多对多关系中的accept_nested_attributes_for - accept_nested_attributes_for in a many-to-many relationship 使用accept_nested_attributes_for进行验证 - Validations with accept_nested_attributes_for Mongomapper父模型验证失败,并带有accept_nested_attributes_for - Mongomapper parent model validation fails with accept_nested_attributes_for accept_nested_attributes_for:allow_destroy,:_ destroy无效 - accept_nested_attributes_for :allow_destroy, :_destroy not working Rails 2.3.5和Ruby 1.9.1中的accept_nested_attributes_for - accept_nested_attributes_for in Rails 2.3.5 and Ruby 1.9.1 accept_nested_attributes_for在Rails上创建一个额外的nil记录 - accept_nested_attributes_for creates one extra nil record on Rails attr_accessor在accept_nested_attributes_for中无法访问 - attr_accessor not accessible in accept_nested_attributes_for Rails属于具有accept_nested_attributes_for的多个模型 - Rails belongs_to multiple models with accept_nested_attributes_for has_one,reject_if和accept_nested_attributes_for仍会触发验证 - has_one, reject_if, and accept_nested_attributes_for still triggers validation accept_nested_attributes_for + reject_if +未保存的子对象的显示错误 - accept_nested_attributes_for + reject_if + display error for unsaved child objects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM