2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-06-12 22:41:27 -04:00
|
|
|
require_dependency 'site_setting'
|
|
|
|
require_dependency 'site_setting_extension'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe SiteSetting do
|
|
|
|
|
2013-02-26 11:27:59 -05:00
|
|
|
describe 'topic_title_length' do
|
|
|
|
it 'returns a range of min/max topic title length' do
|
2015-01-05 11:04:23 -05:00
|
|
|
expect(SiteSetting.topic_title_length).to eq(
|
2013-04-10 08:54:10 -04:00
|
|
|
(SiteSetting.defaults[:min_topic_title_length]..SiteSetting.defaults[:max_topic_title_length])
|
2015-01-05 11:04:23 -05:00
|
|
|
)
|
2013-02-26 11:27:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-28 13:54:12 -05:00
|
|
|
describe 'post_length' do
|
|
|
|
it 'returns a range of min/max post length' do
|
2015-01-05 11:04:23 -05:00
|
|
|
expect(SiteSetting.post_length).to eq(SiteSetting.defaults[:min_post_length]..SiteSetting.defaults[:max_post_length])
|
2013-02-28 13:54:12 -05:00
|
|
|
end
|
|
|
|
end
|
2013-06-04 17:58:25 -04:00
|
|
|
|
2015-03-19 10:17:55 -04: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 17:58:25 -04:00
|
|
|
describe 'private_message_title_length' do
|
|
|
|
it 'returns a range of min/max pm topic title length' do
|
2018-01-31 00:56:00 -05: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 17:58:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-22 23:35:06 -04: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 16:31:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "anonymous_homepage" do
|
|
|
|
it "returns latest" do
|
|
|
|
expect(SiteSetting.anonymous_homepage).to eq('latest')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "top_menu" do
|
2015-02-26 19:45:56 -05:00
|
|
|
before { SiteSetting.top_menu = 'one,-nope|two|three,-not|four,ignored|category/xyz|latest' }
|
2013-06-22 23:35:06 -04:00
|
|
|
|
2013-06-21 16:31:40 -04: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
|
|
|
|
expect(SiteSetting.homepage).to eq('one')
|
|
|
|
end
|
|
|
|
end
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
2016-10-11 13:22:43 -04:00
|
|
|
describe "min_redirected_to_top_period" do
|
|
|
|
|
|
|
|
context "has_enough_top_topics" do
|
|
|
|
|
|
|
|
before do
|
2016-10-12 19:28:54 -04:00
|
|
|
SiteSetting.topics_per_period_in_top_page = 2
|
|
|
|
SiteSetting.top_page_default_timeframe = 'daily'
|
2016-11-23 21:29:44 -05:00
|
|
|
|
|
|
|
2.times do
|
|
|
|
TopTopic.create!(daily_score: 2.5)
|
|
|
|
end
|
|
|
|
|
2016-10-12 19:28:54 -04:00
|
|
|
TopTopic.refresh!
|
2016-10-11 13:22:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should_return_a_time_period" do
|
2016-10-12 19:28:54 -04:00
|
|
|
expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(:daily)
|
2016-10-11 13:22:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context "does_not_have_enough_top_topics" do
|
|
|
|
|
|
|
|
before do
|
2016-10-12 19:28:54 -04:00
|
|
|
SiteSetting.topics_per_period_in_top_page = 20
|
|
|
|
SiteSetting.top_page_default_timeframe = 'daily'
|
|
|
|
TopTopic.refresh!
|
2016-10-11 13:22:43 -04:00
|
|
|
end
|
|
|
|
|
2016-10-12 19:28:54 -04:00
|
|
|
it "should_return_a_time_period" do
|
2016-10-11 13:22:43 -04:00
|
|
|
expect(SiteSetting.min_redirected_to_top_period(1.days.ago)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-12-16 05:44:59 -05:00
|
|
|
describe "scheme" do
|
2016-06-27 05:26:43 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.force_https = true
|
|
|
|
end
|
|
|
|
|
2013-12-16 05:44:59 -05:00
|
|
|
it "returns http when ssl is disabled" do
|
2016-06-27 05:26:43 -04:00
|
|
|
SiteSetting.force_https = false
|
2015-01-05 11:04:23 -05:00
|
|
|
expect(SiteSetting.scheme).to eq("http")
|
2013-12-16 05:44:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns https when using ssl" do
|
2015-01-05 11:04:23 -05:00
|
|
|
expect(SiteSetting.scheme).to eq("https")
|
2013-12-16 05:44:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-06-27 05:26:43 -04:00
|
|
|
context 'deprecated site settings' do
|
|
|
|
|
|
|
|
describe '#use_https' do
|
2018-01-31 13:30:14 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.force_https = true
|
|
|
|
end
|
|
|
|
|
2016-06-27 05:26:43 -04:00
|
|
|
it 'should act as a proxy to the new methods' do
|
|
|
|
expect(SiteSetting.use_https).to eq(true)
|
|
|
|
expect(SiteSetting.use_https?).to eq(true)
|
|
|
|
|
|
|
|
SiteSetting.use_https = false
|
|
|
|
|
|
|
|
expect(SiteSetting.force_https).to eq(false)
|
|
|
|
expect(SiteSetting.force_https?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2018-01-31 13:30:14 -05:00
|
|
|
|
|
|
|
describe 'rename private message to personal message' do
|
|
|
|
before do
|
|
|
|
SiteSetting.min_personal_message_title_length = 15
|
|
|
|
SiteSetting.enable_personal_messages = true
|
|
|
|
SiteSetting.personal_email_time_window_seconds = 15
|
|
|
|
SiteSetting.max_personal_messages_per_day = 15
|
|
|
|
SiteSetting.default_email_personal_messages = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should act as a proxy to the new methods' do
|
|
|
|
expect(SiteSetting.min_private_message_title_length).to eq(15)
|
|
|
|
SiteSetting.min_private_message_title_length = 5
|
|
|
|
expect(SiteSetting.min_personal_message_title_length).to eq(5)
|
|
|
|
|
|
|
|
expect(SiteSetting.enable_private_messages).to eq(true)
|
|
|
|
SiteSetting.enable_private_messages = false
|
|
|
|
expect(SiteSetting.enable_personal_messages).to eq(false)
|
|
|
|
|
|
|
|
expect(SiteSetting.private_email_time_window_seconds).to eq(15)
|
|
|
|
SiteSetting.private_email_time_window_seconds = 5
|
|
|
|
expect(SiteSetting.personal_email_time_window_seconds).to eq(5)
|
|
|
|
|
|
|
|
expect(SiteSetting.max_private_messages_per_day).to eq(15)
|
|
|
|
SiteSetting.max_private_messages_per_day = 5
|
|
|
|
expect(SiteSetting.max_personal_messages_per_day).to eq(5)
|
|
|
|
|
|
|
|
expect(SiteSetting.default_email_private_messages).to eq(true)
|
|
|
|
SiteSetting.default_email_private_messages = false
|
|
|
|
expect(SiteSetting.default_email_personal_messages).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2016-06-27 05:26:43 -04:00
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|