mercy 1.6.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 +4 -4
- data/.circleci/config.yml +74 -12
- 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 +3 -0
- data/.rubocop.yml +38 -1
- data/.rubocop_todo.yml +6 -317
- data/AGENTS.md +58 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +18 -3
- data/Gemfile +26 -1
- data/README.md +8 -4
- data/Rakefile +3 -0
- data/config/check_specs.yml +7 -0
- data/config/yardstick.yml +11 -3
- 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 +14 -27
- data/scripts/bump_version.sh +62 -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 +113 -191
- 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::Range do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let(:
|
|
6
|
+
subject { described_class.new(options) }
|
|
7
|
+
|
|
8
|
+
let(:errors) { 1 }
|
|
9
|
+
let(:successes) { 1 }
|
|
10
|
+
let(:old_errors) { 2 }
|
|
7
11
|
let(:old_sucesses) { 2 }
|
|
8
|
-
let(:period)
|
|
9
|
-
let(:scope)
|
|
10
|
-
let(:maximum)
|
|
11
|
-
let(:minimum)
|
|
12
|
+
let(:period) { 1.day }
|
|
13
|
+
let(:scope) { :with_error }
|
|
14
|
+
let(:maximum) { nil }
|
|
15
|
+
let(:minimum) { nil }
|
|
12
16
|
let(:options) do
|
|
13
17
|
{
|
|
14
18
|
period: period,
|
|
@@ -18,20 +22,27 @@ describe Mercy::Report::Range do
|
|
|
18
22
|
maximum: maximum
|
|
19
23
|
}.clean
|
|
20
24
|
end
|
|
21
|
-
let(:subject) { described_class.new(options) }
|
|
22
25
|
let(:types) { [:a] }
|
|
26
|
+
|
|
23
27
|
before do
|
|
24
28
|
Document.all.each(&:destroy)
|
|
25
29
|
types.each do |type|
|
|
26
30
|
successes.times { Document.create status: :success, doc_type: type }
|
|
31
|
+
|
|
27
32
|
errors.times do |i|
|
|
28
|
-
Document.create status: :error,
|
|
33
|
+
Document.create status: :error,
|
|
34
|
+
external_id: (10 * successes) + i,
|
|
35
|
+
outter_external_id: i, doc_type: type
|
|
29
36
|
end
|
|
37
|
+
|
|
30
38
|
old_errors.times do
|
|
31
|
-
Document.create status: :error,
|
|
39
|
+
Document.create status: :error, doc_type: type,
|
|
40
|
+
created_at: 2.days.ago, updated_at: 2.days.ago
|
|
32
41
|
end
|
|
42
|
+
|
|
33
43
|
old_sucesses.times do
|
|
34
|
-
Document.create status: :success,
|
|
44
|
+
Document.create status: :success, doc_type: type,
|
|
45
|
+
created_at: 2.days.ago, updated_at: 2.days.ago
|
|
35
46
|
end
|
|
36
47
|
end
|
|
37
48
|
end
|
|
@@ -39,32 +50,37 @@ describe Mercy::Report::Range do
|
|
|
39
50
|
describe '#status' do
|
|
40
51
|
context 'when looking for maximum counts' do
|
|
41
52
|
context 'when there are more errors than the allowed by the maximum' do
|
|
42
|
-
let(:errors)
|
|
53
|
+
let(:errors) { 2 }
|
|
43
54
|
let(:maximum) { 1 }
|
|
55
|
+
|
|
44
56
|
it { expect(subject.status).to eq(:error) }
|
|
45
57
|
end
|
|
46
58
|
|
|
47
59
|
context 'when the maximum is 0 and there are no errors' do
|
|
48
60
|
let(:errors) { 0 }
|
|
49
61
|
let(:maximum) { 0 }
|
|
62
|
+
|
|
50
63
|
it { expect(subject.status).to eq(:ok) }
|
|
51
64
|
end
|
|
52
65
|
|
|
53
66
|
context 'when the maximum is nil and there are no errors' do
|
|
54
67
|
let(:errors) { 0 }
|
|
55
68
|
let(:maximum) { nil }
|
|
69
|
+
|
|
56
70
|
it { expect(subject.status).to eq(:ok) }
|
|
57
71
|
end
|
|
58
72
|
|
|
59
73
|
context 'when the count is the same as the maximum' do
|
|
60
74
|
let(:errors) { 1 }
|
|
61
75
|
let(:maximum) { 1 }
|
|
76
|
+
|
|
62
77
|
it { expect(subject.status).to eq(:ok) }
|
|
63
78
|
end
|
|
64
79
|
|
|
65
80
|
context 'when the count is less than the maximum' do
|
|
66
81
|
let(:errors) { 1 }
|
|
67
82
|
let(:maximum) { 2 }
|
|
83
|
+
|
|
68
84
|
it { expect(subject.status).to eq(:ok) }
|
|
69
85
|
end
|
|
70
86
|
|
|
@@ -77,7 +93,7 @@ describe Mercy::Report::Range do
|
|
|
77
93
|
|
|
78
94
|
context 'when passing a bigger period' do
|
|
79
95
|
let(:period) { 3.days }
|
|
80
|
-
|
|
96
|
+
|
|
81
97
|
it 'consider the older errros' do
|
|
82
98
|
expect(subject.status).to eq(:error)
|
|
83
99
|
end
|
|
@@ -87,33 +103,39 @@ describe Mercy::Report::Range do
|
|
|
87
103
|
|
|
88
104
|
context 'when looking for minimum' do
|
|
89
105
|
let(:scope) { :with_success }
|
|
106
|
+
|
|
90
107
|
context 'when there are less successes than the allowed by the minimum' do
|
|
91
108
|
let(:successes) { 1 }
|
|
92
|
-
let(:minimum)
|
|
109
|
+
let(:minimum) { 2 }
|
|
110
|
+
|
|
93
111
|
it { expect(subject.status).to eq(:error) }
|
|
94
112
|
end
|
|
95
113
|
|
|
96
114
|
context 'when the minimum is 0 and there are no sucesses' do
|
|
97
115
|
let(:successes) { 0 }
|
|
98
116
|
let(:minimum) { 0 }
|
|
117
|
+
|
|
99
118
|
it { expect(subject.status).to eq(:ok) }
|
|
100
119
|
end
|
|
101
120
|
|
|
102
121
|
context 'when the minimum is nil and there are no sucesses' do
|
|
103
122
|
let(:successes) { 0 }
|
|
104
123
|
let(:minimum) { nil }
|
|
124
|
+
|
|
105
125
|
it { expect(subject.status).to eq(:ok) }
|
|
106
126
|
end
|
|
107
127
|
|
|
108
128
|
context 'when the count is the same as the minimum' do
|
|
109
129
|
let(:successes) { 1 }
|
|
110
130
|
let(:minimum) { 1 }
|
|
131
|
+
|
|
111
132
|
it { expect(subject.status).to eq(:ok) }
|
|
112
133
|
end
|
|
113
134
|
|
|
114
135
|
context 'when the count is greater than the minimum' do
|
|
115
136
|
let(:successes) { 2 }
|
|
116
137
|
let(:minimum) { 1 }
|
|
138
|
+
|
|
117
139
|
it { expect(subject.status).to eq(:ok) }
|
|
118
140
|
end
|
|
119
141
|
|
|
@@ -127,7 +149,7 @@ describe Mercy::Report::Range do
|
|
|
127
149
|
|
|
128
150
|
context 'when passing a bigger period' do
|
|
129
151
|
let(:period) { 3.days }
|
|
130
|
-
|
|
152
|
+
|
|
131
153
|
it 'consider the older sucesses' do
|
|
132
154
|
expect(subject.status).to eq(:ok)
|
|
133
155
|
end
|
|
@@ -136,44 +158,50 @@ describe Mercy::Report::Range do
|
|
|
136
158
|
end
|
|
137
159
|
|
|
138
160
|
context 'when looking for a range' do
|
|
139
|
-
let(:scope)
|
|
161
|
+
let(:scope) { :all }
|
|
140
162
|
let(:minimum) { 2 }
|
|
141
163
|
let(:maximum) { 4 }
|
|
142
164
|
|
|
143
165
|
context 'when there are less documents than the allowed by the minimum' do
|
|
144
166
|
let(:successes) { 1 }
|
|
145
167
|
let(:errors) { 0 }
|
|
168
|
+
|
|
146
169
|
it { expect(subject.status).to eq(:error) }
|
|
147
170
|
end
|
|
148
171
|
|
|
149
172
|
context 'when the count is the same as the minimum' do
|
|
150
173
|
let(:successes) { 1 }
|
|
151
|
-
let(:errors) {
|
|
174
|
+
let(:errors) { 1 }
|
|
175
|
+
|
|
152
176
|
it { expect(subject.status).to eq(:ok) }
|
|
153
177
|
end
|
|
154
178
|
|
|
155
179
|
context 'when the count is inside the range' do
|
|
156
180
|
let(:successes) { 1 }
|
|
157
181
|
let(:errors) { 2 }
|
|
182
|
+
|
|
158
183
|
it { expect(subject.status).to eq(:ok) }
|
|
159
184
|
end
|
|
160
185
|
|
|
161
186
|
context 'when the count is the same as the maximum' do
|
|
162
187
|
let(:successes) { 2 }
|
|
163
188
|
let(:errors) { 2 }
|
|
189
|
+
|
|
164
190
|
it { expect(subject.status).to eq(:ok) }
|
|
165
191
|
end
|
|
166
192
|
|
|
167
193
|
context 'when the count is greater than the maximum' do
|
|
168
194
|
let(:successes) { 3 }
|
|
169
195
|
let(:errors) { 2 }
|
|
196
|
+
|
|
170
197
|
it { expect(subject.status).to eq(:error) }
|
|
171
198
|
end
|
|
172
199
|
|
|
173
200
|
context 'when the minimum is 0 and the count is 0' do
|
|
174
201
|
let(:successes) { 0 }
|
|
175
|
-
let(:errors)
|
|
202
|
+
let(:errors) { 0 }
|
|
176
203
|
let(:minimum) { 0 }
|
|
204
|
+
|
|
177
205
|
it { expect(subject.status).to eq(:ok) }
|
|
178
206
|
end
|
|
179
207
|
|
|
@@ -181,34 +209,34 @@ describe Mercy::Report::Range do
|
|
|
181
209
|
let(:old_errors) { 1 }
|
|
182
210
|
let(:old_sucesses) { 2 }
|
|
183
211
|
|
|
184
|
-
context '
|
|
212
|
+
context 'when the regular documents are not enough' do
|
|
185
213
|
let(:successes) { 1 }
|
|
186
214
|
let(:errors) { 0 }
|
|
187
|
-
|
|
215
|
+
|
|
188
216
|
it 'ignores the older sucesses' do
|
|
189
217
|
expect(subject.status).to eq(:error)
|
|
190
218
|
end
|
|
191
219
|
|
|
192
220
|
context 'when passing a bigger period' do
|
|
193
221
|
let(:period) { 3.days }
|
|
194
|
-
|
|
222
|
+
|
|
195
223
|
it 'consider the older sucesses' do
|
|
196
224
|
expect(subject.status).to eq(:ok)
|
|
197
225
|
end
|
|
198
226
|
end
|
|
199
227
|
end
|
|
200
228
|
|
|
201
|
-
context '
|
|
229
|
+
context 'when the regular documents are almost in the limit' do
|
|
202
230
|
let(:successes) { 2 }
|
|
203
|
-
let(:errors)
|
|
204
|
-
|
|
231
|
+
let(:errors) { 1 }
|
|
232
|
+
|
|
205
233
|
it 'ignores the older sucesses' do
|
|
206
234
|
expect(subject.status).to eq(:ok)
|
|
207
235
|
end
|
|
208
236
|
|
|
209
237
|
context 'when passing a bigger period' do
|
|
210
238
|
let(:period) { 3.days }
|
|
211
|
-
|
|
239
|
+
|
|
212
240
|
it 'consider the older documents' do
|
|
213
241
|
expect(subject.status).to eq(:error)
|
|
214
242
|
end
|
|
@@ -218,21 +246,21 @@ describe Mercy::Report::Range do
|
|
|
218
246
|
end
|
|
219
247
|
end
|
|
220
248
|
|
|
221
|
-
describe '#count' do
|
|
222
|
-
let(:types)
|
|
249
|
+
describe '#count' do
|
|
250
|
+
let(:types) { %i[a b] }
|
|
223
251
|
let(:errors) { 1 }
|
|
224
|
-
let(:scope)
|
|
252
|
+
let(:scope) { :with_error }
|
|
225
253
|
|
|
226
254
|
it 'returns all the documents found' do
|
|
227
255
|
expect(subject.count).to eq(2)
|
|
228
256
|
end
|
|
229
|
-
|
|
257
|
+
|
|
230
258
|
context 'when configuring with a complex scope' do
|
|
231
259
|
let(:old_errors) { 0 }
|
|
232
|
-
let(:scope)
|
|
260
|
+
let(:scope) { :'with_error.type_b' }
|
|
233
261
|
let(:errors) { 1 }
|
|
234
262
|
|
|
235
|
-
context '
|
|
263
|
+
context 'with symbol' do
|
|
236
264
|
let(:scope) { :'with_error.type_b' }
|
|
237
265
|
|
|
238
266
|
it 'fetches from each scope in order' do
|
|
@@ -240,7 +268,7 @@ describe Mercy::Report::Range do
|
|
|
240
268
|
end
|
|
241
269
|
end
|
|
242
270
|
|
|
243
|
-
context '
|
|
271
|
+
context 'with string where scope' do
|
|
244
272
|
let(:scope) { "status = 'error' and doc_type = 'b'" }
|
|
245
273
|
|
|
246
274
|
it 'fetches from each scope in order' do
|
|
@@ -248,7 +276,7 @@ describe Mercy::Report::Range do
|
|
|
248
276
|
end
|
|
249
277
|
end
|
|
250
278
|
|
|
251
|
-
context '
|
|
279
|
+
context 'with hash where scope' do
|
|
252
280
|
let(:scope) { { status: :error, doc_type: :b } }
|
|
253
281
|
|
|
254
282
|
it 'fetches from each scope in order' do
|
|
@@ -259,16 +287,17 @@ describe Mercy::Report::Range do
|
|
|
259
287
|
end
|
|
260
288
|
|
|
261
289
|
describe '#error?' do
|
|
262
|
-
let(:errors)
|
|
290
|
+
let(:errors) { 2 }
|
|
263
291
|
let(:maximum) { 1 }
|
|
264
292
|
|
|
265
293
|
context 'when errors count overcome maximum' do
|
|
266
|
-
it { expect(subject
|
|
294
|
+
it { expect(subject).to be_error }
|
|
267
295
|
end
|
|
268
296
|
|
|
269
297
|
context 'when errors count do not overcome maximum' do
|
|
270
298
|
let(:errors) { 0 }
|
|
271
|
-
|
|
299
|
+
|
|
300
|
+
it { expect(subject).not_to be_error }
|
|
272
301
|
end
|
|
273
302
|
end
|
|
274
303
|
|
|
@@ -278,10 +307,10 @@ describe Mercy::Report::Range do
|
|
|
278
307
|
end
|
|
279
308
|
|
|
280
309
|
context 'when everything is ok' do
|
|
281
|
-
let(:errors)
|
|
310
|
+
let(:errors) { 1 }
|
|
282
311
|
let(:status_expected) { :ok }
|
|
283
|
-
let(:count_expected)
|
|
284
|
-
let(:maximum)
|
|
312
|
+
let(:count_expected) { errors }
|
|
313
|
+
let(:maximum) { 2 }
|
|
285
314
|
|
|
286
315
|
it 'returns the count and status' do
|
|
287
316
|
expect(subject.as_json).to eq(expected)
|
|
@@ -291,8 +320,8 @@ describe Mercy::Report::Range do
|
|
|
291
320
|
context 'when there is an error' do
|
|
292
321
|
let(:errors) { 2 }
|
|
293
322
|
let(:status_expected) { :error }
|
|
294
|
-
let(:count_expected)
|
|
295
|
-
let(:maximum)
|
|
323
|
+
let(:count_expected) { errors }
|
|
324
|
+
let(:maximum) { 1 }
|
|
296
325
|
|
|
297
326
|
it 'returns the count and status' do
|
|
298
327
|
expect(subject.as_json).to eq(expected)
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Mercy::ReportBuilder do
|
|
4
|
-
let(:errors)
|
|
5
|
-
let(:successes)
|
|
6
|
-
let(:old_errors)
|
|
7
|
-
let(:key)
|
|
8
|
-
let(:threshold)
|
|
9
|
-
let(:period)
|
|
6
|
+
let(:errors) { 1 }
|
|
7
|
+
let(:successes) { 3 }
|
|
8
|
+
let(:old_errors) { 2 }
|
|
9
|
+
let(:key) { :errors }
|
|
10
|
+
let(:threshold) { 0.02 }
|
|
11
|
+
let(:period) { 1.day }
|
|
10
12
|
let(:external_key) { :external_id }
|
|
11
13
|
let(:config) do
|
|
12
14
|
{
|
|
@@ -20,32 +22,42 @@ describe Mercy::ReportBuilder do
|
|
|
20
22
|
end
|
|
21
23
|
let(:parameters) { {} }
|
|
22
24
|
let(:report) { subject.build(key, parameters) }
|
|
25
|
+
|
|
23
26
|
before do
|
|
24
27
|
subject.add_config(key, config)
|
|
25
28
|
Document.all.each(&:destroy)
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
|
|
30
|
+
successes.times do |i|
|
|
31
|
+
Document.create status: :success, external_id: 30 + i
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
errors.times do |i|
|
|
35
|
+
Document.create status: :error, external_id: 10 + i
|
|
36
|
+
end
|
|
37
|
+
|
|
28
38
|
old_errors.times do |i|
|
|
29
|
-
Document.create status: :error, external_id: 20+i,
|
|
39
|
+
Document.create status: :error, external_id: 20 + i,
|
|
40
|
+
created_at: 2.days.ago, updated_at: 2.days.ago
|
|
30
41
|
end
|
|
31
42
|
end
|
|
32
43
|
|
|
33
44
|
describe '#build' do
|
|
34
|
-
let(:ids) { [
|
|
45
|
+
let(:ids) { [10] }
|
|
46
|
+
|
|
35
47
|
it do
|
|
36
48
|
expect(report).to be_a(Mercy::Report::Error)
|
|
37
49
|
end
|
|
38
50
|
|
|
39
51
|
it 'builds the report using the given configuration' do
|
|
40
|
-
expect(report.as_json).to eq(
|
|
41
|
-
expect(report
|
|
52
|
+
expect(report.as_json).to eq(ids: ids, percentage: 0.25, status: :error)
|
|
53
|
+
expect(report).to be_error
|
|
42
54
|
end
|
|
43
55
|
|
|
44
56
|
context 'when passing a custom threshold parameter' do
|
|
45
57
|
let(:parameters) { { threshold: 1 } }
|
|
46
58
|
|
|
47
59
|
it 'uses custom threshold parameter' do
|
|
48
|
-
expect(report
|
|
60
|
+
expect(report).not_to be_error
|
|
49
61
|
end
|
|
50
62
|
end
|
|
51
63
|
|
|
@@ -53,18 +65,23 @@ describe Mercy::ReportBuilder do
|
|
|
53
65
|
let(:parameters) { { threshold: 0.4, period: 10.days, status: :error } }
|
|
54
66
|
|
|
55
67
|
it 'uses custom period parameter' do
|
|
56
|
-
expect(report
|
|
68
|
+
expect(report).to be_error
|
|
57
69
|
end
|
|
58
70
|
end
|
|
59
71
|
|
|
60
72
|
context 'when passing a custom other parameters' do
|
|
61
73
|
let(:parameters) do
|
|
62
|
-
{
|
|
74
|
+
{
|
|
75
|
+
scope: :with_success,
|
|
76
|
+
clazz: Mercy::Report::Error,
|
|
77
|
+
external_key: :id,
|
|
78
|
+
id: :failures
|
|
79
|
+
}
|
|
63
80
|
end
|
|
64
81
|
|
|
65
82
|
it 'ignores the non customizable parameters' do
|
|
66
|
-
expect(report.as_json).to eq(
|
|
67
|
-
expect(report
|
|
83
|
+
expect(report.as_json).to eq(ids: ids, percentage: 0.25, status: :error)
|
|
84
|
+
expect(report).to be_error
|
|
68
85
|
expect(report.id).to eq(:errors)
|
|
69
86
|
end
|
|
70
87
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Mercy::ReportConfig do
|
|
6
|
+
subject { described_class.new(config) }
|
|
7
|
+
|
|
8
|
+
let(:config) { {} }
|
|
9
|
+
let(:parameters) { {} }
|
|
10
|
+
|
|
11
|
+
describe '#build' do
|
|
12
|
+
context 'when no config is given' do
|
|
13
|
+
it do
|
|
14
|
+
expect(subject.build(parameters)).to be_a(Mercy::Report::Error)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'when a dummy type is given' do
|
|
19
|
+
let(:config) { { type: :dummy_report } }
|
|
20
|
+
|
|
21
|
+
let!(:expected) { Mercy::Report::DummyReport }
|
|
22
|
+
|
|
23
|
+
it do
|
|
24
|
+
expect(subject.build(parameters)).to be_a(expected)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context 'when a class is given as type' do
|
|
29
|
+
let(:config) { { type: Mercy::Report::DummyReport } }
|
|
30
|
+
|
|
31
|
+
let!(:expected) { Mercy::Report::DummyReport }
|
|
32
|
+
|
|
33
|
+
it do
|
|
34
|
+
expect(subject.build(parameters)).to be_a(expected)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context 'when a global class is given as type' do
|
|
39
|
+
let(:config) { { type: DummyReport } }
|
|
40
|
+
|
|
41
|
+
let!(:expected) { DummyReport }
|
|
42
|
+
|
|
43
|
+
it do
|
|
44
|
+
expect(subject.build(parameters)).to be_a(expected)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,22 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Mercy::Report do
|
|
4
|
-
class Mercy::Report::Dummy1 < Mercy::Report
|
|
5
|
-
DEFAULT_OPTION = {
|
|
6
|
-
option_value: 1,
|
|
7
|
-
other_option: 10
|
|
8
|
-
}
|
|
9
|
-
expose :option_value, :other_option, case: :snake
|
|
10
|
-
end
|
|
11
|
-
class Mercy::Report::Dummy2 < Mercy::Report::Dummy1; end
|
|
12
|
-
class Mercy::Report::Dummy3 < Mercy::Report::Dummy1
|
|
13
|
-
DEFAULT_OPTION = { option_value: 5 }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
6
|
describe 'default_options' do
|
|
7
|
+
subject { report_class.new }
|
|
8
|
+
|
|
17
9
|
let(:report_class) { described_class::Dummy1 }
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
|
|
20
11
|
it 'setup the attributes using class default options' do
|
|
21
12
|
expect(subject.option_value).to eq(1)
|
|
22
13
|
expect(subject.other_option).to eq(10)
|
|
@@ -41,4 +32,3 @@ describe Mercy::Report do
|
|
|
41
32
|
end
|
|
42
33
|
end
|
|
43
34
|
end
|
|
44
|
-
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Mercy::StatusBuilder do
|
|
4
|
-
let(:errors)
|
|
5
|
-
let(:successes)
|
|
6
|
-
let(:old_errors)
|
|
7
|
-
let(:key)
|
|
8
|
-
let(:threshold)
|
|
9
|
-
let(:period)
|
|
6
|
+
let(:errors) { 1 }
|
|
7
|
+
let(:successes) { 3 }
|
|
8
|
+
let(:old_errors) { 2 }
|
|
9
|
+
let(:key) { :errors }
|
|
10
|
+
let(:threshold) { 0.02 }
|
|
11
|
+
let(:period) { 1.day }
|
|
10
12
|
let(:external_key) { :external_id }
|
|
11
13
|
let(:config) do
|
|
12
14
|
{
|
|
@@ -21,29 +23,38 @@ describe Mercy::StatusBuilder do
|
|
|
21
23
|
end
|
|
22
24
|
let(:parameters) { {} }
|
|
23
25
|
let(:status) { subject.build(key, parameters) }
|
|
26
|
+
|
|
24
27
|
before do
|
|
25
28
|
subject.add_report_config(key, config)
|
|
26
29
|
Document.all.each(&:destroy)
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
successes.times do |i|
|
|
32
|
+
Document.create status: :success, external_id: 30 + i
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
errors.times do |i|
|
|
36
|
+
Document.create status: :error, external_id: 10 + i
|
|
37
|
+
end
|
|
38
|
+
|
|
29
39
|
old_errors.times do |i|
|
|
30
|
-
Document.create status: :error, external_id: 20+i,
|
|
40
|
+
Document.create status: :error, external_id: 20 + i,
|
|
41
|
+
created_at: 2.days.ago, updated_at: 2.days.ago
|
|
31
42
|
end
|
|
32
43
|
end
|
|
33
44
|
|
|
34
45
|
describe '#build' do
|
|
35
|
-
let(:ids) { [
|
|
46
|
+
let(:ids) { [10] }
|
|
36
47
|
let(:status_expected) { :error }
|
|
37
|
-
let(:percentage)
|
|
48
|
+
let(:percentage) { 0.25 }
|
|
38
49
|
let(:json_expected) do
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
{
|
|
51
|
+
status: status_expected,
|
|
52
|
+
failures: {
|
|
53
|
+
ids: ids,
|
|
54
|
+
percentage: percentage,
|
|
55
|
+
status: status_expected
|
|
56
|
+
}
|
|
57
|
+
}
|
|
47
58
|
end
|
|
48
59
|
|
|
49
60
|
it do
|
|
@@ -51,7 +62,7 @@ describe Mercy::StatusBuilder do
|
|
|
51
62
|
end
|
|
52
63
|
|
|
53
64
|
context 'when not specifying where to report' do
|
|
54
|
-
let(:key) {}
|
|
65
|
+
let(:key) { nil }
|
|
55
66
|
|
|
56
67
|
it 'register report under default' do
|
|
57
68
|
expect(subject.build(:default).as_json).to eq(json_expected)
|
|
@@ -63,7 +74,7 @@ describe Mercy::StatusBuilder do
|
|
|
63
74
|
end
|
|
64
75
|
|
|
65
76
|
context 'when passing a custom threshold parameter' do
|
|
66
|
-
let(:parameters)
|
|
77
|
+
let(:parameters) { { threshold: 1 } }
|
|
67
78
|
let(:status_expected) { :ok }
|
|
68
79
|
|
|
69
80
|
it 'uses custom threshold parameter' do
|
|
@@ -72,7 +83,7 @@ describe Mercy::StatusBuilder do
|
|
|
72
83
|
end
|
|
73
84
|
|
|
74
85
|
context 'when passing a custom period parameter' do
|
|
75
|
-
let(:ids) { [
|
|
86
|
+
let(:ids) { [10, 20, 21] }
|
|
76
87
|
let(:percentage) { 0.5 }
|
|
77
88
|
let(:parameters) { { threshold: 0.4, period: 10.days } }
|
|
78
89
|
|