Fix #3871: Autocomplete can return duplicate tags.

This commit is contained in:
evazion
2018-09-05 18:55:49 -05:00
parent 4b9f3e384f
commit c2cf6a5441
2 changed files with 6 additions and 1 deletions

View File

@@ -23,7 +23,7 @@ module TagAutocomplete
end
def count_sort(query, words)
words.uniq.sort_by do |x|
words.uniq(&:name).sort_by do |x|
x.post_count * x.weight
end.reverse.slice(0, LIMIT)
end

View File

@@ -8,6 +8,11 @@ class TagAutocompleteTest < ActiveSupport::TestCase
create(:tag, name: "abcdef", post_count: 1)
assert_equal(["abcdef"], subject.search("A").map(&:name))
end
should "not return duplicates" do
create(:tag, name: "red_eyes", post_count: 5001)
assert_equal(%w[red_eyes], subject.search("re").map(&:name))
end
end
context "#search_exact" do