removed alterable config, and added a test

This commit is contained in:
John Bender 2010-01-29 22:03:07 -08:00
parent e9d731cfcf
commit dbc10a840f
2 changed files with 11 additions and 30 deletions

View File

@ -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)

View File

@ -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