From 38d901ac91683a9b17738aead030ffac9578f48d Mon Sep 17 00:00:00 2001 From: cpradio Date: Fri, 24 Oct 2014 19:20:41 -0400 Subject: [PATCH] FIX: Do not show unconfirmed users in search results --- lib/search.rb | 2 +- spec/components/search_spec.rb | 9 +++++++++ spec/fabricators/user_fabricator.rb | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/search.rb b/lib/search.rb index 9c830d3a9..2330ddc69 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -263,7 +263,7 @@ class Search def user_search users = User.includes(:user_search_data) - .where("user_search_data.search_data @@ #{ts_query("simple")}") + .where("active = true AND user_search_data.search_data @@ #{ts_query("simple")}") .order("CASE WHEN username_lower = '#{@original_term.downcase}' THEN 0 ELSE 1 END") .order("last_posted_at DESC") .limit(@limit) diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 8ec653172..ffe61971d 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -87,6 +87,15 @@ describe Search do end end + context 'inactive users' do + let!(:inactive_user) { Fabricate(:inactive_user, active: false) } + let(:result) { Search.execute('bruce') } + + it 'does not return a result' do + result.users.length.should == 0 + end + end + context 'topics' do let(:post) { Fabricate(:post) } let(:topic) { post.topic} diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 2caea8993..de200ec4c 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -32,6 +32,13 @@ Fabricator(:walter_white, from: :user) do password 'letscook' end +Fabricator(:inactive_user, from: :user) do + name 'Inactive User' + username 'inactive_user' + email 'inactive@idontexist.com' + active false +end + Fabricator(:moderator, from: :user) do name { sequence(:name) {|i| "A#{i} Moderator"} } username { sequence(:username) {|i| "moderator#{i}"} }