Commit 8657fd7a authored by georg's avatar georg

Merge branch '271-introduce-erb-templating-and-env-vars-in-specs-config' into 'master'

Introduce ERB templating and env vars in specs config

Closes #271

See merge request schleuder/schleuder!120
parents 13c9e364 6fe5bf59
require 'erb'
module Schleuder
class Conf
include Singleton
......@@ -120,7 +122,7 @@ module Schleuder
def load_config_file(filename)
file = Pathname.new(filename)
if file.readable?
YAML.load(file.read)
YAML.load(ERB.new(file.read).result)
else
{}
end
......
database:
test:
adapter: sqlite3
database: db/test.sqlite3
lists_dir: /tmp/schleuder-test/
listlogs_dir: /tmp/schleuder-test/
database: <%= ENV["SCHLEUDER_DB_PATH"] || 'db/test.sqlite3' %>
lists_dir: <%= ENV["SCHLEUDER_TMP_DIR"] || '/tmp/schleuder-test/' %>
listlogs_dir: <%= ENV["SCHLEUDER_TMP_DIR"] || '/tmp/schleuder-test/' %>
smtp_settings:
port: 2523
keyserver: hkp://127.0.0.1:9999
api:
tls_cert_file: 'spec/schleuder-certificate.pem'
tls_key_file: 'spec/schleuder-private-key.pem'
valid_api_keys: 'test_api_key'
\ No newline at end of file
valid_api_keys: 'test_api_key'
require "spec_helper"
describe Schleuder::Conf do
it "reads ERB code in config files" do
# Suppress warnings about already defined constants
# if using "load" further below
verbose_orig = $VERBOSE
$VERBOSE = nil
# Define constants
val_old = "val_old"
# Check if env var is set
if not ENV["SCHLEUDER_DB_PATH"].nil?
val_old = ENV["SCHLEUDER_DB_PATH"]
end
# Set env var, reload the config and check whether the correct value
# is returned
val_test = "SCHLEUDER_ERB_TEST"
ENV["SCHLEUDER_DB_PATH"] = val_test
load "schleuder/conf.rb"
expect(Schleuder::Conf.database["database"]).to eql(val_test)
# Reset the env var
ENV["SCHLEUDER_DB_PATH"] = nil
# Set the env var to the original value
if val_old != "val_old"
ENV["SCHLEUDER_DB_PATH"] = val_old
end
load "schleuder/conf.rb"
# Set verbose level to original value
$VERBOSE = $verbose_orig
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment