Skip to content

Instantly share code, notes, and snippets.

@herestomwiththeweather
Created November 27, 2010 07:35
Show Gist options
  • Save herestomwiththeweather/717685 to your computer and use it in GitHub Desktop.
Save herestomwiththeweather/717685 to your computer and use it in GitHub Desktop.
RSpec and CanCan Authorization for Intentional Economics
can :create, Exchange do |exchange|
unless exchange.group
# the presence of group is validated when creating an exchange
# group will be nil for the new method, so allow it
true
else
membership = Membership.mem(person,exchange.group)
unless membership
false
else
account = person.account(exchange.group)
account && (account.authorized? exchange.amount)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment