Skip to content

Instantly share code, notes, and snippets.

View isokcevic's full-sized avatar
:shipit:

Ivan Sokcevic isokcevic

:shipit:
View GitHub Profile
@isokcevic
isokcevic / WhitelistMatcher.rb
Created March 7, 2012 16:19
A matcher for whitelisted attributes
module WhitelistMatcher
# Checks if all of the specified attributes are mass-assignable, and if all the others are protected.
# If used with should_not, then ONLY the specified attributes should be protected from mass assignment, and for all other it should be allowed
# (i.e. behavior similar to :except )
# It also supports roles by chaining as()
#
# it { should whitelist(:email, :password, :password_confirmation) }
# it { should_not whitelist(:admin, :balance)
# it { should whitelist(:owner).as(:superuser)
#