Fix order dependency in site_setting_spec.rb
The spec contained an order dependency which would cause the default bool test to fail. You can confirm this by running the spec with the option "--order rand" a couple times. This dependency was caused by surprising behavior in SiteSetting::setting as shown below: SiteSetting.setting(:bool_setting?, false) SiteSetting.refresh! SiteSetting.bool_setting? #=> false SiteSetting.random_setting = true SiteSetting.bool_setting? #=> true SiteSetting.setting(:bool_setting?, false) SiteSetting.refresh! SiteSetting.bool_setting? #=> true! The spec is merely desriptive, and I have labeled what I think could be possible bugs.
This commit is contained in:
parent
dfafadfe41
commit
1f94ac154b
|
@ -8,7 +8,7 @@ describe SiteSetting do
|
||||||
SiteSetting.refresh!
|
SiteSetting.refresh!
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have a key in all_settings' do
|
it "should have a key in all_settings" do
|
||||||
SiteSetting.all_settings.detect {|s| s[:setting] == :test_setting }.should be_present
|
SiteSetting.all_settings.detect {|s| s[:setting] == :test_setting }.should be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -21,19 +21,34 @@ describe SiteSetting do
|
||||||
SiteSetting.test_setting.should == 77
|
SiteSetting.test_setting.should == 77
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when overidden" do
|
context "when overidden" do
|
||||||
before :all do
|
after :each do
|
||||||
SiteSetting.test_setting = 100
|
|
||||||
end
|
|
||||||
|
|
||||||
after :all do
|
|
||||||
SiteSetting.remove_override!(:test_setting)
|
SiteSetting.remove_override!(:test_setting)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have the correct override" do
|
it "should have the correct override" do
|
||||||
|
SiteSetting.test_setting = 100
|
||||||
SiteSetting.test_setting.should == 100
|
SiteSetting.test_setting.should == 100
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should coerce correct string to int" do
|
||||||
|
SiteSetting.test_setting = "101"
|
||||||
|
SiteSetting.test_setting.should.eql? 101
|
||||||
|
end
|
||||||
|
|
||||||
|
#POSSIBLE BUG
|
||||||
|
it "should coerce incorrect string to 0" do
|
||||||
|
SiteSetting.test_setting = "pie"
|
||||||
|
SiteSetting.test_setting.should.eql? 0
|
||||||
|
end
|
||||||
|
|
||||||
|
#POSSIBLE BUG
|
||||||
|
it "should not set default when reset" do
|
||||||
|
SiteSetting.test_setting = 100
|
||||||
|
SiteSetting.setting(:test_setting, 77)
|
||||||
|
SiteSetting.refresh!
|
||||||
|
SiteSetting.test_setting.should_not == 77
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,6 +61,17 @@ describe SiteSetting do
|
||||||
it "should have the correct default" do
|
it "should have the correct default" do
|
||||||
SiteSetting.test_str.should == "str"
|
SiteSetting.test_str.should == "str"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when overridden" do
|
||||||
|
after :each do
|
||||||
|
SiteSetting.remove_override!(:test_str)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should coerce int to string" do
|
||||||
|
SiteSetting.test_str = 100
|
||||||
|
SiteSetting.test_str.should.eql? "100"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "bool setting" do
|
describe "bool setting" do
|
||||||
|
@ -58,22 +84,33 @@ describe SiteSetting do
|
||||||
SiteSetting.test_hello?.should == false
|
SiteSetting.test_hello?.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be overridable" do
|
context "when overridden" do
|
||||||
SiteSetting.test_hello = true
|
after :each do
|
||||||
SiteSetting.refresh!
|
SiteSetting.remove_override!(:test_hello?)
|
||||||
SiteSetting.test_hello?.should == true
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "should coerce true strings to true" do
|
it "should have the correct override" do
|
||||||
SiteSetting.test_hello = "true"
|
SiteSetting.test_hello = true
|
||||||
SiteSetting.refresh!
|
SiteSetting.test_hello?.should == true
|
||||||
SiteSetting.test_hello?.should == true
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "should coerce all other strings to false" do
|
it "should coerce true strings to true" do
|
||||||
SiteSetting.test_hello = "f"
|
SiteSetting.test_hello = "true"
|
||||||
SiteSetting.refresh!
|
SiteSetting.test_hello?.should.eql? true
|
||||||
SiteSetting.test_hello?.should == false
|
end
|
||||||
|
|
||||||
|
it "should coerce all other strings to false" do
|
||||||
|
SiteSetting.test_hello = "f"
|
||||||
|
SiteSetting.test_hello?.should.eql? false
|
||||||
|
end
|
||||||
|
|
||||||
|
#POSSIBLE BUG
|
||||||
|
it "should not set default when reset" do
|
||||||
|
SiteSetting.test_hello = true
|
||||||
|
SiteSetting.setting(:test_hello?, false)
|
||||||
|
SiteSetting.refresh!
|
||||||
|
SiteSetting.test_hello?.should_not == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue