From 1ca4add525b3f788934718c0b9474d41c1a5e005 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 14 Oct 2019 23:13:49 -0500 Subject: [PATCH] related tags: fix exception on copyright tags with nonexistent wiki pages. --- app/logical/related_tag_query.rb | 2 +- test/functional/related_tags_controller_test.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/logical/related_tag_query.rb b/app/logical/related_tag_query.rb index 940192943..3981085f6 100644 --- a/app/logical/related_tag_query.rb +++ b/app/logical/related_tag_query.rb @@ -48,7 +48,7 @@ class RelatedTagQuery def other_wiki_pages return [] unless Tag.category_for(query) == Tag.categories.copyright - other_wikis = DText.parse_wiki_titles(wiki_page.body).grep(/\Alist_of_/i) + other_wikis = DText.parse_wiki_titles(wiki_page&.body&.to_s).grep(/\Alist_of_/i) other_wikis = other_wikis.map { |name| WikiPage.titled(name).first } other_wikis = other_wikis.select { |wiki| wiki.tags.present? } other_wikis diff --git a/test/functional/related_tags_controller_test.rb b/test/functional/related_tags_controller_test.rb index 4b0c2c81a..dded86b0e 100644 --- a/test/functional/related_tags_controller_test.rb +++ b/test/functional/related_tags_controller_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class RelatedTagsControllerTest < ActionDispatch::IntegrationTest context "The related tags controller" do setup do - create(:post, tag_string: "touhou") + create(:post, tag_string: "copy:touhou") end context "show action" do @@ -16,6 +16,11 @@ class RelatedTagsControllerTest < ActionDispatch::IntegrationTest get related_tag_path(format: :json), params: { query: "touhou" } assert_response :success end + + should "work for .js responses for copyright tags without a wiki" do + get related_tag_path(format: :js), params: { query: "touhou" }, xhr: true + assert_response :success + end end end end