Add ability to mark tags as deprecated
* Deprecated tags can't be added to posts, but existing deprecated tags in a post won't be removed * Only empty tags can be marked as deprecated manually * No tags can be manually undeprecated ** These limits don't apply to admins * Deprecating or undeprecating a tag will create a new mod action to prevent people from going rogue * Added deprecate/undeprecate commands for BURs * Deprecating a tag via BUR removes all implications to and from it as well
This commit is contained in:
@@ -119,6 +119,51 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
context "for deprecation" do
|
||||
setup do
|
||||
@deprecated_tag = create(:tag, name: "bad_tag", category: Tag.categories.general, post_count: 0, is_deprecated: true)
|
||||
@nondeprecated_tag = create(:tag, name: "log", category: Tag.categories.general, post_count: 0)
|
||||
@normal_tag = create(:tag, name: "random", category: Tag.categories.general, post_count: 1000)
|
||||
@normal_user = create(:user)
|
||||
@admin = create(:admin_user)
|
||||
end
|
||||
|
||||
should "not remove deprecated status if the user is not an admin" do
|
||||
put_auth tag_path(@deprecated_tag), @normal_user, params: {tag: { is_deprecated: false }}
|
||||
|
||||
assert_response 403
|
||||
assert(true, @deprecated_tag.reload.is_deprecated?)
|
||||
end
|
||||
|
||||
should "remove the deprecated status if the user is admin" do
|
||||
put_auth tag_path(@deprecated_tag), @admin, params: {tag: { is_deprecated: false }}
|
||||
|
||||
assert_redirected_to @deprecated_tag
|
||||
assert(false, @deprecated_tag.reload.is_deprecated?)
|
||||
end
|
||||
|
||||
should "allow marking a tag as deprecated if it's empty" do
|
||||
put_auth tag_path(@nondeprecated_tag), @normal_user, params: {tag: { is_deprecated: true }}
|
||||
|
||||
assert_redirected_to @nondeprecated_tag
|
||||
assert(true, @nondeprecated_tag.reload.is_deprecated?)
|
||||
end
|
||||
|
||||
should "not allow marking a tag as deprecated if it's not empty" do
|
||||
put_auth tag_path(@normal_tag), @normal_user, params: {tag: { is_deprecated: true }}
|
||||
|
||||
assert_response 403
|
||||
assert(false, @normal_tag.reload.is_deprecated?)
|
||||
end
|
||||
|
||||
should "allow admins to mark tags as deprecated" do
|
||||
put_auth tag_path(@normal_tag), @admin, params: {tag: { is_deprecated: true }}
|
||||
|
||||
assert_redirected_to @normal_tag
|
||||
assert(true, @normal_tag.reload.is_deprecated?)
|
||||
end
|
||||
end
|
||||
|
||||
should "not change category when the tag is too large to be changed by a builder" do
|
||||
@tag.update(category: Tag.categories.general, post_count: 1001)
|
||||
put_auth tag_path(@tag), @user, params: {:tag => {:category => Tag.categories.artist}}
|
||||
|
||||
@@ -446,6 +446,34 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "the deprecate command" do
|
||||
should "deprecate the tag" do
|
||||
@tag = create(:tag, name: "silver_hair")
|
||||
@bur = create_bur!("deprecate silver_hair", @admin)
|
||||
|
||||
assert_equal(true, @tag.reload.is_deprecated?)
|
||||
end
|
||||
|
||||
should "remove implications" do
|
||||
@ti1 = create(:tag_implication, antecedent_name: "silver_hair", consequent_name: "old_woman")
|
||||
@ti2 = create(:tag_implication, antecedent_name: "my_literal_dog", consequent_name: "silver_hair")
|
||||
@bur = create_bur!("deprecate silver_hair", @admin)
|
||||
|
||||
assert_equal("deleted", @ti1.reload.status)
|
||||
assert_equal("deleted", @ti2.reload.status)
|
||||
assert_equal("approved", @bur.reload.status)
|
||||
end
|
||||
end
|
||||
|
||||
context "the undeprecate command" do
|
||||
should "undeprecate the tag" do
|
||||
@tag = create(:tag, name: "silver_hair", is_deprecated: true)
|
||||
@bur = create_bur!("undeprecate silver_hair", @admin)
|
||||
|
||||
assert_equal(false, @tag.reload.is_deprecated?)
|
||||
end
|
||||
end
|
||||
|
||||
context "that contains a mass update followed by an alias" do
|
||||
should "make the alias take effect after the mass update" do
|
||||
@p1 = create(:post, tag_string: "maid_dress")
|
||||
|
||||
@@ -479,6 +479,23 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "tagged with a deprecated tag" do
|
||||
should "not remove the tag if the tag was already in the post" do
|
||||
bad_tag = create(:tag, name: "bad_tag")
|
||||
old_post = FactoryBot.create(:post, tag_string: "bad_tag")
|
||||
bad_tag.update!(is_deprecated: true)
|
||||
old_post.update!(tag_string: "asd bad_tag")
|
||||
assert_equal("asd bad_tag", old_post.reload.tag_string)
|
||||
|
||||
end
|
||||
|
||||
should "not add the tag if it is being added" do
|
||||
create(:tag, name: "a_bad_tag", is_deprecated: true)
|
||||
@post.update!(tag_string: "asd a_bad_tag")
|
||||
assert_equal("asd", @post.reload.tag_string)
|
||||
end
|
||||
end
|
||||
|
||||
context "tagged with a metatag" do
|
||||
context "for typing a tag" do
|
||||
setup do
|
||||
|
||||
Reference in New Issue
Block a user