Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Regression in cancan 3.0.0: ArgumentError using symbol-to-proc
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "cancancan", "3.0.0"
gem "rails", "5.2.3"
gem "sqlite3"
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)
ActiveRecord::Schema.define do
create_table :tasks, force: true do |t|
t.datetime :deleted_on
end
end
class Task < ActiveRecord::Base
# wrong number of arguments (given 1, expected 0)
def deleted?
deleted_on.present?
end
end
class Ability
include CanCan::Ability
def initialize(user)
can :edit, Task
cannot :edit, Task, &:deleted?
# Workaround: change the above to this form
#
# cannot :edit, Task do |t|
# t.deleted?
# end
end
end
class BugTest < Minitest::Test
def test_association_stuff
task = Task.create!
ability = Ability.new(nil)
assert ability.can?(:edit, task)
# Error:
# BugTest#test_association_stuff:
# ArgumentError: wrong number of arguments (given 1, expected 0)
#
# Exception `ArgumentError' at
# .../cancancan-3.0.0/lib/cancan/conditions_matcher.rb:24 -
# wrong number of arguments (given 1, expected 0)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment