marty 2.5.2 → 2.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +11 -589
- data/Gemfile +9 -9
- data/Gemfile.lock +1 -1
- data/Rakefile +1 -3
- data/app/components/marty/api_auth_view.rb +3 -3
- data/app/components/marty/api_config_view.rb +8 -8
- data/app/components/marty/api_log_view.rb +16 -20
- data/app/components/marty/auth_app.rb +6 -6
- data/app/components/marty/base_rule_view.rb +27 -19
- data/app/components/marty/config_view.rb +12 -9
- data/app/components/marty/data_grid_view.rb +26 -26
- data/app/components/marty/delorean_rule_view.rb +0 -1
- data/app/components/marty/event_view.rb +27 -27
- data/app/components/marty/extras/layout.rb +26 -26
- data/app/components/marty/extras/misc.rb +2 -2
- data/app/components/marty/grid.rb +13 -13
- data/app/components/marty/grid_append_only.rb +0 -1
- data/app/components/marty/import_type_view.rb +13 -13
- data/app/components/marty/import_view.rb +17 -16
- data/app/components/marty/log_view.rb +16 -14
- data/app/components/marty/main_auth_app.rb +59 -59
- data/app/components/marty/main_auth_app/client/main_auth_app.js +3 -3
- data/app/components/marty/mcfly_grid_panel.rb +10 -10
- data/app/components/marty/new_posting_form.rb +11 -11
- data/app/components/marty/new_posting_window.rb +0 -1
- data/app/components/marty/posting_grid.rb +12 -13
- data/app/components/marty/promise_view.rb +6 -6
- data/app/components/marty/report_form.rb +50 -53
- data/app/components/marty/report_select.rb +27 -27
- data/app/components/marty/reporting.rb +4 -4
- data/app/components/marty/script_form.rb +40 -42
- data/app/components/marty/script_grid.rb +24 -24
- data/app/components/marty/script_tester.rb +40 -42
- data/app/components/marty/scripting.rb +25 -27
- data/app/components/marty/simple_app.rb +24 -9
- data/app/components/marty/tag_grid.rb +12 -13
- data/app/components/marty/user_view.rb +35 -35
- data/app/controllers/marty/application_controller.rb +3 -4
- data/app/controllers/marty/components_controller.rb +1 -1
- data/app/controllers/marty/delayed_job_controller.rb +1 -0
- data/app/controllers/marty/diagnostic/controller.rb +4 -6
- data/app/controllers/marty/job_controller.rb +6 -6
- data/app/controllers/marty/report_controller.rb +11 -11
- data/app/controllers/marty/rpc_controller.rb +15 -16
- data/app/helpers/marty/script_set.rb +4 -4
- data/app/models/marty/api_auth.rb +4 -5
- data/app/models/marty/api_config.rb +1 -1
- data/app/models/marty/base.rb +9 -8
- data/app/models/marty/base_rule.rb +18 -13
- data/app/models/marty/config.rb +4 -5
- data/app/models/marty/data_grid.rb +157 -181
- data/app/models/marty/delorean_rule.rb +63 -62
- data/app/models/marty/enum.rb +1 -1
- data/app/models/marty/event.rb +56 -59
- data/app/models/marty/helper.rb +38 -6
- data/app/models/marty/import_type.rb +6 -6
- data/app/models/marty/log.rb +3 -2
- data/app/models/marty/name_validator.rb +3 -2
- data/app/models/marty/pg_enum.rb +3 -4
- data/app/models/marty/posting.rb +20 -24
- data/app/models/marty/promise.rb +28 -30
- data/app/models/marty/script.rb +30 -28
- data/app/models/marty/tag.rb +8 -8
- data/app/models/marty/token.rb +2 -2
- data/app/models/marty/user.rb +24 -23
- data/app/models/marty/vw_promise.rb +10 -11
- data/config/routes.rb +2 -2
- data/delorean/blame_report.dl +268 -0
- data/{spec/dummy/delorean/fields.dl → delorean/marty_fields.dl} +8 -0
- data/delorean/table_report.dl +34 -0
- data/docker-compose.dummy.yml +2 -3
- data/lib/marty/aws/base.rb +8 -8
- data/lib/marty/aws/request.rb +4 -4
- data/lib/marty/cache_adapters/mcfly_ruby_cache.rb +1 -0
- data/lib/marty/content_handler.rb +25 -25
- data/lib/marty/data_change.rb +49 -71
- data/lib/marty/data_conversion.rb +20 -28
- data/lib/marty/data_exporter.rb +25 -28
- data/lib/marty/data_importer.rb +25 -27
- data/lib/marty/engine.rb +1 -2
- data/lib/marty/json_schema.rb +22 -24
- data/lib/marty/logger.rb +6 -9
- data/lib/marty/mcfly_model.rb +20 -24
- data/lib/marty/migrations.rb +37 -35
- data/lib/marty/monkey.rb +33 -33
- data/lib/marty/permissions.rb +18 -18
- data/lib/marty/promise_job.rb +17 -17
- data/lib/marty/promise_proxy.rb +6 -6
- data/lib/marty/relation.rb +6 -7
- data/lib/marty/rpc_call.rb +13 -12
- data/lib/marty/rule_script_set.rb +32 -28
- data/lib/marty/schema_helper.rb +37 -51
- data/lib/marty/util.rb +25 -24
- data/lib/marty/version.rb +1 -1
- data/lib/marty/xl.rb +121 -115
- data/make-dummy.mk +3 -0
- data/marty.gemspec +21 -21
- data/other/marty/api/base.rb +34 -35
- data/other/marty/diagnostic/aws/ec2_instance.rb +8 -8
- data/other/marty/diagnostic/base.rb +13 -14
- data/other/marty/diagnostic/collection.rb +2 -1
- data/other/marty/diagnostic/connections.rb +8 -6
- data/other/marty/diagnostic/database.rb +1 -0
- data/other/marty/diagnostic/delayed_job_version.rb +7 -9
- data/other/marty/diagnostic/delayed_job_worker_total_count.rb +1 -1
- data/other/marty/diagnostic/delayed_job_workers.rb +1 -1
- data/other/marty/diagnostic/environment_variables.rb +17 -15
- data/other/marty/diagnostic/fatal.rb +1 -1
- data/other/marty/diagnostic/node.rb +5 -9
- data/other/marty/diagnostic/nodes.rb +7 -5
- data/other/marty/diagnostic/packer.rb +7 -7
- data/other/marty/diagnostic/reporter.rb +24 -27
- data/other/marty/diagnostic/version.rb +3 -5
- data/script/rails +2 -1
- data/spec/controllers/application_controller_spec.rb +6 -6
- data/spec/controllers/delayed_job_controller_spec.rb +4 -4
- data/spec/controllers/diagnostic/controller_spec.rb +59 -60
- data/spec/controllers/job_controller_spec.rb +68 -69
- data/spec/controllers/rpc_controller_spec.rb +353 -359
- data/spec/controllers/rpc_import_spec.rb +15 -16
- data/spec/dummy/delorean/blame_report.dl +110 -15
- data/spec/dummy/delorean/data_report.dl +4 -4
- data/spec/dummy/delorean/marty_fields.dl +63 -0
- data/spec/dummy/delorean/table_report.dl +34 -0
- data/spec/features/auth_app_spec.rb +1 -2
- data/spec/features/data_import_spec.rb +2 -3
- data/spec/features/enum_spec.rb +42 -46
- data/spec/features/jobs_dashboard_spec.rb +14 -8
- data/spec/features/log_view_spec.rb +40 -43
- data/spec/features/reporting_spec.rb +15 -15
- data/spec/features/rule_spec.rb +195 -190
- data/spec/features/scripting_spec.rb +17 -20
- data/spec/features/scripting_test_spec.rb +32 -33
- data/spec/features/user_view_spec.rb +15 -17
- data/spec/job_helper.rb +11 -11
- data/spec/lib/data_blame_spec.rb +82 -0
- data/spec/lib/data_exporter_spec.rb +31 -32
- data/spec/lib/data_importer_spec.rb +382 -395
- data/spec/lib/delorean_query_spec.rb +117 -119
- data/spec/lib/json_schema_spec.rb +382 -392
- data/spec/lib/logger_spec.rb +23 -24
- data/spec/lib/mcfly_model_spec.rb +112 -109
- data/spec/lib/migrations_spec.rb +10 -10
- data/spec/lib/struct_compare_spec.rb +6 -6
- data/spec/lib/table_report_spec.rb +90 -0
- data/spec/lib/xl_spec.rb +63 -65
- data/spec/lib/xl_styles_spec.rb +16 -19
- data/spec/models/api_auth_spec.rb +30 -30
- data/spec/models/config_spec.rb +32 -32
- data/spec/models/data_grid_spec.rb +642 -655
- data/spec/models/event_spec.rb +96 -88
- data/spec/models/import_type_spec.rb +20 -20
- data/spec/models/posting_spec.rb +35 -35
- data/spec/models/promise_spec.rb +5 -5
- data/spec/models/rule_spec.rb +280 -269
- data/spec/models/script_spec.rb +27 -18
- data/spec/models/user_spec.rb +9 -9
- data/spec/other/diagnostic/base_spec.rb +20 -19
- data/spec/other/diagnostic/collection_spec.rb +6 -5
- data/spec/other/diagnostic/delayed_job_version_spec.rb +1 -1
- data/spec/other/diagnostic/delayed_job_workers_spec.rb +8 -8
- data/spec/other/diagnostic/reporter_spec.rb +31 -33
- data/spec/spec_helper.rb +5 -5
- data/spec/support/chromedriver.rb +3 -5
- data/spec/support/components/netzke_combobox.rb +1 -1
- data/spec/support/components/netzke_grid.rb +17 -17
- data/spec/support/custom_matchers.rb +2 -2
- data/spec/support/download_helper.rb +1 -1
- data/spec/support/helper.rb +1 -2
- data/spec/support/netzke.rb +31 -31
- data/spec/support/performance_helper.rb +8 -8
- data/spec/support/post_run_logger.rb +1 -2
- data/spec/support/setup.rb +1 -4
- data/spec/support/shared_connection.rb +2 -2
- data/spec/support/structure_compare.rb +21 -22
- data/spec/support/suite.rb +1 -2
- data/spec/support/users.rb +5 -6
- metadata +32 -26
data/spec/lib/logger_spec.rb
CHANGED
@@ -14,7 +14,7 @@ module Marty
|
|
14
14
|
self.use_transactional_tests = true
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'log has its own connection' do
|
18
18
|
log_conn = Marty::Log.connection.raw_connection
|
19
19
|
posting_conn = Marty::Posting.connection.raw_connection
|
20
20
|
script_conn = Marty::Script.connection.raw_connection
|
@@ -23,26 +23,26 @@ module Marty
|
|
23
23
|
expect(posting_conn).to equal(script_conn)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
27
|
-
info_s = {'info' => 'message'}
|
28
|
-
error_s = [1, 2, 3, {'error' =>'message'}]
|
29
|
-
fatal_s = [
|
30
|
-
'another_key' => 'value'}]
|
26
|
+
it 'logs' do
|
27
|
+
info_s = { 'info' => 'message' }
|
28
|
+
error_s = [1, 2, 3, { 'error' => 'message' }]
|
29
|
+
fatal_s = ['string', 123, { 'fatal' => 'message',
|
30
|
+
'another_key' => 'value' }]
|
31
31
|
Marty::Logger.info('info message', info_s)
|
32
32
|
Marty::Logger.error('error message', error_s)
|
33
33
|
Marty::Logger.fatal('fatal message', fatal_s)
|
34
34
|
log = Marty::Log.all
|
35
|
-
log_detail = log.map{|l| [l[:message_type], l[:message], l[:details]]}
|
36
|
-
log_ts = log.map{|l| l[:timestamp]}
|
37
|
-
expect(log_detail[0]).to eq([
|
38
|
-
expect(log_detail[1]).to eq([
|
39
|
-
expect(log_detail[2]).to eq([
|
35
|
+
log_detail = log.map { |l| [l[:message_type], l[:message], l[:details]] }
|
36
|
+
log_ts = log.map { |l| l[:timestamp] }
|
37
|
+
expect(log_detail[0]).to eq(['info', 'info message', info_s])
|
38
|
+
expect(log_detail[1]).to eq(['error', 'error message', error_s])
|
39
|
+
expect(log_detail[2]).to eq(['fatal', 'fatal message', fatal_s])
|
40
40
|
log_ts.each do |ts|
|
41
41
|
expect(ts.to_i).to be_within(5).of(Time.zone.now.to_i)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'with_logging' do
|
46
46
|
bd = 'block description'
|
47
47
|
the_error = 'error during my block'
|
48
48
|
data = [1, 2, 3, Marty::User.first]
|
@@ -50,19 +50,19 @@ module Marty
|
|
50
50
|
Marty::Logger.with_logging(bd, data) do
|
51
51
|
raise the_error
|
52
52
|
end
|
53
|
-
rescue => e
|
53
|
+
rescue StandardError => e
|
54
54
|
raised = e.message
|
55
55
|
end
|
56
56
|
expect(raised).to eq("#{bd}: #{the_error}")
|
57
57
|
log = Marty::Log.first
|
58
58
|
expect(log.message_type).to eq('error')
|
59
59
|
expect(log.message).to eq(bd)
|
60
|
-
expect(log.details).to eq(
|
61
|
-
|
60
|
+
expect(log.details).to eq('message' => the_error,
|
61
|
+
'data' => JSON.parse(data.to_json))
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe
|
65
|
+
describe 'Exercise' do
|
66
66
|
before(:all) do
|
67
67
|
@clean_file = "/tmp/clean_#{Process.pid}.psql"
|
68
68
|
save_clean_db(@clean_file)
|
@@ -81,28 +81,27 @@ module Marty
|
|
81
81
|
after(:all) do
|
82
82
|
restore_clean_db(@clean_file)
|
83
83
|
stop_delayed_job
|
84
|
-
File.unlink(
|
84
|
+
File.unlink('/tmp/logaction.txt')
|
85
85
|
Marty::Log.cleanup(0)
|
86
86
|
self.use_transactional_tests = true
|
87
87
|
end
|
88
88
|
|
89
|
-
it
|
90
|
-
File.open(Rails.root.join(
|
89
|
+
it 'handles heavy load' do
|
90
|
+
File.open(Rails.root.join('log/test.log')) do |f|
|
91
91
|
f.seek(0, IO::SEEK_END)
|
92
92
|
engine = Marty::ScriptSet.new.get_engine(NAME_K)
|
93
93
|
|
94
94
|
res = (1..1000).map do |i|
|
95
|
-
engine.background_eval(
|
95
|
+
engine.background_eval('LOGGER', { 'msgid' => i }, ['result'])
|
96
96
|
end
|
97
97
|
|
98
98
|
# wait for all the jobs to finish; collect/check their result
|
99
|
-
expect(res.map {|x| x[
|
99
|
+
expect(res.map { |x| x['result'] }.sort).to eq (1..1000).to_a
|
100
100
|
|
101
|
-
line_count = File.readlines(
|
101
|
+
line_count = File.readlines('/tmp/logaction.txt').count
|
102
102
|
|
103
103
|
log_count = Marty::Log.all.count
|
104
|
-
failed_count = f.readlines.select do
|
105
|
-
|l|
|
104
|
+
failed_count = f.readlines.select do |l|
|
106
105
|
l == "Marty::Logger failure: database is locked\n"
|
107
106
|
end.count
|
108
107
|
|
@@ -1,18 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Marty
|
4
|
-
|
5
|
-
entities =<<EOF
|
4
|
+
entities = <<EOF
|
6
5
|
name
|
7
6
|
PLS
|
8
7
|
EOF
|
9
|
-
bud_cats
|
8
|
+
bud_cats = <<EOF
|
10
9
|
name
|
11
10
|
Conv Fixed 30
|
12
11
|
Conv Fixed 20
|
13
12
|
EOF
|
14
13
|
|
15
|
-
fannie_bup
|
14
|
+
fannie_bup = <<EOF
|
16
15
|
entity bud_category note_rate buy_up buy_down settlement_mm settlement_yy
|
17
16
|
Conv Fixed 30 2.250 4.42000 7.24000 12 2012
|
18
17
|
Conv Fixed 30 2.375 4.42000 7.24000 12 2012
|
@@ -30,7 +29,7 @@ PLS Conv Fixed 20 2.875 5.24800 7.95900 12 2012
|
|
30
29
|
PLS Conv Fixed 20 2.875 5.24800 7.95900 11 2012
|
31
30
|
EOF
|
32
31
|
|
33
|
-
script
|
32
|
+
script = <<EOF
|
34
33
|
A:
|
35
34
|
pt =?
|
36
35
|
entity =?
|
@@ -48,21 +47,21 @@ A:
|
|
48
47
|
a_func = Gemini::FannieBup.a_func('infinity', e_id, bc_id)
|
49
48
|
b_func = Gemini::FannieBup.b_func('infinity', e_id, bc_id, 12)
|
50
49
|
EOF
|
51
|
-
errscript
|
50
|
+
errscript = <<EOF
|
52
51
|
Err:
|
53
52
|
pt =?
|
54
53
|
entity =?
|
55
54
|
note_rate =?
|
56
55
|
result = Gemini::FannieBup.%s(pt, entity, note_rate, 1)
|
57
56
|
EOF
|
58
|
-
errscript2
|
57
|
+
errscript2 = <<EOF
|
59
58
|
Err:
|
60
59
|
pt =?
|
61
60
|
e_id =?
|
62
61
|
bc_id =?
|
63
62
|
result = Gemini::FannieBup.%s(pt, e_id, bc_id, nil)
|
64
63
|
EOF
|
65
|
-
errscript3
|
64
|
+
errscript3 = <<EOF
|
66
65
|
Err:
|
67
66
|
pt =?
|
68
67
|
e_id =?
|
@@ -71,128 +70,132 @@ Err:
|
|
71
70
|
result = Gemini::FannieBup.%s(pt, e_id, bc_id, mm, {})
|
72
71
|
EOF
|
73
72
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
describe 'McflyModel' do
|
74
|
+
before(:all) do
|
75
|
+
@clean_file = "/tmp/clean_#{Process.pid}.psql"
|
76
|
+
save_clean_db(@clean_file)
|
77
|
+
marty_whodunnit
|
78
|
+
dt = Date.today
|
79
|
+
Marty::DataImporter.do_import_summary(Gemini::Entity, entities)
|
80
|
+
Marty::DataImporter.do_import_summary(Gemini::BudCategory, bud_cats)
|
81
|
+
Marty::DataImporter.do_import_summary(Gemini::FannieBup, fannie_bup)
|
82
|
+
Marty::Script.load_script_bodies(
|
83
|
+
{
|
84
|
+
'AA' => script,
|
85
|
+
}, dt)
|
86
|
+
@errs = ['E1', 'lookup_p',
|
87
|
+
'E2', 'clookup_p',
|
88
|
+
'E3', 'lookupn_p',
|
89
|
+
'E4', 'clookupn_p']
|
90
|
+
|
91
|
+
@errs.in_groups_of(2) do |name, fn|
|
83
92
|
Marty::Script.load_script_bodies(
|
84
|
-
{
|
85
|
-
"AA" => script,
|
86
|
-
}, dt)
|
87
|
-
@errs = ['E1', 'lookup_p',
|
88
|
-
'E2', 'clookup_p',
|
89
|
-
'E3', 'lookupn_p',
|
90
|
-
'E4', 'clookupn_p']
|
91
|
-
|
92
|
-
@errs.in_groups_of(2) do |name, fn|
|
93
|
-
Marty::Script.load_script_bodies(
|
94
93
|
{
|
95
94
|
name => (errscript % fn),
|
96
95
|
}, Date.today)
|
97
|
-
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
98
|
+
Marty::Script.load_script_bodies({ 'E5' => (errscript2 % 'a_func_p') }, dt)
|
99
|
+
Marty::Script.load_script_bodies({ 'E6' => (errscript3 % 'b_func_p') }, dt)
|
101
100
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
101
|
+
@engine = Marty::ScriptSet.new.get_engine('AA')
|
102
|
+
end
|
103
|
+
after(:all) do
|
104
|
+
restore_clean_db(@clean_file)
|
105
|
+
Marty::ScriptSet.clear_cache
|
106
|
+
end
|
107
|
+
let(:params) do
|
108
|
+
{ 'pt' => 'infinity',
|
109
|
+
'entity' => Gemini::Entity.all.first,
|
110
|
+
'note_rate' => 2.875 }
|
111
|
+
end
|
112
|
+
it 'lookup mode default' do
|
113
|
+
a1 = @engine.evaluate('A', 'lookup', params)
|
114
|
+
a2 = @engine.evaluate('A', 'clookup', params)
|
115
|
+
expect(a1).to eq(a2) # cache/non return same
|
116
|
+
expect(a1.class).to eq(OpenStruct) # mode default so return OS
|
117
|
+
expect(a2.class).to eq(OpenStruct)
|
118
|
+
|
119
|
+
# check that keys are non mcfly non uniqueness
|
120
|
+
expect(a1.to_h.keys.to_set).to eq(Set[:buy_up, :buy_down])
|
121
|
+
end
|
121
122
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
123
|
+
it 'lookup non generated' do
|
124
|
+
# a1 will be AR Relations
|
125
|
+
# b1 will be OpenStructs because the b fns return #first
|
126
|
+
e_id = Gemini::Entity.where(name: 'PLS').first.id
|
127
|
+
bc_id = Gemini::BudCategory.where(name: 'Conv Fixed 20').first.id
|
128
|
+
p = { 'e_id' => e_id, 'bc_id' => bc_id }
|
129
|
+
a1 = @engine.evaluate('A', 'a_func', p)
|
130
|
+
b1 = @engine.evaluate('A', 'b_func', p)
|
130
131
|
|
131
|
-
|
132
|
-
|
133
|
-
|
132
|
+
# all return relations
|
133
|
+
expect(ActiveRecord::Relation === a1).to be_truthy
|
134
|
+
expect(ActiveRecord::Base === a1.first).to be_truthy
|
134
135
|
|
135
|
-
|
136
|
+
expect(a1.to_a.count).to eq(2)
|
136
137
|
|
137
|
-
|
138
|
-
|
138
|
+
# a1 lookup did not include extra attrs
|
139
|
+
expect(a1.first.attributes.keys.to_set).to eq(Set['id', 'buy_up', 'buy_down'])
|
139
140
|
|
140
|
-
|
141
|
-
|
141
|
+
# a1 is AR but still missing the FK entity_id so will raise
|
142
|
+
expect { a1.first.entity }.to raise_error(/missing attribute: entity_id/)
|
142
143
|
|
143
|
-
|
144
|
+
expect(b1.class).to eq(OpenStruct)
|
144
145
|
|
145
|
-
|
146
|
-
|
147
|
-
|
146
|
+
# make sure b1 has correct keys
|
147
|
+
expect(b1.to_h.keys.to_set).to eq(Set[:buy_up, :buy_down])
|
148
|
+
end
|
148
149
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
150
|
+
it 'lookup mode nil' do
|
151
|
+
# make sure ARs are returned
|
152
|
+
a1 = @engine.evaluate('A', 'lookupn', params)
|
153
|
+
a2 = @engine.evaluate('A', 'clookupn', params)
|
154
|
+
expect(a1).to eq(a2)
|
155
|
+
expect(ActiveRecord::Relation === a1).to be_truthy
|
156
|
+
expect(a1.to_a.count).to eq(4)
|
157
|
+
end
|
157
158
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
159
|
+
it "private methods can't be called by delorean" do
|
160
|
+
# generated methods
|
161
|
+
aggregate_failures 'errors' do
|
162
|
+
@errs.in_groups_of(2) do |name, fn|
|
163
|
+
err = /Too many args to #{fn}/
|
163
164
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
165
|
+
expect do
|
166
|
+
Marty::ScriptSet.new.get_engine(name)
|
167
|
+
end.to raise_error(Delorean::BadCallError, err)
|
168
168
|
end
|
169
169
|
end
|
170
|
+
end
|
170
171
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
end
|
172
|
+
it "private methods can't be called by delorean (2)" do
|
173
|
+
# non-generated
|
174
|
+
aggregate_failures 'errors' do
|
175
|
+
['E5', 'a_func_p', 'E6', 'b_func_p'].in_groups_of(2) do |scr, fn|
|
176
|
+
err = /Too many args to #{fn}/
|
177
|
+
expect { Marty::ScriptSet.new.get_engine(scr) }.to raise_error(
|
178
|
+
Delorean::BadCallError, err)
|
179
179
|
end
|
180
180
|
end
|
181
|
+
end
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
y=Benchmark.measure { 10000.times {
|
190
|
-
Gemini::FannieBup.ca_func(ts,
|
191
|
-
1, 2)
|
192
|
-
}
|
193
|
-
}
|
194
|
-
# x time should be 30x or more than y time
|
195
|
-
expect(x.real / y.real).to be > 30
|
183
|
+
it 'caching times' do
|
184
|
+
ts = DateTime.now
|
185
|
+
x = Benchmark.measure do
|
186
|
+
10000.times do
|
187
|
+
Gemini::FannieBup.a_func(ts,
|
188
|
+
1, 2)
|
189
|
+
end
|
196
190
|
end
|
191
|
+
y = Benchmark.measure do
|
192
|
+
10000.times do
|
193
|
+
Gemini::FannieBup.ca_func(ts,
|
194
|
+
1, 2)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
# x time should be 30x or more than y time
|
198
|
+
expect(x.real / y.real).to be > 30
|
197
199
|
end
|
198
200
|
end
|
201
|
+
end
|
data/spec/lib/migrations_spec.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Marty
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
tdir = File.dirname(__FILE__) +
|
4
|
+
describe 'Migrations' do
|
5
|
+
it 'writes db views correctly' do
|
6
|
+
tdir = File.dirname(__FILE__) + '/migrations/'
|
7
7
|
Marty::Migrations.write_view(tdir,
|
8
8
|
'vw_marty_postings',
|
9
|
-
Marty::Posting, {}, [
|
10
|
-
[[
|
11
|
-
|
12
|
-
filename =
|
13
|
-
genfile = File.join(tdir,filename)
|
9
|
+
Marty::Posting, {}, ['comment'],
|
10
|
+
[['marty_posting_types', 'id',
|
11
|
+
'post_type_id']])
|
12
|
+
filename = 'vw_marty_postings.sql'
|
13
|
+
genfile = File.join(tdir, filename)
|
14
14
|
generated = File.read(genfile)
|
15
|
-
expected = File.read(File.join(tdir,"#{filename}.expected"))
|
15
|
+
expected = File.read(File.join(tdir, "#{filename}.expected"))
|
16
16
|
expect(generated).to eq(expected)
|
17
17
|
File.delete(genfile)
|
18
18
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
it
|
3
|
+
describe 'StructCompare' do
|
4
|
+
it 'compares correctly' do
|
5
5
|
p = File.expand_path('../../fixtures/misc', __FILE__)
|
6
|
-
fname =
|
6
|
+
fname = '%s/%s' % [p, 'struct_compare_tests.txt']
|
7
7
|
aggregate_failures 'struct_compare' do
|
8
8
|
data = JSON.parse(File.read(fname))
|
9
9
|
data.each do |ex|
|
10
|
-
args = [ex[
|
10
|
+
args = [ex['v1'], ex['v2'], ex['cmp_opts']].compact
|
11
11
|
comp = struct_compare(*args)
|
12
12
|
comparison = comp.nil? ? false : comp
|
13
|
-
num = ex[
|
13
|
+
num = ex['example_number']
|
14
14
|
binding.pry if comparison != ex['res']
|
15
|
-
expect(comparison).to eq(ex[
|
15
|
+
expect(comparison).to eq(ex['res']), "Test ##{num} failed: #{comparison}"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Blame Report', slow: true do
|
4
|
+
RES0 = [
|
5
|
+
['bud_category', 'note_rate', 'settlement_mm', 'settlement_yy', 'buy_up'],
|
6
|
+
['Govt Fixed 30', '2.25', '22', '2010', '12.123'],
|
7
|
+
['Conv Fixed 30', '2.25', '12', '2012', '1.127']
|
8
|
+
].freeze
|
9
|
+
|
10
|
+
RES1 = [
|
11
|
+
['entity', 'bud_category', 'note_rate', 'settlement_mm', 'settlement_yy',
|
12
|
+
'buy_up', 'buy_down'],
|
13
|
+
[nil, 'Govt Fixed 30', '2.25', '22', '2014', '2.123', '3.345'],
|
14
|
+
[nil, 'Govt Fixed 30', '2.25', '22', '2010', '12.123', '3.345'],
|
15
|
+
[nil, 'Conv Fixed 30', '2.25', '12', '2012', '1.126', '2.345']
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
before do
|
19
|
+
marty_whodunnit
|
20
|
+
|
21
|
+
Marty::Script.load_scripts(nil, Time.zone.now)
|
22
|
+
|
23
|
+
time1 = Time.zone.parse '2019-01-23 05:14:50 -0800'
|
24
|
+
time2 = Time.zone.parse '2019-01-24 05:14:50 -0800'
|
25
|
+
time3 = Time.zone.parse '2019-01-25 05:14:50 -0800'
|
26
|
+
time4 = Time.zone.parse '2019-01-26 05:14:50 -0800'
|
27
|
+
time5 = Time.zone.parse '2019-01-27 05:14:50 -0800'
|
28
|
+
|
29
|
+
posting = Marty::Posting.do_create('BASE', time5 - 2.hours, 'base posting')
|
30
|
+
@pt_name = Marty::Posting.find_by_name(posting.name).name
|
31
|
+
|
32
|
+
bc = Gemini::BudCategory.create(name: 'Conv Fixed 30', created_dt: time1)
|
33
|
+
bc2 = Gemini::BudCategory.create(name: 'Govt Fixed 30', created_dt: time1)
|
34
|
+
|
35
|
+
fannie_bup1 = Gemini::FannieBup.create(bud_category: bc,
|
36
|
+
note_rate: 2.250,
|
37
|
+
buy_up: 1.123,
|
38
|
+
buy_down: 2.345,
|
39
|
+
settlement_mm: 12,
|
40
|
+
settlement_yy: 2012,
|
41
|
+
created_dt: time1
|
42
|
+
)
|
43
|
+
|
44
|
+
fannie_bup2 = Gemini::FannieBup.create(bud_category: bc2,
|
45
|
+
note_rate: 2.250,
|
46
|
+
buy_up: 2.123,
|
47
|
+
buy_down: 3.345,
|
48
|
+
settlement_mm: 22,
|
49
|
+
settlement_yy: 2014,
|
50
|
+
created_dt: time4
|
51
|
+
)
|
52
|
+
|
53
|
+
fannie_bup3 = Gemini::FannieBup.create(bud_category: bc2,
|
54
|
+
note_rate: 2.250,
|
55
|
+
buy_up: 12.123,
|
56
|
+
buy_down: 3.345,
|
57
|
+
settlement_mm: 22,
|
58
|
+
settlement_yy: 2010,
|
59
|
+
created_dt: time4
|
60
|
+
)
|
61
|
+
|
62
|
+
fannie_bup2.destroy!
|
63
|
+
fannie_bup1.update!(buy_up: 1.125, created_dt: time2)
|
64
|
+
fannie_bup1.update!(buy_up: 1.126, created_dt: time4)
|
65
|
+
fannie_bup1.update!(buy_up: 1.127, created_dt: time5)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should generate Table report' do
|
69
|
+
engine = Marty::ScriptSet.new.get_engine('TableReport')
|
70
|
+
ws = engine.evaluate(
|
71
|
+
'TableReport', 'result',
|
72
|
+
'pt_name' => 'NOW',
|
73
|
+
'class_name' => 'Gemini::FannieBup',
|
74
|
+
'exclude_attrs' => ['entity_id', 'buy_down'],
|
75
|
+
'sort_field' => 'settlement_yy'
|
76
|
+
)
|
77
|
+
|
78
|
+
parsed_csv = CSV.parse(ws)
|
79
|
+
expect(parsed_csv).to eq RES0
|
80
|
+
|
81
|
+
ws = engine.evaluate(
|
82
|
+
'TableReport', 'result',
|
83
|
+
'pt_name' => @pt_name,
|
84
|
+
'class_name' => 'Gemini::FannieBup',
|
85
|
+
)
|
86
|
+
|
87
|
+
parsed_csv = CSV.parse(ws)
|
88
|
+
expect(parsed_csv).to eq RES1
|
89
|
+
end
|
90
|
+
end
|