Fix #3937: Blank lines in tagbox if certain taggroups are absent
This commit is contained in:
@@ -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: "")
|
||||
|
||||
27
test/unit/tag_set_presenter_test.rb
Normal file
27
test/unit/tag_set_presenter_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user