json_schema_spec 0.0.5 → 0.0.6

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: 6cd0d258423bc24155cdc2e252897c17d43e37c2
4
- data.tar.gz: b8d3ec662bb13e7d699876354b66f3a7d7b467b5
3
+ metadata.gz: e4bfd7bd1989b315c60dfa41ff86e355f4fd4911
4
+ data.tar.gz: 266803e4339603af2970620e1cacefc40707c2af
5
5
  SHA512:
6
- metadata.gz: 77b75873e619dfedf68d0e5b203951fc26489d116a6b99df15fe55a0047a50d8ecd8a719d5c48885974ca4cc0264f5fa14b14b8ab7a68502c941829177a897bb
7
- data.tar.gz: 1437925a4b9a5f7e7ac6d18fe20bde80509ae7f8fb7ca803d346c5f4e05d7fd70d9efcd5b5d60eb4be81f69af759f9243487d74913ea891d9269d17d49bfdac4
6
+ metadata.gz: 45ba5b2e0895881ff441e34cc55682ef11052bde228280c9fc719098807d7cde9d558f4aec038a318c29f521e8a047055418402c7a8722910baa4161fd07fef9
7
+ data.tar.gz: 3c6b53cda5fc19b7fcbd95ebd1ddc0092d734ffa017259da5e26a3907e608c14d7c61ed114a153246fa61ca79f8a404093045ded9e6c8f745f099ededece7f86
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "json_schema_spec"
7
- spec.version = "0.0.5"
7
+ spec.version = "0.0.6"
8
8
  spec.authors = ["Winton Welsh"]
9
9
  spec.email = ["mail@wintoni.us"]
10
10
  spec.description = %q{Generate fixtures from JSON schemas.}
@@ -31,8 +31,6 @@ module JsonSchemaSpec
31
31
  def json_schema_params(resource, method, merge={})
32
32
  schema = json_schema(resource, method)
33
33
  params = json_schema_to_params(schema)
34
-
35
- # TODO: make this handle array merging
36
34
  params = Util.deep_merge(params, merge)
37
35
 
38
36
  unless merge.empty?
@@ -10,21 +10,23 @@ module JsonSchemaSpec
10
10
  duplicate
11
11
  end
12
12
 
13
- def deep_merge(hash, other_hash)
14
- other_hash.each_pair do |k,v|
15
- tv = hash[k]
16
- if tv.is_a?(Hash) && v.is_a?(Hash)
17
- hash[k] = deep_merge(tv, v)
18
- elsif tv.is_a?(Array) && v.is_a?(Array)
19
- (0..([ tv.length, v.length ].max - 1)).each do |i|
20
- tv[i] = deep_merge(tv[i], v[i])
21
- end
22
- hash[k] = tv
23
- else
24
- hash[k] = v
13
+ def deep_merge(value, other_value)
14
+ if value.is_a?(Hash) && other_value.is_a?(Hash)
15
+ other_value.each_pair do |k, v|
16
+ value[k] = deep_merge(value[k], v)
25
17
  end
18
+
19
+ elsif value.is_a?(Array) && other_value.is_a?(Array)
20
+ value = (0..([ value.length, other_value.length ].max - 1)).collect do |i|
21
+ deep_merge(value[i], other_value[i])
22
+ end
23
+
24
+ elsif other_value
25
+
26
+ value = other_value
26
27
  end
27
- hash
28
+
29
+ value
28
30
  end
29
31
 
30
32
  def symbolize_keys(hash)
@@ -12,28 +12,30 @@ user.json:
12
12
  type: string
13
13
  response:
14
14
  title: GET user.json (response)
15
- type: object
16
- additionalProperties: false
17
- properties:
18
- id:
19
- type: integer
20
- avatar:
21
- type: string
22
- optional: true
23
- name:
24
- type: string
25
- company:
26
- type: object
27
- additionalProperties: false
28
- properties:
29
- name:
30
- type: string
31
- articles:
32
- type: array
33
- items:
15
+ type: array
16
+ items:
17
+ type: object
18
+ additionalProperties: false
19
+ properties:
20
+ id:
21
+ type: integer
22
+ avatar:
23
+ type: string
24
+ optional: true
25
+ name:
26
+ type: string
27
+ company:
34
28
  type: object
29
+ additionalProperties: false
35
30
  properties:
36
- title:
31
+ name:
37
32
  type: string
38
- body:
39
- type: string
33
+ articles:
34
+ type: array
35
+ items:
36
+ type: object
37
+ properties:
38
+ title:
39
+ type: string
40
+ body:
41
+ type: string
@@ -3,12 +3,30 @@ require 'spec_helper'
3
3
  describe JsonSchemaSpec::Util do
4
4
  describe "#deep_merge" do
5
5
 
6
- it "handles arrays appropriately" do
7
- result = JsonSchemaSpec::Util.deep_merge(
6
+ let(:input) do
7
+ [
8
8
  { :a => [ { :b => 1, :d => 3 } ], :a2 => true },
9
9
  { :a => [ { :c => 2, :e => 4 } ] }
10
+ ]
11
+ end
12
+
13
+ let(:output) do
14
+ {
15
+ :a => [ { :b => 1, :c => 2, :d => 3, :e => 4 } ],
16
+ :a2 => true
17
+ }
18
+ end
19
+
20
+ it "handles hashes with arrays" do
21
+ result = JsonSchemaSpec::Util.deep_merge(input[0], input[1])
22
+ expect(result).to eq(output)
23
+ end
24
+
25
+ it "handles arrays with hashes" do
26
+ result = JsonSchemaSpec::Util.deep_merge(
27
+ [ input[0] ], [ input[1] ]
10
28
  )
11
- expect(result).to eq(:a => [ { :b => 1, :c => 2, :d => 3, :e => 4 } ], :a2 => true)
29
+ expect(result).to eq([ output ])
12
30
  end
13
31
  end
14
32
  end
@@ -11,8 +11,8 @@ describe JsonSchemaSpec do
11
11
  :token => "token"
12
12
  )
13
13
 
14
- expect(response).to eq(
15
- :id => response[:id],
14
+ expect(response).to eq([{
15
+ :id => response[0][:id],
16
16
  :name => "name",
17
17
  :company => {
18
18
  :name => "company:name"
@@ -23,7 +23,7 @@ describe JsonSchemaSpec do
23
23
  :title => "articles:title"
24
24
  }
25
25
  ]
26
- )
26
+ }])
27
27
  end
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-13 00:00:00.000000000 Z
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json