ruby_doozer 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb1a71fd888931d010aeffdf2a732c921672a28d
4
- data.tar.gz: e31970bb09b093c59ee6e221dd302c4ce1a00d81
3
+ metadata.gz: 53d62af2e149701f6286454279bc9a3c0926f8fe
4
+ data.tar.gz: fddfe20acb8c854bce8978cf42f5a8454015ac2f
5
5
  SHA512:
6
- metadata.gz: a8a41f827035cf8a419c4eaa3f95965d6aa390660d6d0af404bd3971bbb7ffaaa0203ffd2bb5ad9e0ee770b9247d3c1425a5faebfe16e2279a63c55b7db46e81
7
- data.tar.gz: 24666f05f96fda73696d672ff0d4b1a83b27d0e4ab5dca2248eb0bf3ea50aa2ee7dac854d446dccf1cc792c736231597fe4f4cb81ac2b7731484488523c51846
6
+ metadata.gz: abd6b9d7abf264cc78177280166a03e6fa46b390a479d8eb33a73b4f6b249a87899d1b8479a0571dd529eef756789e4aa4ace209ab24c45aae11fcd02b679257
7
+ data.tar.gz: 754a8d03f0cd1be7ab4bcc4a09960e503a530bb2617888bc0494313f0f28a28c68ffa3d63ad615357d3baffc774a36a02a1074aa30ab881b5f5df48e5e3fa024
@@ -41,7 +41,7 @@ module RubyDoozer
41
41
  @current_revision = doozer.current_revision
42
42
  # Fetch all the configuration information from Doozer and set the internal copy
43
43
  doozer.walk(key, @current_revision) do |key, value, revision|
44
- set_cached_value(relative_key(key), value)
44
+ set_cached_value(relative_key(key), @deserializer.deserialize(value))
45
45
  end
46
46
  end
47
47
 
@@ -7,6 +7,8 @@ module RubyDoozer
7
7
  def self.serialize(value)
8
8
  if value.is_a?(Hash) || value.is_a?(Array)
9
9
  MultiJson.encode(desymbolize(value))
10
+ elsif value.is_a?(Symbol)
11
+ desymbolize_symbol(value)
10
12
  else
11
13
  value.to_s
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module RubyDoozer #:nodoc
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -16,17 +16,32 @@ SemanticLogger.add_appender('test.log') if SemanticLogger.appenders.size == 0
16
16
  # Unit Test for RubyDoozer::Client
17
17
  class CachedRegistryTest < Test::Unit::TestCase
18
18
  context RubyDoozer::CachedRegistry do
19
- context "with test data" do
19
+ setup do
20
+ @date = Date.parse('2013-04-04')
21
+ @time = Time.at(1365102658)
22
+ @test_data = {
23
+ 'bar' => 'test',
24
+ 'one' => 'one',
25
+ 'string_with_underscores' => 'and_a_value',
26
+ 'two' => :two,
27
+ 'integer' => 10,
28
+ 'float' => 10.5,
29
+ 'date' => @date,
30
+ 'time' => @time,
31
+ 'false' => false,
32
+ 'true' => true,
33
+ 'child' => { :symbol_with_underscores => :and_a_value, :this => 'is', :an => ['array', :symbol, :smallest => {'a' => 'b', :c => :d}]}
34
+ }
35
+ # @test_data['all_types'] = @test_data.dup
36
+ end
37
+ context "with cached registry" do
20
38
  setup do
21
- @test_data = {
22
- 'bar' => 'test',
23
- 'one' => 'one',
24
- 'two' => 'two',
25
- }
26
- # Doozer does not allow '_' in path names
27
- @root_path = "/registrytest"
28
- @registry = RubyDoozer::CachedRegistry.new(:root_path => @root_path)
29
- @test_data.each_pair {|k,v| @registry[k] = v}
39
+ # Pre-load 'child' into registry before registry is created
40
+ registry = RubyDoozer::Registry.new(:root => "/registrytest")
41
+ registry['child'] = @test_data['child']
42
+ registry.finalize
43
+ @registry = RubyDoozer::CachedRegistry.new(:root => "/registrytest")
44
+ @test_data.each_pair {|k,v| @registry[k] = v unless k == 'child'}
30
45
  # Give doozer time to send back the changes
31
46
  sleep 0.5
32
47
  end
@@ -39,22 +54,30 @@ class CachedRegistryTest < Test::Unit::TestCase
39
54
  end
40
55
  end
41
56
 
42
- should "have complete registry" do
57
+ should 'have pre-loaded element' do
58
+ assert_hash_equal @test_data['child'], @registry['child']
59
+ end
60
+
61
+ should "#[]" do
43
62
  @test_data.each_pair do |k,v|
44
63
  assert_equal v, @registry[k], "Expected #{k}=>#{v}, #{@registry.to_h.inspect}"
45
64
  end
46
65
  end
47
66
 
48
- should "iterate over complete registry" do
49
- @registry.each_pair do |k,v|
50
- assert_equal v, @test_data[k], "Registry #{k}=>#{v}, #{@registry.to_h.inspect}"
51
- end
67
+ should "#each_pair" do
68
+ h = {}
69
+ @registry.each_pair {|k,v| h[k] = v}
70
+ assert_hash_equal @test_data, h
71
+ end
72
+
73
+ should "#to_h" do
74
+ assert_hash_equal @test_data, @registry.to_h
52
75
  end
53
76
 
54
- should "successfully set and retrieve data" do
77
+ should "#[]=" do
55
78
  @registry['three'] = 'value'
56
79
  # Give doozer time to send back the change
57
- sleep 0.5
80
+ sleep 0.3
58
81
  result = @registry['three']
59
82
  assert_equal 'value', result
60
83
  end
@@ -160,4 +183,16 @@ class CachedRegistryTest < Test::Unit::TestCase
160
183
  end
161
184
 
162
185
  end
186
+
187
+ # Verify that two hashes match
188
+ def assert_hash_equal(expected, actual)
189
+ assert_equal expected.size, actual.size, "Actual hash only has #{actual.size} elements when it should have #{expected.size}. Expected:#{expected.inspect}, Actual#{actual.inspect}"
190
+ expected.each_pair do |k,v|
191
+ if v.is_a?(Hash)
192
+ assert_hash_equal(v, actual[k])
193
+ else
194
+ assert_equal expected[k], actual[k], "Expected: #{expected.inspect}, Actual:#{actual.inspect}"
195
+ end
196
+ end
197
+ end
163
198
  end
@@ -16,47 +16,89 @@ SemanticLogger.add_appender('test.log') if SemanticLogger.appenders.size == 0
16
16
  # Unit Test for RubyDoozer::Client
17
17
  class RegistryTest < Test::Unit::TestCase
18
18
  context RubyDoozer::Registry do
19
- context "with test data" do
19
+ setup do
20
+ @date = Date.parse('2013-04-04')
21
+ @time = Time.at(1365102658)
22
+ @test_data = {
23
+ 'bar' => 'test',
24
+ 'one' => 'one',
25
+ 'string_with_underscores' => 'and_a_value',
26
+ 'two' => :two,
27
+ 'integer' => 10,
28
+ 'float' => 10.5,
29
+ 'date' => @date,
30
+ 'time' => @time,
31
+ 'false' => false,
32
+ 'true' => true,
33
+ 'child' => { :symbol_with_underscores => :and_a_value, :this => 'is', :an => ['array', :symbol, :smallest => {'a' => 'b', :c => :d}]}
34
+ }
35
+ @test_data['all_types'] = @test_data.dup
36
+ end
37
+
38
+ context "serialization" do
20
39
  setup do
21
- @test_data = {
22
- 'bar' => 'test',
23
- 'one' => 'one',
24
- 'two' => 'two',
40
+ @json = {
41
+ 'bar' => 'test',
42
+ 'one' => 'one',
43
+ 'string_with_underscores' => 'and_a_value',
44
+ 'two' => ':two',
45
+ 'integer' => '10',
46
+ 'float' => '10.5',
47
+ 'date' => @date.to_s,
48
+ 'time' => @time.to_s,
49
+ 'false' => 'false',
50
+ 'true' => 'true',
51
+ 'child' => "{\":symbol_with_underscores\":\":and_a_value\",\":this\":\"is\",\":an\":[\"array\",\":symbol\",{\":smallest\":{\"a\":\"b\",\":c\":\":d\"}}]}",
52
+ 'all_types' => "{\"bar\":\"test\",\"one\":\"one\",\"string_with_underscores\":\"and_a_value\",\"two\":\":two\",\"integer\":\"10\",\"float\":\"10.5\",\"date\":\"2013-04-04\",\"time\":\"2013-04-04 15:10:58 -0400\",\"false\":\"false\",\"true\":\"true\",\"child\":{\":symbol_with_underscores\":\":and_a_value\",\":this\":\"is\",\":an\":[\"array\",\":symbol\",{\":smallest\":{\"a\":\"b\",\":c\":\":d\"}}]}}"
25
53
  }
26
- # Doozer does not allow '_' in path names
27
- @root_path = "/registrytest"
28
- @client = RubyDoozer::Client.new(:server => 'localhost:8046')
29
- @test_data.each_pair {|k,v| @client.set("#{@root_path}/#{k}",v)}
54
+ end
30
55
 
31
- @registry = RubyDoozer::Registry.new(:root_path => @root_path)
56
+ should ".serialize" do
57
+ @test_data.each_pair do |k,v|
58
+ assert_equal @json[k], RubyDoozer::Json::Serializer.serialize(v), "Key: #{k}"
59
+ end
60
+ end
61
+
62
+ should ".deserialize" do
63
+ @json.each_pair do |k,v|
64
+ assert_equal @test_data[k], RubyDoozer::Json::Deserializer.deserialize(v), "Key: #{k}"
65
+ end
66
+ end
67
+ end
68
+
69
+ context "with registry" do
70
+ setup do
71
+ @registry = RubyDoozer::Registry.new(:root => "/registrytest")
72
+ @test_data.each_pair {|k,v| @registry[k] = v}
32
73
  end
33
74
 
34
75
  def teardown
35
- @registry.finalize if @registry
36
- if @client
37
- @test_data.each_pair do |k,v|
38
- @client.delete("#{@root_path}/#{k}")
39
- end
40
- @client.delete("#{@root_path}/three")
41
- @client.close
76
+ if @registry
77
+ @test_data.each_pair {|k,v| @registry.delete(k)}
78
+ @registry.delete("three")
79
+ @registry.finalize
42
80
  end
43
81
  end
44
82
 
45
- should "have complete registry" do
83
+ should "#[]" do
46
84
  @test_data.each_pair do |k,v|
47
85
  assert_equal v, @registry[k], "Expected #{k}=>#{v}, #{@registry.to_h.inspect}"
48
86
  end
49
87
  end
50
88
 
51
- should "iterate over complete registry" do
52
- @registry.each_pair do |k,v|
53
- assert_equal v, @test_data[k], "Registry #{k}=>#{v}, #{@registry.to_h.inspect}"
54
- end
89
+ should "#each_pair" do
90
+ h = {}
91
+ @registry.each_pair {|k,v| h[k] = v}
92
+ assert_hash_equal @test_data, h
93
+ end
94
+
95
+ should "#to_h" do
96
+ assert_hash_equal @test_data, @registry.to_h
55
97
  end
56
98
 
57
- should "successfully set and retrieve data" do
99
+ should "#[]=" do
58
100
  @registry['three'] = 'value'
59
- # Allow doozer to send back the change
101
+ # Give doozer time to send back the change
60
102
  sleep 0.3
61
103
  result = @registry['three']
62
104
  assert_equal 'value', result
@@ -136,4 +178,16 @@ class RegistryTest < Test::Unit::TestCase
136
178
 
137
179
  end
138
180
  end
181
+
182
+ # Verify that two hashes match
183
+ def assert_hash_equal(expected, actual)
184
+ expected.each_pair do |k,v|
185
+ if v.is_a?(Hash)
186
+ assert_hash_equal(v, actual[k])
187
+ else
188
+ assert_equal expected[k], actual[k], "Expected: #{expected.inspect}, Actual:#{actual.inspect}"
189
+ end
190
+ end
191
+ end
192
+
139
193
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_doozer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-04 00:00:00.000000000 Z
11
+ date: 2013-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: semantic_logger