diff --git a/app/logical/alias_and_implication_importer.rb b/app/logical/alias_and_implication_importer.rb index 6bd599e90..86320e9cd 100644 --- a/app/logical/alias_and_implication_importer.rb +++ b/app/logical/alias_and_implication_importer.rb @@ -100,12 +100,12 @@ private tag_implication.approve!(approver: approver, update_topic: false) when :remove_alias - tag_alias = TagAlias.where("antecedent_name = ?", token[1]).first + tag_alias = TagAlias.active.find_by(antecedent_name: token[1], consequent_name: token[2]) raise Error, "Alias for #{token[1]} not found" if tag_alias.nil? tag_alias.reject!(update_topic: false) when :remove_implication - tag_implication = TagImplication.where("antecedent_name = ? and consequent_name = ?", token[1], token[2]).first + tag_implication = TagImplication.active.find_by(antecedent_name: token[1], consequent_name: token[2]) raise Error, "Implication for #{token[1]} not found" if tag_implication.nil? tag_implication.reject!(update_topic: false) diff --git a/test/unit/alias_and_implication_importer_test.rb b/test/unit/alias_and_implication_importer_test.rb index 01954912b..b7a371f7b 100644 --- a/test/unit/alias_and_implication_importer_test.rb +++ b/test/unit/alias_and_implication_importer_test.rb @@ -84,10 +84,10 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase remove alias a -> b remove implication c -> d } + @importer = AliasAndImplicationImporter.new(@script, nil) end should "set aliases and implications as deleted" do - @importer = AliasAndImplicationImporter.new(@script, nil) @importer.process! assert_equal("deleted", @ta.reload.status) @@ -95,12 +95,19 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase end should "create modactions for each removal" do - @importer = AliasAndImplicationImporter.new(@script, nil) - assert_difference(-> { ModAction.count }, 2) do @importer.process! end end + + should "only remove active aliases and implications" do + @ta2 = FactoryBot.create(:tag_alias, antecedent_name: "a", consequent_name: "b", status: "pending") + @ti2 = FactoryBot.create(:tag_implication, antecedent_name: "c", consequent_name: "d", status: "pending") + + @importer.process! + assert_equal("pending", @ta2.reload.status) + assert_equal("pending", @ti2.reload.status) + end end end end