FIX: Unable to change homepage style via wizard (#19462)

Depending on the current state of things, sometimes the homepage style
wouldn't update because we were incorrectly blocking updates the
`desktop_category_page_style` site setting if the first item in the top
menu was 'categories'.

Added a test case to handle this situation.

See https://meta.discourse.org/t/248354
This commit is contained in:
Blake Erickson 2022-12-13 17:52:59 -07:00 committed by GitHub
parent d147e92953
commit 492f68c462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -166,7 +166,7 @@ class Wizard
if updater.fields[:homepage_style] == 'latest' && top_menu[0] != "latest" if updater.fields[:homepage_style] == 'latest' && top_menu[0] != "latest"
top_menu.delete("latest") top_menu.delete("latest")
top_menu.insert(0, "latest") top_menu.insert(0, "latest")
elsif updater.fields[:homepage_style] != 'latest' && top_menu[0] != "categories" elsif updater.fields[:homepage_style] != 'latest'
top_menu.delete("categories") top_menu.delete("categories")
top_menu.insert(0, "categories") top_menu.insert(0, "categories")
updater.update_setting(:desktop_category_page_style, updater.fields[:homepage_style]) updater.update_setting(:desktop_category_page_style, updater.fields[:homepage_style])

View File

@ -257,6 +257,27 @@ RSpec.describe Wizard::StepUpdater do
expect(SiteSetting.top_menu).to eq('latest|categories|new|top') expect(SiteSetting.top_menu).to eq('latest|categories|new|top')
end end
it "updates style even when categories is first in top menu" do
SiteSetting.top_menu = "categories|new|latest"
updater = wizard.create_updater('styling',
body_font: 'arial',
heading_font: 'arial',
homepage_style: "categories_with_featured_topics"
)
updater.update
expect(updater).to be_success
expect(SiteSetting.desktop_category_page_style).to eq('categories_with_featured_topics')
updater = wizard.create_updater('styling',
body_font: 'arial',
heading_font: 'arial',
homepage_style: "subcategories_with_featured_topics"
)
updater.update
expect(updater).to be_success
expect(SiteSetting.desktop_category_page_style).to eq('subcategories_with_featured_topics')
end
it "does not overwrite top_menu site setting" do it "does not overwrite top_menu site setting" do
SiteSetting.top_menu = "latest|unread|unseen|categories" SiteSetting.top_menu = "latest|unread|unseen|categories"
updater = wizard.create_updater('styling', updater = wizard.create_updater('styling',