diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index 6c3f3b1d6..34df8fb15 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -70,6 +70,14 @@ class TagRelationship < ApplicationRecord where_ilike(:antecedent_name, name).or(where_ilike(:consequent_name, name)) end + def consequent_name_matches(name) + where_like(:consequent_name, Tag.normalize_name(name)) + end + + def antecedent_name_matches(name) + where_like(:antecedent_name, Tag.normalize_name(name)) + end + def status_matches(status) where(status: status.downcase) end @@ -81,6 +89,14 @@ class TagRelationship < ApplicationRecord q = q.name_matches(params[:name_matches]) end + if params[:consequent_name_matches].present? + q = q.consequent_name_matches(params[:consequent_name_matches]) + end + + if params[:antecedent_name_matches].present? + q = q.antecedent_name_matches(params[:antecedent_name_matches]) + end + if params[:status].present? q = q.status_matches(params[:status]) end diff --git a/app/views/tag_relationships/_search.html.erb b/app/views/tag_relationships/_search.html.erb index 7568fc065..ed9dc5b99 100644 --- a/app/views/tag_relationships/_search.html.erb +++ b/app/views/tag_relationships/_search.html.erb @@ -1,8 +1,8 @@ <%# url %> <%= search_form_for(url) do |f| %> - <%= f.input :antecedent_name_ilike, label: "From", input_html: { value: params[:search][:antecedent_name_ilike], data: { autocomplete: "tag" } } %> - <%= f.input :consequent_name_ilike, label: "To", input_html: { value: params[:search][:consequent_name_ilike], data: { autocomplete: "tag" } } %> + <%= f.input :antecedent_name_matches, label: "From", input_html: { value: params[:search][:antecedent_name_matches], data: { autocomplete: "tag" } } %> + <%= f.input :consequent_name_matches, label: "To", input_html: { value: params[:search][:consequent_name_matches], data: { autocomplete: "tag" } } %> <%= f.input :reason_ilike, label: "Reason", input_html: { value: params[:search][:reason_ilike] } %> <%= f.simple_fields_for :antecedent_tag do |fa| %> <%= fa.input :category, label: "From Category", collection: TagCategory.canonical_mapping.to_a, include_blank: true, selected: params.dig(:search, :antecedent_tag, :category) %> diff --git a/test/functional/tag_aliases_controller_test.rb b/test/functional/tag_aliases_controller_test.rb index b0a38b08a..16561726d 100644 --- a/test/functional/tag_aliases_controller_test.rb +++ b/test/functional/tag_aliases_controller_test.rb @@ -19,7 +19,7 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest @consequent_wiki = create(:wiki_page, title: "touhou_project") @other_alias = create(:tag_alias, antecedent_name: "touhou", consequent_name: "touhou_project", creator: @user, status: "deleted", forum_topic: @forum_topic, forum_post: @forum_post) - @unrelated_alias = create(:tag_alias) + @unrelated_alias = create(:tag_alias, antecedent_name: "yellow_hair", consequent_name: "blonde_hair") end should "render" do @@ -31,6 +31,8 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest should respond_to_search(antecedent_name: "aaa").with { @tag_alias } should respond_to_search(consequent_name: "bbb").with { @tag_alias } should respond_to_search(status: "deleted").with { @other_alias } + should respond_to_search(antecedent_name_matches: " YELLOW HAIR ").with { @unrelated_alias } + should respond_to_search(consequent_name_matches: " blonde hair ").with { @unrelated_alias } context "using includes" do should respond_to_search(antecedent_tag: {post_count: 1000}).with { @other_alias } diff --git a/test/functional/tag_implications_controller_test.rb b/test/functional/tag_implications_controller_test.rb index 50948340b..638830388 100644 --- a/test/functional/tag_implications_controller_test.rb +++ b/test/functional/tag_implications_controller_test.rb @@ -19,7 +19,7 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest @consequent_wiki = create(:wiki_page, title: "weapon") @other_implication = create(:tag_implication, antecedent_name: "cannon", consequent_name: "weapon", creator: @user, status: "deleted", forum_topic: @forum_topic, forum_post: @forum_post) - @unrelated_implication = create(:tag_implication) + @unrelated_implication = create(:tag_implication, antecedent_name: "cat_ears", consequent_name: "animal_ears") end should "render" do @@ -31,6 +31,8 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest should respond_to_search(antecedent_name: "aaa").with { @tag_implication } should respond_to_search(consequent_name: "bbb").with { @tag_implication } should respond_to_search(status: "deleted").with { @other_implication } + should respond_to_search(antecedent_name_matches: " CAT EARS ").with { @unrelated_implication } + should respond_to_search(consequent_name_matches: " animal ears ").with { @unrelated_implication } context "using includes" do should respond_to_search(antecedent_tag: {post_count: 10}).with { @other_implication }