Commit b5d25938 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang Committed by Eric Davis

Adds a method to temporarily override configuration settings.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4949 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent d2886124
......@@ -70,6 +70,16 @@ module Redmine
@config[name]
end
# Yields a block with the specified hash configuration settings
def with(settings)
settings.stringify_keys!
load unless @config
was = settings.keys.inject({}) {|h,v| h[v] = @config[v]; h}
@config.merge! settings
yield if block_given?
@config.merge! was
end
private
def load_from_yaml(filename, env)
......
......@@ -41,6 +41,15 @@ class Redmine::ConfigurationTest < ActiveSupport::TestCase
assert_equal 'bar', @conf['somesetting']
end
def test_with
load_conf('default.yml', 'test')
assert_equal 'foo', @conf['somesetting']
@conf.with 'somesetting' => 'bar' do
assert_equal 'bar', @conf['somesetting']
end
assert_equal 'foo', @conf['somesetting']
end
private
def load_conf(file, env)
......
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