Created
June 16, 2012 21:26
-
-
Save tyrel86/2942536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test for one model: | |
it "Should protect id from mass assignment" do | |
attributes = @user.attributes | |
attributes['id'] = 42 | |
lambda do | |
User.create(attributes).id.should_not equal 42 | |
end.should raise_error ActiveModel::MassAssignmentSecurity::Error | |
end | |
passes | |
test for another model | |
it "Should not allow ID to be mass assigned" do | |
attributes = @dispensary.attributes | |
attributes['id'] = 42 | |
disp = Dispensary.create( attributes ) | |
disp.id.should_not equal 42 | |
end | |
also passes | |
if I write a similar test for the first one instead of checking the exception like | |
it "Should not allow ID to be mass assigned" do | |
attributes = @dispensary.attributes | |
attributes['id'] = 42 | |
disp = Dispensary.create( attributes ) | |
disp.id.should_not equal 42 | |
end | |
Rspec stops because an error was raised. I am confused what variable am I missing thank you |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment