summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-02-16 14:26:15 -0800
committerStan Hu <stanhu@gmail.com>2019-02-19 15:36:05 -0800
commite87c255d9e76fb3ca691267107e83d48c90bc816 (patch)
tree9ff03ae5830a34f1269a82f482f967adb213d82a
parentab9f8785ebf5483e5d2cd02497b57fa05a47561e (diff)
downloadgitlab-ce-e87c255d9e76fb3ca691267107e83d48c90bc816.tar.gz
Make Admin::UsersController work with Ruby 2.6
Ruby 2.6 introduced `Enumerable#filter`, which takes no arguments. Attempting to call `filter` on an `ActiveRecord::Relation` with a scope will fail with a `wrong number of arguments (given 1, expected 0)` message because the `Enumerable#filter` implementation overrides the delegated `ActiveRecord::Relation#filter` method. To make Admin::UsersController compatible with Ruby 2.6, rename `User.filter` to `User.filter_items`.
-rw-r--r--app/controllers/admin/users_controller.rb2
-rw-r--r--app/models/user.rb2
-rw-r--r--spec/controllers/admin/users_controller_spec.rb14
-rw-r--r--spec/models/user_spec.rb14
4 files changed, 23 insertions, 9 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 0eae007715a..bfa7c7d0109 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -7,7 +7,7 @@ class Admin::UsersController < Admin::ApplicationController
before_action :check_impersonation_availability, only: :impersonate
def index
- @users = User.order_name_asc.filter(params[:filter])
+ @users = User.filter_items(params[:filter]).order_name_asc
@users = @users.search_with_secondary_emails(params[:search_query]) if params[:search_query].present?
@users = @users.sort_by_attribute(@sort = params[:sort])
@users = @users.page(params[:page])
diff --git a/app/models/user.rb b/app/models/user.rb
index fd32d838e53..ee51c35d576 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -388,7 +388,7 @@ class User < ApplicationRecord
find_by(id: user_id)
end
- def filter(filter_name)
+ def filter_items(filter_name)
case filter_name
when 'admins'
admins
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb
index c934db9e237..cb24a6ef142 100644
--- a/spec/controllers/admin/users_controller_spec.rb
+++ b/spec/controllers/admin/users_controller_spec.rb
@@ -8,6 +8,20 @@ describe Admin::UsersController do
sign_in(admin)
end
+ describe 'GET #index' do
+ it 'retrieves all users' do
+ get :index
+
+ expect(assigns(:users)).to match_array([user, admin])
+ end
+
+ it 'filters by admins' do
+ get :index, params: { filter: 'admins' }
+
+ expect(assigns(:users)).to eq([admin])
+ end
+ end
+
describe 'GET :id' do
it 'finds a user case-insensitively' do
user = create(:user, username: 'CaseSensitive')
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 1edd8e69b8f..85b157a9435 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -976,43 +976,43 @@ describe User do
end
end
- describe '.filter' do
+ describe '.filter_items' do
let(:user) { double }
it 'filters by active users by default' do
expect(described_class).to receive(:active).and_return([user])
- expect(described_class.filter(nil)).to include user
+ expect(described_class.filter_items(nil)).to include user
end
it 'filters by admins' do
expect(described_class).to receive(:admins).and_return([user])
- expect(described_class.filter('admins')).to include user
+ expect(described_class.filter_items('admins')).to include user
end
it 'filters by blocked' do
expect(described_class).to receive(:blocked).and_return([user])
- expect(described_class.filter('blocked')).to include user
+ expect(described_class.filter_items('blocked')).to include user
end
it 'filters by two_factor_disabled' do
expect(described_class).to receive(:without_two_factor).and_return([user])
- expect(described_class.filter('two_factor_disabled')).to include user
+ expect(described_class.filter_items('two_factor_disabled')).to include user
end
it 'filters by two_factor_enabled' do
expect(described_class).to receive(:with_two_factor).and_return([user])
- expect(described_class.filter('two_factor_enabled')).to include user
+ expect(described_class.filter_items('two_factor_enabled')).to include user
end
it 'filters by wop' do
expect(described_class).to receive(:without_projects).and_return([user])
- expect(described_class.filter('wop')).to include user
+ expect(described_class.filter_items('wop')).to include user
end
end