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:
@@ -5,7 +5,7 @@ class TagAlias < TagRelationship
|
|||||||
after_save :create_mod_action
|
after_save :create_mod_action
|
||||||
validates_uniqueness_of :antecedent_name
|
validates_uniqueness_of :antecedent_name
|
||||||
validate :absence_of_transitive_relation
|
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
|
validate :mininum_antecedent_count, on: :create, unless: :skip_secondary_validations
|
||||||
|
|
||||||
module CacheMethods
|
module CacheMethods
|
||||||
@@ -195,8 +195,10 @@ class TagAlias < TagRelationship
|
|||||||
destroy
|
destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def consequent_has_wiki_page
|
def wiki_pages_present
|
||||||
if consequent_wiki.nil?
|
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"
|
errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,6 +42,25 @@ class TagAliasTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should_not allow_value(nil).for(:creator_id)
|
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_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
|
end
|
||||||
|
|
||||||
should "populate the creator information" do
|
should "populate the creator information" do
|
||||||
|
|||||||
Reference in New Issue
Block a user