diff options
author | Poornima <poornima.malepati@gmail.com> | 2017-08-26 18:05:25 +0530 |
---|---|---|
committer | Poornima <poornima.malepati@gmail.com> | 2018-02-05 23:05:54 +0530 |
commit | cca13d1e40812b60462461ca4387324778654960 (patch) | |
tree | 3112c01fd9df0205c196fbbdc7bf9d46fd546983 | |
parent | 1214d8de691494138cbaab10da242c71504158de (diff) | |
download | gitlab-ce-cca13d1e40812b60462461ca4387324778654960.tar.gz |
Using correct column for sorting users by Recent Sign-in
Removing last_sign_in_at in specs
-rw-r--r-- | app/models/user.rb | 4 | ||||
-rw-r--r-- | changelogs/unreleased/26468-fix-sort-by-recent-sign-in.yml | 4 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 22 |
3 files changed, 20 insertions, 10 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index a57ba3740c9..3a3eced0e31 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -230,8 +230,8 @@ class User < ActiveRecord::Base scope :active, -> { with_state(:active).non_internal } scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members WHERE user_id IS NOT NULL AND requested_at IS NULL)') } scope :todo_authors, ->(user_id, state) { where(id: Todo.where(user_id: user_id, state: state).select(:author_id)) } - scope :order_recent_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'DESC')) } - scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('last_sign_in_at', 'ASC')) } + scope :order_recent_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'DESC')) } + scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'ASC')) } def self.with_two_factor joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id") diff --git a/changelogs/unreleased/26468-fix-sort-by-recent-sign-in.yml b/changelogs/unreleased/26468-fix-sort-by-recent-sign-in.yml new file mode 100644 index 00000000000..a2c81f6c995 --- /dev/null +++ b/changelogs/unreleased/26468-fix-sort-by-recent-sign-in.yml @@ -0,0 +1,4 @@ +--- +title: Fix Sort by Recent Sign-in in Admin Area +merge_request: 13852 +author: Poornima M diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 18c91d4cffd..27b33e29060 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1433,28 +1433,34 @@ describe User do describe '#sort' do before do described_class.delete_all - @user = create :user, created_at: Date.today, last_sign_in_at: Date.today, name: 'Alpha' - @user1 = create :user, created_at: Date.today - 1, last_sign_in_at: Date.today - 1, name: 'Omega' - @user2 = create :user, created_at: Date.today - 2, last_sign_in_at: nil, name: 'Beta' + @user = create :user, created_at: Date.today, current_sign_in_at: Date.today, name: 'Alpha' + @user1 = create :user, created_at: Date.today - 1, current_sign_in_at: Date.today - 1, name: 'Omega' + @user2 = create :user, created_at: Date.today - 2, name: 'Beta' end context 'when sort by recent_sign_in' do - it 'sorts users by the recent sign-in time' do - expect(described_class.sort('recent_sign_in').first).to eq(@user) + let(:users) { described_class.sort('recent_sign_in') } + + it 'sorts users by recent sign-in time' do + expect(users.first).to eq(@user) + expect(users.second).to eq(@user1) end it 'pushes users who never signed in to the end' do - expect(described_class.sort('recent_sign_in').third).to eq(@user2) + expect(users.third).to eq(@user2) end end context 'when sort by oldest_sign_in' do + let(:users) { described_class.sort('oldest_sign_in') } + it 'sorts users by the oldest sign-in time' do - expect(described_class.sort('oldest_sign_in').first).to eq(@user1) + expect(users.first).to eq(@user1) + expect(users.second).to eq(@user) end it 'pushes users who never signed in to the end' do - expect(described_class.sort('oldest_sign_in').third).to eq(@user2) + expect(users.third).to eq(@user2) end end |