From 8cf9c15a46a0aa66f0e91804f74c76b6e28f4f13 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Thu, 24 Oct 2019 18:34:12 +0300 Subject: [PATCH] Revert change of active user definition Closes #2560 Active users are needed for selectize, and the active definition changed to show recent users in #2297 This reverts that change, and provides * active scope (user not disabled) * recent scope (for use in #2297 changes, ie user distribution) --- app/models/user.rb | 7 +++++-- spec/models/user_spec.rb | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ec3132e1..7c764fa1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -34,7 +34,7 @@ class User < ApplicationRecord scope :comment_notifiable, ->(conference) {joins(:roles).where('roles.name IN (?)', [:organizer, :cfp]).where('roles.resource_type = ? AND roles.resource_id = ?', 'Conference', conference.id)} # scopes for user distributions - scope :active, lambda { + scope :recent, lambda { where('last_sign_in_at > ?', Date.today - 3.months).where(is_disabled: false) } scope :unconfirmed, -> { where('confirmed_at IS NULL') } @@ -86,6 +86,9 @@ class User < ApplicationRecord accepts_nested_attributes_for :roles scope :admin, -> { where(is_admin: true) } + scope :active, lambda { + where(is_disabled: false) + } validates :email, presence: true @@ -174,7 +177,7 @@ class User < ApplicationRecord # * +hash+ -> hash def self.distribution { - 'Active' => User.active.count, + 'Active' => User.recent.count, 'Unconfirmed' => User.unconfirmed.count, 'Dead' => User.dead.count } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fc80d484..29aadfe6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -101,9 +101,9 @@ describe User do end describe 'user distribution scopes' do - it 'scopes active users' do + it 'scopes recent users' do create(:user, last_sign_in_at: Date.today - 3.months + 1.day) # active - expect(User.active.count).to eq(1) + expect(User.recent.count).to eq(1) end it 'scopes unconfirmed users' do