]> source.dussan.org Git - redmine.git/commitdiff
Adds a method to temporarily override configuration settings.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 25 Feb 2011 14:30:05 +0000 (14:30 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 25 Feb 2011 14:30:05 +0000 (14:30 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4949 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/configuration.rb
test/unit/lib/redmine/configuration_test.rb

index 1d2443a9c8ea6d00815db21d9d6c3a6cb08ad28f..34880ce58b2d0f3cff22765a336b81e74207dea0 100644 (file)
@@ -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)
index 239f2d3d449bf020ed8ef8a3a48468c9a1fa71ab..d172c95f5872a5802ada091cb02549fdfb054ae2 100644 (file)
@@ -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)