discourse/spec/models/global_setting_spec.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

2013-12-20 00:17:21 -05:00
require 'spec_helper'
require 'tempfile'
describe GlobalSetting::EnvProvider do
it "can detect keys from env" do
ENV['DISCOURSE_BLA'] = '1'
GlobalSetting::EnvProvider.new.keys.should include(:bla)
end
end
2013-12-20 00:17:21 -05:00
describe GlobalSetting::FileProvider do
it "can parse a simple file" do
f = Tempfile.new('foo')
f.write(" # this is a comment\n")
f.write("\n")
f.write("a = 1000 # this is a comment\n")
f.write("b = \"10 # = 00\" # this is a # comment\n")
f.write("c = \'10 # = 00\' # this is a # comment\n")
2013-12-29 16:42:55 -05:00
f.write("d =\n")
2013-12-20 00:17:21 -05:00
f.close
provider = GlobalSetting::FileProvider.from(f.path)
provider.lookup(:a,"").should == 1000
provider.lookup(:b,"").should == "10 # = 00"
provider.lookup(:c,"").should == "10 # = 00"
2013-12-29 16:42:55 -05:00
provider.lookup(:d,"bob").should == nil
provider.lookup(:e,"bob").should == "bob"
2013-12-20 00:17:21 -05:00
provider.keys.sort.should == [:a, :b, :c, :d]
2013-12-20 00:17:21 -05:00
f.unlink
end
it "uses ERB" do
f = Tempfile.new('foo')
f.write("a = <%= 500 %> # this is a comment\n")
f.close
provider = GlobalSetting::FileProvider.from(f.path)
provider.lookup(:a,"").should == 500
f.unlink
end
2013-12-20 00:17:21 -05:00
end