Skip to content

Commit

Permalink
Merge branch 'sudoremo-nil_arguments' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
coorasse committed Jul 6, 2022
2 parents 65ada12 + cc66e63 commit 603d5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/cancan/conditions_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ def subject_class?(subject)
[Class, Module].include? klass
end

def matches_block_conditions(subject, *extra_args)
def matches_block_conditions(subject, attribute, *extra_args)
return @base_behavior if subject_class?(subject)

@block.call(subject, *extra_args.compact)
if attribute
@block.call(subject, attribute, *extra_args)
else
@block.call(subject, *extra_args)
end
end

def matches_non_block_conditions(subject)
Expand Down
11 changes: 11 additions & 0 deletions spec/cancan/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@
expect(@block_called).to be(true)
end

it 'allows passing nil as extra arguments' do
@ability.can :to_s, Integer do |integer, arg1, arg2|
expect(integer).to eq(42)
expect(arg1).to eq(nil)
expect(arg2).to eq(:foo)
@block_called = true
end
@ability.can?(:to_s, 42, nil, nil, :foo)
expect(@block_called).to be(true)
end

it 'passes nil to object when comparing class with can check' do
@ability.can do |action, object_class, object|
expect(action).to eq(:foo)
Expand Down

0 comments on commit 603d5e9

Please sign in to comment.