Skip to content

Commit

Permalink
parent c426bb2
Browse files Browse the repository at this point in the history
author Remo Fritzsche <remo.fritzsche@sitrox.com> 1612868567 +0100
committer Alessandro Rodi <coorasse@gmail.com> 1657114188 +0200

# This is a combination of 4 commits.
# This is the 1st commit message:

Preserve nil values as extra arguments

# This is the commit message #2:

Fix link (#744)

# This is the commit message #3:

Documentation fixes and improvements

- fix typo, punctuations, and grammar
- fix broken and misformatted links
- fix code sample

# This is the commit message #4:

Format documentation/guides and fix linting issues

The motivation of the changes is to make these documents neater when
reading offline using a text or code editor.

Reading the documentation offline is faster, and the source code is
readily available for further learning.

The changes do not affect the meaning of each documentation or
instruction.

The following changes were made:
- remove extra and trailing spaces
- add new lines to separate the title, explanation, code samples, etc
- fix headings, links
- specify code block language (bash, ruby)

Updated Devise.md as exception is changed

CanCan::Unathorized exception not exists anymore, CanCan::AccessDenied is used. Also added responses for different content types as a recommendation.

Add support for non-hash conditions

Co-authored-by: Juleffel <juleffel@protonmail.com>

Improve ability checks with Hashes

Add Ruby 3.0 and Ruby 3.1 to CI

Drop ActiveRecord4 from CI (#778)
  • Loading branch information
sudoremo authored and coorasse committed Jul 6, 2022
1 parent c426bb2 commit 79d2e6b
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, arg_1, arg_2|
expect(integer).to eq(42)
expect(arg_1).to eq(nil)
expect(arg_2).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 79d2e6b

Please sign in to comment.