canvas_sync 0.16.2 → 0.17.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -137
- data/app/models/canvas_sync/sync_batch.rb +5 -0
- data/db/migrate/20170915210836_create_canvas_sync_job_log.rb +12 -31
- data/db/migrate/20180725155729_add_job_id_to_canvas_sync_job_logs.rb +4 -13
- data/db/migrate/20190916154829_add_fork_count_to_canvas_sync_job_logs.rb +3 -11
- data/db/migrate/20201018210836_create_canvas_sync_sync_batches.rb +11 -0
- data/lib/canvas_sync.rb +36 -118
- data/lib/canvas_sync/concerns/api_syncable.rb +27 -0
- data/lib/canvas_sync/job.rb +5 -5
- data/lib/canvas_sync/job_batches/batch.rb +399 -0
- data/lib/canvas_sync/job_batches/batch_aware_job.rb +62 -0
- data/lib/canvas_sync/job_batches/callback.rb +153 -0
- data/lib/canvas_sync/job_batches/chain_builder.rb +210 -0
- data/lib/canvas_sync/job_batches/context_hash.rb +147 -0
- data/lib/canvas_sync/job_batches/jobs/base_job.rb +7 -0
- data/lib/canvas_sync/job_batches/jobs/concurrent_batch_job.rb +18 -0
- data/lib/canvas_sync/job_batches/jobs/serial_batch_job.rb +73 -0
- data/lib/canvas_sync/job_batches/sidekiq.rb +93 -0
- data/lib/canvas_sync/job_batches/status.rb +63 -0
- data/lib/canvas_sync/jobs/begin_sync_chain_job.rb +34 -0
- data/lib/canvas_sync/jobs/report_checker.rb +3 -6
- data/lib/canvas_sync/jobs/report_processor_job.rb +2 -5
- data/lib/canvas_sync/jobs/report_starter.rb +27 -19
- data/lib/canvas_sync/jobs/sync_accounts_job.rb +3 -5
- data/lib/canvas_sync/jobs/sync_admins_job.rb +2 -4
- data/lib/canvas_sync/jobs/sync_assignment_groups_job.rb +2 -4
- data/lib/canvas_sync/jobs/sync_assignments_job.rb +2 -4
- data/lib/canvas_sync/jobs/sync_context_module_items_job.rb +2 -4
- data/lib/canvas_sync/jobs/sync_context_modules_job.rb +2 -4
- data/lib/canvas_sync/jobs/sync_provisioning_report_job.rb +5 -35
- data/lib/canvas_sync/jobs/sync_roles_job.rb +2 -5
- data/lib/canvas_sync/jobs/sync_simple_table_job.rb +11 -32
- data/lib/canvas_sync/jobs/sync_submissions_job.rb +2 -4
- data/lib/canvas_sync/jobs/sync_terms_job.rb +25 -8
- data/lib/canvas_sync/misc_helper.rb +15 -0
- data/lib/canvas_sync/version.rb +1 -1
- data/spec/canvas_sync/canvas_sync_spec.rb +136 -153
- data/spec/canvas_sync/jobs/job_spec.rb +9 -17
- data/spec/canvas_sync/jobs/report_checker_spec.rb +1 -3
- data/spec/canvas_sync/jobs/report_processor_job_spec.rb +0 -3
- data/spec/canvas_sync/jobs/report_starter_spec.rb +19 -28
- data/spec/canvas_sync/jobs/sync_admins_job_spec.rb +1 -4
- data/spec/canvas_sync/jobs/sync_assignment_groups_job_spec.rb +2 -1
- data/spec/canvas_sync/jobs/sync_assignments_job_spec.rb +3 -2
- data/spec/canvas_sync/jobs/sync_context_module_items_job_spec.rb +3 -2
- data/spec/canvas_sync/jobs/sync_context_modules_job_spec.rb +3 -2
- data/spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb +3 -35
- data/spec/canvas_sync/jobs/sync_roles_job_spec.rb +1 -4
- data/spec/canvas_sync/jobs/sync_simple_table_job_spec.rb +5 -12
- data/spec/canvas_sync/jobs/sync_submissions_job_spec.rb +2 -1
- data/spec/canvas_sync/jobs/sync_terms_job_spec.rb +1 -4
- data/spec/dummy/app/models/account.rb +3 -0
- data/spec/dummy/app/models/pseudonym.rb +14 -0
- data/spec/dummy/app/models/submission.rb +1 -0
- data/spec/dummy/app/models/user.rb +1 -0
- data/spec/dummy/config/environments/test.rb +2 -0
- data/spec/dummy/db/migrate/20201016181346_create_pseudonyms.rb +24 -0
- data/spec/dummy/db/schema.rb +24 -4
- data/spec/job_batching/batch_aware_job_spec.rb +100 -0
- data/spec/job_batching/batch_spec.rb +363 -0
- data/spec/job_batching/callback_spec.rb +38 -0
- data/spec/job_batching/flow_spec.rb +91 -0
- data/spec/job_batching/integration/integration.rb +57 -0
- data/spec/job_batching/integration/nested.rb +88 -0
- data/spec/job_batching/integration/simple.rb +47 -0
- data/spec/job_batching/integration/workflow.rb +134 -0
- data/spec/job_batching/integration_helper.rb +48 -0
- data/spec/job_batching/sidekiq_spec.rb +124 -0
- data/spec/job_batching/status_spec.rb +92 -0
- data/spec/job_batching/support/base_job.rb +14 -0
- data/spec/job_batching/support/sample_callback.rb +2 -0
- data/spec/spec_helper.rb +17 -0
- metadata +90 -8
- data/lib/canvas_sync/job_chain.rb +0 -57
- data/lib/canvas_sync/jobs/fork_gather.rb +0 -59
- data/spec/canvas_sync/jobs/fork_gather_spec.rb +0 -73
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class GoodJob < CanvasSync::Job
|
4
|
-
def perform(
|
4
|
+
def perform(argument)
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
8
|
class EvilError < StandardError; end;
|
9
9
|
|
10
10
|
class BadJob < CanvasSync::Job
|
11
|
-
def perform(
|
11
|
+
def perform(argument)
|
12
12
|
raise EvilError
|
13
13
|
end
|
14
14
|
|
@@ -25,19 +25,19 @@ RSpec.describe CanvasSync::Job do
|
|
25
25
|
describe '#perform' do
|
26
26
|
it 'creates a CanvasSync::JobLog and logs relevant data on it' do
|
27
27
|
expect {
|
28
|
-
GoodJob.perform_now(
|
28
|
+
GoodJob.perform_now("argument")
|
29
29
|
}.to change { CanvasSync::JobLog.count }.by(1)
|
30
30
|
|
31
31
|
job_log = CanvasSync::JobLog.last
|
32
32
|
expect(job_log.started_at).to_not be_nil
|
33
33
|
expect(job_log.job_class).to eq(GoodJob.to_s)
|
34
|
-
expect(job_log.job_arguments).to eq([
|
34
|
+
expect(job_log.job_arguments).to eq(["argument"])
|
35
35
|
expect(job_log.completed_at).to_not be_nil
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'logs exceptions on the CanvasSync::JobLog and then re-raises' do
|
39
39
|
expect {
|
40
|
-
BadJob.perform_now(
|
40
|
+
BadJob.perform_now("argument")
|
41
41
|
}.to raise_exception(StandardError)
|
42
42
|
|
43
43
|
job_log = CanvasSync::JobLog.last
|
@@ -47,25 +47,17 @@ RSpec.describe CanvasSync::Job do
|
|
47
47
|
|
48
48
|
it 'invokes an error handler' do
|
49
49
|
expect(BadJob).to receive(:good_catcher).once
|
50
|
+
set_batch_context(on_failure: 'BadJob.good_catcher')
|
50
51
|
expect {
|
51
|
-
BadJob.perform_now(
|
52
|
-
jobs: [],
|
53
|
-
global_options: {
|
54
|
-
on_failure: 'BadJob.good_catcher'
|
55
|
-
}
|
56
|
-
})
|
52
|
+
BadJob.perform_now()
|
57
53
|
}.to raise_exception(StandardError)
|
58
54
|
end
|
59
55
|
|
60
56
|
it 'logs a failing error handler' do
|
61
57
|
expect(BadJob).to receive(:bad_catcher).once.and_call_original
|
58
|
+
set_batch_context(on_failure: 'BadJob.bad_catcher')
|
62
59
|
expect {
|
63
|
-
BadJob.perform_now(
|
64
|
-
jobs: [],
|
65
|
-
global_options: {
|
66
|
-
on_failure: 'BadJob.bad_catcher'
|
67
|
-
}
|
68
|
-
})
|
60
|
+
BadJob.perform_now()
|
69
61
|
}.to raise_exception(StandardError)
|
70
62
|
job_log = CanvasSync::JobLog.last
|
71
63
|
expect(job_log.backtrace).to include "Error Occurred while handling an Error"
|
@@ -5,12 +5,10 @@ RSpec.describe CanvasSync::Jobs::ReportChecker do
|
|
5
5
|
let(:report_id) { 1 }
|
6
6
|
let(:report_name) { 'provisioning_csv' }
|
7
7
|
let(:processor) { 'FakeProcessor' }
|
8
|
-
let(:job_chain) { { jobs: [], global_options: {} } }
|
9
8
|
|
10
9
|
describe '#perform' do
|
11
10
|
def start_job
|
12
11
|
CanvasSync::Jobs::ReportChecker.perform_now(
|
13
|
-
job_chain,
|
14
12
|
'provisioning_csv',
|
15
13
|
report_id,
|
16
14
|
processor,
|
@@ -25,7 +23,7 @@ RSpec.describe CanvasSync::Jobs::ReportChecker do
|
|
25
23
|
.and_return({ 'status' => 'complete', 'attachment' => { 'url' => 'blah' } })
|
26
24
|
|
27
25
|
expect(CanvasSync::Jobs::ReportProcessorJob).to receive(:perform_later)
|
28
|
-
.with(
|
26
|
+
.with(report_name, 'blah', processor, {}, report_id)
|
29
27
|
|
30
28
|
start_job
|
31
29
|
end
|
@@ -6,17 +6,14 @@ RSpec.describe CanvasSync::Jobs::ReportProcessorJob do
|
|
6
6
|
let(:report_name) { 'provisioning_csv' }
|
7
7
|
let(:report_url) { 'https://test.instructure.com/sample_report_download' }
|
8
8
|
let(:processor) { FakeProcessor.to_s }
|
9
|
-
let(:job_chain) { { jobs: [], global_options: {} } }
|
10
9
|
let(:report_id) { 1 }
|
11
10
|
|
12
11
|
describe '#perform' do
|
13
12
|
it 'downloads the report to a file and then calls the process method on the processor, and then invokes the next job' do
|
14
13
|
expect(IO).to receive(:copy_stream)
|
15
14
|
expect(FakeProcessor).to receive(:process)
|
16
|
-
expect(CanvasSync).to receive(:invoke_next).with(job_chain)
|
17
15
|
|
18
16
|
CanvasSync::Jobs::ReportProcessorJob.perform_now(
|
19
|
-
job_chain,
|
20
17
|
report_name,
|
21
18
|
report_url,
|
22
19
|
processor,
|
@@ -16,7 +16,6 @@ RSpec.describe CanvasSync::Jobs::ReportStarter do
|
|
16
16
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
17
17
|
|
18
18
|
CanvasSync::Jobs::ReportStarter.perform_now(
|
19
|
-
{ jobs: [], global_options: {} },
|
20
19
|
report_name,
|
21
20
|
report_params,
|
22
21
|
processor,
|
@@ -24,30 +23,27 @@ RSpec.describe CanvasSync::Jobs::ReportStarter do
|
|
24
23
|
end
|
25
24
|
|
26
25
|
context 'allow_redownloads is true' do
|
27
|
-
context 'the report has already been cached' do
|
28
|
-
|
29
|
-
|
30
|
-
job_chain = { jobs: [], global_options: { report_name => 1 } }
|
26
|
+
# context 'the report has already been cached' do
|
27
|
+
# it 'runs the report checker for the already started report' do
|
28
|
+
# expect_any_instance_of(Bearcat::Client).to_not receive(:start_report)
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
)
|
30
|
+
# expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_return(report_checker_double)
|
31
|
+
# expect(report_checker_double).to receive(:perform_later).with(
|
32
|
+
# report_name,
|
33
|
+
# 1,
|
34
|
+
# processor,
|
35
|
+
# options
|
36
|
+
# )
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
38
|
+
# CanvasSync::Jobs::ReportStarter.perform_now(
|
39
|
+
# report_name,
|
40
|
+
# report_params,
|
41
|
+
# processor,
|
42
|
+
# options,
|
43
|
+
# allow_redownloads: true
|
44
|
+
# )
|
45
|
+
# end
|
46
|
+
# end
|
51
47
|
|
52
48
|
context 'the report has not been started before' do
|
53
49
|
it 'starts a new report and caches the report id' do
|
@@ -55,12 +51,8 @@ RSpec.describe CanvasSync::Jobs::ReportStarter do
|
|
55
51
|
.with('self', report_name, report_params)
|
56
52
|
.and_return({ 'id' => 1 })
|
57
53
|
|
58
|
-
orig_job_chain = { jobs: [], global_options: {} }
|
59
|
-
new_job_chain = { jobs: [], global_options: { report_name => 1 } }
|
60
|
-
|
61
54
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_return(report_checker_double)
|
62
55
|
expect(report_checker_double).to receive(:perform_later).with(
|
63
|
-
new_job_chain,
|
64
56
|
report_name,
|
65
57
|
1,
|
66
58
|
processor,
|
@@ -68,7 +60,6 @@ RSpec.describe CanvasSync::Jobs::ReportStarter do
|
|
68
60
|
)
|
69
61
|
|
70
62
|
CanvasSync::Jobs::ReportStarter.perform_now(
|
71
|
-
orig_job_chain,
|
72
63
|
report_name,
|
73
64
|
report_params,
|
74
65
|
processor,
|
@@ -4,13 +4,10 @@ RSpec.describe CanvasSync::Jobs::SyncAdminsJob do
|
|
4
4
|
describe '#perform' do
|
5
5
|
let!(:account) { FactoryGirl.create(:account, canvas_id: 1) }
|
6
6
|
let(:admin_params) { open_canvas_fixture('admins') }
|
7
|
-
let(:job_chain) { { jobs: [], global_options: {}} }
|
8
7
|
|
9
8
|
it 'retrieves all admins from the Canvas API and then invokes the next job' do
|
10
|
-
expect(CanvasSync).to receive(:invoke_next).with(job_chain)
|
11
|
-
|
12
9
|
expect {
|
13
|
-
CanvasSync::Jobs::SyncAdminsJob.perform_now(
|
10
|
+
CanvasSync::Jobs::SyncAdminsJob.perform_now({})
|
14
11
|
}.to change { Admin.count }.by(admin_params.length)
|
15
12
|
end
|
16
13
|
end
|
@@ -10,7 +10,8 @@ RSpec.describe CanvasSync::Jobs::SyncAssignmentGroupsJob do
|
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
12
12
|
|
13
|
-
|
13
|
+
set_batch_context(canvas_term_id: 1)
|
14
|
+
CanvasSync::Jobs::SyncAssignmentGroupsJob.perform_now({})
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -10,7 +10,8 @@ RSpec.describe CanvasSync::Jobs::SyncAssignmentsJob do
|
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
12
12
|
|
13
|
-
|
13
|
+
set_batch_context(canvas_term_id: 1)
|
14
|
+
CanvasSync::Jobs::SyncAssignmentsJob.perform_now({})
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -22,7 +23,7 @@ RSpec.describe CanvasSync::Jobs::SyncAssignmentsJob do
|
|
22
23
|
|
23
24
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
24
25
|
|
25
|
-
CanvasSync::Jobs::SyncAssignmentsJob.perform_now({
|
26
|
+
CanvasSync::Jobs::SyncAssignmentsJob.perform_now({})
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
@@ -10,7 +10,8 @@ RSpec.describe CanvasSync::Jobs::SyncContextModuleItemsJob do
|
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
12
12
|
|
13
|
-
|
13
|
+
set_batch_context(canvas_term_id: 1)
|
14
|
+
CanvasSync::Jobs::SyncContextModuleItemsJob.perform_now({})
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -22,7 +23,7 @@ RSpec.describe CanvasSync::Jobs::SyncContextModuleItemsJob do
|
|
22
23
|
|
23
24
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
24
25
|
|
25
|
-
CanvasSync::Jobs::SyncContextModuleItemsJob.perform_now({
|
26
|
+
CanvasSync::Jobs::SyncContextModuleItemsJob.perform_now({})
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
@@ -10,7 +10,8 @@ RSpec.describe CanvasSync::Jobs::SyncContextModulesJob do
|
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
12
12
|
|
13
|
-
|
13
|
+
set_batch_context(canvas_term_id: 1)
|
14
|
+
CanvasSync::Jobs::SyncContextModulesJob.perform_now({})
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -22,7 +23,7 @@ RSpec.describe CanvasSync::Jobs::SyncContextModulesJob do
|
|
22
23
|
|
23
24
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
24
25
|
|
25
|
-
CanvasSync::Jobs::SyncContextModulesJob.perform_now({
|
26
|
+
CanvasSync::Jobs::SyncContextModulesJob.perform_now({})
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
@@ -2,59 +2,29 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do
|
4
4
|
describe '#perform' do
|
5
|
-
let(:job_chain) { {jobs: [], global_options: {}} }
|
6
|
-
|
7
5
|
context 'a term scope is specified' do
|
8
|
-
let!(:
|
9
|
-
let!(:active_term_2) { FactoryGirl.create(:term) }
|
10
|
-
let!(:inactive_term_1) { FactoryGirl.create(:term, workflow_state: 'inactive') }
|
6
|
+
let!(:term) { FactoryGirl.create(:term) }
|
11
7
|
|
12
8
|
it 'enqueues a ReportStarter for a provisioning report for the specified models for each term' do
|
13
|
-
expected_job_chain = Marshal.load(Marshal.dump(job_chain))
|
14
|
-
expected_job_chain[:global_options][:canvas_term_id] = active_term_1.canvas_id
|
15
|
-
expected_job_chain[:global_options] = hash_including(expected_job_chain[:global_options])
|
16
|
-
|
17
|
-
expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later)
|
18
|
-
.with(
|
19
|
-
expected_job_chain,
|
20
|
-
'proservices_provisioning_csv',
|
21
|
-
{
|
22
|
-
parameters: {
|
23
|
-
include_deleted: true,
|
24
|
-
'users' => true,
|
25
|
-
'courses' => true,
|
26
|
-
enrollment_term_id: active_term_1.canvas_id
|
27
|
-
}
|
28
|
-
},
|
29
|
-
CanvasSync::Processors::ProvisioningReportProcessor.to_s,
|
30
|
-
{ models: ['users', 'courses'], term_scope: 'active' }
|
31
|
-
)
|
32
|
-
|
33
|
-
expected_job_chain_2 = Marshal.load(Marshal.dump(job_chain))
|
34
|
-
expected_job_chain_2[:global_options][:canvas_term_id] = active_term_2.canvas_id
|
35
|
-
expected_job_chain_2[:global_options] = hash_including(expected_job_chain_2[:global_options])
|
36
|
-
|
37
9
|
expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later)
|
38
10
|
.with(
|
39
|
-
expected_job_chain_2,
|
40
11
|
'proservices_provisioning_csv',
|
41
12
|
{
|
42
13
|
parameters: {
|
43
14
|
include_deleted: true,
|
44
15
|
'users' => true,
|
45
16
|
'courses' => true,
|
46
|
-
enrollment_term_id:
|
17
|
+
enrollment_term_id: term.canvas_id
|
47
18
|
}
|
48
19
|
},
|
49
20
|
CanvasSync::Processors::ProvisioningReportProcessor.to_s,
|
50
21
|
{ models: ['users', 'courses'], term_scope: 'active' }
|
51
22
|
)
|
52
23
|
|
24
|
+
set_batch_context(canvas_term_id: term.canvas_id)
|
53
25
|
CanvasSync::Jobs::SyncProvisioningReportJob.perform_now(
|
54
|
-
job_chain,
|
55
26
|
{ models: ['users', 'courses'], term_scope: 'active' }
|
56
27
|
)
|
57
|
-
expect(CanvasSync::JobLog.last.fork_count).to eq 2
|
58
28
|
end
|
59
29
|
end
|
60
30
|
|
@@ -62,7 +32,6 @@ RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do
|
|
62
32
|
it 'enqueues a single ReportStarter for a provisioning report across all terms for the specified models' do
|
63
33
|
expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later)
|
64
34
|
.with(
|
65
|
-
job_chain,
|
66
35
|
'proservices_provisioning_csv',
|
67
36
|
{
|
68
37
|
parameters: {
|
@@ -76,7 +45,6 @@ RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do
|
|
76
45
|
)
|
77
46
|
|
78
47
|
CanvasSync::Jobs::SyncProvisioningReportJob.perform_now(
|
79
|
-
job_chain,
|
80
48
|
{ models: ['users', 'courses'] }
|
81
49
|
)
|
82
50
|
end
|
@@ -4,13 +4,10 @@ RSpec.describe CanvasSync::Jobs::SyncRolesJob do
|
|
4
4
|
describe '#perform' do
|
5
5
|
let!(:account) { FactoryGirl.create(:account, canvas_id: 1) }
|
6
6
|
let(:role_params) { open_canvas_fixture('roles') }
|
7
|
-
let(:job_chain) { { jobs: [], global_options: {}} }
|
8
7
|
|
9
8
|
it 'retrieves all roles from the Canvas API and then invokes the next job' do
|
10
|
-
expect(CanvasSync).to receive(:invoke_next).with(job_chain)
|
11
|
-
|
12
9
|
expect {
|
13
|
-
CanvasSync::Jobs::SyncRolesJob.perform_now(
|
10
|
+
CanvasSync::Jobs::SyncRolesJob.perform_now({})
|
14
11
|
}.to change { Role.count }.by(role_params.length)
|
15
12
|
end
|
16
13
|
end
|
@@ -2,25 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe CanvasSync::Jobs::SyncSimpleTableJob do
|
4
4
|
describe '#perform' do
|
5
|
-
let(:job_chain) { {jobs: [], global_options: {}} }
|
6
|
-
|
7
5
|
context 'Simple report' do
|
8
|
-
let!(:
|
9
|
-
let!(:inactive_term_1) { FactoryGirl.create(:term, workflow_state: 'inactive') }
|
6
|
+
let!(:term) { FactoryGirl.create(:term) }
|
10
7
|
|
11
8
|
it 'enqueues a ReportStarter for a provisioning report for the specified model for a term' do
|
12
|
-
expected_job_chain = Marshal.load(Marshal.dump(job_chain))
|
13
|
-
expected_job_chain[:global_options][:canvas_term_id] = active_term_1.canvas_id
|
14
|
-
expected_job_chain[:global_options] = hash_including(expected_job_chain[:global_options])
|
15
|
-
|
16
9
|
expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later)
|
17
10
|
.with(
|
18
|
-
expected_job_chain,
|
19
11
|
'proservices_provisioning_csv',
|
20
12
|
{
|
21
13
|
"parameters[include_deleted]" => true,
|
22
14
|
"parameters[courses]" => true,
|
23
|
-
"parameters[enrollment_term_id]" =>
|
15
|
+
"parameters[enrollment_term_id]" => term.canvas_id
|
24
16
|
},
|
25
17
|
CanvasSync::Processors::NormalProcessor.to_s,
|
26
18
|
{
|
@@ -32,13 +24,14 @@ RSpec.describe CanvasSync::Jobs::SyncSimpleTableJob do
|
|
32
24
|
params: {
|
33
25
|
"parameters[include_deleted]" => true,
|
34
26
|
"parameters[courses]" => true,
|
35
|
-
"parameters[enrollment_term_id]" =>
|
27
|
+
"parameters[enrollment_term_id]" => term.canvas_id
|
36
28
|
}
|
37
29
|
}
|
38
30
|
)
|
39
31
|
|
32
|
+
set_batch_context(canvas_term_id: term.canvas_id)
|
33
|
+
|
40
34
|
CanvasSync::Jobs::SyncSimpleTableJob.perform_now(
|
41
|
-
job_chain,
|
42
35
|
{
|
43
36
|
report_name: 'proservices_provisioning_csv',
|
44
37
|
model: 'courses',
|
@@ -10,7 +10,8 @@ RSpec.describe CanvasSync::Jobs::SyncSubmissionsJob do
|
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
12
12
|
|
13
|
-
|
13
|
+
set_batch_context(canvas_term_id: 1)
|
14
|
+
CanvasSync::Jobs::SyncSubmissionsJob.perform_now({})
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -3,13 +3,10 @@ require 'spec_helper'
|
|
3
3
|
RSpec.describe CanvasSync::Jobs::SyncTermsJob do
|
4
4
|
describe '#perform' do
|
5
5
|
let(:term_params) { open_canvas_fixture('terms')['enrollment_terms'] }
|
6
|
-
let(:job_chain) { { jobs: [], global_options: {}} }
|
7
6
|
|
8
7
|
it 'retrieves all terms from the Canvas API and then invokes the next job' do
|
9
|
-
expect(CanvasSync).to receive(:invoke_next).with(job_chain)
|
10
|
-
|
11
8
|
expect {
|
12
|
-
CanvasSync::Jobs::SyncTermsJob.perform_now(
|
9
|
+
CanvasSync::Jobs::SyncTermsJob.perform_now({})
|
13
10
|
}.to change { Term.count }.by(term_params.length)
|
14
11
|
end
|
15
12
|
end
|
@@ -20,6 +20,9 @@ class Account < ApplicationRecord
|
|
20
20
|
primary_key: :canvas_id, foreign_key: :canvas_parent_account_id
|
21
21
|
has_many :groups, primary_key: :canvas_id, foreign_key: :canvas_account_id
|
22
22
|
|
23
|
+
scope :active, -> { where.not(workflow_state: 'deleted') }
|
24
|
+
# scope :should_canvas_sync, -> { active } # Optional - uses .active if not given
|
25
|
+
|
23
26
|
api_syncable({
|
24
27
|
name: :name,
|
25
28
|
workflow_state: :workflow_state,
|