diff --git a/app/logical/bulk_update_request_processor.rb b/app/logical/bulk_update_request_processor.rb index af8536637..332155f95 100644 --- a/app/logical/bulk_update_request_processor.rb +++ b/app/logical/bulk_update_request_processor.rb @@ -1,4 +1,6 @@ class BulkUpdateRequestProcessor + MAXIMUM_RENAME_COUNT = 200 + include ActiveModel::Validations class Error < StandardError; end @@ -87,6 +89,8 @@ class BulkUpdateRequestProcessor tag = Tag.find_by_name(args[0]) if tag.nil? errors[:base] << "Can't rename #{args[0]} -> #{args[1]} (the '#{args[0]}' tag doesn't exist)" + elsif tag.post_count > MAXIMUM_RENAME_COUNT + errors[:base] << "Can't rename #{args[0]} -> #{args[1]} ('#{args[0]}' has more than #{MAXIMUM_RENAME_COUNT} posts, use an alias instead)" end when :mass_update, :nuke diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index fd063f875..bbba6aae0 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -265,6 +265,14 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase assert_equal(["Can't rename aaa -> bbb (the 'aaa' tag doesn't exist)"], @bur.errors.full_messages) end + should "fail if the old tag has more than 200 posts" do + create(:tag, name: "aaa", post_count: 1000) + @bur = build(:bulk_update_request, script: "rename aaa -> bbb") + + assert_equal(false, @bur.valid?) + assert_equal(["Can't rename aaa -> bbb ('aaa' has more than 200 posts, use an alias instead)"], @bur.errors.full_messages) + end + context "when renaming a character tag with a *_(cosplay) tag" do should "move the *_(cosplay) tag as well" do @post = create(:post, tag_string: "toosaka_rin_(cosplay)")