pupa 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77d431c205df726539ae647437d320f79bf4a2c6
4
- data.tar.gz: 9a8ab849b2865d4211d86cb6b7e86fe959e8edde
3
+ metadata.gz: b9732b4a0ea1dbd2eb9d8fff1d533bbfd397db6a
4
+ data.tar.gz: 659874bfd458daa7c09be7f0f2a5feeb9deec005
5
5
  SHA512:
6
- metadata.gz: 0c43992f870cd679e8b4ede85413d871b3018d4e30cb6d55c0e4eb208099bfadf7febaaf1a54bbedc19ea7baa470877de74516aaa49a09c738dcb8e75dce7390
7
- data.tar.gz: f885fb7ffee30f5be495bd02cced6423494055a0b7c2a4b6ff1ca5eb8dbc97436a7d21be42039ec6d20a20e606445d1c1379b75ee5bcb31d818fbe0dd456a2bf
6
+ metadata.gz: f24268480ad0447df95bbfa82a86c13d4d82e015309932571b102b73813d480e52d35124ca900f94d9740d58d1b8f3f84e2b9b484dc8c3b879ab6efec8593683
7
+ data.tar.gz: e09836eb51002368554645177bbfbee70e91b3dd5900746e26aa10f3196adb5651e455b1d3a87617e325381169367debc5af0b3d3f2ace604aa8d517c8fc585a
@@ -152,7 +152,7 @@ module Pupa
152
152
  def validate!
153
153
  if self.class.json_schema
154
154
  # JSON::Validator#initialize_data runs fastest if given a hash.
155
- JSON::Validator.validate!(self.class.json_schema, to_h.deep_stringify_keys)
155
+ JSON::Validator.validate!(self.class.json_schema, stringify_keys(to_h))
156
156
  end
157
157
  end
158
158
 
@@ -183,5 +183,24 @@ module Pupa
183
183
  b.delete(:_id)
184
184
  a == b
185
185
  end
186
+
187
+ private
188
+
189
+ def stringify_keys(object)
190
+ case object
191
+ when Hash
192
+ {}.tap do |hash|
193
+ object.each do |key,value|
194
+ hash[key.to_s] = stringify_keys(value)
195
+ end
196
+ end
197
+ when Array
198
+ object.map do |value|
199
+ stringify_keys(value)
200
+ end
201
+ else
202
+ object
203
+ end
204
+ end
186
205
  end
187
206
  end
@@ -1,3 +1,3 @@
1
1
  module Pupa
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -6,20 +6,26 @@ describe Pupa::Base do
6
6
  self.schema = {
7
7
  '$schema' => 'http://json-schema.org/draft-03/schema#',
8
8
  'properties' => {
9
- 'url' => {
10
- 'type' => 'string',
11
- 'format' => 'uri',
9
+ 'links' => {
10
+ 'items' => {
11
+ 'properties' => {
12
+ 'url' => {
13
+ 'type' => 'string',
14
+ 'format' => 'uri',
15
+ },
16
+ },
17
+ },
12
18
  },
13
19
  },
14
20
  }
15
- attr_accessor :name, :url, :label, :founding_date, :inactive, :label_id, :manager_id
21
+ attr_accessor :name, :label, :founding_date, :inactive, :label_id, :manager_id, :links
16
22
  foreign_key :label_id, :manager_id
17
23
  foreign_object :label
18
24
  end
19
25
  end
20
26
 
21
27
  let :properties do
22
- {name: 'Moderat', url: 'http://moderat.fm/', label: {name: 'Mute'}, inactive: false, manager_id: '1'}
28
+ {name: 'Moderat', label: {name: 'Mute'}, inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
23
29
  end
24
30
 
25
31
  let :object do
@@ -28,7 +34,7 @@ describe Pupa::Base do
28
34
 
29
35
  describe '#attr_accessor' do
30
36
  it 'should add properties' do
31
- Music::Band.properties.to_a.should == [:_id, :_type, :extras, :name, :url, :label, :founding_date, :inactive, :label_id, :manager_id]
37
+ Music::Band.properties.to_a.should == [:_id, :_type, :extras, :name, :label, :founding_date, :inactive, :label_id, :manager_id, :links]
32
38
  end
33
39
  end
34
40
 
@@ -61,9 +67,15 @@ describe Pupa::Base do
61
67
  Music::Band.json_schema.should == {
62
68
  '$schema' => 'http://json-schema.org/draft-03/schema#',
63
69
  'properties' => {
64
- 'url' => {
65
- 'type' => 'string',
66
- 'format' => 'uri',
70
+ 'links' => {
71
+ 'items' => {
72
+ 'properties' => {
73
+ 'url' => {
74
+ 'type' => 'string',
75
+ 'format' => 'uri',
76
+ },
77
+ },
78
+ },
67
79
  },
68
80
  },
69
81
  }
@@ -89,7 +101,10 @@ describe Pupa::Base do
89
101
 
90
102
  it 'should set properties' do
91
103
  object.name.should == 'Moderat'
92
- object.url.should == 'http://moderat.fm/'
104
+ object.label.should == {name: 'Mute'}
105
+ object.inactive.should == false
106
+ object.manager_id.should == '1'
107
+ object.links.should == [{url: 'http://moderat.fm/'}]
93
108
  end
94
109
  end
95
110
 
@@ -135,7 +150,7 @@ describe Pupa::Base do
135
150
 
136
151
  describe '#fingerprint' do
137
152
  it 'should return the fingerprint' do
138
- object.fingerprint.should == {_type: 'music/band', name: 'Moderat', url: 'http://moderat.fm/', inactive: false, manager_id: '1'}
153
+ object.fingerprint.should == {_type: 'music/band', name: 'Moderat', inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
139
154
  end
140
155
  end
141
156
 
@@ -159,18 +174,18 @@ describe Pupa::Base do
159
174
  end
160
175
 
161
176
  it 'should raise an error if the object is invalid' do
162
- object[:url] = 'invalid'
177
+ object[:links][0][:url] = 'invalid'
163
178
  expect{object.validate!}.to raise_error(JSON::Schema::ValidationError)
164
179
  end
165
180
  end
166
181
 
167
182
  describe '#to_h' do
168
183
  it 'should not include foreign objects by default' do
169
- object.to_h.should == {_id: object._id, _type: 'music/band', name: 'Moderat', url: 'http://moderat.fm/', inactive: false, manager_id: '1'}
184
+ object.to_h.should == {_id: object._id, _type: 'music/band', name: 'Moderat', inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
170
185
  end
171
186
 
172
187
  it 'should include foreign objects if desired' do
173
- object.to_h(include_foreign_objects: true).should == {_id: object._id, _type: 'music/band', name: 'Moderat', url: 'http://moderat.fm/', label: {name: 'Mute'}, inactive: false, manager_id: '1'}
188
+ object.to_h(include_foreign_objects: true).should == {_id: object._id, _type: 'music/band', name: 'Moderat', label: {name: 'Mute'}, inactive: false, manager_id: '1', links: [{url: 'http://moderat.fm/'}]}
174
189
  end
175
190
 
176
191
  it 'should not include blank properties' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pupa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Open North