BURs: fix normalization of uppercase characters in scripts.

Only downcase tags in aliases, implications, and category change
commands. Don't downcase mass update commands. Mass updates are
potentially case sensitive (for example: `mass update source:imageboard -> source:Imageboard`).
This commit is contained in:
evazion
2020-08-24 17:54:53 -05:00
parent 1ddcc661e1
commit d9085877be
3 changed files with 25 additions and 14 deletions

View File

@@ -19,17 +19,17 @@ class BulkUpdateRequestProcessor
case line
when /\A(?:create alias|aliasing|alias) (\S+) -> (\S+)\z/i
[:create_alias, $1, $2]
[:create_alias, Tag.normalize_name($1), Tag.normalize_name($2)]
when /\A(?:create implication|implicating|implicate|imply) (\S+) -> (\S+)\z/i
[:create_implication, $1, $2]
[:create_implication, Tag.normalize_name($1), Tag.normalize_name($2)]
when /\A(?:remove alias|unaliasing|unalias) (\S+) -> (\S+)\z/i
[:remove_alias, $1, $2]
[:remove_alias, Tag.normalize_name($1), Tag.normalize_name($2)]
when /\A(?:remove implication|unimplicating|unimplicate|unimply) (\S+) -> (\S+)\z/i
[:remove_implication, $1, $2]
[:remove_implication, Tag.normalize_name($1), Tag.normalize_name($2)]
when /\A(?:mass update|updating|update|change) (.+?) -> (.*)\z/i
[:mass_update, $1, $2]
when /\Acategory (\S+) -> (#{Tag.categories.regexp})\z/i
[:change_category, $1, $2]
[:change_category, Tag.normalize_name($1), $2.downcase]
else
[:invalid_line, line]
end

View File

@@ -8,7 +8,6 @@ class BulkUpdateRequest < ApplicationRecord
belongs_to :forum_post, optional: true
belongs_to :approver, optional: true, class_name: "User"
before_validation :normalize_text
validates_presence_of :reason, on: :create
validates_presence_of :script
validates_presence_of :title, if: ->(rec) {rec.forum_topic_id.blank?}
@@ -117,10 +116,6 @@ class BulkUpdateRequest < ApplicationRecord
extend SearchMethods
include ApprovalMethods
def normalize_text
self.script = script.downcase
end
def update_tags
self.tags = processor.affected_tags
end

View File

@@ -65,6 +65,16 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal(false, @bur.valid?)
assert_equal(["Can't create alias bbb -> aaa (A tag alias for aaa already exists)"], @bur.errors.full_messages)
end
should "be case-insensitive" do
@bur = create(:bulk_update_request, script: "CREATE ALIAS AAA -> BBB")
@bur.approve!(@admin)
perform_enqueued_jobs
@alias = TagAlias.find_by(antecedent_name: "aaa", consequent_name: "bbb")
assert_equal(true, @alias.present?)
assert_equal(true, @alias.is_active?)
end
end
context "the create implication command" do
@@ -161,6 +171,16 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
should "update the tags" do
assert_equal("bar", @post.reload.tag_string)
end
should "be case-sensitive" do
@post = create(:post, source: "imageboard")
@bur = create(:bulk_update_request, script: "mass update source:imageboard -> source:Imageboard")
@bur.approve!(@admin)
perform_enqueued_jobs
assert_equal("Imageboard", @post.reload.source)
end
end
end
@@ -294,10 +314,6 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal("pending", @req.status)
end
should "downcase the text" do
assert_equal("create alias aaa -> bbb", @req.script)
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@req.approve!(@admin)