-
-
Save TylerRick/0a41a8f5b5dc21d5ae6d6ec1bc465b92 to your computer and use it in GitHub Desktop.
CanCanCan Issue
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
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'rails', '5.1.4' | |
gem 'cancancan' | |
end | |
require 'cancancan' | |
require 'minitest/autorun' | |
require 'logger' | |
class Option | |
include Singleton | |
def self.all | |
[X.instance, Y.instance, Any.instance ] | |
end | |
end | |
class X < Option; end | |
class Y < Option; end | |
class Any < Option | |
def to_a | |
[X.instance, Y.instance] | |
end | |
end | |
class Ability | |
include CanCan::Ability | |
def initialize | |
Option.all.each do |option| | |
can :read, option | |
# Workaround: | |
# can :read, [option] | |
end | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_bug | |
ability = Ability.new | |
#[X.instance, Y.instance].each do |option| | |
Option.all.each do |option| | |
assert_equal true, ability.can?(:read, option) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment