I’m working with Rails 3.2.2. And I have a devise model called user.
In my user model I set:
attr_protected :is_admin
(is_admin is a boolean attribute)
For test this property I made:
test "should not be able to change to admin" do
user = User.create(:name => "Joaquim", :email => "example@test.com", :password => "123456", :is_admin => true)
assert user.errors.get(:is_admin), "Cant change admin configuration"
end
When I run this test raise error:
1) Error:
test_should_not_be_able_to_change_to_admin(UserTest):
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: is_admin
test/unit/user_test.rb:44:in `test_should_not_be_able_to_change_to_admin'
What assert do I have to use for this test?
Thanks!
You can use
In rspec you’d do