pigeon_hole 0.1.4 → 0.1.6

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: 5832510bdae9abe38905c94cafa44a3085266589
4
- data.tar.gz: 99128a94f31c571c22bd6b4ec6e3c1b16e4012b3
3
+ metadata.gz: 706952f2c2f0ca67d0aafca1db9d9adadfac728e
4
+ data.tar.gz: 991c0e967ed1c8b1a6863c985d4fe1328c531075
5
5
  SHA512:
6
- metadata.gz: 0413017c6b960c23db3390750c45a74a4e3a322ddb8c0b349894f33f10095f96ffad16cda9fc861eb8d24fddb654222506f2dc100f1397e5d3bf2a62862ade79
7
- data.tar.gz: 2e6ef6ff33385381b51db529b41cea61a4a960137d120663aa78d205cf82f4135c79f56562e34b1d8e31d538e41e638bf1da16091ac4d89171008fd8d2ce2c93
6
+ metadata.gz: ad6440197be629b26bd60880373a263a78bef20209b301a6fd5466606a0ee769bebdf313ac18eec1894c60c1ae78b1ad823859bfa2569f73cab060e0f7df9079
7
+ data.tar.gz: 67f9d3926b38a53381e4daf84d7c3d603ac79d786bd8406d42320d55a8ebc01b267bdb6e21daf50b6d11e447746eb1e194436af02ab22ed1798f689153dc7ae4
@@ -27,6 +27,16 @@ module PigeonHole
27
27
  end
28
28
  end
29
29
 
30
+ class DuplicatedKey < ArgumentError
31
+ attr_reader :key
32
+
33
+ def initialize(key)
34
+ @key = key
35
+
36
+ super("Hash has a duplicated key=#{key}")
37
+ end
38
+ end
39
+
30
40
  BASIC_TYPES = [
31
41
  NilClass,
32
42
  String,
@@ -102,6 +112,10 @@ module PigeonHole
102
112
  hash = {}
103
113
 
104
114
  value.each do |k, v|
115
+ if hash.key?(k.to_s) || hash.key?(k.to_sym)
116
+ raise DuplicatedKey.new(k)
117
+ end
118
+
105
119
  begin
106
120
  hash[k] = serialize_value(v)
107
121
  rescue UnsupportedType => e
@@ -98,6 +98,44 @@ describe "serializing nested hashes" do
98
98
  end
99
99
  end
100
100
 
101
+ describe "serializing hashes with symbols" do
102
+ let(:input) do
103
+ {
104
+ :foo => :temp
105
+ }
106
+ end
107
+
108
+ subject { PigeonHole.generate(input) }
109
+
110
+ it "serializes hash into a string" do
111
+ result = subject
112
+ expect(result).to_not be_empty
113
+ end
114
+
115
+ it "hash keys are converted to strings" do
116
+ result = subject
117
+ hash = PigeonHole.parse(result)
118
+
119
+ expect(hash["foo"]).to eq(input[:foo])
120
+ expect(hash.keys).to_not include(:foo)
121
+ end
122
+ end
123
+
124
+ describe "serializing hashes with duplicated keys" do
125
+ let(:input) do
126
+ {
127
+ :foo => :temp,
128
+ "foo" => :bar
129
+ }
130
+ end
131
+
132
+ subject { PigeonHole.generate(input) }
133
+
134
+ it "raises an error on generation" do
135
+ expect { subject }.to raise_error(PigeonHole::TypedJSON::DuplicatedKey)
136
+ end
137
+ end
138
+
101
139
  describe "preserving order of hashes" do
102
140
  let(:input) do
103
141
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pigeon_hole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Binns
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-17 00:00:00.000000000 Z
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: