From dbc10a840ff1b7afd55450f169f7c99a23063b59 Mon Sep 17 00:00:00 2001 From: John Bender Date: Fri, 29 Jan 2010 22:03:07 -0800 Subject: [PATCH] removed alterable config, and added a test --- lib/hobo/config.rb | 12 ++++-------- test/hobo/config_test.rb | 29 +++++++---------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/lib/hobo/config.rb b/lib/hobo/config.rb index aee924000..80c0a230c 100644 --- a/lib/hobo/config.rb +++ b/lib/hobo/config.rb @@ -1,21 +1,17 @@ module Hobo module_function - def config @@config end - def alterable_config - @@alterable_config - end - def config!(hash) - @@alterable_config = hash.dup - @@config = hash.freeze + @@config = hash end - def set_config_value(chain, val, cfg=@@alterable_config) + def set_config_value(chain, val, cfg=@@config) keys = chain.split('.') + return if keys.empty? + key = keys.shift.to_sym if keys.empty? raise InvalidSettingAlteration if cfg[key].instance_of?(Hash) diff --git a/test/hobo/config_test.rb b/test/hobo/config_test.rb index 1711e5557..f9e94b8df 100644 --- a/test/hobo/config_test.rb +++ b/test/hobo/config_test.rb @@ -7,30 +7,9 @@ class ConfigTest < Test::Unit::TestCase Hobo.config!(@settings) end - should "prevent alteration after initial creation" do - assert_raise TypeError do - Hobo.config[:a] = 1 - end - end - - should "leave the actual config unaltered when changing the alterable version" do - Hobo.alterable_config[:a] = 1 - assert_equal Hobo.config, @settings - end - - should "ensure that the alterable config and config match initially" do - assert_equal Hobo.config, Hobo.alterable_config - end - - # TODO of debatable usefulness this test is - should "allow for the alteration of the config" do - Hobo.alterable_config[:a] = 1 - assert_not_equal Hobo.alterable_config, Hobo.config - end - should "alter the config given a dot chain of keys" do Hobo.set_config_value 'a.b', 2 - assert_equal Hobo.alterable_config[:a][:b], 2 + assert_equal Hobo.config[:a][:b], 2 end should "prevent the alteration of a non leaf setting value" do @@ -38,5 +17,11 @@ class ConfigTest < Test::Unit::TestCase Hobo.set_config_value('a', 2) end end + + should "not alter settings through the chain method when provided and empty string" do + prev = Hobo.config + Hobo.set_config_value '', 2 + assert_equal Hobo.config, prev + end end end