summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/redmine/configuration.rb10
-rw-r--r--test/unit/lib/redmine/configuration_test.rb9
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/redmine/configuration.rb b/lib/redmine/configuration.rb
index 1d2443a9c..34880ce58 100644
--- a/lib/redmine/configuration.rb
+++ b/lib/redmine/configuration.rb
@@ -66,6 +66,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)
diff --git a/test/unit/lib/redmine/configuration_test.rb b/test/unit/lib/redmine/configuration_test.rb
index 239f2d3d4..d172c95f5 100644
--- a/test/unit/lib/redmine/configuration_test.rb
+++ b/test/unit/lib/redmine/configuration_test.rb
@@ -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)