From b09350c0dc3a0ab1487ffa3298811e07dc6925da Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 24 Jun 2020 18:39:55 -0500 Subject: [PATCH] tests: add more Tag.search tests. Improve tag model test coverage. --- test/factories/tag.rb | 2 +- test/functional/tags_controller_test.rb | 40 ++++++++++++++++--------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/test/factories/tag.rb b/test/factories/tag.rb index 8a6b31d33..a2eb396e7 100644 --- a/test/factories/tag.rb +++ b/test/factories/tag.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory(:tag) do name {"#{FFaker::Name.first_name.downcase}#{rand(1000)}"} - post_count {0} + post_count { 100 } category {Tag.categories.general} factory(:artist_tag) do diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 83b01a1a9..5f0ab23a3 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -20,26 +20,38 @@ class TagsControllerTest < ActionDispatch::IntegrationTest assert_response :success end - context "with search parameters" do - should "render" do - 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 should "strip the blank parameters with a redirect" do get tags_path, params: { search: { name: "touhou", category: "" } } assert_redirected_to tags_path(search: { name: "touhou" }) end end + + context "searching" do + setup do + as(@user) do + @miku = create(:tag, name: "hatsune_miku", category: Tag.categories.character) + @wokada = create(:tag, name: "wokada", category: Tag.categories.artist) + @vocaloid = create(:tag, name: "vocaloid", category: Tag.categories.copyright) + @empty = create(:tag, name: "empty", post_count: 0) + + create(:tag_alias, antecedent_name: "miku", consequent_name: "hatsune_miku") + create(:wiki_page, title: "hatsune_miku") + create(:artist, name: "wokada") + end + end + + should respond_to_search(name_matches: "hatsune_miku").with { @miku } + should respond_to_search(name_normalize: "HATSUNE_MIKU ").with { @miku } + should respond_to_search(name_or_alias_matches: "miku").with { @miku } + should respond_to_search(fuzzy_name_matches: "miku_hatsune", order: "similarity").with { @miku } + should respond_to_search(name: "empty", hide_empty: "true").with { [] } + should respond_to_search(name: "empty", hide_empty: "false").with { [@empty] } + should respond_to_search(name: "wokada", has_artist: "true").with { @wokada } + should respond_to_search(name: "hatsune_miku", has_artist: "false").with { @miku } + should respond_to_search(name: "hatsune_miku", has_wiki: "true").with { @miku } + should respond_to_search(name: "vocaloid", has_wiki: "false").with { @vocaloid } + end end context "autocomplete action" do