0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/spec/lib/validators/top_menu_validator_spec.rb
Roman Rizzi d1c05c8b9f
FIX: Prevent empty top menu configuration (#41710)
The unified new view change replaced the top menu presence validator and
allowed blank values. This let an admin clear the setting, causing
homepage resolution to fail because it expects a first menu item.

Reject blank top menus again while preserving the unified new validation
for the removed unread item.
2026-07-14 20:36:02 -03:00

43 lines
1.6 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe TopMenuValidator do
describe "#valid_value?" do
subject(:validator) { described_class.new }
it "returns false for blank values" do
expect(validator.valid_value?("")).to eq(false)
expect(validator.error_message).to eq(I18n.t("site_settings.errors.must_include_latest"))
expect(validator.valid_value?(nil)).to eq(false)
expect(validator.error_message).to eq(I18n.t("site_settings.errors.must_include_latest"))
end
it "returns false when latest is missing" do
expect(validator.valid_value?("categories|new")).to eq(false)
expect(validator.error_message).to eq(I18n.t("site_settings.errors.must_include_latest"))
end
it "returns false when a choice is not in TopMenu.choices" do
expect(validator.valid_value?("latest|random")).to eq(false)
end
it "returns true for a valid subset of choices that includes latest" do
expect(validator.valid_value?("latest|new|hot|categories")).to eq(true)
end
it "returns false when unread is included and unified new is enabled" do
SiteSetting.enable_unified_new = true
expect(validator.valid_value?("latest|new|unread|hot|categories")).to eq(false)
expect(validator.error_message).to eq(
I18n.t("site_settings.errors.top_menu_unread_not_allowed_with_unified_new"),
)
end
it "returns true when unread is included and unified new is disabled" do
SiteSetting.enable_unified_new = false
expect(validator.valid_value?("latest|new|unread|hot|categories")).to eq(true)
end
end
end