fitting 2.12.1 → 2.13.0

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: 1415f580792a267f0db27df63a8ef8334d0cd0cc
4
- data.tar.gz: 4e5868e53b370121ab7cfad0e1762d014b4f310d
3
+ metadata.gz: 3cb768409f791b3b1af04fdcee07ae65bb5156ee
4
+ data.tar.gz: 2ff46f1b9f5412cc3d79c9d3908243584d896bee
5
5
  SHA512:
6
- metadata.gz: f93db3c0f9c83d2ec34b84ab4d3e91e8b5d06ba988bc5f4d40eb9c2e63664a30589857909c054e4d19b3099ca223403df2cd8026856a25360dae4ab050cf4dce
7
- data.tar.gz: 81ce958a9daed16da84fea079964caf4b7e396bb473a5d89f856f6ff9a453e398b742aedd667a1dbaebb56a71347b3056d3b61f4b188b32615e1050dfb75e3c3
6
+ metadata.gz: 70f5a4114b36c30a665cc3792b73000c557b78c8d1fd925a10d66b5aac3df16f953aa40b72be5093dca176915059697867807f8e8923ced92151f990da7aaceb
7
+ data.tar.gz: aaecda82b7dcc6307a7dc168c162f2654568cae2ea0327653127e7b688bec23969b0f51eb7090aec58e8ba46e18d144f3734da8813d405e0a0220217d2678c08
@@ -1,5 +1,14 @@
1
1
  # Change log
2
2
 
3
+ ### 2.13.0 - 2020-02-26
4
+
5
+ * features
6
+ * use request tests
7
+
8
+ * patch
9
+ * improve combination name for enum cover
10
+ * improve combination name for required cover
11
+
3
12
  ### 2.12.1 - 2020-02-07
4
13
 
5
14
  * fixes
@@ -16,6 +16,7 @@ module Fitting
16
16
  end
17
17
 
18
18
  def statistics
19
+ puts 'DEPRECATED: deprecated method statistics, use new method save_test_data'
19
20
  responses = Fitting::Storage::Responses.new
20
21
 
21
22
  RSpec.configure do |config|
@@ -35,6 +36,10 @@ module Fitting
35
36
  FileUtils.rm_r Dir.glob("fitting_tests/*"), :force => true
36
37
 
37
38
  RSpec.configure do |config|
39
+ config.after(:each, type: :request) do
40
+ responses.add(response, inspect)
41
+ end
42
+
38
43
  config.after(:each, type: :controller) do
39
44
  responses.add(response, inspect)
40
45
  end
@@ -3,95 +3,34 @@ module Fitting
3
3
  class JSONSchema
4
4
  def initialize(json_schema)
5
5
  @json_schema = json_schema
6
+ @combinations = []
6
7
  end
7
8
 
8
9
  def combi
9
- return @combinations if @combinations
10
- @combinations = new_required(@json_schema)
11
-
12
- return @combinations unless @json_schema['properties']
13
- @combinations = new_super_each(@json_schema['properties'], { 'properties' => nil }, @json_schema, @combinations, 'properties')
14
-
15
- @combinations
16
- end
17
-
18
- def new_super_each(json_schema, old_keys_hash, lol_schema, combinations, old_key)
19
- json_schema.each do |key, value|
20
- next unless value.is_a?(Hash)
21
-
22
- new_keys_hash = clone_hash(old_keys_hash)
23
- add_super_key(new_keys_hash, key)
24
-
25
- combinations = new_super_each(value, new_keys_hash, lol_schema, combinations, [old_key, key].compact.join('.'))
26
-
27
- qwe = new_required(value)
28
- qwe.map do |asd|
29
- new_json_shema = clone_hash(lol_schema)
30
- super_merge(new_keys_hash, asd[0], new_json_shema)
31
- combinations.push([new_json_shema, [asd[1][0], [old_key, key, asd[1][1]].compact.join('.')]])
32
- end
33
- end
34
- combinations
35
- end
36
-
37
- def add_super_key(vbn, new_key)
38
- vbn.each do |key, value|
39
- if value
40
- add_super_key(value, new_key)
41
- else
42
- vbn[key] = { new_key => nil }
43
- end
10
+ inception(@json_schema, @combinations).each do |combination|
11
+ combination[0] = @json_schema.merge(combination[0])
12
+ combination[1] = ['required', combination[1]]
44
13
  end
45
14
  end
46
15
 
47
- def super_merge(vbn, asd, old_json_schema)
48
- vbn.each do |key, value|
49
- if value
50
- super_merge(value, asd, old_json_schema[key])
51
- else
52
- old_json_schema[key].merge!(asd)
53
- end
54
- end
55
- old_json_schema
56
- end
57
-
58
- def clone_hash(old_json_schema)
59
- new_json_schema = {}
60
- old_json_schema.each do |key, value|
61
- if value.is_a?(Hash)
62
- new_json_schema.merge!(key => clone_hash(value))
63
- elsif value
64
- new_json_schema.merge!(key => value.clone)
65
- else
66
- new_json_schema.merge!(key => nil)
67
- end
68
- end
69
- new_json_schema
70
- end
71
-
72
- def new_required(json_schema)
73
- res = []
74
- new_keys(json_schema).map do |new_key|
75
- new_json_shema = json_schema.dup
76
- if new_json_shema['required']
77
- new_json_shema['required'] += [new_key]
78
- else
79
- new_json_shema['required'] = [new_key]
16
+ def inception(json_schema, combinations)
17
+ json_schema.each do |key, value|
18
+ if key == 'properties' and json_schema['required'] != value.keys
19
+ one_of = json_schema.delete('required') || []
20
+ json_schema['properties'].each_key do |property|
21
+ next if one_of.include?(property)
22
+ combinations.push([json_schema.merge('required' => one_of + [property]), "required.#{property}"])
23
+ end
24
+ elsif value.is_a?(Hash)
25
+ inception(value, combinations)
26
+ combinations.each do |combination|
27
+ combination[0] = { key => combination[0]}
28
+ combination[1] = "#{key}.#{combination[1]}"
29
+ end
80
30
  end
81
- res.push([new_json_shema, ['required', new_key]])
82
31
  end
83
- res
84
- end
85
32
 
86
- def new_keys(json_schema)
87
- return [] unless json_schema && json_schema['properties']
88
- all = json_schema['properties'].keys.map(&:to_s)
89
- old = json_schema['required']
90
- if old
91
- all - old
92
- else
93
- all
94
- end
33
+ combinations
95
34
  end
96
35
  end
97
36
  end
@@ -3,85 +3,33 @@ module Fitting
3
3
  class JSONSchemaEnum
4
4
  def initialize(json_schema)
5
5
  @json_schema = json_schema
6
- end
7
-
8
- def combi
9
- return @combinations if @combinations
10
6
  @combinations = []
11
-
12
- return @combinations unless @json_schema['properties']
13
- @combinations = new_super_each(@json_schema['properties'], { 'properties' => nil }, @json_schema, @combinations, 'properties')
14
-
15
- @combinations
16
- end
17
-
18
- def new_super_each(json_schema, old_keys_hash, lol_schema, combinations, old_key)
19
- json_schema.each do |key, value|
20
- next unless value.is_a?(Hash)
21
-
22
- new_keys_hash = clone_hash(old_keys_hash)
23
- add_super_key(new_keys_hash, key)
24
-
25
- combinations = new_super_each(value, new_keys_hash, lol_schema, combinations, [old_key, key].compact.join('.'))
26
-
27
- qwe = new_enum(value)
28
- qwe.map do |asd|
29
- new_json_shema = clone_hash(lol_schema)
30
- super_merge(new_keys_hash, asd[0], new_json_shema)
31
- combinations.push([new_json_shema, [asd[1][0], [old_key, key, asd[1][1]].compact.join('.')]])
32
- end
33
- end
34
- combinations
35
7
  end
36
8
 
37
- def add_super_key(vbn, new_key)
38
- vbn.each do |key, value|
39
- if value
40
- add_super_key(value, new_key)
41
- else
42
- vbn[key] = { new_key => nil }
43
- end
44
- end
45
- end
46
-
47
- def super_merge(vbn, asd, old_json_schema)
48
- vbn.each do |key, value|
49
- if value
50
- super_merge(value, asd, old_json_schema[key])
51
- else
52
- old_json_schema[key].merge!(asd)
53
- end
9
+ def combi
10
+ inception(@json_schema, @combinations).each do |combination|
11
+ combination[0] = @json_schema.merge(combination[0])
12
+ combination[1] = ['enum', combination[1]]
54
13
  end
55
- old_json_schema
56
14
  end
57
15
 
58
- def clone_hash(old_json_schema)
59
- new_json_schema = {}
60
- old_json_schema.each do |key, value|
61
- if value.is_a?(Hash)
62
- new_json_schema.merge!(key => clone_hash(value))
63
- elsif value
64
- new_json_schema.merge!(key => value.clone)
65
- else
66
- new_json_schema.merge!(key => nil)
16
+ def inception(json_schema, combinations)
17
+ json_schema.each do |key, value|
18
+ if key == 'enum'
19
+ one_of = json_schema.delete('enum')
20
+ one_of.each_index do |index|
21
+ combinations.push([json_schema.merge('enum' => [one_of[index]]), "enum.#{one_of[index]}"])
22
+ end
23
+ elsif value.is_a?(Hash)
24
+ inception(value, combinations)
25
+ combinations.each do |combination|
26
+ combination[0] = { key => combination[0]}
27
+ combination[1] = "#{key}.#{combination[1]}"
28
+ end
67
29
  end
68
30
  end
69
- new_json_schema
70
- end
71
-
72
- def new_enum(json_schema)
73
- res = []
74
- new_keys(json_schema).map do |new_key|
75
- new_json_shema = json_schema.dup
76
- new_json_shema['enum'] = [new_key]
77
- res.push([new_json_shema, ['enum', new_key]])
78
- end
79
- res
80
- end
81
31
 
82
- def new_keys(json_schema)
83
- return [] unless json_schema['enum']
84
- json_schema['enum']
32
+ combinations
85
33
  end
86
34
  end
87
35
  end
@@ -1,3 +1,3 @@
1
1
  module Fitting
2
- VERSION = '2.12.1'.freeze
2
+ VERSION = '2.13.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fitting
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.1
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-07 00:00:00.000000000 Z
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema