aliases: warn about conflicting wikis when alias is requested.

* Warn about conflicting wiki pages during secondary validation.

* Only warn about missing wiki if both tags are missing a wiki page.
This commit is contained in:
evazion
2018-12-26 17:30:07 -06:00
parent 365e04b5f9
commit 719f556dd5
2 changed files with 24 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ class TagAlias < TagRelationship
after_save :create_mod_action
validates_uniqueness_of :antecedent_name
validate :absence_of_transitive_relation
validate :consequent_has_wiki_page, on: :create, unless: :skip_secondary_validations
validate :wiki_pages_present, on: :create, unless: :skip_secondary_validations
validate :mininum_antecedent_count, on: :create, unless: :skip_secondary_validations
module CacheMethods
@@ -195,8 +195,10 @@ class TagAlias < TagRelationship
destroy
end
def consequent_has_wiki_page
if consequent_wiki.nil?
def wiki_pages_present
if antecedent_wiki.present? && consequent_wiki.present?
errors[:base] << conflict_message
elsif antecedent_wiki.blank? && consequent_wiki.blank?
errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page"
end
end

View File

@@ -42,6 +42,25 @@ 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)
end
context "on secondary validation" do
should "warn about missing wiki pages" do
ti = FactoryBot.build(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", skip_secondary_validations: false)
assert(ti.invalid?)
assert_includes(ti.errors[:base], "The bbb tag needs a corresponding wiki page")
end
should "warn about conflicting wiki pages" do
FactoryBot.create(:wiki_page, title: "aaa", body: "aaa")
FactoryBot.create(:wiki_page, title: "bbb", body: "bbb")
ti = FactoryBot.build(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", skip_secondary_validations: false)
assert(ti.invalid?)
assert_includes(ti.errors[:base], "The tag alias [[aaa]] -> [[bbb]] has conflicting wiki pages. [[bbb]] should be updated to include information from [[aaa]] if necessary.")
end
end
should "populate the creator information" do