Fix #3937: Blank lines in tagbox if certain taggroups are absent

This commit is contained in:
evazion
2018-10-01 19:47:39 -05:00
parent eeadd1ef11
commit 0c5452cdc3
2 changed files with 28 additions and 1 deletions

View File

@@ -58,7 +58,7 @@ class TagSetPresenter < Presenter
def split_tag_list_text(category_list: TagCategory.categorized_list)
category_list.map do |category|
tags_for_category(category).map(&:name).join(" ")
end.join(" \n")
end.reject(&:blank?).join(" \n")
end
def humanized_essential_tag_string(category_list: TagCategory.humanized_list, default: "")

View File

@@ -0,0 +1,27 @@
require 'test_helper'
class TagSetPresenterTest < ActiveSupport::TestCase
context "TagSetPresenter" do
setup do
FactoryBot.create(:tag, name: "bkub", category: Tag.categories.artist)
FactoryBot.create(:tag, name: "chen", category: Tag.categories.character)
FactoryBot.create(:tag, name: "cirno", category: Tag.categories.character)
FactoryBot.create(:tag, name: "solo", category: Tag.categories.general)
FactoryBot.create(:tag, name: "touhou", category: Tag.categories.copyright)
@categories = %w[copyright character artist meta general]
end
context "#split_tag_list_text method" do
should "list all categories in order" do
text = TagSetPresenter.new(%w[bkub chen cirno solo touhou]).split_tag_list_text(category_list: @categories)
assert_equal("touhou \nchen cirno \nbkub \nsolo", text)
end
should "skip empty categories" do
text = TagSetPresenter.new(%w[bkub solo]).split_tag_list_text(category_list: @categories)
assert_equal("bkub \nsolo", text)
end
end
end
end