canvas_sync 0.10.3 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +57 -2
- data/db/migrate/20190916154829_add_fork_count_to_canvas_sync_job_logs.rb +13 -0
- data/lib/canvas_sync.rb +43 -8
- data/lib/canvas_sync/api_syncable.rb +8 -0
- data/lib/canvas_sync/generators/templates/migrations/create_admins.rb +7 -4
- data/lib/canvas_sync/generators/templates/migrations/create_roles.rb +3 -4
- data/lib/canvas_sync/generators/templates/models/account.rb +2 -0
- data/lib/canvas_sync/generators/templates/models/admin.rb +4 -5
- data/lib/canvas_sync/generators/templates/models/role.rb +0 -4
- data/lib/canvas_sync/generators/templates/models/term.rb +0 -2
- data/lib/canvas_sync/importers/bulk_importer.rb +7 -4
- data/lib/canvas_sync/job.rb +24 -1
- data/lib/canvas_sync/jobs/fork_gather.rb +59 -0
- data/lib/canvas_sync/jobs/report_starter.rb +12 -1
- data/lib/canvas_sync/jobs/sync_admins_job.rb +9 -5
- data/lib/canvas_sync/jobs/sync_assignment_groups_job.rb +2 -8
- data/lib/canvas_sync/jobs/sync_assignments_job.rb +2 -8
- data/lib/canvas_sync/jobs/sync_context_module_items_job.rb +2 -8
- data/lib/canvas_sync/jobs/sync_context_modules_job.rb +2 -8
- data/lib/canvas_sync/jobs/sync_provisioning_report_job.rb +23 -11
- data/lib/canvas_sync/jobs/sync_roles_job.rb +8 -5
- data/lib/canvas_sync/jobs/sync_simple_table_job.rb +17 -7
- data/lib/canvas_sync/jobs/sync_submissions_job.rb +1 -5
- data/lib/canvas_sync/jobs/sync_terms_job.rb +8 -2
- data/lib/canvas_sync/jobs/sync_users_job.rb +5 -7
- data/lib/canvas_sync/processors/assignment_groups_processor.rb +3 -2
- data/lib/canvas_sync/processors/assignments_processor.rb +3 -2
- data/lib/canvas_sync/processors/context_module_items_processor.rb +3 -2
- data/lib/canvas_sync/processors/context_modules_processor.rb +3 -2
- data/lib/canvas_sync/processors/normal_processor.rb +2 -1
- data/lib/canvas_sync/processors/provisioning_report_processor.rb +7 -2
- data/lib/canvas_sync/processors/submissions_processor.rb +3 -2
- data/lib/canvas_sync/version.rb +1 -1
- data/spec/canvas_sync/canvas_sync_spec.rb +17 -0
- data/spec/canvas_sync/jobs/fork_gather_spec.rb +73 -0
- data/spec/canvas_sync/jobs/job_spec.rb +39 -5
- data/spec/canvas_sync/jobs/sync_admins_job_spec.rb +2 -1
- data/spec/canvas_sync/jobs/sync_assignment_groups_job_spec.rb +1 -1
- data/spec/canvas_sync/jobs/sync_assignments_job_spec.rb +2 -2
- data/spec/canvas_sync/jobs/sync_context_module_items_job_spec.rb +2 -2
- data/spec/canvas_sync/jobs/sync_context_modules_job_spec.rb +2 -2
- data/spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb +20 -11
- data/spec/canvas_sync/jobs/sync_roles_job_spec.rb +2 -1
- data/spec/canvas_sync/jobs/sync_simple_table_job_spec.rb +1 -0
- data/spec/canvas_sync/jobs/sync_submissions_job_spec.rb +1 -1
- data/spec/canvas_sync/jobs/sync_users_job_spec.rb +1 -1
- data/spec/canvas_sync/models/admins_spec.rb +3 -5
- data/spec/canvas_sync/models/roles_spec.rb +5 -5
- data/spec/canvas_sync/models/term_spec.rb +3 -3
- data/spec/dummy/app/models/account.rb +2 -0
- data/spec/dummy/app/models/admin.rb +4 -5
- data/spec/dummy/app/models/role.rb +0 -4
- data/spec/dummy/app/models/term.rb +0 -2
- data/spec/dummy/db/migrate/{20190702203628_create_roles.rb → 20190927204545_create_roles.rb} +3 -4
- data/spec/dummy/db/migrate/{20190702203629_create_admins.rb → 20190927204546_create_admins.rb} +7 -4
- data/spec/dummy/db/schema.rb +12 -9
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1248 -0
- data/spec/dummy/log/test.log +43258 -0
- data/spec/factories/admin_factory.rb +0 -1
- data/spec/support/fake_canvas.rb +2 -2
- data/spec/support/fixtures/canvas_responses/roles.json +6 -0
- data/spec/support/fixtures/reports/provisioning_csv_unzipped/courses.csv +3 -0
- data/spec/support/fixtures/reports/provisioning_csv_unzipped/users.csv +4 -0
- metadata +25 -12
@@ -8,15 +8,16 @@ module CanvasSync
|
|
8
8
|
# @param options [Hash]
|
9
9
|
class SubmissionsProcessor < ReportProcessor
|
10
10
|
def self.process(report_file_path, _options, report_id)
|
11
|
-
new(report_file_path)
|
11
|
+
new(report_file_path, _options)
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(report_file_path)
|
14
|
+
def initialize(report_file_path, options)
|
15
15
|
CanvasSync::Importers::BulkImporter.import(
|
16
16
|
report_file_path,
|
17
17
|
mapping[:submissions][:report_columns],
|
18
18
|
Submission,
|
19
19
|
mapping[:submissions][:conflict_target].to_sym,
|
20
|
+
import_args: options
|
20
21
|
)
|
21
22
|
end
|
22
23
|
end
|
data/lib/canvas_sync/version.rb
CHANGED
@@ -24,6 +24,23 @@ RSpec.describe CanvasSync do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '.default_provisioning_report_chain' do
|
27
|
+
it 'splits an options: Hash into options for separate models' do
|
28
|
+
chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], :active, options: {
|
29
|
+
terms: { a: 1 },
|
30
|
+
users: { b: 2 },
|
31
|
+
provisioning: { c: 3 },
|
32
|
+
global: { d: 4 },
|
33
|
+
})
|
34
|
+
expect(chain).to eq({
|
35
|
+
jobs: [
|
36
|
+
{ job: CanvasSync::Jobs::SyncTermsJob.to_s, options: { a: 1 } },
|
37
|
+
{ job: CanvasSync::Jobs::SyncUsersJob.to_s, options: { b: 2 } },
|
38
|
+
{ job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'], c: 3 } }
|
39
|
+
],
|
40
|
+
global_options: { legacy_support: false, d: 4 }
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
27
44
|
context 'we are syncing users with a term scope' do
|
28
45
|
it 'syncs the users in a separate job that runs first' do
|
29
46
|
chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], :active)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe CanvasSync::Jobs::ForkGather do
|
4
|
+
describe '#perform' do
|
5
|
+
let!(:job_log) { CanvasSync::JobLog.create!(job_id: 'BLAH', fork_count: 3) }
|
6
|
+
let(:job_chain) { {jobs: [], global_options: { fork_path: ['BLAH'] }} }
|
7
|
+
|
8
|
+
it 'decrements fork_count' do
|
9
|
+
CanvasSync::Jobs::ForkGather.perform_now(job_chain, {})
|
10
|
+
expect(job_log.reload.fork_count).to eq 2
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does not continue chain if fork_count > 0' do
|
14
|
+
expect(CanvasSync).not_to receive(:invoke_next)
|
15
|
+
CanvasSync::Jobs::ForkGather.perform_now(job_chain, {})
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'continues the chain if fork_count <= 0' do
|
19
|
+
job_log.update!(fork_count: 1)
|
20
|
+
expect(CanvasSync).to receive(:invoke_next)
|
21
|
+
CanvasSync::Jobs::ForkGather.perform_now(job_chain, {})
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'continues if no fork_path is specified' do
|
25
|
+
job_chain[:global_options].delete(:fork_path)
|
26
|
+
expect(CanvasSync).to receive(:invoke_next)
|
27
|
+
CanvasSync::Jobs::ForkGather.perform_now(job_chain, {})
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'pops the most-recent fork_path enrty' do
|
31
|
+
job_log.update!(fork_count: 1)
|
32
|
+
expect(CanvasSync).to receive(:invoke_next) do |*args|
|
33
|
+
expect(args[0][:global_options][:fork_path]).to eq []
|
34
|
+
end
|
35
|
+
CanvasSync::Jobs::ForkGather.perform_now(job_chain, {})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'handle_branch_error' do
|
40
|
+
let(:error) { StandardError.new }
|
41
|
+
|
42
|
+
let(:job_chain) {
|
43
|
+
{
|
44
|
+
jobs: [
|
45
|
+
{ job: 'CanvasSync::Jobs::ReportChecker' },
|
46
|
+
{ job: 'CanvasSync::Jobs::ReportChecker' },
|
47
|
+
{ job: 'CanvasSync::Jobs::ForkGather' },
|
48
|
+
{ job: 'CanvasSync::Jobs::ReportChecker' },
|
49
|
+
],
|
50
|
+
global_options: {
|
51
|
+
fork_path: ['BLAH'],
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
it 'skips to and performs the next ForkGatherJob' do
|
57
|
+
expect(CanvasSync).to receive(:invoke_next) do |*args|
|
58
|
+
expect(args[0][:jobs][0][:job]).to eq 'CanvasSync::Jobs::ForkGather'
|
59
|
+
end
|
60
|
+
expect(CanvasSync::Jobs::ForkGather.handle_branch_error(error, job_chain: job_chain)).to be true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'does nothing if no ForkGather is in the chain' do
|
64
|
+
job_chain[:jobs].delete_at(2)
|
65
|
+
expect(CanvasSync::Jobs::ForkGather.handle_branch_error(error, job_chain: job_chain)).to be nil
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'does nothing if no fork_path is present' do
|
69
|
+
job_chain[:global_options][:fork_path] = []
|
70
|
+
expect(CanvasSync::Jobs::ForkGather.handle_branch_error(error, job_chain: job_chain)).to be nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -1,40 +1,74 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class GoodJob < CanvasSync::Job
|
4
|
-
def perform(argument)
|
4
|
+
def perform(job_chain, 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(argument)
|
11
|
+
def perform(job_chain, argument)
|
12
12
|
raise EvilError
|
13
13
|
end
|
14
|
+
|
15
|
+
def self.evil_catcher(e, *opts)
|
16
|
+
raise EvilError
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.good_catcher(e, *opts)
|
20
|
+
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
RSpec.describe CanvasSync::Job do
|
17
25
|
describe '#perform' do
|
18
26
|
it 'creates a CanvasSync::JobLog and logs relevant data on it' do
|
19
27
|
expect {
|
20
|
-
GoodJob.perform_now("argument")
|
28
|
+
GoodJob.perform_now({}, "argument")
|
21
29
|
}.to change { CanvasSync::JobLog.count }.by(1)
|
22
30
|
|
23
31
|
job_log = CanvasSync::JobLog.last
|
24
32
|
expect(job_log.started_at).to_not be_nil
|
25
33
|
expect(job_log.job_class).to eq(GoodJob.to_s)
|
26
|
-
expect(job_log.job_arguments).to eq(["argument"])
|
34
|
+
expect(job_log.job_arguments).to eq([{}, "argument"])
|
27
35
|
expect(job_log.completed_at).to_not be_nil
|
28
36
|
end
|
29
37
|
|
30
38
|
it 'logs exceptions on the CanvasSync::JobLog and then re-raises' do
|
31
39
|
expect {
|
32
|
-
BadJob.perform_now("argument")
|
40
|
+
BadJob.perform_now({}, "argument")
|
33
41
|
}.to raise_exception(StandardError)
|
34
42
|
|
35
43
|
job_log = CanvasSync::JobLog.last
|
36
44
|
expect(job_log.exception).to eq("EvilError: EvilError")
|
37
45
|
expect(job_log.backtrace).to_not be_nil
|
38
46
|
end
|
47
|
+
|
48
|
+
it 'invokes an error handler' do
|
49
|
+
expect(BadJob).to receive(:good_catcher).once
|
50
|
+
expect {
|
51
|
+
BadJob.perform_now({
|
52
|
+
jobs: [],
|
53
|
+
global_options: {
|
54
|
+
on_failure: 'BadJob.good_catcher'
|
55
|
+
}
|
56
|
+
})
|
57
|
+
}.to raise_exception(StandardError)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'logs a failing error handler' do
|
61
|
+
expect(BadJob).to receive(:bad_catcher).once.and_call_original
|
62
|
+
expect {
|
63
|
+
BadJob.perform_now({
|
64
|
+
jobs: [],
|
65
|
+
global_options: {
|
66
|
+
on_failure: 'BadJob.bad_catcher'
|
67
|
+
}
|
68
|
+
})
|
69
|
+
}.to raise_exception(StandardError)
|
70
|
+
job_log = CanvasSync::JobLog.last
|
71
|
+
expect(job_log.backtrace).to include "Error Occurred while handling an Error"
|
72
|
+
end
|
39
73
|
end
|
40
74
|
end
|
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe CanvasSync::Jobs::SyncAdminsJob do
|
4
4
|
describe '#perform' do
|
5
|
+
let!(:account) { FactoryGirl.create(:account, canvas_id: 1) }
|
5
6
|
let(:admin_params) { open_canvas_fixture('admins') }
|
6
7
|
let(:job_chain) { { jobs: [], global_options: {}} }
|
7
8
|
|
8
|
-
it 'retrieves all
|
9
|
+
it 'retrieves all admins from the Canvas API and then invokes the next job' do
|
9
10
|
expect(CanvasSync).to receive(:invoke_next).with(job_chain)
|
10
11
|
|
11
12
|
expect {
|
@@ -5,7 +5,7 @@ RSpec.describe CanvasSync::Jobs::SyncAssignmentGroupsJob do
|
|
5
5
|
context "a term id is in the global_options" do
|
6
6
|
it "enqueues a ReportStarter for the proserv_assignment_group_export_csv for the given term" do
|
7
7
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
8
|
-
.with("self", "proserv_assignment_group_export_csv",
|
8
|
+
.with("self", "proserv_assignment_group_export_csv", { parameters: { enrollment_term_id: 1 } })
|
9
9
|
.and_return("id" => 1)
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -5,7 +5,7 @@ RSpec.describe CanvasSync::Jobs::SyncAssignmentsJob do
|
|
5
5
|
context "a term id is in the global_options" do
|
6
6
|
it "enqueues a ReportStarter for the proserv_assignment_export_csv for the given term" do
|
7
7
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
8
|
-
.with("self", "proserv_assignment_export_csv",
|
8
|
+
.with("self", "proserv_assignment_export_csv", { parameters: { enrollment_term_id: 1 } })
|
9
9
|
.and_return("id" => 1)
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -17,7 +17,7 @@ RSpec.describe CanvasSync::Jobs::SyncAssignmentsJob do
|
|
17
17
|
context "no term id is specified" do
|
18
18
|
it "enqueues a ReportStarter for the proserv_assignment_export_csv for all terms" do
|
19
19
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
20
|
-
.with("self", "proserv_assignment_export_csv", {})
|
20
|
+
.with("self", "proserv_assignment_export_csv", { parameters: {} })
|
21
21
|
.and_return("id" => 1)
|
22
22
|
|
23
23
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -5,7 +5,7 @@ RSpec.describe CanvasSync::Jobs::SyncContextModuleItemsJob do
|
|
5
5
|
context "a term id is in the global_options" do
|
6
6
|
it "enqueues a ReportStarter for the proserv_context_module_items_csv for the given term" do
|
7
7
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
8
|
-
.with("self", "proserv_context_module_items_csv",
|
8
|
+
.with("self", "proserv_context_module_items_csv", { parameters: { enrollment_term_id: 1 } })
|
9
9
|
.and_return("id" => 1)
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -17,7 +17,7 @@ RSpec.describe CanvasSync::Jobs::SyncContextModuleItemsJob do
|
|
17
17
|
context "no term id is specified" do
|
18
18
|
it "enqueues a ReportStarter for the proserv_context_module_items_csv for all terms" do
|
19
19
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
20
|
-
.with("self", "proserv_context_module_items_csv", {})
|
20
|
+
.with("self", "proserv_context_module_items_csv", { parameters: { } })
|
21
21
|
.and_return("id" => 1)
|
22
22
|
|
23
23
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -5,7 +5,7 @@ RSpec.describe CanvasSync::Jobs::SyncContextModulesJob do
|
|
5
5
|
context "a term id is in the global_options" do
|
6
6
|
it "enqueues a ReportStarter for the proserv_context_modules_csv for the given term" do
|
7
7
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
8
|
-
.with("self", "proserv_context_modules_csv",
|
8
|
+
.with("self", "proserv_context_modules_csv", { parameters: { enrollment_term_id: 1 } })
|
9
9
|
.and_return("id" => 1)
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -17,7 +17,7 @@ RSpec.describe CanvasSync::Jobs::SyncContextModulesJob do
|
|
17
17
|
context "no term id is specified" do
|
18
18
|
it "enqueues a ReportStarter for the proserv_context_modules_csv for all terms" do
|
19
19
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
20
|
-
.with("self", "proserv_context_modules_csv", {})
|
20
|
+
.with("self", "proserv_context_modules_csv", { parameters: { } })
|
21
21
|
.and_return("id" => 1)
|
22
22
|
|
23
23
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -12,16 +12,19 @@ RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do
|
|
12
12
|
it 'enqueues a ReportStarter for a provisioning report for the specified models for each term' do
|
13
13
|
expected_job_chain = Marshal.load(Marshal.dump(job_chain))
|
14
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])
|
15
16
|
|
16
17
|
expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later)
|
17
18
|
.with(
|
18
19
|
expected_job_chain,
|
19
20
|
'proservices_provisioning_csv',
|
20
21
|
{
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
parameters: {
|
23
|
+
include_deleted: true,
|
24
|
+
'users' => true,
|
25
|
+
'courses' => true,
|
26
|
+
enrollment_term_id: active_term_1.canvas_id
|
27
|
+
}
|
25
28
|
},
|
26
29
|
CanvasSync::Processors::ProvisioningReportProcessor.to_s,
|
27
30
|
{ models: ['users', 'courses'], term_scope: 'active' }
|
@@ -29,16 +32,19 @@ RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do
|
|
29
32
|
|
30
33
|
expected_job_chain_2 = Marshal.load(Marshal.dump(job_chain))
|
31
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])
|
32
36
|
|
33
37
|
expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later)
|
34
38
|
.with(
|
35
39
|
expected_job_chain_2,
|
36
40
|
'proservices_provisioning_csv',
|
37
41
|
{
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
parameters: {
|
43
|
+
include_deleted: true,
|
44
|
+
'users' => true,
|
45
|
+
'courses' => true,
|
46
|
+
enrollment_term_id: active_term_2.canvas_id
|
47
|
+
}
|
42
48
|
},
|
43
49
|
CanvasSync::Processors::ProvisioningReportProcessor.to_s,
|
44
50
|
{ models: ['users', 'courses'], term_scope: 'active' }
|
@@ -48,6 +54,7 @@ RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do
|
|
48
54
|
job_chain,
|
49
55
|
{ models: ['users', 'courses'], term_scope: 'active' }
|
50
56
|
)
|
57
|
+
expect(CanvasSync::JobLog.last.fork_count).to eq 2
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
@@ -58,9 +65,11 @@ RSpec.describe CanvasSync::Jobs::SyncProvisioningReportJob do
|
|
58
65
|
job_chain,
|
59
66
|
'proservices_provisioning_csv',
|
60
67
|
{
|
61
|
-
|
62
|
-
|
63
|
-
|
68
|
+
parameters: {
|
69
|
+
include_deleted: true,
|
70
|
+
'users' => true,
|
71
|
+
'courses' => true,
|
72
|
+
}
|
64
73
|
},
|
65
74
|
CanvasSync::Processors::ProvisioningReportProcessor.to_s,
|
66
75
|
{ models: ['users', 'courses'] }
|
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe CanvasSync::Jobs::SyncRolesJob do
|
4
4
|
describe '#perform' do
|
5
|
+
let!(:account) { FactoryGirl.create(:account, canvas_id: 1) }
|
5
6
|
let(:role_params) { open_canvas_fixture('roles') }
|
6
7
|
let(:job_chain) { { jobs: [], global_options: {}} }
|
7
8
|
|
8
|
-
it 'retrieves all
|
9
|
+
it 'retrieves all roles from the Canvas API and then invokes the next job' do
|
9
10
|
expect(CanvasSync).to receive(:invoke_next).with(job_chain)
|
10
11
|
|
11
12
|
expect {
|
@@ -11,6 +11,7 @@ RSpec.describe CanvasSync::Jobs::SyncSimpleTableJob do
|
|
11
11
|
it 'enqueues a ReportStarter for a provisioning report for the specified model for a term' do
|
12
12
|
expected_job_chain = Marshal.load(Marshal.dump(job_chain))
|
13
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])
|
14
15
|
|
15
16
|
expect(CanvasSync::Jobs::ReportStarter).to receive(:perform_later)
|
16
17
|
.with(
|
@@ -5,7 +5,7 @@ RSpec.describe CanvasSync::Jobs::SyncSubmissionsJob do
|
|
5
5
|
context "a term id is in the global_options" do
|
6
6
|
it "enqueues a ReportStarter for the proserv_student_submissions_csv for the given term" do
|
7
7
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
8
|
-
.with("self", "proserv_student_submissions_csv",
|
8
|
+
.with("self", "proserv_student_submissions_csv", { parameters: { enrollment_term_id: 1, include_all: nil } })
|
9
9
|
.and_return("id" => 1)
|
10
10
|
|
11
11
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -4,7 +4,7 @@ RSpec.describe CanvasSync::Jobs::SyncUsersJob do
|
|
4
4
|
describe '#perform' do
|
5
5
|
it 'enqueues a ReportStarter for a provisioning report across all terms with just users' do
|
6
6
|
expect_any_instance_of(Bearcat::Client).to receive(:start_report)
|
7
|
-
.with('self', 'proservices_provisioning_csv',
|
7
|
+
.with('self', 'proservices_provisioning_csv', { parameters: { users: true, include_deleted: true } })
|
8
8
|
.and_return({ 'id' => 1 })
|
9
9
|
|
10
10
|
expect(CanvasSync::Jobs::ReportChecker).to receive(:set).and_call_original
|
@@ -8,19 +8,18 @@ RSpec.describe Admin, type: :model do
|
|
8
8
|
it { should validate_uniqueness_of(:canvas_id) }
|
9
9
|
end
|
10
10
|
|
11
|
-
describe '.
|
11
|
+
describe '.create_or_update_from_api_params' do
|
12
12
|
let(:admin_params) { open_canvas_fixture('admins')[0] }
|
13
13
|
|
14
14
|
context 'the admin does not already exist' do
|
15
15
|
it 'creates it' do
|
16
16
|
expect {
|
17
|
-
Admin.
|
17
|
+
Admin.create_or_update_from_api_params(admin_params)
|
18
18
|
}.to change { Admin.count }.by(1)
|
19
19
|
|
20
20
|
admin = Admin.last
|
21
21
|
expect(admin.role_name).to eq(admin_params['role'])
|
22
22
|
expect(admin.canvas_role_id).to eq(admin_params['role_id'])
|
23
|
-
expect(admin.user_data).to eq(admin_params['user'])
|
24
23
|
expect(admin.canvas_user_id).to eq(admin_params['user']['id'])
|
25
24
|
expect(admin.workflow_state).to eq(admin_params['workflow_state'])
|
26
25
|
end
|
@@ -31,13 +30,12 @@ RSpec.describe Admin, type: :model do
|
|
31
30
|
|
32
31
|
it 'updates it' do
|
33
32
|
expect {
|
34
|
-
Admin.
|
33
|
+
Admin.create_or_update_from_api_params(admin_params)
|
35
34
|
}.to_not change { Admin.count }
|
36
35
|
|
37
36
|
existing_admin.reload
|
38
37
|
expect(existing_admin.role_name).to eq(admin_params['role'])
|
39
38
|
expect(existing_admin.canvas_role_id).to eq(admin_params['role_id'])
|
40
|
-
expect(existing_admin.user_data).to eq(admin_params['user'])
|
41
39
|
expect(existing_admin.canvas_user_id).to eq(admin_params['user']['id'])
|
42
40
|
expect(existing_admin.workflow_state).to eq(admin_params['workflow_state'])
|
43
41
|
end
|
@@ -8,19 +8,19 @@ RSpec.describe Role, type: :model do
|
|
8
8
|
it { should validate_uniqueness_of(:canvas_id) }
|
9
9
|
end
|
10
10
|
|
11
|
-
describe '.
|
11
|
+
describe '.create_or_update_from_api_params' do
|
12
12
|
let(:role_params) { open_canvas_fixture('roles')[0] }
|
13
13
|
|
14
14
|
context 'the role does not already exist' do
|
15
15
|
it 'creates it' do
|
16
16
|
expect {
|
17
|
-
Role.
|
17
|
+
Role.create_or_update_from_api_params(role_params)
|
18
18
|
}.to change { Role.count }.by(1)
|
19
19
|
|
20
20
|
role = Role.last
|
21
21
|
expect(role.label).to eq(role_params['label'])
|
22
22
|
expect(role.base_role_type).to eq(role_params['base_role_type'])
|
23
|
-
expect(role.
|
23
|
+
expect(role.canvas_account_id).to eq(role_params['account']['id'])
|
24
24
|
expect(role.permissions).to eq(role_params['permissions'])
|
25
25
|
expect(role.workflow_state).to eq(role_params['workflow_state'])
|
26
26
|
end
|
@@ -31,13 +31,13 @@ RSpec.describe Role, type: :model do
|
|
31
31
|
|
32
32
|
it 'updates it' do
|
33
33
|
expect {
|
34
|
-
Role.
|
34
|
+
Role.create_or_update_from_api_params(role_params)
|
35
35
|
}.to_not change { Role.count }
|
36
36
|
|
37
37
|
existing_role.reload
|
38
38
|
expect(existing_role.label).to eq(role_params['label'])
|
39
39
|
expect(existing_role.base_role_type).to eq(role_params['base_role_type'])
|
40
|
-
expect(existing_role.
|
40
|
+
expect(existing_role.canvas_account_id).to eq(role_params['account']['id'])
|
41
41
|
expect(existing_role.permissions).to eq(role_params['permissions'])
|
42
42
|
expect(existing_role.workflow_state).to eq(role_params['workflow_state'])
|
43
43
|
end
|