marty 0.5.15 → 0.5.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +27 -0
- data/.rspec +3 -0
- data/.travis.yml +23 -0
- data/Gemfile +23 -0
- data/INDEPENDENCE_ISSUES.md +23 -0
- data/app/assets/images/marty/.gitkeep +0 -0
- data/app/components/marty/report_form.rb +9 -4
- data/gemini_deprecations.md +6 -0
- data/lib/marty/data_change.rb +99 -0
- data/lib/marty/data_conversion.rb +11 -3
- data/lib/marty/data_exporter.rb +9 -0
- data/lib/marty/version.rb +1 -1
- data/marty.gemspec +35 -0
- data/script/rails +8 -0
- data/spec/controllers/application_controller_spec.rb +52 -0
- data/spec/controllers/job_controller_spec.rb +226 -0
- data/spec/controllers/rpc_controller_spec.rb +379 -0
- data/spec/controllers/rpc_import_spec.rb +45 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/components_controller.rb +7 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/gemini/amortization_type.rb +5 -0
- data/spec/dummy/app/models/gemini/bud_category.rb +7 -0
- data/spec/dummy/app/models/gemini/entity.rb +2 -0
- data/spec/dummy/app/models/gemini/extras/data_import.rb +5 -0
- data/spec/dummy/app/models/gemini/extras/settlement_import.rb +28 -0
- data/spec/dummy/app/models/gemini/fannie_bup.rb +29 -0
- data/spec/dummy/app/models/gemini/grouping.rb +8 -0
- data/spec/dummy/app/models/gemini/grouping_head_version.rb +14 -0
- data/spec/dummy/app/models/gemini/head.rb +7 -0
- data/spec/dummy/app/models/gemini/head_version.rb +14 -0
- data/spec/dummy/app/models/gemini/helper.rb +44 -0
- data/spec/dummy/app/models/gemini/loan_program.rb +11 -0
- data/spec/dummy/app/models/gemini/mortgage_type.rb +5 -0
- data/spec/dummy/app/models/gemini/simple.rb +6 -0
- data/spec/dummy/app/models/gemini/streamline_type.rb +16 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +82 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml.example +10 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +35 -0
- data/spec/dummy/config/environments/production.rb +69 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/delayed_job.rb +5 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +12 -0
- data/spec/dummy/db/migrate/20140801000000_create_groupings.rb +11 -0
- data/spec/dummy/db/migrate/20150406171536_create_categories.rb +27 -0
- data/spec/dummy/db/migrate/20150408200916_create_loan_programs.rb +26 -0
- data/spec/dummy/db/migrate/20150408201429_create_types.rb +21 -0
- data/spec/dummy/db/migrate/20150420000001_create_heads.rb +14 -0
- data/spec/dummy/db/migrate/20150420000002_create_head_versions.rb +15 -0
- data/spec/dummy/db/migrate/20150420000003_create_grouping_head_versions.rb +12 -0
- data/spec/dummy/db/migrate/20151023000001_create_simple.rb +12 -0
- data/spec/dummy/db/seeds.rb +8 -0
- data/spec/dummy/delorean/blame_report.dl +171 -0
- data/spec/dummy/delorean/data_report.dl +105 -0
- data/spec/dummy/delorean/fields.dl +52 -0
- data/spec/dummy/delorean/styles.dl +134 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/lib/class_list.rb +3 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/icons/READ.txt +3 -0
- data/spec/dummy/public/icons/application_cascade.png +0 -0
- data/spec/dummy/public/icons/application_delete.png +0 -0
- data/spec/dummy/public/icons/application_put.png +0 -0
- data/spec/dummy/public/icons/application_view_detail.png +0 -0
- data/spec/dummy/public/icons/arrow_in.png +0 -0
- data/spec/dummy/public/icons/arrow_refresh.png +0 -0
- data/spec/dummy/public/icons/database_save.png +0 -0
- data/spec/dummy/public/icons/door_in.png +0 -0
- data/spec/dummy/public/icons/door_out.png +0 -0
- data/spec/dummy/public/icons/group.png +0 -0
- data/spec/dummy/public/icons/page_lightning.png +0 -0
- data/spec/dummy/public/icons/printer.png +0 -0
- data/spec/dummy/public/icons/report_disk.png +0 -0
- data/spec/dummy/public/icons/report_go.png +0 -0
- data/spec/dummy/public/icons/report_magnify.png +0 -0
- data/spec/dummy/public/icons/script.png +0 -0
- data/spec/dummy/public/icons/script_add.png +0 -0
- data/spec/dummy/public/icons/script_go.png +0 -0
- data/spec/dummy/public/icons/script_key.png +0 -0
- data/spec/dummy/public/icons/table_go.png +0 -0
- data/spec/dummy/public/icons/time.png +0 -0
- data/spec/dummy/public/icons/time_add.png +0 -0
- data/spec/dummy/public/icons/time_go.png +0 -0
- data/spec/dummy/public/icons/timeline_marker.png +0 -0
- data/spec/dummy/public/icons/user_add.png +0 -0
- data/spec/dummy/public/icons/user_delete.png +0 -0
- data/spec/dummy/public/icons/user_edit.png +0 -0
- data/spec/dummy/public/icons/wrench.png +0 -0
- data/spec/dummy/script/delayed_job +6 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/features/javascripts/job_dashboard_live_search.js.coffee +8 -0
- data/spec/features/javascripts/login.js.coffee +8 -0
- data/spec/features/jobs_dashboard_netzke_spec.rb +24 -0
- data/spec/features/jobs_dashboard_spec.rb +49 -0
- data/spec/fixtures/scripts/load_tests/script1.dl +2 -0
- data/spec/fixtures/scripts/load_tests/script2.dl +2 -0
- data/spec/job_helper.rb +102 -0
- data/spec/lib/data_exporter_spec.rb +71 -0
- data/spec/lib/data_importer_spec.rb +461 -0
- data/spec/lib/xl_spec.rb +198 -0
- data/spec/lib/xl_styles_spec.rb +115 -0
- data/spec/models/api_auth_spec.rb +187 -0
- data/spec/models/posting_spec.rb +107 -0
- data/spec/models/promise_spec.rb +65 -0
- data/spec/models/script_spec.rb +187 -0
- data/spec/models/user_spec.rb +68 -0
- data/spec/requests/routes_spec.rb +12 -0
- data/spec/spec_helper.rb +61 -0
- data/spec/support/clean_db_helpers.rb +18 -0
- data/spec/support/delayed_job_helpers.rb +12 -0
- data/spec/support/user_helpers.rb +12 -0
- metadata +139 -89
- data/app/components/marty/auth_app.rb~ +0 -51
- data/app/components/marty/auth_app/javascripts/auth_app.js~ +0 -91
- data/app/components/marty/cm_form_panel.rb~ +0 -5
- data/app/components/marty/cm_grid_panel.rb~ +0 -35
- data/app/components/marty/data_import_view.rb~ +0 -142
- data/app/components/marty/extras/layout.rb~ +0 -46
- data/app/components/marty/live_search_grid_panel.rb~ +0 -49
- data/app/components/marty/main_auth_app.rb~ +0 -238
- data/app/components/marty/mcfly_grid_panel.rb~ +0 -80
- data/app/components/marty/new_posting_form.rb~ +0 -46
- data/app/components/marty/new_posting_window.rb~ +0 -21
- data/app/components/marty/pivot_grid.rb +0 -52
- data/app/components/marty/pivot_grid/endpoints.rb +0 -45
- data/app/components/marty/pivot_grid/javascripts/extensions.js +0 -150
- data/app/components/marty/pivot_grid/javascripts/pivot_grid.js +0 -86
- data/app/components/marty/pivot_grid/services.rb +0 -44
- data/app/components/marty/posting_grid.rb~ +0 -140
- data/app/components/marty/promise_view.rb~ +0 -157
- data/app/components/marty/promise_view/stylesheets/promise_view.css~ +0 -15
- data/app/components/marty/report_form.rb~ +0 -217
- data/app/components/marty/report_select.rb~ +0 -133
- data/app/components/marty/reporting.rb~ +0 -39
- data/app/components/marty/script_detail.rb~ +0 -430
- data/app/components/marty/script_form.rb~ +0 -233
- data/app/components/marty/script_form/javascripts/Ext.ux.form.field.CodeMirror.js~ +0 -909
- data/app/components/marty/script_grid.rb~ +0 -99
- data/app/components/marty/script_tester.rb~ +0 -213
- data/app/components/marty/scripting.rb~ +0 -124
- data/app/components/marty/select_report.rb~ +0 -143
- data/app/components/marty/simple_app.rb~ +0 -101
- data/app/components/marty/tag_grid.rb~ +0 -89
- data/app/components/marty/tree_panel.rb~ +0 -256
- data/app/components/marty/tree_panel/javascripts/tree_panel.js~ +0 -317
- data/app/components/marty/user_pivot.rb +0 -128
- data/app/components/marty/user_view.rb~ +0 -188
- data/app/controllers/marty/application_controller.rb~ +0 -133
- data/app/controllers/marty/components_controller.rb~ +0 -37
- data/app/controllers/marty/job_controller.rb~ +0 -28
- data/app/controllers/marty/rpc_controller.rb~ +0 -61
- data/app/helpers/marty/script_set.rb~ +0 -59
- data/app/models/marty/api_auth.rb~ +0 -48
- data/app/models/marty/data_change.rb~ +0 -141
- data/app/models/marty/enum.rb~ +0 -16
- data/app/models/marty/import_type.rb~ +0 -48
- data/app/models/marty/poop.rb~ +0 -169
- data/app/models/marty/posting.rb~ +0 -86
- data/app/models/marty/posting_type.rb~ +0 -21
- data/app/models/marty/promise.rb~ +0 -196
- data/app/models/marty/role.rb~ +0 -10
- data/app/models/marty/script.rb~ +0 -62
- data/app/models/marty/tag.rb~ +0 -91
- data/app/models/marty/user.rb~ +0 -148
- data/app/models/marty/user_role.rb~ +0 -13
- data/app/views/layouts/marty/application.html.erb~ +0 -11
- data/config/routes.rb~ +0 -10
- data/db/migrate/019_create_marty_postings.rb~ +0 -19
- data/db/migrate/095_create_marty_tags.rb~ +0 -19
- data/lib/marty.rb~ +0 -13
- data/lib/marty/content_handler.rb~ +0 -93
- data/lib/marty/data_exporter.rb~ +0 -137
- data/lib/marty/data_importer.rb~ +0 -114
- data/lib/marty/data_row_processor.rb~ +0 -206
- data/lib/marty/drop_folder_hook.rb~ +0 -17
- data/lib/marty/folder_hook.rb~ +0 -9
- data/lib/marty/lazy_column_loader.rb~ +0 -47
- data/lib/marty/mcfly_query.rb~ +0 -188
- data/lib/marty/migrations.rb~ +0 -65
- data/lib/marty/monkey.rb~ +0 -160
- data/lib/marty/permissions.rb~ +0 -69
- data/lib/marty/promise.rb~ +0 -41
- data/lib/marty/promise_job.rb~ +0 -121
- data/lib/marty/promise_proxy.rb~ +0 -69
- data/lib/marty/util.rb~ +0 -80
- data/lib/marty/version.rb~ +0 -3
- data/lib/marty/xl.rb~ +0 -526
- data/lib/pyxll/README.txt~ +0 -16
- data/lib/pyxll/gemini.py~ +0 -110
- data/lib/pyxll/pyxll.cfg~ +0 -12
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Marty
|
4
|
+
describe Posting do
|
5
|
+
describe "validations" do
|
6
|
+
it "requires unique names" do
|
7
|
+
dt = "20130215 0800"
|
8
|
+
c = Posting.count
|
9
|
+
Posting.do_create("BASE", dt, 'a comment')
|
10
|
+
Posting.count.should == c + 1
|
11
|
+
expect { s = Posting.do_create("BASE", dt, 'a comment') }.
|
12
|
+
to raise_error(ActiveRecord::RecordInvalid)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "creates name based on PDT" do
|
16
|
+
d, t, tz = "20130215", "0900", "PST8PDT"
|
17
|
+
dt_tz = [d, t, tz].join(' ')
|
18
|
+
p = Posting.do_create("BASE", dt_tz, 'a comment')
|
19
|
+
expect(p.name).to match /BASE-#{d}-#{t}/
|
20
|
+
p.reload
|
21
|
+
expect(p.created_dt).to eq Time.zone.parse(dt_tz)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "lookups" do
|
26
|
+
it "are seeded with a NOW posting" do
|
27
|
+
expect(Posting.lookup_dt("NOW")).to eq Float::INFINITY
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".get_latest" do
|
31
|
+
it "provide a list of latest of postings in descending order" do
|
32
|
+
4.times { |d|
|
33
|
+
Posting.do_create("BASE", d.day.from_now, 'a comment')
|
34
|
+
}
|
35
|
+
dt3 = 3.day.from_now
|
36
|
+
|
37
|
+
latest = Posting.get_latest(1)
|
38
|
+
expect(latest.count).to eq 1
|
39
|
+
expect(latest[0].name).to match /BASE-#{dt3.strftime("%Y%m%d-%H%M")}/
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ".get_latest_by_type" do
|
44
|
+
context "when invalid parameters are supplied" do
|
45
|
+
it "raises 'posting type list missing' error" do
|
46
|
+
expect { Posting.get_latest_by_type(10, nil) }.
|
47
|
+
to raise_error "missing posting types list"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "raises 'bad posting types list' error" do
|
51
|
+
expect { Posting.get_latest_by_type(10, 'BASE') }.
|
52
|
+
to raise_error "bad posting types list"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when valid parameters are supplied" do
|
57
|
+
before do
|
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
|
+
end
|
67
|
+
|
68
|
+
it "filters on a single posting type" do
|
69
|
+
# First param is just the limit (max) to return
|
70
|
+
res = Posting.get_latest_by_type(10, ['BASE'])
|
71
|
+
expect(res.count).to eq 1
|
72
|
+
expect(res[0].comment).to eq 'base posting'
|
73
|
+
end
|
74
|
+
|
75
|
+
it "filters on multiple posting types" do
|
76
|
+
res = Posting.get_latest_by_type(10, ['BASE', 'SNAPSHOT'])
|
77
|
+
expect(res.count).to eq 4
|
78
|
+
# snapshot3 is most recent with this filter
|
79
|
+
expect(res[0].comment).to eq 'snapshot3 posting'
|
80
|
+
expect(res[3].comment).to eq 'base posting'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "filters on posting types that are single or double quoted" do
|
84
|
+
res = Posting.get_latest_by_type(10, ['SNAPSHOT', "OTHER"])
|
85
|
+
expect(res.count).to eq 5
|
86
|
+
# other2 is most recent with this filter
|
87
|
+
expect(res[0].comment).to eq 'other2 posting'
|
88
|
+
expect(res[4].comment).to eq 'snapshot1 posting'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "filters and limits on multiple posting types" do
|
92
|
+
res = Posting.get_latest_by_type(3, ['SNAPSHOT', 'OTHER'])
|
93
|
+
expect(res.count).to eq 3
|
94
|
+
# other2 is most recent with this filter
|
95
|
+
expect(res[0].comment).to eq 'other2 posting'
|
96
|
+
expect(res[2].comment).to eq 'other1 posting'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns nothing with an empty posting type list" do
|
100
|
+
res = Posting.get_latest_by_type(10, [])
|
101
|
+
expect(res.count).to eq 0
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marty'
|
3
|
+
require 'delorean_lang'
|
4
|
+
require 'job_helper'
|
5
|
+
|
6
|
+
describe Marty::Promise, slow: true do
|
7
|
+
before(:all) do
|
8
|
+
@clean_file = "/tmp/clean_#{Process.pid}.psql"
|
9
|
+
save_clean_db(@clean_file)
|
10
|
+
# transactional fixtures interfere with queueing jobs
|
11
|
+
self.use_transactional_fixtures = false
|
12
|
+
|
13
|
+
# Needed here because shutting transactional fixtures off
|
14
|
+
# means we lose the globally set user
|
15
|
+
Mcfly.whodunnit = UserHelpers.system_user
|
16
|
+
|
17
|
+
Marty::Script.load_script_bodies(promise_bodies, Date.today)
|
18
|
+
|
19
|
+
start_delayed_job
|
20
|
+
end
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
@time = DateTime.now
|
24
|
+
expect(Marty::Promise.unscoped.count).to eq(0)
|
25
|
+
engine = Marty::ScriptSet.new.get_engine(NAME_A)
|
26
|
+
engine.background_eval("Y", {"p_title" => NAME_A}, ["d"])
|
27
|
+
sleep 5
|
28
|
+
Marty::Promise.cleanup
|
29
|
+
expect(Marty::Promise.unscoped.count).to eq(10)
|
30
|
+
end
|
31
|
+
|
32
|
+
after(:each) do
|
33
|
+
Marty::Promise.where('parent_id IS NULL').destroy_all
|
34
|
+
Timecop.return
|
35
|
+
end
|
36
|
+
|
37
|
+
after(:all) do
|
38
|
+
restore_clean_db(@clean_file)
|
39
|
+
stop_delayed_job
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should retain jobs that were run less than 4 hours ago" do
|
43
|
+
Timecop.freeze(@time + 4.hours)
|
44
|
+
Marty::Promise.cleanup
|
45
|
+
expect(Marty::Promise.unscoped.count).to eq(10)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should cleanup jobs that are older than 4 hours" do
|
49
|
+
Timecop.freeze(@time + 4.hours + 1.minute)
|
50
|
+
Marty::Promise.cleanup
|
51
|
+
expect(Marty::Promise.unscoped.count).to eq(0)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow cleanup of all jobs when forced by admin" do
|
55
|
+
Timecop.freeze(@time + 4.hours)
|
56
|
+
Marty::Promise.cleanup(true)
|
57
|
+
expect(Marty::Promise.unscoped.count).to eq(0)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should provide a live search scope for filtering by user or role" do
|
61
|
+
expect(Marty::Promise.live_search('XXX').size).to eq(0)
|
62
|
+
expect(Marty::Promise.live_search('marty').size).to eq(10)
|
63
|
+
expect(Marty::Promise.live_search('Admin').size).to eq(10)
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
s1 =<<eof
|
4
|
+
NodeA:
|
5
|
+
attr = 123
|
6
|
+
eof
|
7
|
+
|
8
|
+
s2 =<<eof
|
9
|
+
NodeB:
|
10
|
+
attr = 456
|
11
|
+
eof
|
12
|
+
|
13
|
+
describe Marty::Script do
|
14
|
+
describe '.load_a_script' do
|
15
|
+
let(:now) { Time.zone.now - 1.minute }
|
16
|
+
|
17
|
+
it "creates a new script if it doesn't already exist" do
|
18
|
+
expect { Marty::Script.load_a_script('TestNew', s1, now) }.
|
19
|
+
to change(Marty::Script, :count).by(1)
|
20
|
+
expect(Marty::Script.lookup('infinity', 'TestNew').created_dt.to_s).
|
21
|
+
to eq(now.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't create a new script entry if it already exists and is the " +
|
25
|
+
"same as the existing" do
|
26
|
+
Marty::Script.load_a_script('TestExistsAndSame', s1)
|
27
|
+
expect { Marty::Script.load_a_script('TestExistsAndSame', s1) }.
|
28
|
+
not_to change(Marty::Script, :count)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'updates the existing script entry if it already exists but is ' +
|
32
|
+
'different' do
|
33
|
+
Marty::Script.load_a_script('TestExistsAndDifferent1', s1)
|
34
|
+
expect { Marty::Script.load_a_script('TestExistsAndDifferent1', s2) }.
|
35
|
+
to change(Marty::Script, :count).by(1)
|
36
|
+
|
37
|
+
Marty::Script.load_a_script('TestExistsAndDifferent2', s1, now - 1.minute)
|
38
|
+
expect { Marty::Script.load_a_script('TestExistsAndDifferent2',
|
39
|
+
s2, now) }.
|
40
|
+
to change { Marty::Script.where(name: 'TestExistsAndDifferent2',
|
41
|
+
obsoleted_dt: 'infinity').count }.by(0)
|
42
|
+
expect(Marty::Script.lookup('infinity', 'TestExistsAndDifferent2').
|
43
|
+
created_dt.to_s).to eq(now.to_s)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.load_script_bodies' do
|
48
|
+
before(:each) do
|
49
|
+
allow(Marty::Script).to receive(:load_a_script)
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:now) { Time.zone.now - 1.minute }
|
53
|
+
|
54
|
+
it 'loads each script given a hash' do
|
55
|
+
Marty::Script.load_script_bodies({'Test1' => s1, 'Test2' => s2}, now)
|
56
|
+
expect(Marty::Script).to have_received(:load_a_script).
|
57
|
+
with('Test1', s1, now)
|
58
|
+
expect(Marty::Script).to have_received(:load_a_script).
|
59
|
+
with('Test2', s2, now)
|
60
|
+
expect(Marty::Script).to have_received(:load_a_script).twice
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'loads each script given an array of tuples' do
|
64
|
+
Marty::Script.load_script_bodies([['Test1', s1], ['Test2', s2]], now)
|
65
|
+
expect(Marty::Script).to have_received(:load_a_script).
|
66
|
+
with('Test1', s1, now)
|
67
|
+
expect(Marty::Script).to have_received(:load_a_script).
|
68
|
+
with('Test2', s2, now)
|
69
|
+
expect(Marty::Script).to have_received(:load_a_script).twice
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'creates a new tag if none exist yet with provided datetime' do
|
73
|
+
expect { @tag = Marty::Script.load_script_bodies({'Test1' => s1,
|
74
|
+
'Test2' => s2}, now) }.
|
75
|
+
to change(Marty::Tag, :count).by(1)
|
76
|
+
expect(@tag.created_dt).to eq(now + 1.second)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'creates a new tag when there is an older one present' do
|
80
|
+
Marty::Tag.do_create(now - 1.minute, 'initial test tag')
|
81
|
+
expect { @tag = Marty::Script.load_script_bodies({'Test1' => s1,
|
82
|
+
'Test2' => s2}, now) }.
|
83
|
+
to change(Marty::Tag, :count).by(1)
|
84
|
+
expect(@tag.created_dt).to eq(now + 1.second)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'creates a new tag when no previous tag is present and no datetime ' +
|
88
|
+
'provided' do
|
89
|
+
expect { tag = Marty::Script.load_script_bodies({'Test1' => s1,
|
90
|
+
'Test2' => s2}) }.
|
91
|
+
to change(Marty::Tag, :count).by(1)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "doesn't create a new tag if one is present and the script wasn't" +
|
95
|
+
"modified" do
|
96
|
+
Marty::Script.create!(name: 'Test1', body: s1, created_dt: now)
|
97
|
+
Marty::Tag.do_create(now + 1.second, 'tag created by test')
|
98
|
+
expect { Marty::Script.load_script_bodies({'Test1' => s1}) }.
|
99
|
+
not_to change(Marty::Tag, :count)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '.load_scripts' do
|
104
|
+
before(:each) do
|
105
|
+
allow(Marty::Script).to receive(:load_script_bodies)
|
106
|
+
end
|
107
|
+
|
108
|
+
let(:scripts_path) do
|
109
|
+
File.expand_path('../../fixtures/scripts/load_tests', __FILE__)
|
110
|
+
end
|
111
|
+
let(:now) { Time.zone.now - 1.minute }
|
112
|
+
let(:ls1) { File.read("#{scripts_path}/script1.dl") }
|
113
|
+
let(:ls2) { File.read("#{scripts_path}/script2.dl") }
|
114
|
+
|
115
|
+
it 'reads in the files and loads the script bodies' do
|
116
|
+
Marty::Script.load_scripts(scripts_path, now)
|
117
|
+
expect(Marty::Script).to have_received(:load_script_bodies).
|
118
|
+
with(match_array([['Script1', ls1], ['Script2', ls2]]), now)
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '.get_script_filenames' do
|
124
|
+
context 'with single directory passed in' do
|
125
|
+
before(:each) do
|
126
|
+
allow(Dir).to receive(:glob).and_return(script_files)
|
127
|
+
end
|
128
|
+
|
129
|
+
let(:script_files) { ['/test/script1.dl', '/test/script2.dl'] }
|
130
|
+
|
131
|
+
it 'gets the files from the specified directory' do
|
132
|
+
Marty::Script.get_script_filenames('/test')
|
133
|
+
expect(Dir).to have_received(:glob).with('/test/*.dl')
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'returns the files in the given directory' do
|
137
|
+
expect(Marty::Script.get_script_filenames('/test')).
|
138
|
+
to match_array(script_files)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'with duplicate script file names' do
|
143
|
+
it 'returns only the unique file names' do
|
144
|
+
allow(Dir).to receive(:glob).with('/test1/*.dl').
|
145
|
+
and_return(['/test1/sc1.dl', '/test1/sc2.dl'])
|
146
|
+
allow(Dir).to receive(:glob).with('/test2/*.dl').
|
147
|
+
and_return(['/test2/sc2.dl', '/test2/sc3.dl'])
|
148
|
+
expect(Marty::Script.get_script_filenames(['/test1', '/test2'])).
|
149
|
+
to match_array(['/test1/sc1.dl', '/test1/sc2.dl', '/test2/sc3.dl'])
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'using default directories' do
|
154
|
+
it 'gets the files from the default paths' do
|
155
|
+
allow(Dir).to receive(:glob).and_return([])
|
156
|
+
Marty::Script.get_script_filenames
|
157
|
+
expect(Dir).to have_received(:glob).with("#{Rails.root}/delorean/*.dl")
|
158
|
+
expect(Dir).to have_received(:glob).
|
159
|
+
with(File.expand_path('../../../delorean/*.dl', __FILE__))
|
160
|
+
expect(Dir).to have_received(:glob).twice
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'with Rails.configuration.marty.delorean_scripts_path' do
|
165
|
+
before(:each) do
|
166
|
+
Rails.configuration.marty.delorean_scripts_path = ['/conf_test']
|
167
|
+
end
|
168
|
+
after(:each) { Rails.configuration.marty.delorean_scripts_path = nil }
|
169
|
+
|
170
|
+
it 'gets the files from the specified path' do
|
171
|
+
allow(Dir).to receive(:glob).and_return([])
|
172
|
+
Marty::Script.get_script_filenames
|
173
|
+
expect(Dir).to have_received(:glob).with('/conf_test/*.dl')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '.delete_scripts' do
|
179
|
+
it 'removes all the scripts' do
|
180
|
+
Marty::Script.create!(name: 'TestScript1', body: s1)
|
181
|
+
Marty::Script.create!(name: 'TestScript2', body: s2)
|
182
|
+
|
183
|
+
Marty::Script.delete_scripts
|
184
|
+
expect(Marty::Script.count).to eq(0)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Marty
|
4
|
+
describe User do
|
5
|
+
before(:each) do
|
6
|
+
Rails.configuration.marty.system_account =
|
7
|
+
UserHelpers.system_user.login
|
8
|
+
end
|
9
|
+
|
10
|
+
let (:tuser) {
|
11
|
+
UserHelpers.create_user('other_user')
|
12
|
+
}
|
13
|
+
|
14
|
+
describe "validations" do
|
15
|
+
it "should require login, firstname and lastname" do
|
16
|
+
user = User.new
|
17
|
+
expect(user).to_not be_valid
|
18
|
+
expect(user.errors[:login].any?).to be true
|
19
|
+
expect(user.errors[:firstname].any?).to be true
|
20
|
+
expect(user.errors[:lastname].any?).to be true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should require unique login" do
|
24
|
+
expect(Mcfly.whodunnit).to_not be_nil
|
25
|
+
user = UserHelpers.system_user.dup
|
26
|
+
expect(user).to_not be_valid
|
27
|
+
expect(user.errors[:login].to_s).to include('already been taken')
|
28
|
+
user.login = 'marty2'
|
29
|
+
expect(user).to be_valid
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not allow Gemini account to be de-activated" do
|
33
|
+
user = UserHelpers.system_user
|
34
|
+
user.active = false
|
35
|
+
expect(user).to_not be_valid
|
36
|
+
expect(user.errors[:base].to_s).
|
37
|
+
to include('application system account cannot be deactivated')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not allow accounts to be deleted" do
|
41
|
+
user = UserHelpers.system_user
|
42
|
+
user.destroy
|
43
|
+
expect(user.destroyed?).to be false
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not allow user managers to edit the Gemini account" do
|
47
|
+
Mcfly.whodunnit = tuser
|
48
|
+
user = UserHelpers.system_user
|
49
|
+
allow_any_instance_of(Marty::User).to receive(:user_manager_only).
|
50
|
+
and_return(true)
|
51
|
+
user.firstname = 'Testing'
|
52
|
+
expect(user).to_not be_valid
|
53
|
+
expect(user.errors[:base].to_s).
|
54
|
+
to include('cannot edit the application system account')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not allow user managers to edit their own account" do
|
58
|
+
Mcfly.whodunnit = tuser
|
59
|
+
allow_any_instance_of(Marty::User).to receive(:user_manager_only).
|
60
|
+
and_return(true)
|
61
|
+
tuser.firstname = 'Testing'
|
62
|
+
expect(tuser).to_not be_valid
|
63
|
+
expect(tuser.errors[:base].to_s).
|
64
|
+
to include('cannot edit or add additional roles')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Marty Rails engine routes', type: :request do
|
4
|
+
it 'can reach the rpc endpoint' do
|
5
|
+
get marty.rpc_path(:evaluate, format: :json)
|
6
|
+
post marty.rpc_path(:evaluate, format: :json)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can reach the jobs endpoint' do
|
10
|
+
get marty.job_path(:download)
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
|
+
|
3
|
+
require 'dummy/config/application'
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'database_cleaner'
|
6
|
+
|
7
|
+
Dummy::Application.initialize!
|
8
|
+
|
9
|
+
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
|
10
|
+
|
11
|
+
Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f }
|
12
|
+
|
13
|
+
class ActiveRecord::Base
|
14
|
+
mattr_accessor :shared_connection
|
15
|
+
|
16
|
+
def self.clear_connection
|
17
|
+
@@shared_connection = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
clear_connection
|
21
|
+
|
22
|
+
def self.connection
|
23
|
+
@@shared_connection || retrieve_connection
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.reset_shared_connection
|
27
|
+
@@shared_connection = retrieve_connection
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
32
|
+
|
33
|
+
RSpec.configure do |config|
|
34
|
+
config.include DelayedJobHelpers
|
35
|
+
config.include CleanDbHelpers
|
36
|
+
|
37
|
+
# TODO: Continue to remove should syntax from specs - remove this line to see
|
38
|
+
# errors
|
39
|
+
config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
|
40
|
+
|
41
|
+
config.run_all_when_everything_filtered = true
|
42
|
+
config.filter_run :focus
|
43
|
+
|
44
|
+
config.order = 'random'
|
45
|
+
|
46
|
+
config.before(:suite) do
|
47
|
+
DatabaseCleaner.clean_with(:truncation)
|
48
|
+
|
49
|
+
Marty::Engine.load_seed
|
50
|
+
Rails.application.load_seed
|
51
|
+
end
|
52
|
+
|
53
|
+
config.before(:each) do
|
54
|
+
Mcfly.whodunnit = UserHelpers.system_user
|
55
|
+
end
|
56
|
+
|
57
|
+
config.infer_spec_type_from_file_location!
|
58
|
+
config.use_transactional_fixtures = true
|
59
|
+
|
60
|
+
Netzke::Testing.rspec_init(config)
|
61
|
+
end
|