How to test attr_accessible fields in RSpec

后端 未结 3 1509
春和景丽
春和景丽 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条回答
  •  梦谈多话
    2020-12-28 16:17

    I was looking for something similar and then I was told about the shoulda-matcher allow_mass_assigment_of. That ended up working for me without creating a custom matcher.

    it { should allow_mass_assignment_of :some_field }
    it { should_not allow_mass_assignment_of :field_name }
    

    Hope this helps someone else.

提交回复
热议问题