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:
parent
b82f6098ce
commit
90fcede832
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue