Skip to content

Instantly share code, notes, and snippets.

@TylerRick

TylerRick/main.rb

Forked from coorasse/main.rb
Created Jan 16, 2018
Embed
What would you like to do?
CanCanCan Issue
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