在 Rspec 和 Rails 2.3.x 中使用质量分配 Shoulda 匹配器
Rspec 的 Shoulda-matchers 不支持 ActiveRecord 类的allow_mass_assignment_of。
作为一种解决方法,您是否认为以下代码是等效的?
it { should_not allow_mass_assignment_of :id }
it { MyClass.protected_attributes.include?("id").should be_true }
Shoulda-matchers for Rspec do not support allow_mass_assignment_of for ActiveRecord classes.
As a workaround, would you regard the following code as equivalent?
it { should_not allow_mass_assignment_of :id }
it { MyClass.protected_attributes.include?("id").should be_true }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据源代码,两者是等效的,但第一行应该可以正常工作。
您可以在 https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb
According to the source code, both are equivalent, but the first line should work correctly.
You can check it on https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb
我也遇到这个问题。以下测试:
失败并显示错误消息,
而以下测试成功(从而确定 Shoulda 存在):
shoulda-matchers 版本 1.0.0,rspec(和所有相关 gems)版本 2.8.0
看起来不是这样,但这是否与此问题有关:https://github.com/mergulhao/shoulda-matchers/commit/3a75c6877c07fbf62e77b1fb0aa852138bd537d6
I too am experiencing this problem. The following test:
fails with the error message
while the following test succeeds (thus establishing that Shoulda is present):
shoulda-matchers version 1.0.0, rspec (and all related gems) version 2.8.0
It doesn't seem like it, but could this somehow be related to this issue: https://github.com/mergulhao/shoulda-matchers/commit/3a75c6877c07fbf62e77b1fb0aa852138bd537d6