BURs: fix remove alias command removing inactive aliases.

Fix the `remove alias` and `remove implication` commands to only remove
active aliases or implications, not pending/deleted/retired ones.
This commit is contained in:
evazion
2019-01-03 16:30:39 -06:00
parent 82b09860f2
commit 886096b47a
2 changed files with 12 additions and 5 deletions

View File

@@ -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)

View File

@@ -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