FIX: allow global settings to include keys that have numbers in them
This commit is contained in:
parent
71fb065133
commit
e82f892c2d
|
@ -88,7 +88,7 @@ class GlobalSetting
|
|||
|
||||
def read
|
||||
ERB.new(File.read(@file)).result().split("\n").each do |line|
|
||||
if line =~ /^\s*([a-z_]+)\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|[^#]*)/
|
||||
if line =~ /^\s*([a-z_]+[a-z0-9_]*)\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|[^#]*)/
|
||||
@data[$1.strip.to_sym] = ($4 || $3 || $2).strip
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,9 @@ require 'tempfile'
|
|||
describe GlobalSetting::EnvProvider do
|
||||
it "can detect keys from env" do
|
||||
ENV['DISCOURSE_BLA'] = '1'
|
||||
ENV['DISCOURSE_BLA_2'] = '2'
|
||||
expect(GlobalSetting::EnvProvider.new.keys).to include(:bla)
|
||||
expect(GlobalSetting::EnvProvider.new.keys).to include(:bla_2)
|
||||
end
|
||||
end
|
||||
describe GlobalSetting::FileProvider do
|
||||
|
@ -17,6 +19,7 @@ describe GlobalSetting::FileProvider do
|
|||
f.write("c = \'10 # = 00\' # this is a # comment\n")
|
||||
f.write("d =\n")
|
||||
f.write("#f = 1\n")
|
||||
f.write("a1 = 1\n")
|
||||
f.close
|
||||
|
||||
provider = GlobalSetting::FileProvider.from(f.path)
|
||||
|
@ -27,8 +30,9 @@ describe GlobalSetting::FileProvider do
|
|||
expect(provider.lookup(:d,"bob")).to eq nil
|
||||
expect(provider.lookup(:e,"bob")).to eq "bob"
|
||||
expect(provider.lookup(:f,"bob")).to eq "bob"
|
||||
expect(provider.lookup(:a1,"")).to eq 1
|
||||
|
||||
expect(provider.keys.sort).to eq [:a, :b, :c, :d]
|
||||
expect(provider.keys.sort).to eq [:a, :a1, :b, :c, :d]
|
||||
|
||||
f.unlink
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue