From 6f0b58ad49afabc252447c3fa2d48cc7d58c8775 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 26 Sep 2019 21:54:22 -0500 Subject: [PATCH] tags: fix typo in order_similarity (fixup 8de692580). --- app/models/tag.rb | 2 +- test/functional/tags_controller_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index db3ebd243..fb6086cca 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -816,7 +816,7 @@ class Tag < ApplicationRecord def order_similarity(name) # trunc(3 * sim) reduces the similarity score from a range of 0.0 -> 1.0 to just 0, 1, or 2. # This groups tags first by approximate similarity, then by largest tags within groups of similar tags. - order(Arel.sql("trunc(3 * similarity(name, #{connection.quote(name)})) DESC", "post_count DESC", "name DESC")) + order(Arel.sql("trunc(3 * similarity(name, #{connection.quote(name)})) DESC"), "post_count DESC", "name DESC") end # ref: https://www.postgresql.org/docs/current/static/pgtrgm.html#idm46428634524336 diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 6936de81e..6d458fb07 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -27,6 +27,13 @@ class TagsControllerTest < ActionDispatch::IntegrationTest get tags_path, params: {:search => {:name_matches => "touhou"}} assert_response :success end + + should "work for search[fuzzy_name_matches]" do + get tags_path, as: :json, params: { search: { fuzzy_name_matches: "touhuo", order: "similarity" }} + + assert_response :success + assert_equal "touhou", response.parsed_body.first["name"] + end end context "with blank search parameters" do