Commit e5c7027f authored by Douwe Maan's avatar Douwe Maan

Merge branch 'sh-fix-users-controller-ruby-2.6-compat' into 'master'

Make Admin::UsersController work with Ruby 2.6

See merge request gitlab-org/gitlab-ce!25316
parents c39e094b e87c255d
...@@ -7,7 +7,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -7,7 +7,7 @@ class Admin::UsersController < Admin::ApplicationController
before_action :check_impersonation_availability, only: :impersonate before_action :check_impersonation_availability, only: :impersonate
def index 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.search_with_secondary_emails(params[:search_query]) if params[:search_query].present?
@users = @users.sort_by_attribute(@sort = params[:sort]) @users = @users.sort_by_attribute(@sort = params[:sort])
@users = @users.page(params[:page]) @users = @users.page(params[:page])
......
...@@ -388,7 +388,7 @@ class User < ApplicationRecord ...@@ -388,7 +388,7 @@ class User < ApplicationRecord
find_by(id: user_id) find_by(id: user_id)
end end
def filter(filter_name) def filter_items(filter_name)
case filter_name case filter_name
when 'admins' when 'admins'
admins admins
......
...@@ -8,6 +8,20 @@ describe Admin::UsersController do ...@@ -8,6 +8,20 @@ describe Admin::UsersController do
sign_in(admin) sign_in(admin)
end 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 describe 'GET :id' do
it 'finds a user case-insensitively' do it 'finds a user case-insensitively' do
user = create(:user, username: 'CaseSensitive') user = create(:user, username: 'CaseSensitive')
......
...@@ -976,43 +976,43 @@ describe User do ...@@ -976,43 +976,43 @@ describe User do
end end
end end
describe '.filter' do describe '.filter_items' do
let(:user) { double } let(:user) { double }
it 'filters by active users by default' do it 'filters by active users by default' do
expect(described_class).to receive(:active).and_return([user]) 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 end
it 'filters by admins' do it 'filters by admins' do
expect(described_class).to receive(:admins).and_return([user]) 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 end
it 'filters by blocked' do it 'filters by blocked' do
expect(described_class).to receive(:blocked).and_return([user]) 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 end
it 'filters by two_factor_disabled' do it 'filters by two_factor_disabled' do
expect(described_class).to receive(:without_two_factor).and_return([user]) 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 end
it 'filters by two_factor_enabled' do it 'filters by two_factor_enabled' do
expect(described_class).to receive(:with_two_factor).and_return([user]) 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 end
it 'filters by wop' do it 'filters by wop' do
expect(described_class).to receive(:without_projects).and_return([user]) 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
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment