json_schema_spec 0.0.4 → 0.0.5
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 +4 -4
- data/json_schema_spec.gemspec +1 -1
- data/lib/json_schema_spec.rb +2 -0
- data/lib/json_schema_spec/util.rb +10 -1
- data/spec/json_schema_spec/util_spec.rb +14 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cd0d258423bc24155cdc2e252897c17d43e37c2
|
4
|
+
data.tar.gz: b8d3ec662bb13e7d699876354b66f3a7d7b467b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77b75873e619dfedf68d0e5b203951fc26489d116a6b99df15fe55a0047a50d8ecd8a719d5c48885974ca4cc0264f5fa14b14b8ab7a68502c941829177a897bb
|
7
|
+
data.tar.gz: 1437925a4b9a5f7e7ac6d18fe20bde80509ae7f8fb7ca803d346c5f4e05d7fd70d9efcd5b5d60eb4be81f69af759f9243487d74913ea891d9269d17d49bfdac4
|
data/json_schema_spec.gemspec
CHANGED
@@ -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.
|
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.}
|
data/lib/json_schema_spec.rb
CHANGED
@@ -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
|
-
|
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
|
+
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
|