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

For the generator specs to pass, I needed to add this: ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
Otherwise, generators specs are failing because of `ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base` error.

I had to require explicitly active_view and active_controller gems for mongoid adapter to make generators specs pass for mongoid.
I changed also mongoid.yml to use clients instead of sessions
I tried to stop logging mongoid queries as it floods travis-ci but travis-ci displays logs from mongodb service directly and reaches 4MB logs limit. I don't know how to stop it
  • Loading branch information
EppO committed Oct 16, 2015
1 parent 99d886e commit cc3a266
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
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
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
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

0 comments on commit cc3a266

Please sign in to comment.