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.
This commit is contained in:
Neil Lalonde
2020-04-01 15:42:36 -04:00
parent b82f6098ce
commit 90fcede832
2 changed files with 44 additions and 3 deletions

View File

@ -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