2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe SiteSetting do
|
2013-02-27 00:27:59 +08:00
|
|
|
describe "topic_title_length" do
|
|
|
|
it "returns a range of min/max topic title length" do
|
2015-01-06 00:04:23 +08:00
|
|
|
expect(SiteSetting.topic_title_length).to eq(
|
2013-04-10 20:54:10 +08:00
|
|
|
(
|
|
|
|
SiteSetting.defaults[:min_topic_title_length]..SiteSetting.defaults[
|
|
|
|
:max_topic_title_length
|
2023-01-09 19:18:21 +08:00
|
|
|
]
|
|
|
|
),
|
2015-01-06 00:04:23 +08:00
|
|
|
)
|
2013-02-27 00:27:59 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-01 02:54:12 +08:00
|
|
|
describe "post_length" do
|
|
|
|
it "returns a range of min/max post length" do
|
2015-01-06 00:04:23 +08:00
|
|
|
expect(SiteSetting.post_length).to eq(
|
|
|
|
SiteSetting.defaults[:min_post_length]..SiteSetting.defaults[:max_post_length],
|
|
|
|
)
|
2013-03-01 02:54:12 +08:00
|
|
|
end
|
|
|
|
end
|
2013-06-05 05:58:25 +08:00
|
|
|
|
2015-03-19 22:17:55 +08:00
|
|
|
describe "first_post_length" do
|
|
|
|
it "returns a range of min/max first post length" do
|
|
|
|
expect(SiteSetting.first_post_length).to eq(
|
|
|
|
SiteSetting.defaults[:min_first_post_length]..SiteSetting.defaults[:max_post_length],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-05 05:58:25 +08:00
|
|
|
describe "private_message_title_length" do
|
|
|
|
it "returns a range of min/max pm topic title length" do
|
2018-01-31 13:56:00 +08:00
|
|
|
expect(SiteSetting.private_message_title_length).to eq(
|
|
|
|
SiteSetting.defaults[:min_personal_message_title_length]..SiteSetting.defaults[
|
|
|
|
:max_topic_title_length
|
2023-01-09 19:18:21 +08:00
|
|
|
],
|
2018-01-31 13:56:00 +08:00
|
|
|
)
|
2013-06-05 05:58:25 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-23 11:35:06 +08:00
|
|
|
describe "in test we do some judo to ensure SiteSetting is always reset between tests" do
|
|
|
|
it "is always the correct default" do
|
|
|
|
expect(SiteSetting.contact_email).to eq("")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets a setting" do
|
|
|
|
SiteSetting.contact_email = "sam@sam.com"
|
|
|
|
end
|
2013-06-22 04:31:40 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "anonymous_homepage" do
|
|
|
|
it "returns latest" do
|
|
|
|
expect(SiteSetting.anonymous_homepage).to eq("latest")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "top_menu" do
|
2018-04-26 15:00:56 +08:00
|
|
|
describe "validations" do
|
|
|
|
it "always demands latest" do
|
|
|
|
expect do SiteSetting.top_menu = "categories" end.to raise_error(
|
|
|
|
Discourse::InvalidParameters,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not allow random text" do
|
|
|
|
expect do SiteSetting.top_menu = "latest|random" end.to raise_error(
|
|
|
|
Discourse::InvalidParameters,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2013-06-23 11:35:06 +08:00
|
|
|
|
2013-06-22 04:31:40 +08:00
|
|
|
describe "items" do
|
|
|
|
let(:items) { SiteSetting.top_menu_items }
|
|
|
|
|
|
|
|
it "returns TopMenuItem objects" do
|
|
|
|
expect(items[0]).to be_kind_of(TopMenuItem)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "homepage" do
|
|
|
|
it "has homepage" do
|
2018-04-26 15:00:56 +08:00
|
|
|
SiteSetting.top_menu = "bookmarks|latest"
|
|
|
|
expect(SiteSetting.homepage).to eq("bookmarks")
|
2013-06-22 04:31:40 +08:00
|
|
|
end
|
|
|
|
end
|
2013-06-23 11:35:06 +08:00
|
|
|
end
|
|
|
|
|
2016-10-12 01:22:43 +08:00
|
|
|
describe "min_redirected_to_top_period" do
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when has_enough_top_topics" do
|
2016-10-12 01:22:43 +08:00
|
|
|
before do
|
2016-10-13 07:28:54 +08:00
|
|
|
SiteSetting.topics_per_period_in_top_page = 2
|
|
|
|
SiteSetting.top_page_default_timeframe = "daily"
|
2016-11-24 10:29:44 +08:00
|
|
|
|
|
|
|
2.times { TopTopic.create!(daily_score: 2.5) }
|
|
|
|
|
2016-10-13 07:28:54 +08:00
|
|
|
TopTopic.refresh!
|
2016-10-12 01:22:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should_return_a_time_period" do
|
2016-10-13 07:28:54 +08:00
|
|
|
expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(:daily)
|
2016-10-12 01:22:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context "when does_not_have_enough_top_topics" do
|
2016-10-12 01:22:43 +08:00
|
|
|
before do
|
2016-10-13 07:28:54 +08:00
|
|
|
SiteSetting.topics_per_period_in_top_page = 20
|
|
|
|
SiteSetting.top_page_default_timeframe = "daily"
|
|
|
|
TopTopic.refresh!
|
2016-10-12 01:22:43 +08:00
|
|
|
end
|
|
|
|
|
2016-10-13 07:28:54 +08:00
|
|
|
it "should_return_a_time_period" do
|
2016-10-12 01:22:43 +08:00
|
|
|
expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-16 18:44:59 +08:00
|
|
|
describe "scheme" do
|
2016-06-27 17:26:43 +08:00
|
|
|
before { SiteSetting.force_https = true }
|
|
|
|
|
2013-12-16 18:44:59 +08:00
|
|
|
it "returns http when ssl is disabled" do
|
2016-06-27 17:26:43 +08:00
|
|
|
SiteSetting.force_https = false
|
2015-01-06 00:04:23 +08:00
|
|
|
expect(SiteSetting.scheme).to eq("http")
|
2013-12-16 18:44:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns https when using ssl" do
|
2015-01-06 00:04:23 +08:00
|
|
|
expect(SiteSetting.scheme).to eq("https")
|
2013-12-16 18:44:59 +08:00
|
|
|
end
|
2018-03-14 03:59:12 +08:00
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
describe ".shared_drafts_enabled?" do
|
2018-03-14 03:59:12 +08:00
|
|
|
it "returns false by default" do
|
|
|
|
expect(SiteSetting.shared_drafts_enabled?).to eq(false)
|
|
|
|
end
|
2013-12-16 18:44:59 +08:00
|
|
|
|
2018-03-14 03:59:12 +08:00
|
|
|
it "returns false when the category is uncategorized" do
|
|
|
|
SiteSetting.shared_drafts_category = SiteSetting.uncategorized_category_id
|
|
|
|
expect(SiteSetting.shared_drafts_enabled?).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true when the category is valid" do
|
|
|
|
SiteSetting.shared_drafts_category = Fabricate(:category).id
|
|
|
|
expect(SiteSetting.shared_drafts_enabled?).to eq(true)
|
|
|
|
end
|
2016-06-27 17:26:43 +08:00
|
|
|
end
|
2019-07-13 02:42:43 +08:00
|
|
|
|
|
|
|
describe "cached settings" do
|
2021-05-21 09:43:47 +08:00
|
|
|
it "should recalculate cached setting when dependent settings are changed" do
|
2020-07-27 08:23:54 +08:00
|
|
|
SiteSetting.blocked_attachment_filenames = "foo"
|
|
|
|
expect(SiteSetting.blocked_attachment_filenames_regex).to eq(/foo/)
|
2019-07-13 02:42:43 +08:00
|
|
|
|
2020-07-27 08:23:54 +08:00
|
|
|
SiteSetting.blocked_attachment_filenames = "foo|bar"
|
|
|
|
expect(SiteSetting.blocked_attachment_filenames_regex).to eq(/foo|bar/)
|
2019-07-13 02:42:43 +08:00
|
|
|
end
|
|
|
|
end
|
2021-10-27 22:33:07 +08:00
|
|
|
|
|
|
|
it "sanitizes the client settings when they are overridden" do
|
|
|
|
xss = "<b onmouseover=alert('Wufff!')>click me!</b><script>alert('TEST');</script>"
|
|
|
|
|
|
|
|
SiteSetting.global_notice = xss
|
|
|
|
|
|
|
|
expect(SiteSetting.global_notice).to eq("<b>click me!</b>alert('TEST');")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't corrupt site settings with special characters" do
|
|
|
|
value = 'OX5y3Oljb+Qt9Bu809vsBQ==<>!%{}*&!@#$%..._-A'
|
|
|
|
settings = new_settings(SiteSettings::LocalProcessProvider.new)
|
|
|
|
settings.setting(:test_setting, "", client: true)
|
|
|
|
|
|
|
|
settings.test_setting = value
|
|
|
|
|
|
|
|
expect(settings.test_setting).to eq(value)
|
|
|
|
end
|
2024-03-18 06:50:39 +08:00
|
|
|
|
|
|
|
describe "#all_settings" do
|
|
|
|
it "does not include the `default_locale` setting if include_locale_setting is false" do
|
|
|
|
expect(SiteSetting.all_settings.map { |s| s[:setting] }).to include("default_locale")
|
|
|
|
expect(
|
|
|
|
SiteSetting.all_settings(include_locale_setting: false).map { |s| s[:setting] },
|
|
|
|
).not_to include("default_locale")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not include the `default_locale` setting if filter_categories are specified" do
|
|
|
|
expect(
|
|
|
|
SiteSetting.all_settings(filter_categories: ["branding"]).map { |s| s[:setting] },
|
|
|
|
).not_to include("default_locale")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not include the `default_locale` setting if filter_plugin is specified" do
|
|
|
|
expect(
|
|
|
|
SiteSetting.all_settings(filter_plugin: "chat").map { |s| s[:setting] },
|
|
|
|
).not_to include("default_locale")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes only settings for the specified category" do
|
|
|
|
expect(SiteSetting.all_settings(filter_categories: ["required"]).count).to eq(12)
|
|
|
|
end
|
|
|
|
end
|
2024-11-08 09:12:49 +08:00
|
|
|
|
|
|
|
describe "Upload" do
|
|
|
|
before { setup_s3 }
|
|
|
|
|
|
|
|
describe "#use_dualstack_endpoint" do
|
2024-11-15 10:05:59 +08:00
|
|
|
context "when the s3 endpoint has been set" do
|
|
|
|
before { SiteSetting.s3_endpoint = "https://s3clone.test.com" }
|
|
|
|
|
|
|
|
it "returns false " do
|
|
|
|
expect(SiteSetting.Upload.use_dualstack_endpoint).to eq(false)
|
|
|
|
end
|
2024-11-08 09:12:49 +08:00
|
|
|
end
|
|
|
|
|
2024-11-15 10:05:59 +08:00
|
|
|
context "when enable_s3_uploads is false" do
|
|
|
|
before { SiteSetting.enable_s3_uploads = false }
|
|
|
|
|
|
|
|
it "returns false" do
|
|
|
|
expect(SiteSetting.Upload.use_dualstack_endpoint).to eq(false)
|
|
|
|
end
|
2024-11-08 09:12:49 +08:00
|
|
|
end
|
|
|
|
|
2024-11-15 10:05:59 +08:00
|
|
|
context "when enable_s3_uploads is true" do
|
|
|
|
before do
|
|
|
|
SiteSetting.enable_s3_uploads = true
|
|
|
|
SiteSetting.s3_endpoint = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if the s3_region is in China" do
|
|
|
|
SiteSetting.s3_region = "cn-north-1"
|
|
|
|
expect(SiteSetting.Upload.use_dualstack_endpoint).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true if the s3_region is not in China" do
|
|
|
|
SiteSetting.s3_region = "us-west-1"
|
|
|
|
expect(SiteSetting.Upload.use_dualstack_endpoint).to eq(true)
|
|
|
|
end
|
2024-11-08 09:12:49 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|