2013-02-06 03:16:51 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SiteSetting do
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
describe "int setting" do
|
|
|
|
before :all do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.setting(:test_setting, 77)
|
|
|
|
SiteSetting.refresh!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have a key in all_settings' do
|
|
|
|
SiteSetting.all_settings.detect {|s| s[:setting] == :test_setting }.should be_present
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "should have the correct desc" do
|
2013-02-06 03:16:51 +08:00
|
|
|
I18n.expects(:t).with("site_settings.test_setting").returns("test description")
|
|
|
|
SiteSetting.description(:test_setting).should == "test description"
|
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
|
|
|
it "should have the correct default" do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.test_setting.should == 77
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
describe "when overidden" do
|
|
|
|
before :all do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.test_setting = 100
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
after :all do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.remove_override!(:test_setting)
|
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
|
|
|
it "should have the correct override" do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.test_setting.should == 100
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
describe "string setting" do
|
|
|
|
before :all do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.setting(:test_str, "str")
|
|
|
|
SiteSetting.refresh!
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "should have the correct default" do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.test_str.should == "str"
|
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
describe "bool setting" do
|
|
|
|
before :all do
|
|
|
|
SiteSetting.setting(:test_hello?, false)
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.refresh!
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "should have the correct default" do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.test_hello?.should == false
|
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
it "should be overridable" do
|
|
|
|
SiteSetting.test_hello = true
|
|
|
|
SiteSetting.refresh!
|
|
|
|
SiteSetting.test_hello?.should == true
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "should coerce true strings to true" do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.test_hello = "true"
|
|
|
|
SiteSetting.refresh!
|
|
|
|
SiteSetting.test_hello?.should == true
|
|
|
|
end
|
|
|
|
|
2013-02-26 00:42:20 +08:00
|
|
|
it "should coerce all other strings to false" do
|
2013-02-06 03:16:51 +08:00
|
|
|
SiteSetting.test_hello = "f"
|
|
|
|
SiteSetting.refresh!
|
|
|
|
SiteSetting.test_hello?.should == false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-15 01:57:26 +08:00
|
|
|
describe 'call_discourse_hub?' do
|
2013-02-06 03:16:51 +08:00
|
|
|
it 'should be true when enforce_global_nicknames is true and discourse_org_access_key is set' do
|
|
|
|
SiteSetting.enforce_global_nicknames = true
|
|
|
|
SiteSetting.discourse_org_access_key = 'asdfasfsafd'
|
|
|
|
SiteSetting.refresh!
|
2013-02-15 01:57:26 +08:00
|
|
|
SiteSetting.call_discourse_hub?.should == true
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false when enforce_global_nicknames is false and discourse_org_access_key is set' do
|
|
|
|
SiteSetting.enforce_global_nicknames = false
|
|
|
|
SiteSetting.discourse_org_access_key = 'asdfasfsafd'
|
|
|
|
SiteSetting.refresh!
|
2013-02-15 01:57:26 +08:00
|
|
|
SiteSetting.call_discourse_hub?.should == false
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false when enforce_global_nicknames is true and discourse_org_access_key is not set' do
|
|
|
|
SiteSetting.enforce_global_nicknames = true
|
|
|
|
SiteSetting.discourse_org_access_key = ''
|
|
|
|
SiteSetting.refresh!
|
2013-02-15 01:57:26 +08:00
|
|
|
SiteSetting.call_discourse_hub?.should == false
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be false when enforce_global_nicknames is false and discourse_org_access_key is not set' do
|
|
|
|
SiteSetting.enforce_global_nicknames = false
|
|
|
|
SiteSetting.discourse_org_access_key = ''
|
|
|
|
SiteSetting.refresh!
|
2013-02-15 01:57:26 +08:00
|
|
|
SiteSetting.call_discourse_hub?.should == false
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|