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

Viewed 964

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.

2 Answers
Related