aliases/implications: allow duplicate inactive aliases/implications.
Allow multiple pending, deleted or retired aliases/implications for the same tag. This is so that deleted or retired aliases can be resubmitted as new pending requests.
This commit is contained in:
@@ -3,7 +3,7 @@ class TagAlias < TagRelationship
|
||||
after_destroy :clear_all_cache
|
||||
after_save :clear_all_cache, if: ->(rec) {rec.is_retired?}
|
||||
after_save :create_mod_action
|
||||
validates_uniqueness_of :antecedent_name
|
||||
validates_uniqueness_of :antecedent_name, scope: :status, conditions: -> { active }
|
||||
validate :absence_of_transitive_relation
|
||||
validate :wiki_pages_present, on: :create, unless: :skip_secondary_validations
|
||||
validate :mininum_antecedent_count, on: :create, unless: :skip_secondary_validations
|
||||
|
||||
@@ -7,7 +7,7 @@ class TagImplication < TagRelationship
|
||||
after_save :update_descendant_names_for_parents
|
||||
after_destroy :update_descendant_names_for_parents
|
||||
after_save :create_mod_action
|
||||
validates_uniqueness_of :antecedent_name, :scope => :consequent_name
|
||||
validates_uniqueness_of :antecedent_name, scope: [:consequent_name, :status], conditions: -> { active }
|
||||
validate :absence_of_circular_relation
|
||||
validate :absence_of_transitive_relation
|
||||
validate :antecedent_is_not_aliased
|
||||
|
||||
@@ -44,6 +44,18 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
|
||||
should_not allow_value(nil).for(:creator_id)
|
||||
should_not allow_value(-1).for(:creator_id).with_message("must exist", against: :creator)
|
||||
|
||||
should "not allow duplicate active aliases" do
|
||||
ta1 = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "active")
|
||||
ta2 = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "retired")
|
||||
ta3 = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "deleted")
|
||||
ta4 = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "deleted")
|
||||
ta5 = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "pending")
|
||||
[ta1, ta2, ta3, ta4, ta5].each { |ta| assert(ta.valid?) }
|
||||
|
||||
ta5.update(status: "active")
|
||||
assert_includes(ta5.errors[:antecedent_name], "has already been taken")
|
||||
end
|
||||
end
|
||||
|
||||
context "on secondary validation" do
|
||||
|
||||
@@ -40,6 +40,18 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
|
||||
should_not allow_value(nil).for(:creator_id)
|
||||
should_not allow_value(-1).for(:creator_id).with_message("must exist", against: :creator)
|
||||
|
||||
should "not allow duplicate active implications" do
|
||||
ti1 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "active")
|
||||
ti2 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "retired")
|
||||
ti3 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "deleted")
|
||||
ti4 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "deleted")
|
||||
ti5 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "pending")
|
||||
[ti1, ti2, ti3, ti4, ti5].each { |ti| assert(ti.valid?) }
|
||||
|
||||
ti5.update(status: "active")
|
||||
assert_includes(ti5.errors[:antecedent_name], "has already been taken")
|
||||
end
|
||||
end
|
||||
|
||||
context "on secondary validation" do
|
||||
|
||||
Reference in New Issue
Block a user