2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-25 13:14:56 -04:00
|
|
|
require 'rails_helper'
|
2016-09-09 16:51:07 -04:00
|
|
|
require_dependency 'wizard'
|
|
|
|
require_dependency 'wizard/builder'
|
2016-08-25 13:14:56 -04:00
|
|
|
require_dependency 'wizard/step_updater'
|
|
|
|
|
|
|
|
describe Wizard::StepUpdater do
|
2016-09-14 16:36:08 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.wizard_enabled = true
|
|
|
|
end
|
|
|
|
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:user) { Fabricate(:admin) }
|
2016-09-09 16:51:07 -04:00
|
|
|
let(:wizard) { Wizard::Builder.new(user).build }
|
2016-08-25 13:14:56 -04:00
|
|
|
|
2016-09-07 18:04:01 -04:00
|
|
|
context "locale" do
|
|
|
|
it "does not require refresh when the language stays the same" do
|
2019-05-15 17:43:00 -04:00
|
|
|
locale = SiteSettings::DefaultsProvider::DEFAULT_LOCALE
|
|
|
|
updater = wizard.create_updater('locale', default_locale: locale)
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-07 18:04:01 -04:00
|
|
|
expect(updater.refresh_required?).to eq(false)
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('locale')).to eq(true)
|
2016-09-07 18:04:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "updates the locale and requires refresh when it does change" do
|
2016-09-12 14:43:00 -04:00
|
|
|
updater = wizard.create_updater('locale', default_locale: 'ru')
|
|
|
|
updater.update
|
2016-09-07 18:04:01 -04:00
|
|
|
expect(SiteSetting.default_locale).to eq('ru')
|
|
|
|
expect(updater.refresh_required?).to eq(true)
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('locale')).to eq(true)
|
2016-09-07 18:04:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-31 13:35:49 -04:00
|
|
|
it "updates the forum title step" do
|
2018-12-13 05:20:01 -05:00
|
|
|
updater = wizard.create_updater('forum_title', title: 'new forum title', site_description: 'neat place', short_site_description: 'best community')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-08-25 13:14:56 -04:00
|
|
|
|
|
|
|
expect(updater.success?).to eq(true)
|
|
|
|
expect(SiteSetting.title).to eq("new forum title")
|
2016-08-31 13:35:49 -04:00
|
|
|
expect(SiteSetting.site_description).to eq("neat place")
|
2018-12-13 05:20:01 -05:00
|
|
|
expect(SiteSetting.short_site_description).to eq("best community")
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('forum-title')).to eq(true)
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|
2016-08-31 13:35:49 -04:00
|
|
|
|
2016-09-20 17:01:54 -04:00
|
|
|
it "updates the introduction step" do
|
|
|
|
topic = Fabricate(:topic, title: "Welcome to Discourse")
|
|
|
|
welcome_post = Fabricate(:post, topic: topic, raw: "this will be the welcome topic post\n\ncool!")
|
|
|
|
|
|
|
|
updater = wizard.create_updater('introduction', welcome: "Welcome to my new awesome forum!")
|
|
|
|
updater.update
|
|
|
|
|
|
|
|
expect(updater.success?).to eq(true)
|
|
|
|
welcome_post.reload
|
|
|
|
expect(welcome_post.raw).to eq("Welcome to my new awesome forum!\n\ncool!")
|
|
|
|
|
|
|
|
expect(wizard.completed_steps?('introduction')).to eq(true)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-09-15 16:01:44 -04:00
|
|
|
it "won't allow updates to the default value, when required" do
|
|
|
|
updater = wizard.create_updater('forum_title', title: SiteSetting.title, site_description: 'neat place')
|
|
|
|
updater.update
|
|
|
|
|
|
|
|
expect(updater.success?).to eq(false)
|
|
|
|
end
|
|
|
|
|
2016-09-09 15:57:44 -04:00
|
|
|
context "privacy settings" do
|
|
|
|
it "updates to open correctly" do
|
2019-04-22 10:17:29 -04:00
|
|
|
updater = wizard.create_updater('privacy', privacy: 'open', privacy_options: 'open')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-09 15:57:44 -04:00
|
|
|
expect(updater.success?).to eq(true)
|
|
|
|
expect(SiteSetting.login_required?).to eq(false)
|
|
|
|
expect(SiteSetting.invite_only?).to eq(false)
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('privacy')).to eq(true)
|
2016-09-09 15:57:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "updates to private correctly" do
|
2019-04-22 10:17:29 -04:00
|
|
|
updater = wizard.create_updater('privacy', privacy: 'restricted', privacy_options: 'invite_only')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-09 15:57:44 -04:00
|
|
|
expect(updater.success?).to eq(true)
|
|
|
|
expect(SiteSetting.login_required?).to eq(true)
|
|
|
|
expect(SiteSetting.invite_only?).to eq(true)
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('privacy')).to eq(true)
|
2016-09-09 15:57:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-31 13:35:49 -04:00
|
|
|
context "contact step" do
|
|
|
|
it "updates the fields correctly" do
|
2018-11-20 18:18:30 -05:00
|
|
|
p = Fabricate(:post, raw: '<contact_email> template')
|
|
|
|
SiteSetting.tos_topic_id = p.topic_id
|
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
updater = wizard.create_updater('contact',
|
|
|
|
contact_email: 'eviltrout@example.com',
|
|
|
|
contact_url: 'http://example.com/custom-contact-url',
|
2016-09-15 16:14:47 -04:00
|
|
|
site_contact: user.username)
|
2016-08-31 13:35:49 -04:00
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-02 11:42:14 -04:00
|
|
|
expect(updater).to be_success
|
2016-08-31 13:35:49 -04:00
|
|
|
expect(SiteSetting.contact_email).to eq("eviltrout@example.com")
|
|
|
|
expect(SiteSetting.contact_url).to eq("http://example.com/custom-contact-url")
|
|
|
|
expect(SiteSetting.site_contact_username).to eq(user.username)
|
2018-11-20 18:18:30 -05:00
|
|
|
|
|
|
|
# Should update the TOS topic
|
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck(:raw).first
|
|
|
|
expect(raw).to eq("<eviltrout@example.com> template")
|
|
|
|
|
|
|
|
# Can update the TOS topic again
|
|
|
|
updater = wizard.create_updater('contact', contact_email: 'alice@example.com')
|
|
|
|
updater.update
|
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck(:raw).first
|
|
|
|
expect(raw).to eq("<alice@example.com> template")
|
|
|
|
|
|
|
|
# Can update the TOS to nothing
|
|
|
|
updater = wizard.create_updater('contact', {})
|
|
|
|
updater.update
|
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck(:raw).first
|
|
|
|
expect(raw).to eq("<contact_email> template")
|
|
|
|
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('contact')).to eq(true)
|
2016-08-31 13:35:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't update when there are errors" do
|
2016-09-12 14:43:00 -04:00
|
|
|
updater = wizard.create_updater('contact',
|
|
|
|
contact_email: 'not-an-email',
|
|
|
|
site_contact_username: 'not-a-username')
|
|
|
|
updater.update
|
2016-09-07 18:04:01 -04:00
|
|
|
expect(updater).to_not be_success
|
2016-08-31 13:35:49 -04:00
|
|
|
expect(updater.errors).to be_present
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('contact')).to eq(false)
|
2016-08-31 13:35:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
context "corporate step" do
|
|
|
|
|
|
|
|
it "updates the fields properly" do
|
|
|
|
|
2018-11-20 18:18:30 -05:00
|
|
|
p = Fabricate(:post, raw: 'company_name - governing_law - city_for_disputes template')
|
2016-09-12 14:43:00 -04:00
|
|
|
SiteSetting.tos_topic_id = p.topic_id
|
|
|
|
|
|
|
|
updater = wizard.create_updater('corporate',
|
2018-11-20 18:18:30 -05:00
|
|
|
company_name: 'ACME, Inc.',
|
|
|
|
governing_law: 'New Jersey law',
|
|
|
|
city_for_disputes: 'Fairfield, New Jersey')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
|
|
|
expect(updater).to be_success
|
2018-11-20 18:18:30 -05:00
|
|
|
expect(SiteSetting.company_name).to eq("ACME, Inc.")
|
|
|
|
expect(SiteSetting.governing_law).to eq("New Jersey law")
|
|
|
|
expect(SiteSetting.city_for_disputes).to eq("Fairfield, New Jersey")
|
2016-09-12 14:43:00 -04:00
|
|
|
|
|
|
|
# Should update the TOS topic
|
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck(:raw).first
|
2018-11-20 18:18:30 -05:00
|
|
|
expect(raw).to eq("ACME, Inc. - New Jersey law - Fairfield, New Jersey template")
|
2016-09-12 14:43:00 -04:00
|
|
|
|
|
|
|
# Can update the TOS topic again
|
|
|
|
updater = wizard.create_updater('corporate',
|
2018-11-20 18:18:30 -05:00
|
|
|
company_name: 'Pied Piper Inc',
|
|
|
|
governing_law: 'California law',
|
|
|
|
city_for_disputes: 'San Francisco, California')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck(:raw).first
|
2018-11-20 18:18:30 -05:00
|
|
|
expect(raw).to eq("Pied Piper Inc - California law - San Francisco, California template")
|
2016-09-12 14:43:00 -04:00
|
|
|
|
|
|
|
# Can update the TOS to nothing
|
|
|
|
updater = wizard.create_updater('corporate', {})
|
|
|
|
updater.update
|
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck(:raw).first
|
2018-11-20 18:18:30 -05:00
|
|
|
expect(raw).to eq("company_name - governing_law - city_for_disputes template")
|
2016-09-14 16:36:08 -04:00
|
|
|
|
|
|
|
expect(wizard.completed_steps?('corporate')).to eq(true)
|
2016-09-12 14:43:00 -04:00
|
|
|
end
|
|
|
|
end
|
2016-09-02 11:42:14 -04:00
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
context "colors step" do
|
2016-09-02 11:42:14 -04:00
|
|
|
context "with an existing color scheme" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
|
2016-09-02 11:42:14 -04:00
|
|
|
|
|
|
|
it "updates the scheme" do
|
2018-07-24 09:00:20 -04:00
|
|
|
updater = wizard.create_updater('colors', theme_previews: 'Dark')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-02 11:42:14 -04:00
|
|
|
expect(updater.success?).to eq(true)
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('colors')).to eq(true)
|
2018-07-12 00:18:21 -04:00
|
|
|
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
2018-07-24 09:00:20 -04:00
|
|
|
expect(theme.color_scheme.base_scheme_id).to eq('Dark')
|
2016-09-02 11:42:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-09 05:22:28 -04:00
|
|
|
context "with an existing default theme" do
|
|
|
|
fab!(:theme) { Fabricate(:theme) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
theme.set_default!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not update the default theme when no option has been selected" do
|
|
|
|
expect do
|
|
|
|
wizard.create_updater('colors', {}).update
|
|
|
|
end.to_not change { SiteSetting.default_theme_id }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-03 23:44:23 -04:00
|
|
|
context "without an existing theme" do
|
|
|
|
before do
|
|
|
|
Theme.delete_all
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'dark theme' do
|
|
|
|
it "creates the theme" do
|
2019-05-09 05:02:32 -04:00
|
|
|
updater = wizard.create_updater('colors', theme_previews: 'Dark')
|
2017-05-03 23:44:23 -04:00
|
|
|
|
|
|
|
expect { updater.update }.to change { Theme.count }.by(1)
|
|
|
|
|
|
|
|
theme = Theme.last
|
|
|
|
|
|
|
|
expect(theme.user_id).to eq(wizard.user.id)
|
2018-07-24 09:00:20 -04:00
|
|
|
expect(theme.color_scheme.base_scheme_id).to eq('Dark')
|
2017-05-03 23:44:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'light theme' do
|
|
|
|
it "creates the theme" do
|
2019-05-09 05:22:28 -04:00
|
|
|
updater = wizard.create_updater('colors',
|
|
|
|
theme_previews: ColorScheme::LIGHT_THEME_ID
|
|
|
|
)
|
2017-05-03 23:44:23 -04:00
|
|
|
|
|
|
|
expect { updater.update }.to change { Theme.count }.by(1)
|
|
|
|
|
|
|
|
theme = Theme.last
|
|
|
|
|
|
|
|
expect(theme.user_id).to eq(wizard.user.id)
|
2019-05-09 05:22:28 -04:00
|
|
|
|
|
|
|
expect(theme.color_scheme).to eq(ColorScheme.find_by(name:
|
|
|
|
ColorScheme::LIGHT_THEME_ID
|
|
|
|
))
|
2017-05-03 23:44:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-02 11:42:14 -04:00
|
|
|
context "without an existing scheme" do
|
|
|
|
it "creates the scheme" do
|
2018-08-08 00:46:34 -04:00
|
|
|
ColorScheme.destroy_all
|
2019-05-09 05:02:32 -04:00
|
|
|
updater = wizard.create_updater('colors', theme_previews: 'Dark')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-02 11:42:14 -04:00
|
|
|
expect(updater.success?).to eq(true)
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('colors')).to eq(true)
|
2016-09-02 11:42:14 -04:00
|
|
|
|
|
|
|
color_scheme = ColorScheme.where(via_wizard: true).first
|
|
|
|
expect(color_scheme).to be_present
|
|
|
|
expect(color_scheme.colors).to be_present
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-07-12 00:18:21 -04:00
|
|
|
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
2017-04-12 10:52:52 -04:00
|
|
|
expect(theme.color_scheme_id).to eq(color_scheme.id)
|
2017-05-03 11:31:16 -04:00
|
|
|
|
|
|
|
expect(Theme.where(user_selectable: true).count).to eq(2)
|
2016-09-02 11:42:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-08 16:58:07 -04:00
|
|
|
context "logos step" do
|
|
|
|
it "updates the fields correctly" do
|
2018-11-14 02:03:02 -05:00
|
|
|
upload = Fabricate(:upload)
|
|
|
|
upload2 = Fabricate(:upload)
|
|
|
|
|
|
|
|
updater = wizard.create_updater(
|
|
|
|
'logos',
|
|
|
|
logo: upload.url,
|
|
|
|
logo_small: upload2.url
|
|
|
|
)
|
|
|
|
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-08 16:58:07 -04:00
|
|
|
|
|
|
|
expect(updater).to be_success
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('logos')).to eq(true)
|
2018-11-14 02:03:02 -05:00
|
|
|
expect(SiteSetting.logo).to eq(upload)
|
|
|
|
expect(SiteSetting.logo_small).to eq(upload2)
|
2016-09-16 12:13:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "icons step" do
|
|
|
|
it "updates the fields correctly" do
|
2018-11-14 02:03:02 -05:00
|
|
|
upload = Fabricate(:upload)
|
|
|
|
upload2 = Fabricate(:upload)
|
|
|
|
|
2016-09-16 12:13:54 -04:00
|
|
|
updater = wizard.create_updater('icons',
|
2018-11-14 02:03:02 -05:00
|
|
|
favicon: upload.url,
|
2019-05-01 09:44:45 -04:00
|
|
|
large_icon: upload2.url
|
2018-11-14 02:03:02 -05:00
|
|
|
)
|
|
|
|
|
2016-09-16 12:13:54 -04:00
|
|
|
updater.update
|
|
|
|
|
|
|
|
expect(updater).to be_success
|
|
|
|
expect(wizard.completed_steps?('icons')).to eq(true)
|
2018-11-14 02:03:02 -05:00
|
|
|
expect(SiteSetting.favicon).to eq(upload)
|
2019-05-01 09:44:45 -04:00
|
|
|
expect(SiteSetting.large_icon).to eq(upload2)
|
2018-06-19 11:37:02 -04:00
|
|
|
end
|
2016-09-08 16:58:07 -04:00
|
|
|
end
|
|
|
|
|
2016-09-21 11:22:46 -04:00
|
|
|
context "emoji step" do
|
|
|
|
it "updates the fields correctly" do
|
|
|
|
updater = wizard.create_updater('emoji', emoji_set: "twitter")
|
|
|
|
updater.update
|
|
|
|
|
|
|
|
expect(updater).to be_success
|
|
|
|
expect(wizard.completed_steps?('emoji')).to eq(true)
|
|
|
|
expect(SiteSetting.emoji_set).to eq('twitter')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-21 16:09:18 -04:00
|
|
|
context "homepage step" do
|
|
|
|
it "updates the fields correctly" do
|
2018-06-14 02:31:56 -04:00
|
|
|
updater = wizard.create_updater('homepage', homepage_style: "categories_and_top_topics")
|
2016-09-21 16:09:18 -04:00
|
|
|
updater.update
|
|
|
|
|
|
|
|
expect(updater).to be_success
|
|
|
|
expect(wizard.completed_steps?('homepage')).to eq(true)
|
|
|
|
expect(SiteSetting.top_menu).to eq('categories|latest|new|unread|top')
|
2018-06-14 02:31:56 -04:00
|
|
|
expect(SiteSetting.desktop_category_page_style).to eq('categories_and_top_topics')
|
2016-09-21 16:09:18 -04:00
|
|
|
|
|
|
|
updater = wizard.create_updater('homepage', homepage_style: "latest")
|
|
|
|
updater.update
|
|
|
|
expect(updater).to be_success
|
|
|
|
expect(SiteSetting.top_menu).to eq('latest|new|unread|top|categories')
|
|
|
|
end
|
|
|
|
end
|
2016-09-16 12:13:54 -04:00
|
|
|
|
2016-09-13 15:14:17 -04:00
|
|
|
context "invites step" do
|
|
|
|
let(:invites) {
|
2017-07-27 21:20:09 -04:00
|
|
|
return [{ email: 'regular@example.com', role: 'regular' },
|
|
|
|
{ email: 'moderator@example.com', role: 'moderator' }]
|
2016-09-13 15:14:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
it "updates the fields correctly" do
|
|
|
|
updater = wizard.create_updater('invites', invite_list: invites.to_json)
|
|
|
|
updater.update
|
|
|
|
|
|
|
|
expect(updater).to be_success
|
2016-09-14 16:36:08 -04:00
|
|
|
expect(wizard.completed_steps?('invites')).to eq(true)
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2016-09-20 13:12:00 -04:00
|
|
|
reg_invite = Invite.where(email: 'regular@example.com').first
|
|
|
|
expect(reg_invite).to be_present
|
|
|
|
expect(reg_invite.moderator?).to eq(false)
|
|
|
|
|
|
|
|
mod_invite = Invite.where(email: 'moderator@example.com').first
|
|
|
|
expect(mod_invite).to be_present
|
|
|
|
expect(mod_invite.moderator?).to eq(true)
|
2016-09-13 15:14:17 -04:00
|
|
|
end
|
|
|
|
end
|
2016-09-08 16:58:07 -04:00
|
|
|
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|