FIX: replace default welcome topic post with new value from wizard

FIX: replace default welcome topic post with new value from wizard

Previously the text entered in the wizard would be prepended onto the default first paragraph.

diff --git a/lib/introduction_updater.rb b/lib/introduction_updater.rb
index b6c1a45..dc2ffbe 100644
--- a/lib/introduction_updater.rb
+++ b/lib/introduction_updater.rb
@@ -18,9 +18,12 @@ class IntroductionUpdater
 
     if previous_value != new_value
       revisor = PostRevisor.new(post)
-
-      remaining = post.raw.split("\n")[1..-1]
-      revisor.revise!(@user, raw: "#{new_value}\n#{remaining.join("\n")}")
+      if post.raw.chomp == I18n.t('discourse_welcome_topic.body', base_path: Discourse.base_path).chomp
+        revisor.revise!(@user, raw: new_value)
+      else
+        remaining = post.raw[previous_value.length..-1]
+        revisor.revise!(@user, raw: "#{new_value}#{remaining}")
+      end
     end
   end
 
diff --git a/spec/lib/introduction_updater_spec.rb b/spec/lib/introduction_updater_spec.rb
index 66f91a6..49698e5 100644
--- a/spec/lib/introduction_updater_spec.rb
+++ b/spec/lib/introduction_updater_spec.rb
@@ -55,4 +55,42 @@ describe IntroductionUpdater do
       end
     end
   end
+
+  describe "update_summary" do
+    let(:welcome_topic) do
+      topic = Fabricate(:topic, title: I18n.t("discourse_welcome_topic.title"))
+      Fabricate(
+        :post,
+        topic: topic,
+        raw: I18n.t("discourse_welcome_topic.body", base_path: Discourse.base_path),
+        post_number: 1
+      )
+      topic
+    end
+
+    let(:first_post) { welcome_topic.posts.first }
+
+    let(:new_summary) { "Welcome to my new site. It's gonna be good." }
+
+    subject { IntroductionUpdater.new(Fabricate(:admin)).update_summary(new_summary) }
+
+    before do
+      SiteSetting.welcome_topic_id = welcome_topic.id
+    end
+
+    it "completely replaces post if it has default value" do
+      subject
+      expect {
+        expect(first_post.reload.raw).to eq(new_summary)
+      }.to_not change { welcome_topic.reload.category_id }
+    end
+
+    it "only replaces first paragraph if it has custom content" do
+      paragraph1 = "This is the summary of my community"
+      paragraph2 = "And this is something I added later"
+      first_post.update!(raw: [paragraph1, paragraph2].join("\n\n"))
+      subject
+      expect(first_post.reload.raw).to eq([new_summary, paragraph2].join("\n\n"))
+    end
+  end
 end

GitHub sha: 90fcede8