json_schema_spec 0.0.4 → 0.0.5

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: fd138ac0bca70e42723ad98f980380c209d49302
4
- data.tar.gz: f1a2281f7c2ffb0bd85012340885b3f4623b538f
3
+ metadata.gz: 6cd0d258423bc24155cdc2e252897c17d43e37c2
4
+ data.tar.gz: b8d3ec662bb13e7d699876354b66f3a7d7b467b5
5
5
  SHA512:
6
- metadata.gz: 9f970e4db6a2c755193f6f7db589c223cbb7fb50254a220f2944fdfae9bc84784c14d55bcafe97d9fcb89addc8df50d72347da596b9ec83cf8715f614acd33a1
7
- data.tar.gz: 95052f70a58503b4beda4e9333500fa6e1c81152ce14a32a598ee99f334f9cd45b3786e5cbc8a08d56e64aeed749c9012bea6424d36b2ab1a7ced437f29a6416
6
+ metadata.gz: 77b75873e619dfedf68d0e5b203951fc26489d116a6b99df15fe55a0047a50d8ecd8a719d5c48885974ca4cc0264f5fa14b14b8ab7a68502c941829177a897bb
7
+ data.tar.gz: 1437925a4b9a5f7e7ac6d18fe20bde80509ae7f8fb7ca803d346c5f4e05d7fd70d9efcd5b5d60eb4be81f69af759f9243487d74913ea891d9269d17d49bfdac4
@@ -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.4"
7
+ spec.version = "0.0.5"
8
8
  spec.authors = ["Winton Welsh"]
9
9
  spec.email = ["mail@wintoni.us"]
10
10
  spec.description = %q{Generate fixtures from JSON schemas.}
@@ -31,6 +31,8 @@ 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
34
36
  params = Util.deep_merge(params, merge)
35
37
 
36
38
  unless merge.empty?
@@ -13,7 +13,16 @@ module JsonSchemaSpec
13
13
  def deep_merge(hash, other_hash)
14
14
  other_hash.each_pair do |k,v|
15
15
  tv = hash[k]
16
- hash[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? deep_merge(tv, v) : v
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
25
+ end
17
26
  end
18
27
  hash
19
28
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe JsonSchemaSpec::Util do
4
+ describe "#deep_merge" do
5
+
6
+ it "handles arrays appropriately" do
7
+ result = JsonSchemaSpec::Util.deep_merge(
8
+ { :a => [ { :b => 1, :d => 3 } ], :a2 => true },
9
+ { :a => [ { :c => 2, :e => 4 } ] }
10
+ )
11
+ expect(result).to eq(:a => [ { :b => 1, :c => 2, :d => 3, :e => 4 } ], :a2 => true)
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schema_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -116,6 +116,7 @@ files:
116
116
  - lib/json_schema_spec/tasks.rb
117
117
  - lib/json_schema_spec/util.rb
118
118
  - spec/fixtures/schema.yml
119
+ - spec/json_schema_spec/util_spec.rb
119
120
  - spec/json_schema_spec_spec.rb
120
121
  - spec/spec_helper.rb
121
122
  homepage: https://github.com/winton/json_schema_spec
@@ -144,5 +145,6 @@ specification_version: 4
144
145
  summary: Generate fixtures from JSON schemas
145
146
  test_files:
146
147
  - spec/fixtures/schema.yml
148
+ - spec/json_schema_spec/util_spec.rb
147
149
  - spec/json_schema_spec_spec.rb
148
150
  - spec/spec_helper.rb