Skip to content

Instantly share code, notes, and snippets.

@justincampbell
Created April 3, 2012 21:09
Show Gist options
  • Save justincampbell/2295519 to your computer and use it in GitHub Desktop.
Save justincampbell/2295519 to your computer and use it in GitHub Desktop.
DRY CanCan specs
[
[%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