[Tag Aliases] Don't update locked tag categories on alias approval.

This commit is contained in:
Kira 2021-02-28 13:30:28 -08:00
parent 9da8e1b1ad
commit 9c6939c302
2 changed files with 11 additions and 35 deletions

View File

@ -248,6 +248,7 @@ class TagAlias < TagRelationship
end
def ensure_category_consistency
return if consequent_tag.is_locked? # Prevent accidentally changing tag type if category locked.
if antecedent_tag.category != consequent_tag.category && antecedent_tag.category != Tag.categories.general
consequent_tag.update_attribute(:category, antecedent_tag.category)
end

View File

@ -78,19 +78,6 @@ class TagAliasTest < ActiveSupport::TestCase
end
end
context "#update_notice" do
setup do
@mock_redis = MockRedis.new
@forum_topic = FactoryBot.create(:forum_topic)
TagChangeNoticeService.stubs(:redis_client).returns(@mock_redis)
end
should "update redis" do
FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", forum_topic: @forum_topic)
assert_equal(@forum_topic.id.to_s, @mock_redis.get("tcn:aaa"))
end
end
should "populate the creator information" do
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
assert_equal(CurrentUser.user.id, ta.creator_id)
@ -105,7 +92,7 @@ class TagAliasTest < ActiveSupport::TestCase
assert_equal(["bbb"], TagAlias.to_aliased("aaa".mb_chars))
assert_equal(["bbb", "ccc"], TagAlias.to_aliased(["aaa", "ccc"]))
assert_equal(["ccc", "bbb"], TagAlias.to_aliased(["ccc", "bbb"]))
assert_equal(["bbb", "bbb"], TagAlias.to_aliased(["aaa", "aaa"]))
assert_equal(["bbb"], TagAlias.to_aliased(["aaa", "aaa"]))
end
should "update any affected posts when saved" do
@ -164,6 +151,15 @@ class TagAliasTest < ActiveSupport::TestCase
assert_equal(1, tag2.reload.category)
end
should "not push the antecedent's category if the consequent is locked" do
tag1 = FactoryBot.create(:tag, name: "aaa", category: 1)
tag2 = FactoryBot.create(:tag, name: "bbb", category: 3, is_locked: true)
ta = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
ta.approve!(approver: @admin)
assert_equal(3, tag2.reload.category)
end
context "with an associated forum topic" do
setup do
@admin = FactoryBot.create(:admin_user)
@ -174,27 +170,6 @@ class TagAliasTest < ActiveSupport::TestCase
end
end
context "and conflicting wiki pages" do
setup do
CurrentUser.scoped(@admin) do
@wiki1 = FactoryBot.create(:wiki_page, :title => "aaa")
@wiki2 = FactoryBot.create(:wiki_page, :title => "bbb")
@alias.approve!(approver: @admin)
end
@admin.reload # reload to get the forum post the approval created.
@topic.reload
end
should "update the forum topic when approved" do
assert_equal("[APPROVED] Tag alias: aaa -> bbb", @topic.title)
assert_match(/The tag alias .* been approved/m, @topic.posts[-2].body)
end
should "warn about conflicting wiki pages when approved" do
assert_match(/has conflicting wiki pages/m, @topic.posts[-1].body)
end
end
should "update the topic when processed" do
assert_difference("ForumPost.count") do
@alias.approve!(approver: @admin)