don't return staged users in mentions

This commit is contained in:
Régis Hanol 2015-11-18 20:57:49 +01:00
parent 4aab904ff6
commit ff10eb32a6
2 changed files with 16 additions and 11 deletions

View File

@ -11,7 +11,7 @@ class UserSearch
end
def scoped_users
users = User.where("active")
users = User.where(active: true, staged: false)
unless @searching_user && @searching_user.staff?
users = users.not_suspended

View File

@ -5,15 +5,17 @@ describe UserSearch do
let(:topic) { Fabricate :topic }
let(:topic2) { Fabricate :topic }
let(:topic3) { Fabricate :topic }
let(:topic4) { Fabricate :topic }
let(:user1) { Fabricate :user, username: "mrb", name: "Michael Madsen", last_seen_at: 10.days.ago }
let(:user2) { Fabricate :user, username: "mrblue", name: "Eddie Code", last_seen_at: 9.days.ago }
let(:user2) { Fabricate :user, username: "mrblue", name: "Eddie Code", last_seen_at: 9.days.ago }
let(:user3) { Fabricate :user, username: "mrorange", name: "Tim Roth", last_seen_at: 8.days.ago }
let(:user4) { Fabricate :user, username: "mrpink", name: "Steve Buscemi", last_seen_at: 7.days.ago }
let(:user5) { Fabricate :user, username: "mrbrown", name: "Quentin Tarantino", last_seen_at: 6.days.ago }
let(:user6) { Fabricate :user, username: "mrwhite", name: "Harvey Keitel", last_seen_at: 5.days.ago }
let!(:inactive) { Fabricate :user, username: "Ghost", active: false }
let!(:inactive) { Fabricate :user, username: "Ghost", active: false }
let(:admin) { Fabricate :admin, username: "theadmin" }
let(:moderator) { Fabricate :moderator, username: "themod" }
let(:staged) { Fabricate :staged }
before do
ActiveRecord::Base.observers.enable :all
@ -24,6 +26,8 @@ describe UserSearch do
Fabricate :post, user: user4, topic: topic
Fabricate :post, user: user5, topic: topic3
Fabricate :post, user: user6, topic: topic
Fabricate :post, user: staged, topic: topic4
user6.update_attributes(suspended_at: 1.day.ago, suspended_till: 1.year.from_now)
end
@ -31,10 +35,9 @@ describe UserSearch do
UserSearch.new(*args).search
end
# this is a seriously expensive integration test, re-creating this entire test db is too expensive
# reuse
# this is a seriously expensive integration test,
# re-creating this entire test db is too expensive reuse
it "operates correctly" do
# normal search
results = search_for(user1.name.split(" ").first)
expect(results.size).to eq(1)
@ -45,7 +48,7 @@ describe UserSearch do
expect(results.size).to eq(1)
expect(results.first).to eq(user1)
# username
# username
results = search_for(user4.username)
expect(results.size).to eq(1)
expect(results.first).to eq(user4)
@ -70,7 +73,6 @@ describe UserSearch do
results = search_for("mrb", searching_user: admin)
expect(results.size).to eq(3)
results = search_for("MR", searching_user: admin)
expect(results.size).to eq(6)
@ -81,7 +83,6 @@ describe UserSearch do
results = search_for("mrb", topic_id: topic.id)
expect(results.first).to eq(user1)
results = search_for("mrb", topic_id: topic2.id)
expect(results[1]).to eq(user2)
@ -105,11 +106,15 @@ describe UserSearch do
expect(results.size).to eq(0)
# find an exact match first
results = search_for("mrB")
results = search_for(user1.username)
expect(results.first.username).to eq(user1.username)
# don't return inactive users
results = search_for("Ghost")
results = search_for(inactive.username)
expect(results).to be_blank
# don't return staged users
results = search_for(staged.username)
expect(results).to be_blank
end