Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behaviour of with_any_role method with no args #365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions spec/generators_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@

if ENV['ADAPTER'] == 'active_record'
require 'active_record/railtie'
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
ActiveRecord::Base.extend Rolify
else
require 'mongoid'
require 'action_view'
require 'action_controller'
end

module TestApp
Expand Down
2 changes: 1 addition & 1 deletion spec/rolify/shared_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subject { admin }

def admin
user_class.first
user_class.where(:login => "admin").first
end

before(:all) do
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
2 changes: 2 additions & 0 deletions spec/support/adapters/mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'mongoid'

Mongoid.load!("spec/support/adapters/mongoid.yml", :test)
Mongoid.logger = ::Logger.new('/dev/null')
Mongo::Logger.logger.level = Logger::INFO

::Mongoid::Document.module_eval do
def self.included(base)
Expand Down
3 changes: 2 additions & 1 deletion spec/support/adapters/mongoid.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
test:
sessions:
clients:
default:
logger: false
database: godfather
hosts:
- localhost:27017