Created
April 3, 2012 21:09
-
-
Save justincampbell/2295519 to your computer and use it in GitHub Desktop.
DRY CanCan specs
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
[ | |
[%w[c r u d], Widget], | |
].each do |tuple| | |
permissions = tuple[0].map!(&:to_sym) | |
model = tuple[1] | |
permissions.map! do |permission| | |
case permission | |
when :c then :create | |
when :r then :read | |
when :u then :update | |
when :d then :delete | |
end | |
end | |
permissions.each do |permission| | |
it "can #{permission} #{model}" do | |
if permission == :create | |
should be_able_to(:create, model) | |
else | |
should be_able_to(permission, model.make!) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment