From 2e6486ab5f4e8117aad6bc719c1856adbb464a61 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 10 Dec 2019 15:17:10 -0600 Subject: [PATCH] BURs: fix exception in category change requests for new tags. `category blah -> character` failed when `blah` didn't exist yet. --- app/logical/alias_and_implication_importer.rb | 2 +- test/unit/bulk_update_request_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/logical/alias_and_implication_importer.rb b/app/logical/alias_and_implication_importer.rb index 7290f895d..25793320d 100644 --- a/app/logical/alias_and_implication_importer.rb +++ b/app/logical/alias_and_implication_importer.rb @@ -155,7 +155,7 @@ private TagBatchChangeJob.perform_later(token[1], token[2], User.system, "127.0.0.1") when :change_category - tag = Tag.find_by_name(token[1]) + tag = Tag.find_or_create_by_name(token[1]) tag.category = Tag.categories.value_for(token[2]) tag.save diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 44c473a28..30ecf6752 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -160,6 +160,14 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase assert_equal(Tag.categories.meta, tag.reload.category) end + + should "work for a new tag" do + bur = FactoryBot.create(:bulk_update_request, :script => "category new_tag -> meta") + bur.approve!(@admin) + + assert_not_nil(Tag.find_by_name("new_tag")) + assert_equal(Tag.categories.meta, Tag.find_by_name("new_tag").category) + end end context "with an associated forum topic" do