A platform for community discussion. Free, open, simple.
FIX: replace default welcome topic post with new value from wizard
Neil Lalonde90fcede832f0
diff --git a/lib/introduction_updater.rb b/lib/introduction_updater.rbindex b6c1a459664..dc2ffbe3a5c 100644--- a/lib/introduction_updater.rb+++ b/lib/introduction_updater.rb@@ -18,9 +18,12 @@ class IntroductionUpdaterif previous_value != new_valuerevisor = 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}")+ endendenddiff --git a/spec/lib/introduction_updater_spec.rb b/spec/lib/introduction_updater_spec.rbindex 66f91a6341f..49698e56e05 100644--- a/spec/lib/introduction_updater_spec.rb+++ b/spec/lib/introduction_updater_spec.rb@@ -55,4 +55,42 @@ describe IntroductionUpdater doendendend++ 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+ endend