未定义的方法`columns_hash'

时间:2013-08-27 07:00:18

标签: ruby-on-rails rspec mongoid

我在shoulda_matchers中使用了specs。对于这个测试

it { should validate_uniqueness_of(:name).scoped_to(:role_id) }

我收到此错误:

Expected errors to include "has already been taken" when name is set to "arbitrary_string", got errors: ["name is already taken (\"arbitrary_string\")"]

当我将测试更改为:

it { should validate_uniqueness_of(:name).scoped_to(:role_id).with_message('is already taken') }

我收到此错误:

 NoMethodError:
       undefined method `columns_hash' for Activity:Class

我的模型只有一个字段 - name

1 个答案:

答案 0 :(得分:2)

Mongoid模型没有columns_hash类方法,shoulda-matchers使用此方法。

mongoid中的相应方法是columns

我能够通过用shoulda替换宝石shoulda-matchersmongoid-rspec来解决此问题。