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,8 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe Mercy::Status do
|
|
6
|
+
subject { described_class.new(reports) }
|
|
7
|
+
|
|
4
8
|
let(:threshold) { 0.02 }
|
|
5
|
-
let(:period)
|
|
9
|
+
let(:period) { 1.day }
|
|
6
10
|
let(:report_options) do
|
|
7
11
|
{
|
|
8
12
|
period: period,
|
|
@@ -19,13 +23,13 @@ describe Mercy::Status do
|
|
|
19
23
|
)
|
|
20
24
|
end
|
|
21
25
|
let(:errors) { 0 }
|
|
22
|
-
let(:successes)
|
|
26
|
+
let(:successes) { 1 }
|
|
23
27
|
let(:error_report) { Mercy::Report::Error.new(report_options) }
|
|
24
28
|
let(:success_report) do
|
|
25
29
|
Mercy::Report::Error.new(success_options)
|
|
26
30
|
end
|
|
27
|
-
let(:reports) { [
|
|
28
|
-
|
|
31
|
+
let(:reports) { [error_report] }
|
|
32
|
+
|
|
29
33
|
before do
|
|
30
34
|
Document.all.each(&:destroy)
|
|
31
35
|
errors.times { Document.create status: :error }
|
|
@@ -34,7 +38,7 @@ describe Mercy::Status do
|
|
|
34
38
|
|
|
35
39
|
describe '#as_json' do
|
|
36
40
|
let(:status_json) { subject.as_json }
|
|
37
|
-
let(:status)
|
|
41
|
+
let(:status) { status_json[:status] }
|
|
38
42
|
|
|
39
43
|
context 'when report is ok' do
|
|
40
44
|
it 'returns a json with ok' do
|
|
@@ -42,7 +46,7 @@ describe Mercy::Status do
|
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
it 'returns the report json' do
|
|
45
|
-
|
|
49
|
+
expect(status_json[:errors]).to eq(error_report.as_json)
|
|
46
50
|
end
|
|
47
51
|
end
|
|
48
52
|
|
|
@@ -58,18 +62,61 @@ describe Mercy::Status do
|
|
|
58
62
|
let(:success_report) do
|
|
59
63
|
Mercy::Report::Error.new(report_options.merge(scope: :with_success))
|
|
60
64
|
end
|
|
61
|
-
let(:reports) { [
|
|
65
|
+
let(:reports) { [success_report, error_report] }
|
|
62
66
|
|
|
63
67
|
it 'returns a json with error' do
|
|
64
68
|
expect(status).to eq(:error)
|
|
65
69
|
end
|
|
66
70
|
end
|
|
71
|
+
|
|
72
|
+
context 'when building the full summary' do
|
|
73
|
+
let(:errors) { 3 }
|
|
74
|
+
let(:ids) { Document.with_error.map(&:id) }
|
|
75
|
+
let(:expected) do
|
|
76
|
+
{
|
|
77
|
+
status: :error,
|
|
78
|
+
errors: {
|
|
79
|
+
ids: ids,
|
|
80
|
+
percentage: 0.75,
|
|
81
|
+
status: :error
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'creates a summary of the reports' do
|
|
87
|
+
expect(subject.as_json).to eq(expected)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context 'when there are both success and error reports' do
|
|
91
|
+
let(:success_ids) { Document.with_success.map(&:id) }
|
|
92
|
+
let(:expected) do
|
|
93
|
+
{
|
|
94
|
+
status: :error,
|
|
95
|
+
errors: {
|
|
96
|
+
ids: ids,
|
|
97
|
+
percentage: 0.75,
|
|
98
|
+
status: :error
|
|
99
|
+
},
|
|
100
|
+
success: {
|
|
101
|
+
ids: success_ids,
|
|
102
|
+
percentage: 0.25,
|
|
103
|
+
status: :error
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
end
|
|
107
|
+
let(:reports) { [success_report, error_report] }
|
|
108
|
+
|
|
109
|
+
it 'creates a summary of all the reports' do
|
|
110
|
+
expect(subject.as_json).to eq(expected)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
67
114
|
end
|
|
68
115
|
|
|
69
|
-
describe '#
|
|
116
|
+
describe '#http_status' do
|
|
70
117
|
context 'when report is ok' do
|
|
71
118
|
it do
|
|
72
|
-
expect(subject.
|
|
119
|
+
expect(subject.http_status).to eq(:ok)
|
|
73
120
|
end
|
|
74
121
|
end
|
|
75
122
|
|
|
@@ -77,58 +124,31 @@ describe Mercy::Status do
|
|
|
77
124
|
let(:errors) { 1 }
|
|
78
125
|
|
|
79
126
|
it do
|
|
80
|
-
expect(subject.
|
|
127
|
+
expect(subject.http_status).to eq(:internal_server_error)
|
|
81
128
|
end
|
|
82
129
|
end
|
|
130
|
+
end
|
|
83
131
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
132
|
+
describe '#status' do
|
|
133
|
+
context 'when report is ok' do
|
|
87
134
|
it do
|
|
88
|
-
expect(subject.status).to eq(:
|
|
135
|
+
expect(subject.status).to eq(:ok)
|
|
89
136
|
end
|
|
90
137
|
end
|
|
91
|
-
end
|
|
92
138
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let(:ids) { Document.with_error.map(&:id) }
|
|
96
|
-
let(:expected) do
|
|
97
|
-
{
|
|
98
|
-
status: :error,
|
|
99
|
-
errors: {
|
|
100
|
-
ids: ids,
|
|
101
|
-
percentage: 0.75,
|
|
102
|
-
status: :error
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
end
|
|
139
|
+
context 'when report is not ok' do
|
|
140
|
+
let(:errors) { 1 }
|
|
106
141
|
|
|
107
|
-
|
|
108
|
-
|
|
142
|
+
it do
|
|
143
|
+
expect(subject.status).to eq(:error)
|
|
144
|
+
end
|
|
109
145
|
end
|
|
110
146
|
|
|
111
147
|
context 'when there are both success and error reports' do
|
|
112
|
-
let(:
|
|
113
|
-
let(:expected) do
|
|
114
|
-
{
|
|
115
|
-
status: :error,
|
|
116
|
-
errors: {
|
|
117
|
-
ids: ids,
|
|
118
|
-
percentage: 0.75,
|
|
119
|
-
status: :error
|
|
120
|
-
},
|
|
121
|
-
success: {
|
|
122
|
-
ids: success_ids,
|
|
123
|
-
percentage: 0.25,
|
|
124
|
-
status: :error
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
end
|
|
128
|
-
let(:reports) { [ success_report, error_report ] }
|
|
148
|
+
let(:reports) { [success_report, error_report] }
|
|
129
149
|
|
|
130
|
-
it
|
|
131
|
-
expect(subject.
|
|
150
|
+
it do
|
|
151
|
+
expect(subject.status).to eq(:error)
|
|
132
152
|
end
|
|
133
153
|
end
|
|
134
154
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'simplecov'
|
|
4
|
+
require 'simplecov-lcov'
|
|
5
|
+
|
|
6
|
+
if ENV['CI']
|
|
7
|
+
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
|
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
|
9
|
+
end
|
|
2
10
|
|
|
3
11
|
SimpleCov.profiles.define 'gem' do
|
|
4
12
|
add_filter '/spec/'
|
|
@@ -10,19 +18,22 @@ require 'pry-nav'
|
|
|
10
18
|
require 'mercy'
|
|
11
19
|
|
|
12
20
|
require 'active_record'
|
|
13
|
-
ActiveRecord::Base.establish_connection(
|
|
21
|
+
ActiveRecord::Base.establish_connection(
|
|
22
|
+
adapter: 'sqlite3', database: ':memory:'
|
|
23
|
+
)
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
require File.expand_path('spec/dummy/config/environment')
|
|
26
|
+
require File.expand_path('spec/dummy/db/schema.rb')
|
|
27
|
+
require 'rspec/rails'
|
|
28
|
+
require 'active_support/railtie'
|
|
29
|
+
|
|
30
|
+
support_files = File.expand_path('spec/support/**/*.rb')
|
|
31
|
+
Dir[support_files].each { |file| require file }
|
|
17
32
|
|
|
18
33
|
RSpec.configure do |config|
|
|
19
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
20
34
|
config.run_all_when_everything_filtered = true
|
|
21
35
|
config.filter_run :focus
|
|
22
36
|
config.filter_run_excluding :integration unless ENV['ALL']
|
|
23
37
|
|
|
24
38
|
config.order = 'random'
|
|
25
|
-
|
|
26
|
-
config.before do
|
|
27
|
-
end
|
|
28
39
|
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'active_support'
|
|
2
4
|
|
|
3
5
|
module FixtureHelpers
|
|
4
6
|
def load_fixture_file(filename)
|
|
5
|
-
|
|
7
|
+
File.read ['./spec/', 'fixtures', filename].join('/')
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
def load_json_fixture_file(filename)
|
|
@@ -12,7 +14,7 @@ module FixtureHelpers
|
|
|
12
14
|
private
|
|
13
15
|
|
|
14
16
|
def cached_json_fixture_file(filename)
|
|
15
|
-
|
|
17
|
+
ActiveSupport::JSON.decode(load_fixture_file(filename))
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.shared_context 'with documents setup' do
|
|
4
|
+
let(:a_successes) { 0 }
|
|
5
|
+
let(:b_successes) { 0 }
|
|
6
|
+
let(:c_successes) { 0 }
|
|
7
|
+
let(:a_errors) { 0 }
|
|
8
|
+
let(:b_errors) { 0 }
|
|
9
|
+
let(:c_errors) { 0 }
|
|
10
|
+
|
|
11
|
+
let(:setup) do
|
|
12
|
+
{
|
|
13
|
+
success: { a: a_successes, b: b_successes, c: c_successes },
|
|
14
|
+
error: { a: a_errors, b: b_errors, c: c_errors }
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
Document.delete_all
|
|
20
|
+
|
|
21
|
+
setup.each do |status, map|
|
|
22
|
+
map.each do |doc_type, quantity|
|
|
23
|
+
quantity.times do
|
|
24
|
+
Document.create(
|
|
25
|
+
status: status, doc_type: doc_type, external_id: Document.count
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|