Skip to content

Commit

Permalink
Fix with_role with :any resource (RolifyCommunity#575)
Browse files Browse the repository at this point in the history
* Use && instead of and for logically correct check

* add spec to cover :any resource
  • Loading branch information
v-kumar authored Feb 8, 2022
1 parent e07e69f commit 0c883f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/rolify/finders.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Rolify
module Finders
def with_role(role_name, resource = nil)
strict = self.strict_rolify and resource and resource != :any
strict = self.strict_rolify && resource && resource != :any
self.adapter.scope(
self,
{ :name => role_name, :resource => resource },
Expand Down Expand Up @@ -46,4 +46,4 @@ def parse_args(args, users, &block)
block.call(users_to_add)
end
end
end
end
9 changes: 7 additions & 2 deletions spec/rolify/shared_examples/shared_examples_for_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
it { subject.with_role("admin".send(param_method), Forum.first).should be_empty }
it { subject.with_role("moderator".send(param_method), Forum.first).should be_empty }
end

context "on any resource" do
it { subject.with_role("admin".send(param_method), :any).should_not be_empty }
it { subject.with_role("moderator".send(param_method), :any).should_not be_empty }
end
end
end
end
Expand Down Expand Up @@ -115,7 +120,7 @@
end
end
end


describe ".with_all_roles" do
it { should respond_to(:with_all_roles) }
Expand Down Expand Up @@ -146,4 +151,4 @@
it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => :any }, { :name => "moderator".send(param_method), :resource => :any }).should =~ [ root, modo, visitor ] }
end
end
end
end

0 comments on commit 0c883f4

Please sign in to comment.