mercy 1.5.0 → 2.0.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 +5 -5
- data/.circleci/config.yml +89 -9
- data/.claude/agents/architect.md +48 -0
- data/.claude/agents/infra.md +36 -0
- data/.claude/agents/ruby.md +45 -0
- data/.claude/configuration/arcanum-repo-config.json +3 -0
- data/.claude/scripts/check_infra.sh +6 -0
- data/.claude/scripts/check_ruby.sh +7 -0
- data/.claude/settings.json +10 -0
- data/.github/commit_message_template-2.0.md +32 -0
- data/.github/commit_message_template.md +10 -0
- data/.github/copilot-instructions.md +1 -0
- data/.github/pull_request_template.md +17 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +39 -0
- data/.rubocop_todo.yml +60 -0
- data/AGENTS.md +58 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +21 -0
- data/Gemfile +26 -1
- data/README.md +13 -4
- data/Rakefile +11 -3
- data/config/check_specs.yml +7 -0
- data/config/rubycritc.rb +12 -0
- data/config/yardstick.rb +13 -0
- data/config/yardstick.yml +41 -0
- data/docker-compose.yml +14 -9
- data/docs/agents/arcanum-split-issue.md +9 -0
- data/docs/agents/architecture.md +61 -0
- data/docs/agents/contributing.md +195 -0
- data/docs/agents/flow.md +5 -0
- data/docs/agents/folder-structure.md +26 -0
- data/docs/agents/issue-enhancement.md +10 -0
- data/docs/agents/issues/.gitkeep +1 -0
- data/docs/agents/plans/.gitkeep +1 -0
- data/lib/arstotzka/type_cast_ext.rb +52 -2
- data/lib/mercy/class_methods.rb +77 -7
- data/lib/mercy/concern.rb +105 -1
- data/lib/mercy/period_parser.rb +46 -3
- data/lib/mercy/report/active_record.rb +20 -16
- data/lib/mercy/report/error.rb +6 -4
- data/lib/mercy/report/multiple.rb +26 -22
- data/lib/mercy/report/range.rb +6 -4
- data/lib/mercy/report.rb +38 -7
- data/lib/mercy/report_builder.rb +2 -0
- data/lib/mercy/report_config.rb +5 -0
- data/lib/mercy/status.rb +7 -1
- data/lib/mercy/status_builder.rb +2 -0
- data/lib/mercy/version.rb +3 -1
- data/lib/mercy.rb +2 -0
- data/mercy.gemspec +19 -25
- data/scripts/bump_version.sh +62 -0
- data/scripts/check_readme.sh +6 -0
- data/scripts/rubycritic.sh +10 -0
- data/spec/dummy/.ruby-version +1 -0
- data/spec/dummy/Rakefile +10 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/document_report_controller.rb +34 -0
- data/spec/dummy/app/controllers/example_report_controller.rb +27 -0
- data/spec/dummy/app/helpers/application_helper.rb +4 -0
- data/spec/dummy/app/jobs/application_job.rb +4 -0
- data/spec/dummy/app/mailers/application_mailer.rb +6 -0
- data/spec/dummy/app/models/application_record.rb +5 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/document.rb +9 -0
- data/spec/dummy/app/models/dummy_report.rb +6 -0
- data/spec/dummy/app/models/mercy/report/doc_type_error.rb +20 -0
- data/spec/dummy/app/models/mercy/report/dummy1.rb +19 -0
- data/spec/dummy/app/models/mercy/report/dummy_report.rb +11 -0
- data/spec/dummy/app/models/mercy/report/multiple/dummy.rb +28 -0
- data/spec/dummy/app/models/mercy/report/multiple/successes.rb +28 -0
- data/spec/dummy/app/models/mercy/report/success.rb +18 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +5 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +38 -0
- data/spec/dummy/bin/update +33 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config/application.rb +24 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +20 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +55 -0
- data/spec/dummy/config/environments/production.rb +95 -0
- data/spec/dummy/config/environments/test.rb +52 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +27 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/inflections.rb +18 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +36 -0
- data/spec/dummy/config/routes.rb +16 -0
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +7 -0
- data/spec/dummy/db/migrate/20190508170435_create_documents.rb +13 -0
- data/spec/dummy/db/schema.rb +27 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/dummy/tmp/.keep +0 -0
- data/spec/dummy/tmp/storage/.keep +0 -0
- data/spec/integration/controller/error_report_controller_spec.rb +196 -0
- data/spec/integration/controller/multiple_report_spec.rb +86 -0
- data/spec/integration/controller/range_report_spec.rb +194 -0
- data/spec/integration/yard/arstotzka/type_cast_spec.rb +43 -0
- data/spec/integration/yard/controller/example_report_controller_spec.rb +95 -0
- data/spec/integration/yard/mercy/period_parser_spec.rb +21 -0
- data/spec/lib/arstotzka/type_cast_spec.rb +10 -9
- data/spec/lib/mercy/period_parser_spec.rb +10 -9
- data/spec/lib/mercy/report/error_spec.rb +93 -70
- data/spec/lib/mercy/report/multiple_spec.rb +9 -57
- data/spec/lib/mercy/report/range_spec.rb +70 -41
- data/spec/lib/mercy/report_builder_spec.rb +34 -17
- data/spec/lib/mercy/report_config_spec.rb +48 -0
- data/spec/lib/mercy/report_spec.rb +5 -15
- data/spec/lib/mercy/status_builder_spec.rb +33 -22
- data/spec/lib/mercy/status_spec.rb +69 -49
- data/spec/spec_helper.rb +18 -7
- data/spec/support/fixture_helpers.rb +4 -2
- data/spec/support/models/arstotzka/type_cast/dummy.rb +9 -0
- data/spec/support/shared_contexts/document_setup.rb +31 -0
- data/spec/support/shared_examples/time_parser.rb +2 -0
- metadata +123 -109
- data/spec/lib/mercy/report/report_config_spec.rb +0 -39
- data/spec/support/models/document.rb +0 -6
- data/spec/support/report/dummy.rb +0 -15
- data/spec/support/schema.rb +0 -11
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Mercy::Report::Error do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let(:
|
|
7
|
-
let(:
|
|
8
|
-
let(:
|
|
6
|
+
subject { described_class.new(options) }
|
|
7
|
+
|
|
8
|
+
let(:errors) { 1 }
|
|
9
|
+
let(:successes) { 1 }
|
|
10
|
+
let(:old_errors) { 2 }
|
|
11
|
+
let(:threshold) { 0.02 }
|
|
12
|
+
let(:period) { 1.day }
|
|
9
13
|
let(:external_key) { :external_id }
|
|
10
|
-
let(:scope)
|
|
11
|
-
let(:base_scope)
|
|
14
|
+
let(:scope) { :with_error }
|
|
15
|
+
let(:base_scope) { :all }
|
|
12
16
|
let(:options) do
|
|
13
17
|
{
|
|
14
18
|
period: period,
|
|
@@ -19,43 +23,51 @@ describe Mercy::Report::Error do
|
|
|
19
23
|
external_key: external_key
|
|
20
24
|
}
|
|
21
25
|
end
|
|
22
|
-
let(:subject) { described_class.new(options) }
|
|
23
26
|
let(:types) { [:a] }
|
|
27
|
+
|
|
24
28
|
before do
|
|
25
29
|
Document.all.each(&:destroy)
|
|
26
30
|
types.each do |type|
|
|
27
31
|
successes.times { Document.create status: :success, doc_type: type }
|
|
32
|
+
|
|
28
33
|
errors.times do |i|
|
|
29
|
-
Document.create status: :error,
|
|
34
|
+
Document.create status: :error, doc_type: type,
|
|
35
|
+
external_id: (10 * successes) + i, outter_external_id: i
|
|
30
36
|
end
|
|
37
|
+
|
|
31
38
|
old_errors.times do
|
|
32
|
-
Document.create status: :error,
|
|
39
|
+
Document.create status: :error, doc_type: type,
|
|
40
|
+
created_at: 2.days.ago, updated_at: 2.days.ago
|
|
33
41
|
end
|
|
34
42
|
end
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
describe '#status' do
|
|
38
46
|
context 'when are more errors than the allowed by the threshold' do
|
|
39
|
-
let(:errors)
|
|
47
|
+
let(:errors) { 1 }
|
|
40
48
|
let(:successes) { 3 }
|
|
49
|
+
|
|
41
50
|
it { expect(subject.status).to eq(:error) }
|
|
42
51
|
end
|
|
43
52
|
|
|
44
53
|
context 'when the threshold is 0 and there are no errors' do
|
|
45
54
|
let(:errors) { 0 }
|
|
46
55
|
let(:threshold) { 0 }
|
|
56
|
+
|
|
47
57
|
it { expect(subject.status).to eq(:ok) }
|
|
48
58
|
end
|
|
49
59
|
|
|
50
60
|
context 'when the threshold is 100% and there is 100% error' do
|
|
51
61
|
let(:successes) { 0 }
|
|
52
62
|
let(:threshold) { 1 }
|
|
63
|
+
|
|
53
64
|
it { expect(subject.status).to eq(:ok) }
|
|
54
65
|
end
|
|
55
66
|
|
|
56
67
|
context 'when there are no documents' do
|
|
57
68
|
let(:successes) { 0 }
|
|
58
69
|
let(:errors) { 0 }
|
|
70
|
+
|
|
59
71
|
it { expect(subject.status).to eq(:ok) }
|
|
60
72
|
end
|
|
61
73
|
|
|
@@ -74,30 +86,44 @@ describe Mercy::Report::Error do
|
|
|
74
86
|
end
|
|
75
87
|
end
|
|
76
88
|
end
|
|
89
|
+
|
|
90
|
+
context 'when errors percentage overcames threshold' do
|
|
91
|
+
it { expect(subject.status).to eq(:error) }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context 'when errors percentage does not overcames threshold' do
|
|
95
|
+
let(:errors) { 0 }
|
|
96
|
+
|
|
97
|
+
it { expect(subject.status).to eq(:ok) }
|
|
98
|
+
end
|
|
77
99
|
end
|
|
78
100
|
|
|
79
101
|
describe 'percentage' do
|
|
80
102
|
context 'when there are 25% erros' do
|
|
81
|
-
let(:errors)
|
|
103
|
+
let(:errors) { 1 }
|
|
82
104
|
let(:successes) { 3 }
|
|
105
|
+
|
|
83
106
|
it { expect(subject.percentage).to eq(0.25) }
|
|
84
107
|
end
|
|
85
108
|
|
|
86
109
|
context 'when there are no errors' do
|
|
87
110
|
let(:errors) { 0 }
|
|
88
111
|
let(:threshold) { 0 }
|
|
112
|
+
|
|
89
113
|
it { expect(subject.percentage).to eq(0) }
|
|
90
114
|
end
|
|
91
115
|
|
|
92
116
|
context 'when there is 100% error' do
|
|
93
117
|
let(:successes) { 0 }
|
|
94
118
|
let(:threshold) { 1 }
|
|
119
|
+
|
|
95
120
|
it { expect(subject.percentage).to eq(1) }
|
|
96
121
|
end
|
|
97
122
|
|
|
98
123
|
context 'when there are no documents' do
|
|
99
124
|
let(:successes) { 0 }
|
|
100
125
|
let(:errors) { 0 }
|
|
126
|
+
|
|
101
127
|
it { expect(subject.percentage).to eq(0) }
|
|
102
128
|
end
|
|
103
129
|
|
|
@@ -118,12 +144,13 @@ describe Mercy::Report::Error do
|
|
|
118
144
|
end
|
|
119
145
|
|
|
120
146
|
context 'when configuring with a complex scope' do
|
|
121
|
-
let(:types) { [
|
|
147
|
+
let(:types) { %i[a b] }
|
|
122
148
|
let(:old_errors) { 0 }
|
|
123
|
-
let(:scope)
|
|
124
|
-
let(:errors)
|
|
125
|
-
let(:successes)
|
|
126
|
-
|
|
149
|
+
let(:scope) { :'with_error.type_b' }
|
|
150
|
+
let(:errors) { 1 }
|
|
151
|
+
let(:successes) { 3 }
|
|
152
|
+
|
|
153
|
+
context 'with symbol' do
|
|
127
154
|
let(:scope) { :'with_error.type_b' }
|
|
128
155
|
|
|
129
156
|
it 'fetches from each scope in order' do
|
|
@@ -131,7 +158,7 @@ describe Mercy::Report::Error do
|
|
|
131
158
|
end
|
|
132
159
|
end
|
|
133
160
|
|
|
134
|
-
context '
|
|
161
|
+
context 'with string where scope' do
|
|
135
162
|
let(:scope) { "status = 'error' and doc_type = 'b'" }
|
|
136
163
|
|
|
137
164
|
it 'fetches from each scope in order' do
|
|
@@ -139,7 +166,7 @@ describe Mercy::Report::Error do
|
|
|
139
166
|
end
|
|
140
167
|
end
|
|
141
168
|
|
|
142
|
-
context '
|
|
169
|
+
context 'with hash where scope' do
|
|
143
170
|
let(:scope) { { status: :error, doc_type: :b } }
|
|
144
171
|
|
|
145
172
|
it 'fetches from each scope in order' do
|
|
@@ -149,12 +176,12 @@ describe Mercy::Report::Error do
|
|
|
149
176
|
end
|
|
150
177
|
|
|
151
178
|
context 'when using a base scope' do
|
|
152
|
-
let(:types)
|
|
179
|
+
let(:types) { %i[a b b b] }
|
|
153
180
|
let(:old_errors) { 0 }
|
|
154
|
-
let(:errors)
|
|
155
|
-
let(:successes)
|
|
181
|
+
let(:errors) { 1 }
|
|
182
|
+
let(:successes) { 3 }
|
|
156
183
|
|
|
157
|
-
context '
|
|
184
|
+
context 'with symbol' do
|
|
158
185
|
let(:base_scope) { :type_b }
|
|
159
186
|
|
|
160
187
|
it 'fetches from each scope in order' do
|
|
@@ -162,7 +189,7 @@ describe Mercy::Report::Error do
|
|
|
162
189
|
end
|
|
163
190
|
end
|
|
164
191
|
|
|
165
|
-
context '
|
|
192
|
+
context 'with where clause' do
|
|
166
193
|
let(:base_scope) { "doc_type = 'b'" }
|
|
167
194
|
|
|
168
195
|
it 'fetches from each scope in order' do
|
|
@@ -170,7 +197,7 @@ describe Mercy::Report::Error do
|
|
|
170
197
|
end
|
|
171
198
|
end
|
|
172
199
|
|
|
173
|
-
context '
|
|
200
|
+
context 'with hash' do
|
|
174
201
|
let(:base_scope) { { doc_type: :b } }
|
|
175
202
|
|
|
176
203
|
it 'fetches from each scope in order' do
|
|
@@ -182,8 +209,9 @@ describe Mercy::Report::Error do
|
|
|
182
209
|
|
|
183
210
|
describe '#scoped' do
|
|
184
211
|
context 'when there are 25% erros' do
|
|
185
|
-
let(:errors)
|
|
212
|
+
let(:errors) { 1 }
|
|
186
213
|
let(:successes) { 3 }
|
|
214
|
+
|
|
187
215
|
it 'returns only the scoped documents' do
|
|
188
216
|
expect(subject.scoped.count).to eq(1)
|
|
189
217
|
end
|
|
@@ -192,12 +220,14 @@ describe Mercy::Report::Error do
|
|
|
192
220
|
context 'when there are no errors' do
|
|
193
221
|
let(:errors) { 0 }
|
|
194
222
|
let(:threshold) { 0 }
|
|
223
|
+
|
|
195
224
|
it { expect(subject.scoped).to be_empty }
|
|
196
225
|
end
|
|
197
226
|
|
|
198
227
|
context 'when there are no documents' do
|
|
199
228
|
let(:successes) { 0 }
|
|
200
229
|
let(:errors) { 0 }
|
|
230
|
+
|
|
201
231
|
it { expect(subject.scoped).to be_empty }
|
|
202
232
|
end
|
|
203
233
|
|
|
@@ -218,65 +248,59 @@ describe Mercy::Report::Error do
|
|
|
218
248
|
end
|
|
219
249
|
|
|
220
250
|
context 'when configured with a complex scope' do
|
|
221
|
-
let(:types) { [
|
|
251
|
+
let(:types) { %i[a b b] }
|
|
222
252
|
let(:old_errors) { 0 }
|
|
223
253
|
|
|
224
|
-
context '
|
|
254
|
+
context 'with symbol' do
|
|
225
255
|
let(:scope) { :'with_error.type_b' }
|
|
226
256
|
|
|
227
257
|
it 'fetches from each scope in order' do
|
|
228
|
-
expect(subject.scoped.count).to eq(
|
|
229
|
-
expect(subject.scoped.count).to eq(2 * Document.with_error.type_a.count)
|
|
258
|
+
expect(subject.scoped.count).to eq(2)
|
|
230
259
|
end
|
|
231
260
|
end
|
|
232
261
|
|
|
233
|
-
context '
|
|
262
|
+
context 'with hash' do
|
|
234
263
|
let(:scope) { { status: :error, doc_type: :b } }
|
|
235
264
|
|
|
236
265
|
it 'fetches from each scope in order' do
|
|
237
|
-
expect(subject.scoped.count).to eq(
|
|
238
|
-
expect(subject.scoped.count).to eq(2 * Document.with_error.type_a.count)
|
|
266
|
+
expect(subject.scoped.count).to eq(2)
|
|
239
267
|
end
|
|
240
268
|
end
|
|
241
269
|
|
|
242
|
-
context '
|
|
270
|
+
context 'with string where scope' do
|
|
243
271
|
let(:scope) { "status = 'error' and doc_type = 'b'" }
|
|
244
272
|
|
|
245
273
|
it 'fetches from each scope in order' do
|
|
246
|
-
expect(subject.scoped.count).to eq(
|
|
247
|
-
expect(subject.scoped.count).to eq(2 * Document.with_error.type_a.count)
|
|
274
|
+
expect(subject.scoped.count).to eq(2)
|
|
248
275
|
end
|
|
249
276
|
end
|
|
250
277
|
end
|
|
251
278
|
|
|
252
279
|
context 'when using a base scope' do
|
|
253
|
-
let(:types)
|
|
280
|
+
let(:types) { %i[a b b b] }
|
|
254
281
|
let(:old_errors) { 0 }
|
|
255
282
|
|
|
256
|
-
context '
|
|
283
|
+
context 'with symbol' do
|
|
257
284
|
let(:base_scope) { :type_b }
|
|
258
285
|
|
|
259
286
|
it 'fetches from each scope in order' do
|
|
260
|
-
expect(subject.scoped.count).to eq(
|
|
261
|
-
expect(subject.scoped.count).to eq(3 * Document.with_error.type_a.count)
|
|
287
|
+
expect(subject.scoped.count).to eq(3)
|
|
262
288
|
end
|
|
263
289
|
end
|
|
264
290
|
|
|
265
|
-
context '
|
|
291
|
+
context 'with where clause' do
|
|
266
292
|
let(:base_scope) { "doc_type = 'b'" }
|
|
267
293
|
|
|
268
294
|
it 'fetches from each scope in order' do
|
|
269
|
-
expect(subject.scoped.count).to eq(
|
|
270
|
-
expect(subject.scoped.count).to eq(3 * Document.with_error.type_a.count)
|
|
295
|
+
expect(subject.scoped.count).to eq(3)
|
|
271
296
|
end
|
|
272
297
|
end
|
|
273
298
|
|
|
274
|
-
context '
|
|
299
|
+
context 'with hash' do
|
|
275
300
|
let(:base_scope) { { doc_type: :b } }
|
|
276
301
|
|
|
277
302
|
it 'fetches from each scope in order' do
|
|
278
|
-
expect(subject.scoped.count).to eq(
|
|
279
|
-
expect(subject.scoped.count).to eq(3 * Document.with_error.type_a.count)
|
|
303
|
+
expect(subject.scoped.count).to eq(3)
|
|
280
304
|
end
|
|
281
305
|
end
|
|
282
306
|
end
|
|
@@ -284,51 +308,44 @@ describe Mercy::Report::Error do
|
|
|
284
308
|
|
|
285
309
|
describe '#error?' do
|
|
286
310
|
context 'when errors percentage overcames threshold' do
|
|
287
|
-
it { expect(subject
|
|
311
|
+
it { expect(subject).to be_error }
|
|
288
312
|
end
|
|
289
313
|
|
|
290
314
|
context 'when errors percentage does not overcames threshold' do
|
|
291
315
|
let(:errors) { 0 }
|
|
292
|
-
it { expect(subject.error?).to be_falsey }
|
|
293
|
-
end
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
describe '#status' do
|
|
297
|
-
context 'when errors percentage overcames threshold' do
|
|
298
|
-
it { expect(subject.status).to eq(:error) }
|
|
299
|
-
end
|
|
300
316
|
|
|
301
|
-
|
|
302
|
-
let(:errors) { 0 }
|
|
303
|
-
it { expect(subject.status).to eq(:ok) }
|
|
317
|
+
it { expect(subject).not_to be_error }
|
|
304
318
|
end
|
|
305
319
|
end
|
|
306
320
|
|
|
307
321
|
describe '#as_json' do
|
|
308
322
|
let(:expected) do
|
|
309
|
-
{
|
|
323
|
+
{
|
|
324
|
+
ids: ids_expected,
|
|
325
|
+
percentage: percentage_expected,
|
|
326
|
+
status: status_expected
|
|
327
|
+
}
|
|
310
328
|
end
|
|
311
329
|
|
|
312
330
|
context 'when everything is ok' do
|
|
313
|
-
let(:errors)
|
|
314
|
-
let(:successes)
|
|
315
|
-
let(:ids_expected)
|
|
316
|
-
let(:status_expected)
|
|
331
|
+
let(:errors) { 1 }
|
|
332
|
+
let(:successes) { 9 }
|
|
333
|
+
let(:ids_expected) { [90] }
|
|
334
|
+
let(:status_expected) { :ok }
|
|
317
335
|
let(:percentage_expected) { 0.1 }
|
|
318
|
-
let(:threshold)
|
|
336
|
+
let(:threshold) { 0.5 }
|
|
319
337
|
|
|
320
338
|
it 'returns the external keys, status and error percentage' do
|
|
321
339
|
expect(subject.as_json).to eq(expected)
|
|
322
340
|
end
|
|
323
|
-
|
|
324
341
|
end
|
|
325
342
|
|
|
326
343
|
context 'when there are 75% erros' do
|
|
327
344
|
let(:status_expected) { :error }
|
|
328
345
|
let(:percentage_expected) { 0.75 }
|
|
329
|
-
let(:errors)
|
|
330
|
-
let(:successes)
|
|
331
|
-
let(:ids_expected)
|
|
346
|
+
let(:errors) { 3 }
|
|
347
|
+
let(:successes) { 1 }
|
|
348
|
+
let(:ids_expected) { [10, 11, 12] }
|
|
332
349
|
|
|
333
350
|
it 'returns the external keys, status and error percentage' do
|
|
334
351
|
expect(subject.as_json).to eq(expected)
|
|
@@ -344,6 +361,7 @@ describe Mercy::Report::Error do
|
|
|
344
361
|
|
|
345
362
|
context 'when some external ids are the same' do
|
|
346
363
|
let(:ids_expected) { [10, 10, 10] }
|
|
364
|
+
|
|
347
365
|
before do
|
|
348
366
|
Document.update_all(outter_external_id: 10)
|
|
349
367
|
end
|
|
@@ -352,8 +370,9 @@ describe Mercy::Report::Error do
|
|
|
352
370
|
expect(subject.as_json).to eq(expected)
|
|
353
371
|
end
|
|
354
372
|
|
|
355
|
-
context '
|
|
373
|
+
context 'when passing uniq option' do
|
|
356
374
|
before { options[:uniq] = true }
|
|
375
|
+
|
|
357
376
|
let(:ids_expected) { [10] }
|
|
358
377
|
|
|
359
378
|
it 'returns the correct external keys only once' do
|
|
@@ -364,6 +383,7 @@ describe Mercy::Report::Error do
|
|
|
364
383
|
|
|
365
384
|
context 'with a limit' do
|
|
366
385
|
before { options[:limit] = 2 }
|
|
386
|
+
|
|
367
387
|
let(:ids_expected) { [0, 1] }
|
|
368
388
|
|
|
369
389
|
it 'returns only the limited ids' do
|
|
@@ -374,7 +394,10 @@ describe Mercy::Report::Error do
|
|
|
374
394
|
|
|
375
395
|
context 'when configurated without external key' do
|
|
376
396
|
before { options.delete(:external_key) }
|
|
377
|
-
|
|
397
|
+
|
|
398
|
+
let(:ids_expected) do
|
|
399
|
+
Document.with_error.where('created_at > ?', 30.hours.ago).map(&:id)
|
|
400
|
+
end
|
|
378
401
|
|
|
379
402
|
it 'returns the ids as default id' do
|
|
380
403
|
expect(subject.as_json).to eq(expected)
|
|
@@ -1,80 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Mercy::Report::Multiple do
|
|
4
|
-
|
|
5
|
-
ALLOWED_PARAMETERS=[:period, :threshold]
|
|
6
|
-
DEFAULT_OPTION = {
|
|
7
|
-
threshold: 0.25,
|
|
8
|
-
clazz: Document,
|
|
9
|
-
external_key: :external_id
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
expose :doc_type, case: :snake
|
|
13
|
-
|
|
14
|
-
def base
|
|
15
|
-
super.where(doc_type: doc_type)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class Mercy::Report::Multiple::Dummy < Mercy::Report
|
|
20
|
-
include Mercy::Report::Multiple
|
|
21
|
-
DEFAULT_OPTION = {
|
|
22
|
-
doc_type: [:a, :b]
|
|
23
|
-
}
|
|
24
|
-
expose :doc_type, case: :snake
|
|
25
|
-
|
|
26
|
-
def reports_ids
|
|
27
|
-
[ doc_type ].flatten
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def sub_report_class
|
|
31
|
-
Mercy::Report::DocTypeError
|
|
32
|
-
end
|
|
6
|
+
subject { described_class::Dummy.new }
|
|
33
7
|
|
|
34
|
-
|
|
35
|
-
:doc_type
|
|
36
|
-
end
|
|
37
|
-
end
|
|
8
|
+
include_context 'with documents setup'
|
|
38
9
|
|
|
39
|
-
let(:
|
|
40
|
-
let(:a_errors) { 1 }
|
|
10
|
+
let(:a_errors) { 1 }
|
|
41
11
|
let(:a_successes) { 1 }
|
|
42
|
-
let(:b_errors)
|
|
12
|
+
let(:b_errors) { 1 }
|
|
43
13
|
let(:b_successes) { 1 }
|
|
44
|
-
let(:setup) do
|
|
45
|
-
{
|
|
46
|
-
success: { a: a_successes, b: b_successes },
|
|
47
|
-
error: { a: a_errors, b: b_errors }
|
|
48
|
-
}
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
before do
|
|
52
|
-
Document.delete_all
|
|
53
|
-
setup.each do |status, map|
|
|
54
|
-
map.each do |doc_type, quantity|
|
|
55
|
-
quantity.times do
|
|
56
|
-
Document.create(status: status, doc_type: doc_type, external_id: Document.count)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
14
|
|
|
62
15
|
describe '#error?' do
|
|
63
16
|
context 'when all subreports are with error' do
|
|
64
|
-
it { expect(subject
|
|
17
|
+
it { expect(subject).to be_error }
|
|
65
18
|
end
|
|
66
19
|
|
|
67
20
|
context 'when one of the reports is not an error' do
|
|
68
21
|
let(:a_successes) { 4 }
|
|
69
22
|
|
|
70
|
-
it { expect(subject
|
|
23
|
+
it { expect(subject).to be_error }
|
|
71
24
|
end
|
|
72
25
|
|
|
73
26
|
context 'when none of the reports is an error' do
|
|
74
27
|
let(:a_successes) { 4 }
|
|
75
28
|
let(:b_successes) { 4 }
|
|
76
29
|
|
|
77
|
-
it { expect(subject
|
|
30
|
+
it { expect(subject).not_to be_error }
|
|
78
31
|
end
|
|
79
32
|
end
|
|
80
33
|
|
|
@@ -119,4 +72,3 @@ describe Mercy::Report::Multiple do
|
|
|
119
72
|
end
|
|
120
73
|
end
|
|
121
74
|
end
|
|
122
|
-
|