Skip to content

Calling can? with class and additional arguments does not call block defined in can #883

Description

@egor-khanko

Example:

# Any additional arguments will be passed into the "can" block definition. This
# can be used to pass more information about the user's request for example.
#
# can? :create, Project, request.remote_ip
#
# can :create, Project do |project, remote_ip|
# # ...
# end

Implemented in a test: https://github.com/egor-khanko/cancancan/blob/f64bb73f0adb6cc5e96fa69ba4a881ae60fe42d2/spec/cancan/ability_spec.rb#L115-L123

Test fails, as the block never called:

Failures:

  1) CanCan::Ability passes object and additional attributes when calling with class
     Failure/Error: expect(@block_called).to be(true)

       expected true
            got nil
     # ./spec/cancan/ability_spec.rb:122:in `block (2 levels) in <top (required)>'

It is caused by following check, which passes and falls back to default behaviour: https://github.com/CanCanCommunity/cancancan/blob/develop/lib/cancan/conditions_matcher.rb#L22

Who is right - code or documentation? Can submit a PR if needed.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions