2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2013-06-12 21:41:27 -05:00
|
|
|
require_dependency 'site_setting'
|
|
|
|
require_dependency 'site_setting_extension'
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
describe SiteSetting do
|
|
|
|
|
2013-02-26 10:27:59 -06:00
|
|
|
describe 'topic_title_length' do
|
|
|
|
it 'returns a range of min/max topic title length' do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(SiteSetting.topic_title_length).to eq(
|
2013-04-10 07:54:10 -05:00
|
|
|
(SiteSetting.defaults[:min_topic_title_length]..SiteSetting.defaults[:max_topic_title_length])
|
2015-01-05 10:04:23 -06:00
|
|
|
)
|
2013-02-26 10:27:59 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-28 12:54:12 -06:00
|
|
|
describe 'post_length' do
|
|
|
|
it 'returns a range of min/max post length' do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(SiteSetting.post_length).to eq(SiteSetting.defaults[:min_post_length]..SiteSetting.defaults[:max_post_length])
|
2013-02-28 12:54:12 -06:00
|
|
|
end
|
|
|
|
end
|
2013-06-04 16:58:25 -05:00
|
|
|
|
2015-03-19 09:17:55 -05: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-04 16:58:25 -05:00
|
|
|
describe 'private_message_title_length' do
|
|
|
|
it 'returns a range of min/max pm topic title length' do
|
2018-01-30 23:56:00 -06:00
|
|
|
expect(SiteSetting.private_message_title_length).to eq(SiteSetting.defaults[:min_personal_message_title_length]..SiteSetting.defaults[:max_topic_title_length])
|
2013-06-04 16:58:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-22 22:35:06 -05: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
|
|
|
|
|
|
|
|
it 'is always the correct default' do
|
|
|
|
expect(SiteSetting.contact_email).to eq('')
|
|
|
|
end
|
2013-06-21 15:31:40 -05: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 02:00:56 -05: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-22 22:35:06 -05:00
|
|
|
|
2013-06-21 15:31:40 -05: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 02:00:56 -05:00
|
|
|
SiteSetting.top_menu = "bookmarks|latest"
|
|
|
|
expect(SiteSetting.homepage).to eq('bookmarks')
|
2013-06-21 15:31:40 -05:00
|
|
|
end
|
|
|
|
end
|
2013-06-22 22:35:06 -05:00
|
|
|
end
|
|
|
|
|
2016-10-11 12:22:43 -05:00
|
|
|
describe "min_redirected_to_top_period" do
|
|
|
|
|
|
|
|
context "has_enough_top_topics" do
|
|
|
|
|
|
|
|
before do
|
2016-10-12 18:28:54 -05:00
|
|
|
SiteSetting.topics_per_period_in_top_page = 2
|
|
|
|
SiteSetting.top_page_default_timeframe = 'daily'
|
2016-11-23 20:29:44 -06:00
|
|
|
|
|
|
|
2.times do
|
|
|
|
TopTopic.create!(daily_score: 2.5)
|
|
|
|
end
|
|
|
|
|
2016-10-12 18:28:54 -05:00
|
|
|
TopTopic.refresh!
|
2016-10-11 12:22:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should_return_a_time_period" do
|
2016-10-12 18:28:54 -05:00
|
|
|
expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(:daily)
|
2016-10-11 12:22:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context "does_not_have_enough_top_topics" do
|
|
|
|
|
|
|
|
before do
|
2016-10-12 18:28:54 -05:00
|
|
|
SiteSetting.topics_per_period_in_top_page = 20
|
|
|
|
SiteSetting.top_page_default_timeframe = 'daily'
|
|
|
|
TopTopic.refresh!
|
2016-10-11 12:22:43 -05:00
|
|
|
end
|
|
|
|
|
2016-10-12 18:28:54 -05:00
|
|
|
it "should_return_a_time_period" do
|
2016-10-11 12:22:43 -05:00
|
|
|
expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-12-16 04:44:59 -06:00
|
|
|
describe "scheme" do
|
2016-06-27 04:26:43 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.force_https = true
|
|
|
|
end
|
|
|
|
|
2013-12-16 04:44:59 -06:00
|
|
|
it "returns http when ssl is disabled" do
|
2016-06-27 04:26:43 -05:00
|
|
|
SiteSetting.force_https = false
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(SiteSetting.scheme).to eq("http")
|
2013-12-16 04:44:59 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns https when using ssl" do
|
2015-01-05 10:04:23 -06:00
|
|
|
expect(SiteSetting.scheme).to eq("https")
|
2013-12-16 04:44:59 -06:00
|
|
|
end
|
2018-03-13 14:59:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "shared_drafts_enabled?" do
|
|
|
|
it "returns false by default" do
|
|
|
|
expect(SiteSetting.shared_drafts_enabled?).to eq(false)
|
|
|
|
end
|
2013-12-16 04:44:59 -06:00
|
|
|
|
2018-03-13 14:59:12 -05: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
|
2013-12-16 04:44:59 -06:00
|
|
|
end
|
|
|
|
|
2016-06-27 04:26:43 -05:00
|
|
|
context 'deprecated site settings' do
|
2018-11-07 01:02:53 -06:00
|
|
|
before do
|
|
|
|
SiteSetting.force_https = true
|
2018-11-14 02:09:26 -06:00
|
|
|
@orig_logger = Rails.logger
|
|
|
|
Rails.logger = @fake_logger = FakeLogger.new
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Rails.logger = @orig_logger
|
2018-11-07 01:02:53 -06:00
|
|
|
end
|
2016-06-27 04:26:43 -05:00
|
|
|
|
2018-11-07 01:02:53 -06:00
|
|
|
it 'should act as a proxy to the new methods' do
|
|
|
|
begin
|
2018-11-14 04:07:04 -06:00
|
|
|
original_settings = SiteSettings::DeprecatedSettings::DEPRECATED_SETTINGS
|
|
|
|
SiteSettings::DeprecatedSettings::DEPRECATED_SETTINGS.clear
|
|
|
|
|
|
|
|
SiteSettings::DeprecatedSettings::DEPRECATED_SETTINGS.push([
|
|
|
|
'use_https', 'force_https', true, '0.0.1'
|
|
|
|
])
|
2018-11-07 01:02:53 -06:00
|
|
|
|
|
|
|
SiteSetting.setup_deprecated_methods
|
2018-01-31 12:30:14 -06:00
|
|
|
|
2018-11-14 02:09:26 -06:00
|
|
|
expect do
|
|
|
|
expect(SiteSetting.use_https).to eq(true)
|
|
|
|
expect(SiteSetting.use_https?).to eq(true)
|
|
|
|
end.to change { @fake_logger.warnings.count }.by(2)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
expect(SiteSetting.use_https(warn: false))
|
|
|
|
end.to_not change { @fake_logger.warnings }
|
2016-06-27 04:26:43 -05:00
|
|
|
|
|
|
|
SiteSetting.use_https = false
|
|
|
|
|
|
|
|
expect(SiteSetting.force_https).to eq(false)
|
|
|
|
expect(SiteSetting.force_https?).to eq(false)
|
2018-11-07 01:02:53 -06:00
|
|
|
ensure
|
2018-11-14 04:07:04 -06:00
|
|
|
SiteSettings::DeprecatedSettings::DEPRECATED_SETTINGS.clear
|
|
|
|
|
|
|
|
SiteSettings::DeprecatedSettings::DEPRECATED_SETTINGS.concat(
|
|
|
|
original_settings
|
|
|
|
)
|
2018-01-31 12:30:14 -06:00
|
|
|
end
|
|
|
|
end
|
2016-06-27 04:26:43 -05:00
|
|
|
end
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|