簡體   English   中英

在Rspec中使用Rails 2.3.x進行質量分配

[英]Using Mass Assignment Shoulda Matchers in Rspec with Rails 2.3.x

Rspec的Shoulda-matcher不支持ActiveRecord類的allow_mass_assignment_of。

作為一種解決方法,您會認為以下代碼是等效的嗎?

it { should_not allow_mass_assignment_of :id }

it { MyClass.protected_attributes.include?("id").should be_true }

根據源代碼,兩者都是等價的,但第一行應該正常工作。 您可以在https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb上查看。

我也遇到了這個問題。 以下測試:

it should allow_mass_assignment_of(:email)

失敗並顯示錯誤消息

undefined method 'allow_mass_assignment_of' for #<Class:0x1044de9c8> (NoMethodError)

而以下測試成功(因此確定了Shoulda存在):

it should validate_uniqueness_of(:email)

shoulda-matcher版本1.0.0,rspec(以及所有相關寶石)版本2.8.0

看起來不像,但這可能與這個問題有關: https//github.com/mergulhao/shoulda-matchers/commit/3a75c6877c07fbf62e77b1fb0aa852138bd537d6

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM