Skip to content

Commit

Permalink
Fix behaviour of with_any_role with no args
Browse files Browse the repository at this point in the history
User.with_any_role with no args should return all User instances having at least one role.
fix #363
  • Loading branch information
EppO committed Oct 16, 2015
1 parent 99d886e commit 23b0087
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rolify/adapters/active_record/role_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def scope(relation, conditions)
query = relation.all
end
query = query.joins(:roles)
query = where(query, conditions)
query = where(query, conditions) if conditions
query
end

Expand Down
1 change: 1 addition & 0 deletions lib/rolify/finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def with_all_roles(*args)
end

def with_any_role(*args)
return self.adapter.scope(self, nil) if args.empty?
users = []
parse_args(args, users) do |users_to_add|
users += users_to_add
Expand Down
1 change: 1 addition & 0 deletions spec/rolify/shared_examples/shared_examples_for_finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
describe ".with_any_role" do
it { should respond_to(:with_any_role) }

it { subject.with_any_role().should eq(subject.joins(:roles).all)}
it { subject.with_any_role("admin".send(param_method), :staff).should eq([ root ]) }
it { subject.with_any_role("admin".send(param_method), :staff, { :name => "moderator".send(param_method), :resource => Group }).should eq([ root ]) }
it { subject.with_any_role("admin".send(param_method), "moderator".send(param_method)).should eq([ root ]) }
Expand Down

0 comments on commit 23b0087

Please sign in to comment.