2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.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
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "introduction" do
|
2022-07-26 21:23:01 -04:00
|
|
|
it "updates the introduction step" do
|
2019-05-15 17:43:00 -04:00
|
|
|
locale = SiteSettings::DefaultsProvider::DEFAULT_LOCALE
|
2022-07-26 21:23:01 -04:00
|
|
|
updater = wizard.create_updater('introduction',
|
|
|
|
title: 'new forum title',
|
|
|
|
site_description: 'neat place',
|
|
|
|
default_locale: locale,
|
|
|
|
contact_email: 'eviltrout@example.com')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2022-07-26 21:23:01 -04:00
|
|
|
|
|
|
|
expect(updater.success?).to eq(true)
|
|
|
|
expect(SiteSetting.title).to eq("new forum title")
|
|
|
|
expect(SiteSetting.site_description).to eq("neat place")
|
|
|
|
expect(SiteSetting.contact_email).to eq("eviltrout@example.com")
|
2016-09-07 18:04:01 -04:00
|
|
|
expect(updater.refresh_required?).to eq(false)
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(wizard.completed_steps?('introduction')).to eq(true)
|
2016-09-07 18:04:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "updates the locale and requires refresh when it does change" do
|
2022-07-26 21:23:01 -04:00
|
|
|
updater = wizard.create_updater('introduction', default_locale: 'ru')
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2016-09-07 18:04:01 -04:00
|
|
|
expect(SiteSetting.default_locale).to eq('ru')
|
|
|
|
expect(updater.refresh_required?).to eq(true)
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(wizard.completed_steps?('introduction')).to eq(true)
|
2016-09-07 18:04:01 -04:00
|
|
|
end
|
2016-09-20 17:01:54 -04:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
it "won't allow updates to the default value, when required" do
|
|
|
|
updater = wizard.create_updater('introduction', title: SiteSetting.title, site_description: 'neat place')
|
|
|
|
updater.update
|
2016-09-15 16:01:44 -04:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(updater.success?).to eq(false)
|
|
|
|
end
|
2016-09-15 16:01:44 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "privacy" do
|
2016-09-09 15:57:44 -04:00
|
|
|
it "updates to open correctly" do
|
2022-12-12 16:30:21 -05:00
|
|
|
updater = wizard.create_updater(
|
|
|
|
'privacy',
|
|
|
|
login_required: false,
|
|
|
|
invite_only: false,
|
|
|
|
must_approve_users: false,
|
|
|
|
enable_sidebar: false
|
|
|
|
)
|
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)
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(SiteSetting.must_approve_users?).to eq(false)
|
2022-12-12 16:30:21 -05:00
|
|
|
expect(SiteSetting.navigation_menu).to eq(NavigationMenuSiteSetting::HEADER_DROPDOWN)
|
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
|
2022-12-12 16:30:21 -05:00
|
|
|
updater = wizard.create_updater(
|
|
|
|
'privacy',
|
|
|
|
login_required: true,
|
|
|
|
invite_only: true,
|
|
|
|
must_approve_users: true,
|
|
|
|
enable_sidebar: true
|
|
|
|
)
|
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)
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(SiteSetting.must_approve_users?).to eq(true)
|
2022-12-12 16:30:21 -05:00
|
|
|
expect(SiteSetting.navigation_menu).to eq(NavigationMenuSiteSetting::SIDEBAR)
|
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
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "styling" do
|
2020-10-05 13:40:41 -04:00
|
|
|
it "updates fonts" do
|
2021-09-02 14:55:38 -04:00
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
body_font: 'open_sans',
|
|
|
|
heading_font: 'oswald',
|
|
|
|
homepage_style: 'latest'
|
|
|
|
)
|
2020-08-31 06:14:09 -04:00
|
|
|
updater.update
|
|
|
|
expect(updater.success?).to eq(true)
|
2021-08-25 17:10:12 -04:00
|
|
|
expect(wizard.completed_steps?('styling')).to eq(true)
|
2020-08-31 06:14:09 -04:00
|
|
|
expect(SiteSetting.base_font).to eq('open_sans')
|
2020-10-05 13:40:41 -04:00
|
|
|
expect(SiteSetting.heading_font).to eq('oswald')
|
2020-08-31 06:14:09 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with colors" do
|
2021-08-25 17:10:12 -04:00
|
|
|
context "with an existing color scheme" do
|
|
|
|
fab!(:color_scheme) { Fabricate(:color_scheme, name: 'existing', via_wizard: true) }
|
2016-09-02 11:42:14 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
it "updates the scheme" do
|
2021-09-02 14:55:38 -04:00
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
color_scheme: 'Dark',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: 'latest'
|
|
|
|
)
|
2021-08-25 17:10:12 -04:00
|
|
|
updater.update
|
|
|
|
expect(updater.success?).to eq(true)
|
|
|
|
expect(wizard.completed_steps?('styling')).to eq(true)
|
2022-08-29 05:40:47 -04:00
|
|
|
expect(updater.refresh_required?).to eq(true)
|
2021-08-25 17:10:12 -04:00
|
|
|
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
|
|
|
expect(theme.color_scheme.base_scheme_id).to eq('Dark')
|
|
|
|
end
|
2016-09-02 11:42:14 -04:00
|
|
|
end
|
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
context "with an existing default theme" do
|
|
|
|
fab!(:theme) { Fabricate(:theme) }
|
2019-05-09 05:22:28 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
before do
|
|
|
|
theme.set_default!
|
|
|
|
end
|
2019-05-09 05:22:28 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
it "should update the color scheme of the default theme" do
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
color_scheme: 'Neutral',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: 'latest'
|
|
|
|
)
|
|
|
|
expect { updater.update }.not_to change { Theme.count }
|
2022-08-29 05:40:47 -04:00
|
|
|
expect(updater.refresh_required?).to eq(true)
|
2021-08-25 17:10:12 -04:00
|
|
|
theme.reload
|
|
|
|
expect(theme.color_scheme.base_scheme_id).to eq('Neutral')
|
|
|
|
end
|
2019-05-09 05:22:28 -04:00
|
|
|
end
|
2020-10-14 10:18:02 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
context "without an existing theme" do
|
|
|
|
before do
|
|
|
|
Theme.delete_all
|
|
|
|
end
|
2019-05-09 05:22:28 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'with dark theme' do
|
2021-08-25 17:10:12 -04:00
|
|
|
it "creates the theme" do
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
color_scheme: 'Dark',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: 'latest'
|
|
|
|
)
|
2017-05-03 23:44:23 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
expect { updater.update }.to change { Theme.count }.by(1)
|
2017-05-03 23:44:23 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
theme = Theme.last
|
2017-05-03 23:44:23 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
expect(theme.user_id).to eq(wizard.user.id)
|
|
|
|
expect(theme.color_scheme.base_scheme_id).to eq('Dark')
|
|
|
|
end
|
|
|
|
end
|
2017-05-03 23:44:23 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context 'with light theme' do
|
2021-08-25 17:10:12 -04:00
|
|
|
it "creates the theme" do
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
color_scheme: ColorScheme::LIGHT_THEME_ID,
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: 'latest'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { updater.update }.to change { Theme.count }.by(1)
|
|
|
|
|
|
|
|
theme = Theme.last
|
|
|
|
|
|
|
|
expect(theme.user_id).to eq(wizard.user.id)
|
|
|
|
|
|
|
|
expect(theme.color_scheme).to eq(ColorScheme.find_by(name:
|
|
|
|
ColorScheme::LIGHT_THEME_ID
|
|
|
|
))
|
|
|
|
end
|
2017-05-03 23:44:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
context "without an existing scheme" do
|
|
|
|
it "creates the scheme" do
|
|
|
|
ColorScheme.destroy_all
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
color_scheme: 'Dark',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: 'latest'
|
2019-05-09 05:22:28 -04:00
|
|
|
)
|
2021-08-25 17:10:12 -04:00
|
|
|
updater.update
|
|
|
|
expect(updater.success?).to eq(true)
|
|
|
|
expect(wizard.completed_steps?('styling')).to eq(true)
|
2017-05-03 23:44:23 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
color_scheme = ColorScheme.where(via_wizard: true).first
|
|
|
|
expect(color_scheme).to be_present
|
|
|
|
expect(color_scheme.colors).to be_present
|
2017-05-03 23:44:23 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
|
|
|
expect(theme.color_scheme_id).to eq(color_scheme.id)
|
2017-05-03 23:44:23 -04:00
|
|
|
end
|
|
|
|
end
|
2021-09-02 14:55:38 -04:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with auto dark mode" do
|
2021-09-02 14:55:38 -04:00
|
|
|
before do
|
|
|
|
dark_scheme = ColorScheme.where(name: "Dark").first
|
|
|
|
SiteSetting.default_dark_mode_color_scheme_id = dark_scheme.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing when selected scheme is light" do
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
color_scheme: 'Neutral',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: 'latest'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { updater.update }.not_to change { SiteSetting.default_dark_mode_color_scheme_id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "unsets auto dark mode site setting when default selected scheme is also dark" do
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
color_scheme: 'Latte',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: 'latest'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { updater.update }.to change { SiteSetting.default_dark_mode_color_scheme_id }.to(-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-03 23:44:23 -04:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with homepage style" do
|
2021-08-25 17:10:12 -04:00
|
|
|
it "updates the fields correctly" do
|
2022-08-02 09:59:34 -04:00
|
|
|
SiteSetting.top_menu = "latest|categories|unread|top"
|
2021-08-25 17:10:12 -04:00
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: "categories_and_top_topics"
|
|
|
|
)
|
2016-09-12 14:43:00 -04:00
|
|
|
updater.update
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
expect(updater).to be_success
|
|
|
|
expect(wizard.completed_steps?('styling')).to eq(true)
|
2022-08-02 09:59:34 -04:00
|
|
|
expect(SiteSetting.top_menu).to eq('categories|latest|unread|top')
|
2021-08-25 17:10:12 -04:00
|
|
|
expect(SiteSetting.desktop_category_page_style).to eq('categories_and_top_topics')
|
|
|
|
|
2022-08-02 09:59:34 -04:00
|
|
|
SiteSetting.top_menu = "categories|latest|new|top"
|
2021-08-25 17:10:12 -04:00
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: "latest"
|
|
|
|
)
|
|
|
|
updater.update
|
|
|
|
expect(updater).to be_success
|
2022-08-02 09:59:34 -04:00
|
|
|
expect(SiteSetting.top_menu).to eq('latest|categories|new|top')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not overwrite top_menu site setting" do
|
|
|
|
SiteSetting.top_menu = "latest|unread|unseen|categories"
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: "latest"
|
|
|
|
)
|
|
|
|
updater.update
|
|
|
|
expect(updater).to be_success
|
|
|
|
expect(SiteSetting.top_menu).to eq('latest|unread|unseen|categories')
|
|
|
|
|
|
|
|
SiteSetting.top_menu = "categories|new|latest"
|
|
|
|
updater = wizard.create_updater('styling',
|
|
|
|
body_font: 'arial',
|
|
|
|
heading_font: 'arial',
|
|
|
|
homepage_style: "categories_and_top_topics"
|
|
|
|
)
|
|
|
|
updater.update
|
|
|
|
expect(updater).to be_success
|
|
|
|
expect(SiteSetting.top_menu).to eq('categories|new|latest')
|
2016-09-02 11:42:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "branding" do
|
2016-09-08 16:58:07 -04:00
|
|
|
it "updates the fields correctly" do
|
2018-11-14 02:03:02 -05:00
|
|
|
upload = Fabricate(:upload)
|
|
|
|
upload2 = Fabricate(:upload)
|
|
|
|
|
|
|
|
updater = wizard.create_updater(
|
2022-07-26 21:23:01 -04:00
|
|
|
'branding',
|
2018-11-14 02:03:02 -05:00
|
|
|
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
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(wizard.completed_steps?('branding')).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
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "corporate" do
|
2022-07-26 21:23:01 -04:00
|
|
|
it "updates the fields properly" do
|
|
|
|
p = Fabricate(:post, raw: 'company_name - governing_law - city_for_disputes template')
|
|
|
|
SiteSetting.tos_topic_id = p.topic_id
|
2018-11-14 02:03:02 -05:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
updater = wizard.create_updater('corporate',
|
|
|
|
company_name: 'ACME, Inc.',
|
|
|
|
governing_law: 'New Jersey law',
|
|
|
|
contact_url: 'http://example.com/custom-contact-url',
|
|
|
|
city_for_disputes: 'Fairfield, New Jersey')
|
2016-09-16 12:13:54 -04:00
|
|
|
updater.update
|
|
|
|
expect(updater).to be_success
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(SiteSetting.company_name).to eq("ACME, Inc.")
|
|
|
|
expect(SiteSetting.governing_law).to eq("New Jersey law")
|
|
|
|
expect(SiteSetting.contact_url).to eq("http://example.com/custom-contact-url")
|
|
|
|
expect(SiteSetting.city_for_disputes).to eq("Fairfield, New Jersey")
|
2016-09-08 16:58:07 -04:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
# Should update the TOS topic
|
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck_first(:raw)
|
|
|
|
expect(raw).to eq("ACME, Inc. - New Jersey law - Fairfield, New Jersey template")
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
# Can update the TOS topic again
|
|
|
|
updater = wizard.create_updater('corporate',
|
|
|
|
company_name: 'Pied Piper Inc',
|
|
|
|
governing_law: 'California law',
|
|
|
|
city_for_disputes: 'San Francisco, California')
|
2016-09-13 15:14:17 -04:00
|
|
|
updater.update
|
2022-07-26 21:23:01 -04:00
|
|
|
raw = Post.where(topic_id: SiteSetting.tos_topic_id, post_number: 1).pluck_first(:raw)
|
|
|
|
expect(raw).to eq("Pied Piper Inc - California law - San Francisco, California template")
|
2016-09-13 15:14:17 -04:00
|
|
|
|
2022-07-26 21:23:01 -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_first(:raw)
|
|
|
|
expect(raw).to eq("company_name - governing_law - city_for_disputes template")
|
2016-09-20 13:12:00 -04:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(wizard.completed_steps?('corporate')).to eq(true)
|
2016-09-13 15:14:17 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-25 13:14:56 -04:00
|
|
|
end
|