ae_easy-qa 0.0.9 → 0.0.10

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
  SHA256:
3
- metadata.gz: bafed4b1d53a9d7be5009972ac51491e4dd19093ed8f2cf6a44946a030e8e1e7
4
- data.tar.gz: 645b71274aae9b5073a829035dfc4cd55937b37b72702d6554e92d9d699306ec
3
+ metadata.gz: 597f50e50e2fd8e79fc77a50126aa15dcf1ff7ece78e3991e789281b8f446ae2
4
+ data.tar.gz: eebfe4e91cc368fec3483e99b5c5f2c35f48b022397f63a3ba43e502f59c1ef2
5
5
  SHA512:
6
- metadata.gz: fcb5e5ec8b809bd08ab964506f4a3ecdde0876c7f272ee0a5af059528e209b9e0d51ca2ff97c4f2e43945ff78966e328a03086aa9aed0c89d3bffba4da2460d5
7
- data.tar.gz: 398615db342570c330f333d99043575aa57085d67466b051b1c3232a606279952677f793c4a54e4abb8e06cefcebd450c89d3150adc422fc7e831f87b2c8293a
6
+ metadata.gz: 41ec82cf6471504ead3385e7aa6d1d74c213cce2f0b3be741b8e16f015b1c40e9a6eae816e6a19a3519a7856dac13e0cb3afb8d12d3b9f52272a0804d5b4fa98
7
+ data.tar.gz: bc7dd542130a0bc709d29050b1e0757ad7f61bc482caa710edb76cc3c32d8096449e47b5bc6602701e01120b9b308dab66e15b3774b9ed3bc03d4b810cd55b33
@@ -1,16 +1,23 @@
1
1
  module AeEasy
2
2
  module Qa
3
3
  class SaveOutput
4
- attr_reader :errors, :collection_name, :outputs, :summary
4
+ attr_reader :total_items, :rules, :errors, :collection_name,
5
+ :outputs, :summary, :error_totals, :fields_to_ignore
5
6
 
6
- def initialize(errors, collection_name, outputs)
7
+ def initialize(total_items, rules, errors, collection_name, outputs)
8
+ @total_items = total_items
9
+ @rules = rules
7
10
  @errors = errors
8
11
  @collection_name = collection_name
9
12
  @outputs = outputs
10
13
  @summary = Hash.new(0)
14
+ @error_totals = {}
15
+ @fields_to_ignore = []
11
16
  end
12
17
 
13
18
  def run
19
+ gather_threshold_totals
20
+ gather_fields_to_ignore
14
21
  save_group_errors
15
22
  save_errors
16
23
  save_summary
@@ -18,6 +25,30 @@ module AeEasy
18
25
 
19
26
  private
20
27
 
28
+ def gather_threshold_totals
29
+ rules.each{|field_to_validate, options|
30
+ if options['threshold']
31
+ error_total = errors[:errored_items].inject(0){|total, errored_item|
32
+ failed_fields = errored_item[:failures].collect{|failure|
33
+ extract_field(failure.keys.first)
34
+ }.uniq
35
+ total + 1 if failed_fields.include?(field_to_validate)
36
+ }
37
+ error_totals[field_to_validate] = error_total
38
+ end
39
+ }
40
+ end
41
+
42
+ def gather_fields_to_ignore
43
+ rules.each{|field_to_validate, options|
44
+ if options['threshold']
45
+ total_errors = error_totals[field_to_validate]
46
+ success_ratio = (total_items - total_errors).to_f / total_items
47
+ fields_to_ignore.push(field_to_validate) if success_ratio > options['threshold']
48
+ end
49
+ }
50
+ end
51
+
21
52
  def save_group_errors
22
53
  errors.each{|error_name, output_hash|
23
54
  if error_name != :errored_items
@@ -29,20 +60,37 @@ module AeEasy
29
60
 
30
61
  def save_errors
31
62
  errors[:errored_items].each do |errored_item|
63
+ remove_threshold_failures(errored_item) if fields_to_ignore.any?
32
64
  errored_item[:failures].each do |failure|
33
65
  key = "#{failure.keys.first.to_s}_#{failure.values.first.to_s}"
34
66
  summary[key] += 1
35
67
  end
36
68
  errored_item['_collection'] = collection_name
37
- outputs << errored_item
69
+ outputs << errored_item if errored_item[:failures].any?
38
70
  end
39
71
  end
40
72
 
73
+ def remove_threshold_failures(errored_item)
74
+ errored_item[:failures].delete_if{|failure_h|
75
+ field_name = extract_field(failure_h.keys.first)
76
+ fields_to_ignore.include?(field_name)
77
+ }
78
+ end
79
+
41
80
  def save_summary
42
81
  if summary.any?
43
- summary['_collection'] = "#{collection_name}_summary"
44
82
  outputs << summary
83
+ else
84
+ summary['pass'] = 'true'
45
85
  end
86
+ summary['_collection'] = "#{collection_name}_summary"
87
+ summary['total_items'] = total_items
88
+ end
89
+
90
+ def extract_field(field_sym)
91
+ a = field_sym.to_s.split('_')
92
+ a.pop
93
+ a.join('_')
46
94
  end
47
95
  end
48
96
  end
@@ -1,11 +1,11 @@
1
1
  module AeEasy
2
2
  module Qa
3
3
  class ValidateExternal
4
- attr_reader :data, :errors, :config, :outputs, :collection_name
4
+ attr_reader :data, :errors, :rules, :outputs, :collection_name
5
5
 
6
6
  def initialize(data, config, outputs, collection_name)
7
7
  @data = data
8
- @config = config
8
+ @rules = config['individual_validations'] if config
9
9
  @outputs = outputs
10
10
  @collection_name = collection_name
11
11
  @errors = { errored_items: [] }
@@ -14,8 +14,8 @@ module AeEasy
14
14
  def run
15
15
  begin
16
16
  ValidateGroups.new(data, collection_name, errors).run
17
- ValidateRules.new(data, errors, config['individual_validations']).run if config
18
- SaveOutput.new(errors, collection_name, outputs).run
17
+ ValidateRules.new(data, errors, rules).run if rules
18
+ SaveOutput.new(data.count, rules, errors, collection_name, outputs).run
19
19
  return errors
20
20
  rescue StandardError => e
21
21
  puts "An error has occurred: #{e}"
@@ -79,8 +79,8 @@ module AeEasy
79
79
 
80
80
  def run
81
81
  ValidateGroups.new(data, collection_name, errors).run
82
- ValidateRules.new(data, errors, rules).run
83
- SaveOutput.new(errors, outputs_collection_name, outputs).run
82
+ ValidateRules.new(data, errors, rules).run if rules
83
+ SaveOutput.new(data, rules, errors, outputs_collection_name, outputs).run
84
84
  end
85
85
 
86
86
  private
@@ -31,7 +31,7 @@ module AeEasy
31
31
  ValidateValue.new(data_hash, field_to_validate, value, errored_item).run if options['required']
32
32
  when 'length'
33
33
  validate_length(data_hash, field_to_validate, value) if options['required']
34
- when 'required'
34
+ when /required|threshold/
35
35
  nil
36
36
  else
37
37
  unknown_validation_error(validation) if validation !~ /format/
@@ -1,5 +1,5 @@
1
1
  module AeEasy
2
2
  module Qa
3
- VERSION = "0.0.9"
3
+ VERSION = "0.0.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_easy-qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lynam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-28 00:00:00.000000000 Z
11
+ date: 2019-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: answersengine
@@ -107,7 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.0.3
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.8
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: AnswersEngine Easy Quality Assurance gem