marty 9.3.0 → 9.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gemignore +2 -0
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +34 -1
  5. data/Gemfile +1 -0
  6. data/Rakefile +10 -0
  7. data/app/assets/javascripts/marty/cable.js +21 -9
  8. data/app/channels/application_cable/connection.rb +1 -1
  9. data/app/channels/marty/notification_channel.rb +4 -1
  10. data/app/components/marty/api_config_view.rb +1 -1
  11. data/app/components/marty/api_log_view.rb +1 -1
  12. data/app/components/marty/auth_app.rb +8 -1
  13. data/app/components/marty/auth_app/client/auth_app.js +6 -0
  14. data/app/components/marty/data_grid_view.rb +6 -6
  15. data/app/components/marty/extras/misc.rb +1 -1
  16. data/app/components/marty/log_view.rb +1 -1
  17. data/app/components/marty/posting_grid.rb +1 -1
  18. data/app/components/marty/script_form.rb +3 -3
  19. data/app/components/marty/user_view.rb +1 -1
  20. data/app/components/marty/users/user_view.rb +1 -1
  21. data/app/controllers/marty/application_controller.rb +7 -7
  22. data/app/controllers/marty/delayed_job_controller.rb +7 -4
  23. data/app/controllers/marty/diagnostic/controller.rb +1 -1
  24. data/app/controllers/marty/job_controller.rb +2 -2
  25. data/app/models/marty/api_auth.rb +3 -3
  26. data/app/models/marty/api_config.rb +1 -1
  27. data/app/models/marty/base_rule.rb +1 -1
  28. data/app/models/marty/config.rb +5 -5
  29. data/app/models/marty/data_grid.rb +3 -3
  30. data/app/models/marty/delorean_rule.rb +2 -2
  31. data/app/models/marty/grid_index_boolean.rb +2 -2
  32. data/app/models/marty/grid_index_int4range.rb +1 -1
  33. data/app/models/marty/grid_index_integer.rb +1 -1
  34. data/app/models/marty/grid_index_numrange.rb +1 -1
  35. data/app/models/marty/grid_index_string.rb +1 -1
  36. data/app/models/marty/import_type.rb +2 -2
  37. data/app/models/marty/notifications/notification.rb +2 -1
  38. data/app/models/marty/posting.rb +6 -6
  39. data/app/models/marty/posting_type.rb +2 -2
  40. data/app/models/marty/promise.rb +4 -3
  41. data/app/models/marty/script.rb +7 -7
  42. data/app/models/marty/tag.rb +5 -5
  43. data/app/models/marty/token.rb +1 -1
  44. data/app/models/marty/user.rb +11 -10
  45. data/app/models/marty/user_role.rb +2 -2
  46. data/app/models/marty/vw_promise.rb +2 -1
  47. data/app/services/marty/background_job/update_schedule.rb +1 -1
  48. data/app/services/marty/data_grid/constraint.rb +4 -3
  49. data/app/services/marty/jobs/schedule.rb +2 -2
  50. data/lib/marty/data_change.rb +1 -1
  51. data/lib/marty/data_conversion.rb +1 -1
  52. data/lib/marty/migrations.rb +2 -2
  53. data/lib/marty/rpc_call.rb +2 -1
  54. data/lib/marty/rule_script_set.rb +1 -3
  55. data/lib/marty/util.rb +2 -2
  56. data/lib/marty/version.rb +1 -1
  57. data/lib/tasks/scripts_tasks.rake +2 -2
  58. data/marty.gemspec +5 -1
  59. data/spec/controllers/job_controller_spec.rb +7 -7
  60. data/spec/controllers/rpc_controller_spec.rb +8 -8
  61. data/spec/controllers/rpc_import_spec.rb +3 -3
  62. data/spec/features/data_blame_report_spec.rb +1 -1
  63. data/spec/features/data_grid_spec.rb +101 -3
  64. data/spec/features/enum_values_report_spec.rb +1 -1
  65. data/spec/features/extjs_spec.rb +1 -1
  66. data/spec/features/jobs_dashboard_spec.rb +2 -2
  67. data/spec/features/log_view_spec.rb +1 -1
  68. data/spec/features/reporting_spec.rb +3 -3
  69. data/spec/features/scripting_spec.rb +3 -3
  70. data/spec/features/scripting_test_spec.rb +3 -3
  71. data/spec/features/user_list_report_spec.rb +1 -1
  72. data/spec/fixtures/misc/data_grid_6.txt +9 -0
  73. data/spec/fixtures/misc/data_grid_7.txt +7 -0
  74. data/spec/fixtures/misc/data_grid_8.txt +10 -0
  75. data/spec/fixtures/misc/data_grid_9.txt +10 -0
  76. data/spec/lib/data_blame_spec.rb +1 -1
  77. data/spec/lib/data_importer_spec.rb +4 -4
  78. data/spec/lib/delorean_query_spec.rb +1 -1
  79. data/spec/lib/logger_spec.rb +1 -1
  80. data/spec/lib/mcfly_model_spec.rb +2 -2
  81. data/spec/lib/table_report_spec.rb +1 -1
  82. data/spec/models/api_auth_spec.rb +2 -2
  83. data/spec/models/data_grid_spec.rb +3 -3
  84. data/spec/models/posting_spec.rb +12 -12
  85. data/spec/models/promise_spec.rb +1 -1
  86. data/spec/models/rule_spec.rb +1 -1
  87. data/spec/models/script_spec.rb +1 -1
  88. data/spec/other/diagnostic/delayed_job_version_spec.rb +1 -1
  89. data/spec/spec_helper.rb +3 -0
  90. data/spec/support/netzke.rb +2 -2
  91. data/spec/support/setup.rb +1 -1
  92. data/spec/support/simplecov_helper.rb +94 -0
  93. data/spec/support/users.rb +2 -2
  94. metadata +8 -3
  95. data/.gitlab-ci.yml +0 -117
@@ -28,7 +28,7 @@ feature 'under Applications menu, Scripting workflows', js: true, speed: :slow d
28
28
  end
29
29
 
30
30
  def with_user(uname, &block)
31
- u = Marty::User.find_by_login(uname)
31
+ u = Marty::User.find_by(login: uname)
32
32
  begin
33
33
  old_u, Mcfly.whodunnit = Mcfly.whodunnit, u
34
34
  block.call(u)
@@ -48,7 +48,7 @@ feature 'under Applications menu, Scripting workflows', js: true, speed: :slow d
48
48
  'A3' => "#3\n",
49
49
  'A4' => "#4\n",
50
50
  'A5' => "#5\n",
51
- }, Date.today)
51
+ }, Time.zone.today)
52
52
 
53
53
  # create 3 additional tags and modify A5 in the process
54
54
  (1..3).each do |i|
@@ -57,7 +57,7 @@ feature 'under Applications menu, Scripting workflows', js: true, speed: :slow d
57
57
  Marty::Script.
58
58
  load_script_bodies({
59
59
  'A5' => body + "##{i}\n"
60
- }, Date.today + i.minute)
60
+ }, Time.zone.today + i.minute)
61
61
  end
62
62
  end
63
63
  end
@@ -20,7 +20,7 @@ feature 'under Applications menu, Scripting (debug) workflows', js: true do
20
20
  end
21
21
 
22
22
  def with_user(uname, &block)
23
- u = Marty::User.find_by_login(uname)
23
+ u = Marty::User.find_by(login: uname)
24
24
  begin
25
25
  old_u, Mcfly.whodunnit = Mcfly.whodunnit, u
26
26
  block.call(u)
@@ -50,7 +50,7 @@ DELOREAN
50
50
  load_script_bodies({
51
51
  'M1' => sample_script,
52
52
  'M2' => sample_script.gsub(/a/, 'aa').gsub(/b/, 'bb'),
53
- }, Date.today)
53
+ }, Time.zone.today)
54
54
 
55
55
  # add a DEV version of M1.
56
56
  s = Marty::Script.find_by(obsoleted_dt: 'infinity', name: 'M1')
@@ -78,7 +78,7 @@ DELOREAN
78
78
  Marty::Script.
79
79
  load_script_bodies({
80
80
  'M3' => sample_script2,
81
- }, Date.today + 2.minute)
81
+ }, Time.zone.today + 2.minutes)
82
82
  end
83
83
  end
84
84
 
@@ -12,7 +12,7 @@ feature 'User List report', js: true do
12
12
  end
13
13
 
14
14
  def with_user(uname)
15
- u = Marty::User.find_by_login(uname)
15
+ u = Marty::User.find_by(login: uname)
16
16
  begin
17
17
  old_u, Mcfly.whodunnit = Mcfly.whodunnit, u
18
18
  yield(u)
@@ -0,0 +1,9 @@
1
+ lenient boolean
2
+ ltv_ratio_percent numrange v
3
+ loan_amortization_period_count int4range v
4
+ fn_ineligible boolean v
5
+
6
+ <60 false
7
+ <=300 false
8
+ true false
9
+ false false
@@ -0,0 +1,7 @@
1
+ Marty::DataGrid
2
+ gridname string v
3
+
4
+ DataGrid2 DataGrid2
5
+ DataGrid3 DataGrid3
6
+ DataGrid4 DataGrid4
7
+ DataGrid5 DataGrid5
@@ -0,0 +1,10 @@
1
+ integer
2
+ mortgage_type string v
3
+ loan_amortization_period_count int4range v
4
+
5
+ FHA|USDA/Rural Housing|VA >=96<=180 180
6
+ FHA|USDA/Rural Housing|VA >180<=360 360
7
+ Conventional >=96<=120 120
8
+ Conventional >120<=180 180
9
+ Conventional >180<=240 240
10
+ Conventional >240<=360 360
@@ -0,0 +1,10 @@
1
+ string
2
+ mortgage_type string v
3
+ loan_amortization_period_count int4range v
4
+
5
+ FHA|USDA/Rural Housing|VA >=96<=180 "180"
6
+ FHA|USDA/Rural Housing|VA >180<=360 "360"
7
+ Conventional >=96<=120 "120"
8
+ Conventional >120<=180 "180"
9
+ Conventional >180<=240 "240"
10
+ Conventional >240<=360 "360"
@@ -16,7 +16,7 @@ describe 'Blame Report', slow: true do
16
16
  time5 = Time.zone.parse '2019-01-27 05:14:50 -0800'
17
17
 
18
18
  posting = Marty::Posting.do_create('BASE', time3 - 2.hours, 'base posting')
19
- @pt = Marty::Posting.find_by_name(posting.name).created_dt
19
+ @pt = Marty::Posting.find_by(name: posting.name).created_dt
20
20
 
21
21
  bc = Gemini::BudCategory.create(name: 'Conv Fixed 30', created_dt: time1)
22
22
  bc2 = Gemini::BudCategory.create(name: 'Govt Fixed 30', created_dt: time1)
@@ -129,7 +129,7 @@ describe DataImporter do
129
129
  Gemini::FannieBup.count.should == 6
130
130
 
131
131
  # spot-check the import
132
- bc = Gemini::BudCategory.find_by_name('Conv Fixed 30')
132
+ bc = Gemini::BudCategory.find_by(name: 'Conv Fixed 30')
133
133
  fb = Gemini::FannieBup.where(bud_category_id: bc.id, note_rate: 2.50).first
134
134
  fb.buy_up.should == 4.41300
135
135
  fb.buy_down.should == 7.22800
@@ -418,7 +418,7 @@ describe DataImporter do
418
418
  end
419
419
 
420
420
  it 'should be able to export' do
421
- Marty::Script.load_scripts(nil, Date.today)
421
+ Marty::Script.load_scripts(nil, Time.zone.today)
422
422
  Marty::ScriptSet.clear_cache
423
423
  Marty::DataImporter.do_import_summary(Gemini::BudCategory, bud_cats)
424
424
  Marty::DataImporter.do_import_summary(Gemini::FannieBup, fannie_bup1)
@@ -441,7 +441,7 @@ describe 'Blame Report without yml translations' do
441
441
  note_rate: nil
442
442
  }
443
443
  )
444
- Marty::Script.load_scripts(nil, Date.today)
444
+ Marty::Script.load_scripts(nil, Time.zone.today)
445
445
  Marty::ScriptSet.clear_cache
446
446
  p = Marty::Posting.do_create('BASE', DateTime.yesterday, 'yesterday')
447
447
  Marty::DataImporter.do_import_summary(Gemini::BudCategory, bud_cats)
@@ -468,7 +468,7 @@ describe 'Blame Report with yml translations' do
468
468
  before(:each) do
469
469
  I18n.backend.store_translations(:en, attributes: { note_rate: 'Note Rate' })
470
470
 
471
- Marty::Script.load_scripts(nil, Date.today)
471
+ Marty::Script.load_scripts(nil, Time.zone.today)
472
472
  Marty::ScriptSet.clear_cache
473
473
  p = Marty::Posting.do_create('BASE', DateTime.yesterday, 'yesterday')
474
474
  Marty::DataImporter.do_import_summary(Gemini::BudCategory, bud_cats)
@@ -88,7 +88,7 @@ describe 'DeloreanQuery' do
88
88
  Marty::Script.load_script_bodies(
89
89
  {
90
90
  'A' => script,
91
- }, Date.today)
91
+ }, Time.zone.today)
92
92
 
93
93
  @engine = Marty::ScriptSet.new.get_engine('A')
94
94
  end
@@ -74,7 +74,7 @@ module Marty
74
74
  # means we lose the globally set user
75
75
  Mcfly.whodunnit = system_user
76
76
 
77
- Marty::Script.load_script_bodies(promise_bodies, Date.today)
77
+ Marty::Script.load_script_bodies(promise_bodies, Time.zone.today)
78
78
  start_delayed_job
79
79
  end
80
80
 
@@ -76,7 +76,7 @@ describe 'McflyModel' do
76
76
  @clean_file = "/tmp/clean_#{Process.pid}.psql"
77
77
  save_clean_db(@clean_file)
78
78
  marty_whodunnit
79
- dt = Date.today
79
+ dt = Time.zone.today
80
80
  Marty::DataImporter.do_import_summary(Gemini::Entity, entities)
81
81
  Marty::DataImporter.do_import_summary(Gemini::BudCategory, bud_cats)
82
82
  Marty::DataImporter.do_import_summary(Gemini::FannieBup, fannie_bup)
@@ -93,7 +93,7 @@ describe 'McflyModel' do
93
93
  Marty::Script.load_script_bodies(
94
94
  {
95
95
  name => (errscript % fn),
96
- }, Date.today)
96
+ }, Time.zone.today)
97
97
  end
98
98
 
99
99
  Marty::Script.load_script_bodies({ 'E5' => (errscript2 % 'a_func_p') }, dt)
@@ -27,7 +27,7 @@ describe 'Blame Report', slow: true do
27
27
  time5 = Time.zone.parse '2019-01-27 05:14:50 -0800'
28
28
 
29
29
  posting = Marty::Posting.do_create('BASE', time5 - 2.hours, 'base posting')
30
- @pt_name = Marty::Posting.find_by_name(posting.name).name
30
+ @pt_name = Marty::Posting.find_by(name: posting.name).name
31
31
 
32
32
  bc = Gemini::BudCategory.create(name: 'Conv Fixed 30', created_dt: time1)
33
33
  bc2 = Gemini::BudCategory.create(name: 'Govt Fixed 30', created_dt: time1)
@@ -6,7 +6,7 @@ module Marty
6
6
  Marty::Script.load_script_bodies({
7
7
  'Script1' => "A:\n a = 1\n",
8
8
  'NewScript1' => "B:\n b = 0\n",
9
- }, Date.today)
9
+ }, Time.zone.today)
10
10
 
11
11
  @api = ApiAuth.new
12
12
  @api.app_name = 'TestApp'
@@ -70,7 +70,7 @@ module Marty
70
70
  s.name = 'TestScript'
71
71
  s.body = '-- Test3'
72
72
  # Creates a script in the future - no tag exists
73
- s.created_dt = Time.now + 1.minute
73
+ s.created_dt = Time.zone.now + 1.minute
74
74
  s.save!
75
75
 
76
76
  api = ApiAuth.new
@@ -608,7 +608,7 @@ EOS
608
608
  end
609
609
 
610
610
  it 'should handle DataGrid typed data grids -- non mcfly' do
611
- ca = Gemini::State.find_by_name('CA')
611
+ ca = Gemini::State.find_by(name: 'CA')
612
612
 
613
613
  res = lookup_grid_helper('infinity', 'Gb', 'property_state' => ca)
614
614
  expect(res).to eq [70, 'Gb']
@@ -620,7 +620,7 @@ EOS
620
620
 
621
621
  it 'should handle typed (enum) data lookup_grid' do
622
622
  pt = 'infinity'
623
- ca = Gemini::State.find_by_name('CA')
623
+ ca = Gemini::State.find_by(name: 'CA')
624
624
 
625
625
  res = Marty::DataGrid.
626
626
  lookup_grid_h(pt, 'Gb', { 'property_state' => ca }, false)
@@ -884,7 +884,7 @@ EOS
884
884
  end
885
885
 
886
886
  it 'should be able to externally export/import grids' do
887
- load_scripts(nil, Date.today)
887
+ load_scripts(nil, Time.zone.today)
888
888
 
889
889
  dg = dg_from_import('G1', G1)
890
890
 
@@ -44,19 +44,19 @@ module Marty
44
44
  before do
45
45
  PostingType.create(name: 'SNAPSHOT')
46
46
  PostingType.create(name: 'OTHER')
47
- Posting.do_create('BASE', 0.day.from_now, 'base posting')
47
+ Posting.do_create('BASE', 0.days.from_now, 'base posting')
48
48
  Posting.do_create('SNAPSHOT', 1.day.from_now, 'snapshot1 posting')
49
- Posting.do_create('SNAPSHOT', 2.day.from_now, 'snapshot2 posting')
50
- Posting.do_create('OTHER', 3.day.from_now, 'other1 posting')
51
- Posting.do_create('SNAPSHOT', 4.day.from_now, 'snapshot3 posting')
52
- Posting.do_create('OTHER', 5.day.from_now, 'other2 posting')
49
+ Posting.do_create('SNAPSHOT', 2.days.from_now, 'snapshot2 posting')
50
+ Posting.do_create('OTHER', 3.days.from_now, 'other1 posting')
51
+ Posting.do_create('SNAPSHOT', 4.days.from_now, 'snapshot3 posting')
52
+ Posting.do_create('OTHER', 5.days.from_now, 'other2 posting')
53
53
  end
54
54
 
55
55
  it 'filters on a single posting type' do
56
56
  # First param is just the limit (max) to return
57
57
  res = Posting.get_latest_by_type(10, ['BASE'])
58
58
  expect(res.count).to eq 1
59
- r0 = Posting.find_by_name(res[0]['name'])
59
+ r0 = Posting.find_by(name: res[0]['name'])
60
60
  expect(r0.comment).to eq 'base posting'
61
61
  end
62
62
 
@@ -64,8 +64,8 @@ module Marty
64
64
  res = Posting.get_latest_by_type(10, ['BASE', 'SNAPSHOT'])
65
65
  expect(res.count).to eq 4
66
66
  # snapshot3 is most recent with this filter
67
- r0 = Posting.find_by_name(res[0]['name'])
68
- r3 = Posting.find_by_name(res[3]['name'])
67
+ r0 = Posting.find_by(name: res[0]['name'])
68
+ r3 = Posting.find_by(name: res[3]['name'])
69
69
  expect(r0.comment).to eq 'snapshot3 posting'
70
70
  expect(r3.comment).to eq 'base posting'
71
71
  end
@@ -74,8 +74,8 @@ module Marty
74
74
  res = Posting.get_latest_by_type(10, ['SNAPSHOT', 'OTHER'])
75
75
  expect(res.count).to eq 5
76
76
  # other2 is most recent with this filter
77
- r0 = Posting.find_by_name(res[0]['name'])
78
- r4 = Posting.find_by_name(res[4]['name'])
77
+ r0 = Posting.find_by(name: res[0]['name'])
78
+ r4 = Posting.find_by(name: res[4]['name'])
79
79
  expect(r0.comment).to eq 'other2 posting'
80
80
  expect(r4.comment).to eq 'snapshot1 posting'
81
81
  end
@@ -84,8 +84,8 @@ module Marty
84
84
  res = Posting.get_latest_by_type(3, ['SNAPSHOT', 'OTHER'])
85
85
  expect(res.count).to eq 3
86
86
  # other2 is most recent with this filter
87
- r0 = Posting.find_by_name(res[0]['name'])
88
- r2 = Posting.find_by_name(res[2]['name'])
87
+ r0 = Posting.find_by(name: res[0]['name'])
88
+ r2 = Posting.find_by(name: res[2]['name'])
89
89
  expect(r0.comment).to eq 'other2 posting'
90
90
  expect(r2.comment).to eq 'other1 posting'
91
91
  end
@@ -12,7 +12,7 @@ describe Marty::Promise, slow: true, retry: 3 do
12
12
  # means we lose the globally set user
13
13
  Mcfly.whodunnit = system_user
14
14
 
15
- Marty::Script.load_script_bodies(promise_bodies, Date.today)
15
+ Marty::Script.load_script_bodies(promise_bodies, Time.zone.today)
16
16
 
17
17
  start_delayed_job
18
18
  end
@@ -437,7 +437,7 @@ module Marty::RuleSpec
437
437
  to receive(:evaluate).and_raise('hi mom')
438
438
  expect do
439
439
  simple.compute(@ruleopts_myrule,
440
- 'pt' => Time.now)
440
+ 'pt' => Time.zone.now)
441
441
  end .to raise_error(/hi mom/)
442
442
  # simple2a should return results without evaluation (they are all fixed)
443
443
  expect(simple2a.compute(@ruleopts_myrule, 'pt' => Time.zone.now)).to eq(
@@ -175,7 +175,7 @@ describe Marty::Script do
175
175
  it 'gets the files from the default paths' do
176
176
  allow(Dir).to receive(:glob).and_return([])
177
177
  Marty::Script.get_script_filenames
178
- expect(Dir).to have_received(:glob).with("#{Rails.root}/delorean/**/*.dl")
178
+ expect(Dir).to have_received(:glob).with(Rails.root.join('delorean/**/*.dl').to_s)
179
179
  expect(Dir).to have_received(:glob).
180
180
  with(File.expand_path('../../../delorean/**/*.dl', __FILE__))
181
181
  expect(Dir).to have_received(:glob).twice
@@ -11,7 +11,7 @@ describe Marty::Diagnostic::DelayedJobVersion do
11
11
  end
12
12
 
13
13
  before(:each) do
14
- Marty::Script.load_scripts(nil, Date.today)
14
+ Marty::Script.load_scripts(nil, Time.zone.today)
15
15
  allow(described_class).to receive(:scope).and_return(nil)
16
16
  end
17
17
 
@@ -1,6 +1,9 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
2
  ENV['TZ'] ||= 'America/Los_Angeles'
3
3
 
4
+ require_relative 'support/simplecov_helper'
5
+ SimpleCovHelper.start!
6
+
4
7
  require 'dummy/config/application'
5
8
  require 'rspec/rails'
6
9
  require 'database_cleaner'
@@ -101,14 +101,14 @@ module Marty; module RSpec; module Netzke
101
101
 
102
102
  def wait_for_element(seconds_to_wait = 2.0, sleeptime = 0.1)
103
103
  res = nil
104
- start_time = current_time = Time.now
104
+ start_time = current_time = Time.zone.now
105
105
  while !res && current_time - start_time < seconds_to_wait
106
106
  begin
107
107
  res = yield
108
108
  rescue StandardError
109
109
  ensure
110
110
  sleep sleeptime
111
- current_time = Time.now
111
+ current_time = Time.zone.now
112
112
  end
113
113
  end
114
114
  res
@@ -1,6 +1,6 @@
1
1
  module Marty; module RSpec; module Setup
2
2
  def marty_whodunnit
3
- Mcfly.whodunnit = Marty::User.find_by_login('marty')
3
+ Mcfly.whodunnit = Marty::User.find_by(login: 'marty')
4
4
  end
5
5
 
6
6
  def load_scripts(path, dt)
@@ -0,0 +1,94 @@
1
+ # Credit to: https://gitlab.com/gitlab-org/gitlab-foss/blob/master/spec/simplecov_env.rb
2
+
3
+ require 'simplecov'
4
+ require 'active_support/core_ext/numeric/time'
5
+
6
+ module SimpleCovHelper
7
+ def self.merge_all_results!
8
+ resultset_files = Pathname.glob(
9
+ File.join(SimpleCov.coverage_path, '**', '.resultset.json')
10
+ )
11
+
12
+ result_array = begin
13
+ resultset_files.map do |result_file|
14
+ SimpleCov::Result.from_hash JSON.parse(result_file.read)
15
+ end
16
+ rescue StandardError => e
17
+ {}
18
+ end
19
+
20
+ merged = SimpleCov::ResultMerger.merge_results(*result_array)
21
+ merged.format!
22
+
23
+ # Print out to console all the groups and their percents + hits/line.
24
+ groups = merged.groups.map do |group, files|
25
+ [group, files.covered_percent, files.covered_strength]
26
+ end
27
+ sorted_groups = groups.sort_by { |_gr, per, _str| -per }
28
+ sorted_groups.each do |group|
29
+ gr_name, percent, strength = group
30
+ puts "Group '#{gr_name}': #{percent} covered at #{strength} hits/line"
31
+ end
32
+ end
33
+
34
+ def self.configure_job
35
+ # This should only be run as part of an RSpec pipeline
36
+ return unless defined?(RSpec)
37
+
38
+ SimpleCov.configure do
39
+ if ENV['GITLAB_CI']
40
+ job_name = ENV['CI_JOB_NAME'] || nil
41
+ coverage_dir "coverage/#{job_name}"
42
+ command_name job_name
43
+ SimpleCov.at_exit { SimpleCov.result }
44
+ else
45
+ command_options = RSpec::Core::ConfigurationOptions.new(ARGV)
46
+ rspec_directories = command_options.options[:files_or_directories_to_run]
47
+ case rspec_directories.length
48
+ when 1
49
+ category = Dir.exist?(rspec_directories[0]) ? rspec_directories[0] : nil
50
+ coverage_dir "coverage/#{category}"
51
+ command_name category
52
+ else
53
+ coverage_dir 'coverage/'
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def self.configure_profile
60
+ SimpleCov.configure do
61
+ load_profile 'test_frameworks'
62
+ load_profile 'root_filter'
63
+ load_profile 'bundler_filter'
64
+ track_files '{app,lib,config}/**/*.rb'
65
+ track_files 'db/seeds.rb'
66
+
67
+ add_filter '/vendor/ruby/'
68
+ add_filter 'spec/'
69
+
70
+ add_group 'Libraries', 'lib'
71
+ add_group 'Assets', 'app/assets'
72
+ add_group 'Channels', 'app/channels'
73
+ add_group 'Netzke Components', 'app/components'
74
+ add_group 'Controllers', 'app/controllers'
75
+ add_group 'Helpers', 'app/helpers'
76
+ add_group 'Jobs', 'app/jobs'
77
+ add_group 'Models', 'app/models'
78
+ add_group 'Services', 'app/services'
79
+ add_group 'Views', 'app/views'
80
+
81
+ use_merging true
82
+ merge_timeout 365.days
83
+ end
84
+ end
85
+
86
+ def self.start!
87
+ return unless ENV['COVERAGE'] == 'true'
88
+
89
+ configure_profile
90
+ configure_job
91
+
92
+ SimpleCov.start
93
+ end
94
+ end