Last active
November 21, 2015 01:48
-
-
Save rsutphin/d4bf91bef5f24b7bc3d9 to your computer and use it in GitHub Desktop.
Demonstrating unexpected behavior in cancancan
This file contains 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
require 'cancan' | |
Hat = Struct.new(:color) | |
class MyAbility | |
include CanCan::Ability | |
def initialize | |
can :see, Hat, color: "red" | |
end | |
end | |
# --- | |
ability = MyAbility.new | |
if ability.can?(:see, Hat.new("red")) | |
$stderr.puts "✅ You can see a particular red hat, as expected" | |
else | |
$stderr.puts "❌ You can't see a particular red hat. Weird." | |
end | |
if ability.can?(:see, Hat.new("blue")) | |
$stderr.puts "❌ You can see a particular blue hat. That shouldn't happen." | |
else | |
$stderr.puts "✅ You can't see a particular blue hat. Good." | |
end | |
if ability.can?(:see, Hat, color: "red") | |
$stderr.puts "✅ You can see any red hat, as expected" | |
else | |
$stderr.puts "❌ You can't see any red hat. Weird." | |
end | |
if ability.can?(:see, Hat, color: "blue") | |
$stderr.puts "❌ You can see any blue hat. That shouldn't happen." | |
else | |
$stderr.puts "✅ You can't see any blue hat. Good." | |
end | |
if ability.can?(:see, Hat) | |
$stderr.puts "❌ You can see any hat. That shouldn't happen." | |
else | |
$stderr.puts "✅ You can't see just any hat. Good." | |
end |
This file contains 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
source 'https://rubygems.org' | |
gem 'cancancan' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue is here: cancancan/issues#277. Summary: working as intended.