mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: Wizard tries harder to find existing Welcome Topic
The wizard searches for: * a topic that with the "is_welcome_topic" custom field * a topic with the correct slug for the current default locale * a topic with the correct slug for the English locale * the oldest globally pinned topic It gives up if it didn't find any of the above.
This commit is contained in:
56
spec/lib/introduction_updater_spec.rb
Normal file
56
spec/lib/introduction_updater_spec.rb
Normal file
@ -0,0 +1,56 @@
|
||||
require 'rails_helper'
|
||||
require 'introduction_updater'
|
||||
|
||||
describe IntroductionUpdater do
|
||||
describe "#get_summary" do
|
||||
subject { IntroductionUpdater.new(Fabricate(:admin)) }
|
||||
|
||||
let(:welcome_post_raw) { "lorem ipsum" }
|
||||
let(:welcome_topic) do
|
||||
topic = Fabricate(:topic)
|
||||
Fabricate(:post, topic: topic, raw: welcome_post_raw, post_number: 1)
|
||||
topic
|
||||
end
|
||||
|
||||
it "finds the welcome topic by custom field" do
|
||||
TopicCustomField.create(topic_id: welcome_topic.id, name: "is_welcome_topic", value: "true")
|
||||
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||
end
|
||||
|
||||
context "without custom field" do
|
||||
it "finds the welcome topic by slug using the default locale" do
|
||||
I18n.locale = :de
|
||||
welcome_topic.title = I18n.t("discourse_welcome_topic.title")
|
||||
welcome_topic.save!
|
||||
|
||||
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||
end
|
||||
|
||||
it "finds the welcome topic by slug using the English locale" do
|
||||
welcome_topic.title = I18n.t("discourse_welcome_topic.title", locale: :en)
|
||||
welcome_topic.save!
|
||||
I18n.locale = :de
|
||||
|
||||
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||
end
|
||||
|
||||
it "doesn't find the topic when slug_generation_method is set to 'none'" do
|
||||
SiteSetting.slug_generation_method = :none
|
||||
welcome_topic.title = I18n.t("discourse_welcome_topic.title")
|
||||
welcome_topic.save!
|
||||
|
||||
expect(subject.get_summary).to be_blank
|
||||
end
|
||||
|
||||
it "finds the oldest globally pinned topic" do
|
||||
welcome_topic.update_columns(pinned_at: Time.zone.now, pinned_globally: true)
|
||||
|
||||
expect(subject.get_summary).to eq(welcome_post_raw)
|
||||
end
|
||||
|
||||
it "doesn't find the topic when there is no globally pinned topic or a topic with the correct slug" do
|
||||
expect(subject.get_summary).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user