diff --git a/app/logical/alias_and_implication_importer.rb b/app/logical/alias_and_implication_importer.rb index a5e720a70..6bd599e90 100644 --- a/app/logical/alias_and_implication_importer.rb +++ b/app/logical/alias_and_implication_importer.rb @@ -102,12 +102,12 @@ private when :remove_alias tag_alias = TagAlias.where("antecedent_name = ?", token[1]).first raise Error, "Alias for #{token[1]} not found" if tag_alias.nil? - tag_alias.destroy + tag_alias.reject!(update_topic: false) when :remove_implication tag_implication = TagImplication.where("antecedent_name = ? and consequent_name = ?", token[1], token[2]).first raise Error, "Implication for #{token[1]} not found" if tag_implication.nil? - tag_implication.destroy + tag_implication.reject!(update_topic: false) when :mass_update Delayed::Job.enqueue(Moderator::TagBatchChange.new(token[1], token[2], CurrentUser.id, CurrentUser.ip_addr), :queue => "default") diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 000f616bf..7db5d7fa2 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -188,11 +188,10 @@ class TagAlias < TagRelationship end end - def reject! + def reject!(update_topic: true) update(status: "deleted") clear_all_cache - forum_updater.update(reject_message(CurrentUser.user), "REJECTED") - destroy + forum_updater.update(reject_message(CurrentUser.user), "REJECTED") if update_topic end def wiki_pages_present diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 463387046..2f0d1a50b 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -169,10 +169,9 @@ class TagImplication < TagRelationship delay(:queue => "default").process!(update_topic: update_topic) end - def reject! + def reject!(update_topic: true) update(status: "deleted") - forum_updater.update(reject_message(CurrentUser.user), "REJECTED") - destroy + forum_updater.update(reject_message(CurrentUser.user), "REJECTED") if update_topic end def create_mod_action diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index a33e045f2..d5f3ae289 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -16,6 +16,7 @@ class TagRelationship < ApplicationRecord has_one :consequent_wiki, through: :consequent_tag, source: :wiki_page scope :active, ->{where(status: "active")} + scope :deleted, ->{where(status: "deleted")} scope :expired, ->{where("created_at < ?", EXPIRY.days.ago)} scope :old, ->{where("created_at >= ? and created_at < ?", EXPIRY.days.ago, EXPIRY_WARNING.days.ago)} scope :pending, ->{where(status: "pending")} diff --git a/app/views/tag_aliases/destroy.js.erb b/app/views/tag_aliases/destroy.js.erb index 478611344..345366b9b 100644 --- a/app/views/tag_aliases/destroy.js.erb +++ b/app/views/tag_aliases/destroy.js.erb @@ -1 +1 @@ -$("#tag-alias-<%= @tag_alias.id %>").remove(); +location.reload(); diff --git a/app/views/tag_implications/destroy.js.erb b/app/views/tag_implications/destroy.js.erb index f99b2b043..345366b9b 100644 --- a/app/views/tag_implications/destroy.js.erb +++ b/app/views/tag_implications/destroy.js.erb @@ -1 +1 @@ -$("#tag-implication-<%= @tag_implication.id %>").remove(); +location.reload(); diff --git a/test/unit/alias_and_implication_importer_test.rb b/test/unit/alias_and_implication_importer_test.rb index 1d0e07678..01954912b 100644 --- a/test/unit/alias_and_implication_importer_test.rb +++ b/test/unit/alias_and_implication_importer_test.rb @@ -75,5 +75,32 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase assert_equal("bbb", artist.name) assert_equal("testing", artist.notes) end + + context "remove alias and remove implication commands" do + setup do + @ta = FactoryBot.create(:tag_alias, antecedent_name: "a", consequent_name: "b", status: "active") + @ti = FactoryBot.create(:tag_implication, antecedent_name: "c", consequent_name: "d", status: "active") + @script = %{ + remove alias a -> b + remove implication c -> d + } + end + + should "set aliases and implications as deleted" do + @importer = AliasAndImplicationImporter.new(@script, nil) + @importer.process! + + assert_equal("deleted", @ta.reload.status) + assert_equal("deleted", @ti.reload.status) + end + + should "create modactions for each removal" do + @importer = AliasAndImplicationImporter.new(@script, nil) + + assert_difference(-> { ModAction.count }, 2) do + @importer.process! + end + end + end end end