marty 2.5.2 → 2.5.4
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/.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/models/event_spec.rb
CHANGED
|
@@ -16,27 +16,27 @@ describe Marty::Event do
|
|
|
16
16
|
|
|
17
17
|
Marty::Script.load_script_bodies(promise_bodies, Date.today)
|
|
18
18
|
start_delayed_job
|
|
19
|
-
Marty::Config[
|
|
19
|
+
Marty::Config['MARTY_EVENT_POLL_SECS'] = 1
|
|
20
20
|
|
|
21
21
|
@time = Time.zone.now
|
|
22
22
|
@date_string = @time.strftime('%Y-%m-%d')
|
|
23
23
|
@old_start = '1970-01-01 08:00:00'
|
|
24
24
|
@old_end = '1970-01-01 09:00:00'
|
|
25
25
|
# add events
|
|
26
|
-
[
|
|
27
|
-
nil
|
|
28
|
-
|
|
29
|
-
nil
|
|
30
|
-
|
|
31
|
-
nil
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Time.zone.parse(@
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
[
|
|
27
|
+
['testcl1', 123, @time, nil, nil, 'AVM', 'a comment',
|
|
28
|
+
nil],
|
|
29
|
+
['testcl1', 123, @time + 2.second, nil, nil, 'CRA', 'b comment',
|
|
30
|
+
nil],
|
|
31
|
+
['testcl1', 123, @time + 4.seconds, nil, 10000, 'PRICING', 'c comment',
|
|
32
|
+
nil],
|
|
33
|
+
['testcl1', 234, @time - 5.seconds, @time, nil, 'PRICING', 'c comment',
|
|
34
|
+
false],
|
|
35
|
+
['testcl2', 123, @time, nil, 2, 'AVM', 'e comment', nil],
|
|
36
|
+
['testcl2', 123, @time + 1.second, nil, 4, 'CRA', 'f comment', nil],
|
|
37
|
+
['testcl2', 123, Time.zone.parse(@old_start),
|
|
38
|
+
Time.zone.parse(@old_end), nil, 'PRICING', 'old event', 0]
|
|
39
|
+
].each do |klass, subjid, startdt, enddt, expire, op, comment, error|
|
|
40
40
|
Marty::Event.create!(klass: klass,
|
|
41
41
|
subject_id: subjid,
|
|
42
42
|
start_dt: startdt,
|
|
@@ -47,18 +47,17 @@ describe Marty::Event do
|
|
|
47
47
|
error: error)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
|
|
51
50
|
engine = Marty::ScriptSet.new.get_engine(NAME_I)
|
|
52
|
-
res = engine.background_eval(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
res = engine.background_eval('SLEEPER', { 'secs' => 5 }, ['a'],
|
|
52
|
+
klass: 'testcl3',
|
|
53
|
+
id: 987,
|
|
54
|
+
operation: 'PRICING')
|
|
56
55
|
res.force
|
|
57
56
|
engine = Marty::ScriptSet.new.get_engine(NAME_J)
|
|
58
|
-
res = engine.background_eval(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
res = engine.background_eval('FAILER', { 'dummy' => 'dummy' }, ['a'],
|
|
58
|
+
klass: 'testcl3',
|
|
59
|
+
id: 654,
|
|
60
|
+
operation: 'PRICING')
|
|
62
61
|
res.force rescue nil
|
|
63
62
|
sleep 5
|
|
64
63
|
save_clean_db(@save_file)
|
|
@@ -75,53 +74,51 @@ describe Marty::Event do
|
|
|
75
74
|
Marty::Event.clear_cache
|
|
76
75
|
end
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
it "reports currently running" do
|
|
77
|
+
it 'reports currently running' do
|
|
80
78
|
expect(Marty::Event.currently_running('testcl1', 123)).
|
|
81
79
|
to eq(['AVM', 'CRA', 'PRICING'])
|
|
82
80
|
expect(Marty::Event.currently_running('testcl2', 123)).to eq([])
|
|
83
81
|
expect(Marty::Event.currently_running('testcl3', 987)).to eq([])
|
|
84
82
|
expect(Marty::Event.last_event('testcl1', 123)).
|
|
85
83
|
to include(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
'klass' => 'testcl1',
|
|
85
|
+
'subject_id' => 123,
|
|
86
|
+
'enum_event_operation' => 'PRICING',
|
|
87
|
+
'comment' => 'c comment', 'expire_secs' => 10000)
|
|
90
88
|
expect(Marty::Event.last_event('testcl2', 123)).
|
|
91
89
|
to include(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
'klass' => 'testcl2',
|
|
91
|
+
'subject_id' => 123,
|
|
92
|
+
'enum_event_operation' => 'PRICING',
|
|
93
|
+
'comment' => 'old event')
|
|
96
94
|
expect(Marty::Event.last_event('testcl3', 987)).
|
|
97
95
|
to include(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
'klass' => 'testcl3',
|
|
97
|
+
'subject_id' => 987,
|
|
98
|
+
'enum_event_operation' => 'PRICING',
|
|
99
|
+
'comment' => nil,
|
|
100
|
+
'expire_secs' => nil)
|
|
103
101
|
|
|
104
|
-
Timecop.freeze(@time+1.second)
|
|
102
|
+
Timecop.freeze(@time + 1.second)
|
|
105
103
|
Marty::Event.clear_cache
|
|
106
104
|
expect(Marty::Event.currently_running('testcl1', 123)).
|
|
107
105
|
to eq(['AVM', 'CRA', 'PRICING'])
|
|
108
106
|
expect(Marty::Event.currently_running('testcl2', 123)).to eq(['AVM', 'CRA'])
|
|
109
107
|
|
|
110
|
-
Timecop.freeze(@time+3.seconds)
|
|
108
|
+
Timecop.freeze(@time + 3.seconds)
|
|
111
109
|
Marty::Event.clear_cache
|
|
112
110
|
expect(Marty::Event.currently_running('testcl1', 123)).
|
|
113
111
|
to eq(['AVM', 'CRA', 'PRICING'])
|
|
114
112
|
expect(Marty::Event.currently_running('testcl2', 123)).to eq(['CRA'])
|
|
115
113
|
|
|
116
|
-
Timecop.freeze(@time+6.seconds)
|
|
114
|
+
Timecop.freeze(@time + 6.seconds)
|
|
117
115
|
expect(Marty::Event.currently_running('testcl1', 123)).
|
|
118
116
|
to eq(['AVM', 'CRA', 'PRICING'])
|
|
119
117
|
expect(Marty::Event.currently_running('testcl2', 123)).to eq([])
|
|
120
118
|
Timecop.return
|
|
121
|
-
|
|
122
119
|
end
|
|
123
120
|
|
|
124
|
-
it
|
|
121
|
+
it 'misc API tests' do
|
|
125
122
|
ev1 = Marty::Event.where(klass: 'testcl3', subject_id: 987).first
|
|
126
123
|
ev2 = Marty::Event.where(klass: 'testcl3', subject_id: 654).first
|
|
127
124
|
af = Marty::Event.all_finished
|
|
@@ -160,39 +157,39 @@ describe Marty::Event do
|
|
|
160
157
|
expect(Marty::Event.currently_running('testcl1', 123)).
|
|
161
158
|
to eq(['CRA', 'PRICING'])
|
|
162
159
|
expect(Marty::Event.currently_running_multi('testcl1', [123])).
|
|
163
|
-
to eq(
|
|
160
|
+
to eq(123 => ['CRA', 'PRICING'])
|
|
164
161
|
|
|
165
162
|
expect(Marty::Event.op_is_running?('testcl1', 123, 'AVM')).to be_falsey
|
|
166
163
|
expect(Marty::Event.op_is_running?('testcl1', 123, 'CRA')).to be_truthy
|
|
167
164
|
|
|
168
165
|
ev = Marty::Event.lookup_event('testcl1', 123, 'AVM')
|
|
169
166
|
expect(ev.length).to eq(1)
|
|
170
|
-
expect(ev.first).to include(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
Marty::Event.update_comment(ev.first,
|
|
167
|
+
expect(ev.first).to include('klass' => 'testcl1',
|
|
168
|
+
'subject_id' => 123,
|
|
169
|
+
'enum_event_operation' => 'AVM',
|
|
170
|
+
'comment' => 'wassup',
|
|
171
|
+
'expire_secs' => nil,
|
|
172
|
+
'error' => false)
|
|
173
|
+
Marty::Event.update_comment(ev.first, 'updated')
|
|
177
174
|
ev = Marty::Event.lookup_event('testcl1', 123, 'AVM')
|
|
178
|
-
expect(ev.first).to include(
|
|
175
|
+
expect(ev.first).to include('comment' => 'updated')
|
|
179
176
|
expect(Marty::Event.compact_end_dt(ev.first)).to match(/\d\d:\d\d/)
|
|
180
177
|
expect(Marty::Event.pretty_op(ev.first)).to eq('Avm')
|
|
181
178
|
ev = Marty::Event.lookup_event('testcl1', 123, 'PRICING').first
|
|
182
179
|
expect(Marty::Event.pretty_op(ev)).to eq('Pricing')
|
|
183
180
|
evs = Marty::Event.last_event_multi('testcl1', [123, 234])
|
|
184
|
-
expect(evs[123]).to include(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
expect(evs[234]).to include(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
181
|
+
expect(evs[123]).to include('klass' => 'testcl1',
|
|
182
|
+
'subject_id' => 123,
|
|
183
|
+
'enum_event_operation' => 'CRA',
|
|
184
|
+
'comment' => 'b comment',
|
|
185
|
+
'expire_secs' => nil,
|
|
186
|
+
'error' => nil)
|
|
187
|
+
expect(evs[234]).to include('klass' => 'testcl1',
|
|
188
|
+
'subject_id' => 234,
|
|
189
|
+
'enum_event_operation' => 'PRICING',
|
|
190
|
+
'comment' => 'c comment',
|
|
191
|
+
'expire_secs' => nil,
|
|
192
|
+
'error' => false)
|
|
196
193
|
|
|
197
194
|
af = Marty::Event.all_finished
|
|
198
195
|
expect(af.count).to eq(4)
|
|
@@ -201,29 +198,41 @@ describe Marty::Event do
|
|
|
201
198
|
expect(af[['testcl1', 123]]['AVM']).to start_with(@date_string)
|
|
202
199
|
end
|
|
203
200
|
|
|
204
|
-
it
|
|
205
|
-
expect
|
|
206
|
-
|
|
201
|
+
it 'raises on error' do
|
|
202
|
+
expect do
|
|
203
|
+
Marty::Event.create_event('testcl', 1234, 'AVM', Time.zone.now, 600,
|
|
204
|
+
'the comment')
|
|
205
|
+
end .not_to raise_error
|
|
207
206
|
|
|
208
|
-
expect
|
|
209
|
-
|
|
207
|
+
expect do
|
|
208
|
+
Marty::Event.create_event('testcl', 1234, 'AVM', Time.zone.now, 600,
|
|
209
|
+
'the comment')
|
|
210
|
+
end.
|
|
210
211
|
to raise_error(%r!AVM is already running for testcl/1234!)
|
|
211
|
-
expect
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
expect do
|
|
213
|
+
Marty::Event.create_event('testcl', 2345, 'AVM', Time.zone.now, 600,
|
|
214
|
+
'the comment')
|
|
215
|
+
end .not_to raise_error
|
|
216
|
+
expect do
|
|
217
|
+
Marty::Event.finish_event('testcl', 1234, 'AVM', false,
|
|
218
|
+
'new comment')
|
|
219
|
+
end.
|
|
215
220
|
not_to raise_error
|
|
216
|
-
expect
|
|
217
|
-
|
|
221
|
+
expect do
|
|
222
|
+
Marty::Event.finish_event('testcl', 1234, 'AVM', false,
|
|
223
|
+
'new comment')
|
|
224
|
+
end.
|
|
218
225
|
to raise_error(%r!event testcl/1234/AVM not found!)
|
|
219
|
-
expect {Marty::Event.finish_event('testcl', 2345, 'AVM', false, 'foobar') }.
|
|
226
|
+
expect { Marty::Event.finish_event('testcl', 2345, 'AVM', false, 'foobar') }.
|
|
220
227
|
not_to raise_error
|
|
221
|
-
expect {Marty::Event.finish_event('testcl', 2345, 'AVM', false, 'foobar') }.
|
|
228
|
+
expect { Marty::Event.finish_event('testcl', 2345, 'AVM', false, 'foobar') }.
|
|
222
229
|
to raise_error(%r!event testcl/2345/AVM not found!)
|
|
223
|
-
expect {Marty::Event.finish_event('testcl', 2345, 'AVM', nil, 'foobar') }.
|
|
230
|
+
expect { Marty::Event.finish_event('testcl', 2345, 'AVM', nil, 'foobar') }.
|
|
224
231
|
to raise_error(/error must be true or false/)
|
|
225
|
-
expect
|
|
226
|
-
|
|
232
|
+
expect do
|
|
233
|
+
Marty::Event.create_event('testcl', 1234, 'AMV', Time.zone.now, 600,
|
|
234
|
+
'the comment')
|
|
235
|
+
end.
|
|
227
236
|
to raise_error(%r!PG::.*invalid input value for enum.*"AMV"!)
|
|
228
237
|
Marty::Event.clear_cache
|
|
229
238
|
af = Marty::Event.all_finished
|
|
@@ -236,8 +245,8 @@ describe Marty::Event do
|
|
|
236
245
|
expect(af[['testcl', 2345]]['AVM']).to start_with(@date_string)
|
|
237
246
|
end
|
|
238
247
|
|
|
239
|
-
it
|
|
240
|
-
long_comment =
|
|
248
|
+
it 'truncates long comment' do
|
|
249
|
+
long_comment = 'comment string abcdefg' * 100
|
|
241
250
|
long_comment_truncated = long_comment.truncate(255)
|
|
242
251
|
Marty::Event.create_event('testcl', 123, 'PRICING', Time.zone.now, 600,
|
|
243
252
|
long_comment)
|
|
@@ -249,16 +258,15 @@ describe Marty::Event do
|
|
|
249
258
|
comment: long_comment)
|
|
250
259
|
|
|
251
260
|
Marty::Event.create_event('testcl', 789, 'AVM', Time.zone.now, 600,
|
|
252
|
-
|
|
261
|
+
'comment')
|
|
253
262
|
Marty::Event.finish_event('testcl', 789, 'AVM', false, long_comment)
|
|
254
263
|
|
|
255
264
|
e1 = Marty::Event.lookup_event('testcl', 123, 'PRICING').first
|
|
256
265
|
e2 = Marty::Event.lookup_event('testcl', 456, 'CRA').first
|
|
257
266
|
e3 = Marty::Event.lookup_event('testcl', 789, 'AVM').first
|
|
258
267
|
|
|
259
|
-
expect(e1[
|
|
260
|
-
expect(e2[
|
|
261
|
-
expect(e3[
|
|
262
|
-
|
|
268
|
+
expect(e1['comment']).to eq(long_comment_truncated)
|
|
269
|
+
expect(e2['comment']).to eq(long_comment_truncated)
|
|
270
|
+
expect(e3['comment']).to eq(long_comment_truncated)
|
|
263
271
|
end
|
|
264
272
|
end
|
|
@@ -17,14 +17,14 @@ module Marty
|
|
|
17
17
|
|
|
18
18
|
before(:each) do
|
|
19
19
|
@import = ImportType.new
|
|
20
|
-
@import.name =
|
|
21
|
-
@import.db_model_name =
|
|
20
|
+
@import.name = 'Test1'
|
|
21
|
+
@import.db_model_name = 'Marty::ARTestModel'
|
|
22
22
|
@import.role_id = role_id
|
|
23
23
|
@import.save!
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
describe
|
|
27
|
-
it
|
|
26
|
+
describe 'validations' do
|
|
27
|
+
it 'require name, db_model and role' do
|
|
28
28
|
it = ImportType.new
|
|
29
29
|
expect(it).to_not be_valid
|
|
30
30
|
expect(it.errors[:name].any?).to be true
|
|
@@ -32,28 +32,28 @@ module Marty
|
|
|
32
32
|
expect(it.errors[:role_id].any?).to be true
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
it
|
|
35
|
+
it 'require a unique name' do
|
|
36
36
|
it = ImportType.new
|
|
37
|
-
it.name =
|
|
38
|
-
it.db_model_name =
|
|
37
|
+
it.name = 'Test1'
|
|
38
|
+
it.db_model_name = 'Marty::ARTestModel'
|
|
39
39
|
it.role_id = role_id
|
|
40
40
|
expect(it).to_not be_valid
|
|
41
41
|
expect(it.errors[:name].any?).to be true
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
it
|
|
44
|
+
it 'require an ActiveRecord model for the db_model_name' do
|
|
45
45
|
it = ImportType.new
|
|
46
|
-
it.name =
|
|
47
|
-
it.db_model_name =
|
|
46
|
+
it.name = 'Test1'
|
|
47
|
+
it.db_model_name = 'Marty::TestModel'
|
|
48
48
|
it.role_id = role_id
|
|
49
49
|
expect(it).to_not be_valid
|
|
50
|
-
expect(it.errors[:base][0]).to eq
|
|
50
|
+
expect(it.errors[:base][0]).to eq 'bad model name'
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
it
|
|
54
|
-
@import.cleaner_function =
|
|
55
|
-
@import.validation_function =
|
|
56
|
-
@import.preprocess_function =
|
|
53
|
+
it 'do not fail on blank strings for functions' do
|
|
54
|
+
@import.cleaner_function = ''
|
|
55
|
+
@import.validation_function = ' '
|
|
56
|
+
@import.preprocess_function = ' '
|
|
57
57
|
|
|
58
58
|
expect(@import).to be_valid
|
|
59
59
|
@import.save!
|
|
@@ -62,15 +62,15 @@ module Marty
|
|
|
62
62
|
expect(@import.preprocess_function).to be nil
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
it
|
|
66
|
-
@import.cleaner_function =
|
|
67
|
-
@import.validation_function =
|
|
65
|
+
it 'require valid functions for cleaner/validation/preprocess' do
|
|
66
|
+
@import.cleaner_function = 'import_cleaner'
|
|
67
|
+
@import.validation_function = 'import_validator'
|
|
68
68
|
expect(@import).to be_valid
|
|
69
69
|
|
|
70
|
-
@import.preprocess_function =
|
|
70
|
+
@import.preprocess_function = 'missing_func'
|
|
71
71
|
expect(@import).to_not be_valid
|
|
72
72
|
expect(@import.errors[:base][0]).
|
|
73
|
-
to eq
|
|
73
|
+
to eq 'unknown class method missing_func'
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
end
|
data/spec/models/posting_spec.rb
CHANGED
|
@@ -2,36 +2,36 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
module Marty
|
|
4
4
|
describe Posting do
|
|
5
|
-
describe
|
|
6
|
-
it
|
|
7
|
-
dt =
|
|
5
|
+
describe 'validations' do
|
|
6
|
+
it 'requires unique names' do
|
|
7
|
+
dt = '20130215 0800'
|
|
8
8
|
c = Posting.count
|
|
9
|
-
Posting.do_create(
|
|
9
|
+
Posting.do_create('BASE', dt, 'a comment')
|
|
10
10
|
Posting.count.should == c + 1
|
|
11
|
-
expect { s = Posting.do_create(
|
|
11
|
+
expect { s = Posting.do_create('BASE', dt, 'a comment') }.
|
|
12
12
|
to raise_error(ActiveRecord::RecordInvalid)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
it
|
|
16
|
-
d, t, tz =
|
|
15
|
+
it 'creates name based on PDT' do
|
|
16
|
+
d, t, tz = '20130215', '0900', 'PST8PDT'
|
|
17
17
|
dt_tz = [d, t, tz].join(' ')
|
|
18
|
-
p = Posting.do_create(
|
|
18
|
+
p = Posting.do_create('BASE', dt_tz, 'a comment')
|
|
19
19
|
expect(p.name).to match /BASE-#{d}-#{t}/
|
|
20
20
|
p.reload
|
|
21
21
|
expect(p.created_dt).to eq Time.zone.parse(dt_tz)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
describe
|
|
26
|
-
it
|
|
27
|
-
expect(Posting.lookup_dt(
|
|
25
|
+
describe 'lookups' do
|
|
26
|
+
it 'are seeded with a NOW posting' do
|
|
27
|
+
expect(Posting.lookup_dt('NOW')).to eq Float::INFINITY
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
describe
|
|
31
|
-
it
|
|
32
|
-
4.times
|
|
33
|
-
Posting.do_create(
|
|
34
|
-
|
|
30
|
+
describe '.get_latest' do
|
|
31
|
+
it 'provide a list of latest of postings in descending order' do
|
|
32
|
+
4.times do |d|
|
|
33
|
+
Posting.do_create('BASE', d.day.from_now, 'a comment')
|
|
34
|
+
end
|
|
35
35
|
dt3 = 3.day.from_now
|
|
36
36
|
|
|
37
37
|
latest = Posting.get_latest(1)
|
|
@@ -40,32 +40,32 @@ module Marty
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
describe
|
|
44
|
-
context
|
|
43
|
+
describe '.get_latest_by_type' do
|
|
44
|
+
context 'when invalid parameters are supplied' do
|
|
45
45
|
it "raises 'posting type list missing' error" do
|
|
46
46
|
expect { Posting.get_latest_by_type(10, nil) }.
|
|
47
|
-
to raise_error
|
|
47
|
+
to raise_error 'missing posting types list'
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "raises 'bad posting types list' error" do
|
|
51
51
|
expect { Posting.get_latest_by_type(10, 'BASE') }.
|
|
52
|
-
to raise_error
|
|
52
|
+
to raise_error 'bad posting types list'
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
context
|
|
56
|
+
context 'when valid parameters are supplied' do
|
|
57
57
|
before do
|
|
58
|
-
PostingType.create(
|
|
59
|
-
PostingType.create(
|
|
60
|
-
Posting.do_create(
|
|
61
|
-
Posting.do_create(
|
|
62
|
-
Posting.do_create(
|
|
63
|
-
Posting.do_create(
|
|
64
|
-
Posting.do_create(
|
|
65
|
-
Posting.do_create(
|
|
58
|
+
PostingType.create(name: 'SNAPSHOT')
|
|
59
|
+
PostingType.create(name: 'OTHER')
|
|
60
|
+
Posting.do_create('BASE', 0.day.from_now, 'base posting')
|
|
61
|
+
Posting.do_create('SNAPSHOT', 1.day.from_now, 'snapshot1 posting')
|
|
62
|
+
Posting.do_create('SNAPSHOT', 2.day.from_now, 'snapshot2 posting')
|
|
63
|
+
Posting.do_create('OTHER', 3.day.from_now, 'other1 posting')
|
|
64
|
+
Posting.do_create('SNAPSHOT', 4.day.from_now, 'snapshot3 posting')
|
|
65
|
+
Posting.do_create('OTHER', 5.day.from_now, 'other2 posting')
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
it
|
|
68
|
+
it 'filters on a single posting type' do
|
|
69
69
|
# First param is just the limit (max) to return
|
|
70
70
|
res = Posting.get_latest_by_type(10, ['BASE'])
|
|
71
71
|
expect(res.count).to eq 1
|
|
@@ -73,7 +73,7 @@ module Marty
|
|
|
73
73
|
expect(r0.comment).to eq 'base posting'
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
it
|
|
76
|
+
it 'filters on multiple posting types' do
|
|
77
77
|
res = Posting.get_latest_by_type(10, ['BASE', 'SNAPSHOT'])
|
|
78
78
|
expect(res.count).to eq 4
|
|
79
79
|
# snapshot3 is most recent with this filter
|
|
@@ -83,8 +83,8 @@ module Marty
|
|
|
83
83
|
expect(r3.comment).to eq 'base posting'
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
-
it
|
|
87
|
-
res = Posting.get_latest_by_type(10, ['SNAPSHOT',
|
|
86
|
+
it 'filters on posting types that are single or double quoted' do
|
|
87
|
+
res = Posting.get_latest_by_type(10, ['SNAPSHOT', 'OTHER'])
|
|
88
88
|
expect(res.count).to eq 5
|
|
89
89
|
# other2 is most recent with this filter
|
|
90
90
|
r0 = Posting.find_by_name(res[0]['name'])
|
|
@@ -93,7 +93,7 @@ module Marty
|
|
|
93
93
|
expect(r4.comment).to eq 'snapshot1 posting'
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
it
|
|
96
|
+
it 'filters and limits on multiple posting types' do
|
|
97
97
|
res = Posting.get_latest_by_type(3, ['SNAPSHOT', 'OTHER'])
|
|
98
98
|
expect(res.count).to eq 3
|
|
99
99
|
# other2 is most recent with this filter
|
|
@@ -103,7 +103,7 @@ module Marty
|
|
|
103
103
|
expect(r2.comment).to eq 'other1 posting'
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
it
|
|
106
|
+
it 'returns nothing with an empty posting type list' do
|
|
107
107
|
res = Posting.get_latest_by_type(10, [])
|
|
108
108
|
expect(res.count).to eq 0
|
|
109
109
|
end
|