How to test for mass assignment errors in Rspec and Rails 4?

rspec, ruby, ruby-on-rails, ruby-on-rails-4

Solution

As Baldrick pointed out rightly there's no need in Rails 4 to test for mass assignment issues in Rspec model tests. The whole idea of Rails 4's Strong Parameters is to move all that functionality to the controller.

Problem

I recently upgraded my Rails app from Rails 3 to 4 and this Rspec test is no longer passing: ``` # spec/models/user_spec.rb: require 'spec_helper' describe User do it "should not allow access to admin" do expect do User.new(:admin => true) end.to raise_error(ActiveModel::MassAssignmentSecurity::Error) end end ``` I am getting this error: ``` Failure/Error: end.to raise_error(ActiveModel::MassAssignmentSecurity::Error) NameError: uninitialized constant ActiveModel::MassAssignmentSecurity ``` I suspect that this is somehow due to the switch to Rails 4's strong parameters. How can I test for mass assignment errors now? Thanks for any help.

Original source