-
Notifications
You must be signed in to change notification settings - Fork 404
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
Change with_any_role and with_all_roles to return an AR relation instead of an Array #441
base: master
Are you sure you want to change the base?
Conversation
Rerunning travis to see what our results are. |
Ok. I might have to merge master in first. |
@dkniffin I looked over the test failures and they appear to be legit. We're getting things like
So it looks like we're adding to the list twice. |
Yea. I'll look into it 👍 |
@wldcordeiro Do you know why this might be happening when I try and run the tests locally?:
|
Hmm. I'm not sure I understand why this expectation exists. Here, we set up the subject to have the roles "admin" everywhere, and "moderator" on Hopefully that makes sense. |
@dkniffin it looks to me that we're testing in the general unscoped sense so we're saying "who has both admin and moderator" roles and the user has only moderator over the https://github.com/RolifyCommunity/rolify/wiki/Usage#finders-methods |
Ok, makes sense. I'll update the code to accomodate that. I'm very glad there's good test cases around all this :) |
7 similar comments
Hmm. So it's failing now with two errors. The first is a For the other, I'm not familiar with mongoid at all, so if you could provide some guidance, I'd appreciate it. |
Somehow it does work on Rails 4.2 but still return an Array using Rails 5. Loading development environment (Rails 4.2.11)
irb(main):006:0> User.with_all_roles :toto
User Load (0.8ms) SELECT DISTINCT "users".* FROM (SELECT "users".* FROM "users" INNER JOIN "users_roles" ON "users_roles"."user_id" = "users"."id" INNER JOIN "roles" ON "roles"."id" = "users_roles"."role_id" WHERE (((roles.name IN ('toto')) AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))) AS users
=> #<ActiveRecord::Relation [#<User id: 1, email: "[email protected]", created_at: "2019-02-27 18:16:18", updated_at: "2019-02-27 18:16:18">]> Loading development environment (Rails 5.2.2)
irb(main):001:0> User.with_all_roles :toto
User Load (0.2ms) SELECT "users".* FROM (SELECT "users".* FROM "users" INNER JOIN "users_roles" ON "users_roles"."user_id" = "users"."id" INNER JOIN "roles" ON "roles"."id" = "users_roles"."role_id" WHERE (((roles.name IN ('toto')) AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))) AS users
=> [#<User id: 1, email: "[email protected]", created_at: "2019-02-27 15:52:58", updated_at: "2019-02-27 15:52:58">, #<User id: 2, email: "[email protected]", created_at: "2019-02-27 15:54:14", updated_at: "2019-02-27 15:54:14">] |
Fixes #292
I couldn't run the tests locally, unfortunately, so I'm hoping they run on travis.