-
-
Save Fryie/46b759ca19efa28e1dfdb41a54742e1b to your computer and use it in GitHub Desktop.
CanCanCan Issue
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
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' # use correct rails version | |
gem 'cancancan', '3.2.0' # use correct cancancan version | |
gem 'sqlite3' # use another DB if necessary | |
gem 'byebug' | |
end | |
require 'active_record' | |
require 'cancancan' | |
require 'cancan/model_adapters/active_record_adapter' | |
require 'cancan/model_adapters/active_record_4_adapter' | |
require 'minitest/autorun' | |
require 'logger' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
# create your tables here | |
ActiveRecord::Schema.define do | |
create_table :parents, force: true do |t| | |
end | |
create_table :children, force: true do |t| | |
end | |
create_table :users, force: true do |t| | |
end | |
end | |
class Parent < ActiveRecord::Base | |
end | |
class Child < Parent | |
end | |
class User < ActiveRecord::Base | |
end | |
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
can :manage, Parent | |
cannot :manage, Child | |
end | |
end | |
class BugTest < Minitest::Test | |
def test_bug | |
user = User.create! | |
ability = Ability.new(user) | |
assert_equal ability.can?(:index, Child), false | |
assert_equal ability.can?(:index, Parent), true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment