From 555f96006787448d98a99b0b10d670da2f537d63 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 21 May 2015 12:57:10 -0700 Subject: [PATCH] fixes #2378 --- app/models/tag_alias.rb | 24 +++++++++++++++++++----- test/unit/tag_alias_test.rb | 13 +++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index bf6703c1a..3e2841ca7 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -198,11 +198,15 @@ class TagAlias < ActiveRecord::Base def rename_wiki_and_artist antecedent_wiki = WikiPage.titled(antecedent_name).first - if antecedent_wiki.present? && WikiPage.titled(consequent_name).blank? - CurrentUser.scoped(creator, creator_ip_addr) do - antecedent_wiki.update_attributes( - :title => consequent_name - ) + if antecedent_wiki.present? + if WikiPage.titled(consequent_name).blank? + CurrentUser.scoped(creator, creator_ip_addr) do + antecedent_wiki.update_attributes( + :title => consequent_name + ) + end + else + update_forum_topic_for_wiki_conflict end end @@ -249,6 +253,16 @@ class TagAlias < ActiveRecord::Base end end + def update_forum_topic_for_wiki_conflict + if forum_topic + CurrentUser.scoped(User.admins.first, "127.0.0.1") do + forum_topic.posts.create( + :body => "The tag alias [[#{antecedent_name}]] -> [[#{consequent_name}]] has conflicting wiki pages. [[#{consequent_name}]] should be updated to include information from [[#{antecedent_name}]] if necessary." + ) + end + end + end + def reject! update_column(:status, "deleted") clear_all_cache diff --git a/test/unit/tag_alias_test.rb b/test/unit/tag_alias_test.rb index 9a6f43649..6d945dbd3 100644 --- a/test/unit/tag_alias_test.rb +++ b/test/unit/tag_alias_test.rb @@ -99,6 +99,19 @@ class TagAliasTest < ActiveSupport::TestCase @alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic) end + context "and conflicting wiki pages" do + setup do + @wiki1 = FactoryGirl.create(:wiki_page, :title => "aaa") + @wiki2 = FactoryGirl.create(:wiki_page, :title => "bbb") + end + + should "update the topic when processed" do + assert_difference("ForumPost.count") do + @alias.rename_wiki_and_artist + end + end + end + should "update the topic when processed" do assert_difference("ForumPost.count") do @alias.process!