How to test attr_accessible fields in RSpec

后端 未结 3 1479
春和景丽
春和景丽 2020-12-28 15:26

So we have been setting up attr_accessible and attr_protected on many fields through out our Rails 3.2 app. For now we really don\'t test to ensure

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-28 16:08

    If for some reason RSpec is tripping up on juicedM3's answer above like mine was you can do something like this:

    specify { expect { Model.new(unaccessible_attr: value) }.to raise_error(ActiveModel::MassAssignmentSecurity::Error) }
    

提交回复
热议问题