Skip to content

Commit

Permalink
Add scope for human users.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Mar 11, 2017
1 parent 6ebddc4 commit 4d4a1a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/about.rb
Expand Up @@ -35,12 +35,12 @@ def description

def moderators
@moderators ||= User.where(moderator: true, admin: false)
.where("id > 0")
.human_users
.order(:username_lower)
end

def admins
@admins ||= User.where(admin: true).where("id > 0").order(:username_lower)
@admins ||= User.where(admin: true).human_users.order(:username_lower)
end

def stats
Expand Down
4 changes: 3 additions & 1 deletion app/models/user.rb
Expand Up @@ -124,8 +124,10 @@ class User < ActiveRecord::Base
# set to true to optimize creation and save for imports
attr_accessor :import_mode

scope :human_users, -> { where('users.id > 0') }

# excluding fake users like the system user or anonymous users
scope :real, -> { where('users.id > 0').where('NOT EXISTS(
scope :real, -> { human_users.where('NOT EXISTS(
SELECT 1
FROM user_custom_fields ucf
WHERE
Expand Down
8 changes: 8 additions & 0 deletions spec/models/user_spec.rb
Expand Up @@ -1485,4 +1485,12 @@ def hash(password, salt)

end

describe '.human_users' do
it 'should only return users with a positive primary key' do
Fabricate(:user, id: -2)
user = Fabricate(:user)

expect(User.human_users).to eq([user])
end
end
end

1 comment on commit 4d4a1a1

@eviltrout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.