Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method reference error #582

Closed
wojw5 opened this issue Apr 11, 2019 · 1 comment · Fixed by #583
Closed

Method reference error #582

wojw5 opened this issue Apr 11, 2019 · 1 comment · Fixed by #583
Assignees
Labels

Comments

@wojw5
Copy link

wojw5 commented Apr 11, 2019

Steps to reproduce

Define ability with method reference instead of block.
Example:

can :read, Book, &:public?

Gist to reproduce:
https://gist.github.com/wojw5/d0f73e6457a8bbb1a976a07a991a5e93

Expected behavior

Error is not thrown, ability is checked

Actual behavior

method CanCan::ConditionsMatcher#matches_block_conditions consumes two arguments (subject, *extra_args), but it is called in with CanCan::ConditionsMatcher#matches_conditions? with three (subject, attribute, *extra_args).
It makes extra_args to be [nil] which is tried to be passed to method reference proc.

1) Error:
BugTest#test_bug:
ArgumentError: wrong number of arguments (given 1, expected 0)
    main.rb:25:in `public?'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/conditions_matcher.rb:24:in `matches_block_conditions'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/conditions_matcher.rb:8:in `matches_conditions?'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:77:in `block (2 levels) in can?'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:76:in `each'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:76:in `detect'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:76:in `block in can?'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:79:in `each'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:79:in `each'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:79:in `each'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:79:in `each'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:79:in `first'
    /Users/wojtek/.rvm/gems/ruby-2.5.5@cancancan/gems/cancancan-3.0.0/lib/cancan/ability.rb:79:in `can?'
    main.rb:47:in `test_bug'

1 runs, 0 assertions, 0 failures, 1 errors, 0 skips

System configuration

Rails version:
4.2.11 (not related)
Ruby version:
2.5.5 (not related)
CanCanCan version
3.0.0

@coorasse coorasse added the bug label Apr 12, 2019
@coorasse coorasse self-assigned this Apr 12, 2019
@coorasse
Copy link
Member

Yes, I confirm that this was working on cancancan 2.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants