2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2013-12-19 23:17:21 -06:00
|
|
|
require 'tempfile'
|
|
|
|
|
2014-01-01 17:46:09 -06:00
|
|
|
describe GlobalSetting::EnvProvider do
|
|
|
|
it "can detect keys from env" do
|
|
|
|
ENV['DISCOURSE_BLA'] = '1'
|
2015-08-14 02:01:06 -05:00
|
|
|
ENV['DISCOURSE_BLA_2'] = '2'
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(GlobalSetting::EnvProvider.new.keys).to include(:bla)
|
2015-08-14 02:01:06 -05:00
|
|
|
expect(GlobalSetting::EnvProvider.new.keys).to include(:bla_2)
|
2014-01-01 17:46:09 -06:00
|
|
|
end
|
|
|
|
end
|
2013-12-19 23:17:21 -06: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")
|
2015-03-08 20:15:10 -05:00
|
|
|
f.write(" a = 1000 # this is a comment\n")
|
2013-12-19 23:17:21 -06:00
|
|
|
f.write("b = \"10 # = 00\" # this is a # comment\n")
|
|
|
|
f.write("c = \'10 # = 00\' # this is a # comment\n")
|
2013-12-29 15:42:55 -06:00
|
|
|
f.write("d =\n")
|
2015-03-08 20:15:10 -05:00
|
|
|
f.write("#f = 1\n")
|
2015-08-14 02:01:06 -05:00
|
|
|
f.write("a1 = 1\n")
|
2013-12-19 23:17:21 -06:00
|
|
|
f.close
|
|
|
|
|
|
|
|
provider = GlobalSetting::FileProvider.from(f.path)
|
|
|
|
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(provider.lookup(:a,"")).to eq 1000
|
|
|
|
expect(provider.lookup(:b,"")).to eq "10 # = 00"
|
|
|
|
expect(provider.lookup(:c,"")).to eq "10 # = 00"
|
|
|
|
expect(provider.lookup(:d,"bob")).to eq nil
|
|
|
|
expect(provider.lookup(:e,"bob")).to eq "bob"
|
2015-03-08 20:15:10 -05:00
|
|
|
expect(provider.lookup(:f,"bob")).to eq "bob"
|
2015-08-14 02:01:06 -05:00
|
|
|
expect(provider.lookup(:a1,"")).to eq 1
|
2013-12-19 23:17:21 -06:00
|
|
|
|
2015-08-14 02:01:06 -05:00
|
|
|
expect(provider.keys.sort).to eq [:a, :a1, :b, :c, :d]
|
2014-01-01 17:46:09 -06:00
|
|
|
|
2013-12-19 23:17:21 -06:00
|
|
|
f.unlink
|
|
|
|
end
|
2014-01-01 17:46:09 -06:00
|
|
|
|
2014-02-14 15:35:30 -06:00
|
|
|
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)
|
|
|
|
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(provider.lookup(:a,"")).to eq 500
|
2014-02-14 15:35:30 -06:00
|
|
|
|
|
|
|
f.unlink
|
|
|
|
end
|
|
|
|
|
2013-12-19 23:17:21 -06:00
|
|
|
end
|