canvas_sync 0.27.11 → 0.27.12
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 +4 -4
- data/lib/canvas_sync/jobs/report_sync_task.rb +4 -2
- data/lib/canvas_sync/jobs/sync_accounts_job.rb +2 -1
- data/lib/canvas_sync/version.rb +1 -1
- data/lib/canvas_sync.rb +1 -0
- data/spec/canvas_sync/jobs/begin_sync_chain_job_spec.rb +9 -3
- data/spec/canvas_sync/jobs/sync_accounts_job_spec.rb +41 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/fake_canvas.rb +4 -0
- data/spec/support/fixtures/canvas_responses/account.json +12 -0
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0cb609547db9a99f1706791e88585c33a02d1d23d0163550ca042fe7a6fc6c2
|
|
4
|
+
data.tar.gz: 16685b41f9bbea87d8c3df59e26ede34d1de8d087204727d0a62af4b8ccdc1de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7815652b4cfdf053ee6f30e8546af592bf60c4e0c21538667d3608d8dd90557f3b4543552a6ea901a0d2027073fe764f06a014afba5ab72004e50b1fc10da325
|
|
7
|
+
data.tar.gz: 7db6393f537f9f585086166baf39f988da1f146e0cbf79ada0a7e015734f7e139757593e344940e65160add7efc8090638b1990a1e575ff772ee53c7949f00d5
|
|
@@ -27,8 +27,10 @@ module CanvasSync
|
|
|
27
27
|
class << self
|
|
28
28
|
def from_context
|
|
29
29
|
report_batch = JobBatches::Batch.current
|
|
30
|
-
base_context = report_batch
|
|
31
|
-
state = report_batch
|
|
30
|
+
base_context = report_batch&.parent&.context
|
|
31
|
+
state = report_batch&.context
|
|
32
|
+
return nil unless state.present?
|
|
33
|
+
|
|
32
34
|
cls = state[:report_class].constantize
|
|
33
35
|
cls.new(state[:report_options], base_context, state)
|
|
34
36
|
end
|
|
@@ -10,7 +10,8 @@ module CanvasSync
|
|
|
10
10
|
# @param options [Hash]
|
|
11
11
|
def perform(options)
|
|
12
12
|
unless options[:root_account] == false
|
|
13
|
-
|
|
13
|
+
task = ReportSyncTask.from_context || nil
|
|
14
|
+
accid = options[:account_id] || task&.options&.dig(:account_id) || batch_context[:account_id] || "self"
|
|
14
15
|
acc_params = CanvasSync.get_canvas_sync_client(batch_context).account(accid)
|
|
15
16
|
update_or_create_model(Account, acc_params)
|
|
16
17
|
end
|
data/lib/canvas_sync/version.rb
CHANGED
data/lib/canvas_sync.rb
CHANGED
|
@@ -170,22 +170,28 @@ RSpec.describe CanvasSync::Jobs::BeginSyncChainJob do
|
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
context 'a "<weekday>/<skip weeks>" schedule (e.g. "sunday/2")' do
|
|
173
|
+
# should_full_sync? asks DateTime.now (the system zone) which weekday it is, so
|
|
174
|
+
# these travel to local noon. Midnight in any single zone lands on the adjacent
|
|
175
|
+
# day for someone, which flips the weekday and the assertion with it.
|
|
176
|
+
let(:sunday) { Time.local(2024, 1, 7, 12, 0, 0) }
|
|
177
|
+
let(:monday) { Time.local(2024, 1, 8, 12, 0, 0) }
|
|
178
|
+
|
|
173
179
|
it 'is true only on the matching weekday once the skip period has elapsed' do
|
|
174
|
-
Timecop.travel(
|
|
180
|
+
Timecop.travel(sunday) do
|
|
175
181
|
CanvasSync::SyncBatch.create!(status: 'completed', full_sync: true, batch_genre: 'default', started_at: 3.weeks.ago)
|
|
176
182
|
expect(job.should_full_sync?('sunday/2')).to eq(true)
|
|
177
183
|
end
|
|
178
184
|
end
|
|
179
185
|
|
|
180
186
|
it 'is false on the matching weekday if the skip period has not yet elapsed' do
|
|
181
|
-
Timecop.travel(
|
|
187
|
+
Timecop.travel(sunday) do
|
|
182
188
|
CanvasSync::SyncBatch.create!(status: 'completed', full_sync: true, batch_genre: 'default', started_at: 1.week.ago)
|
|
183
189
|
expect(job.should_full_sync?('sunday/2')).to eq(false)
|
|
184
190
|
end
|
|
185
191
|
end
|
|
186
192
|
|
|
187
193
|
it 'is false on a non-matching weekday even if the skip period has elapsed' do
|
|
188
|
-
Timecop.travel(
|
|
194
|
+
Timecop.travel(monday) do
|
|
189
195
|
CanvasSync::SyncBatch.create!(status: 'completed', full_sync: true, batch_genre: 'default', started_at: 3.weeks.ago)
|
|
190
196
|
expect(job.should_full_sync?('sunday/2')).to eq(false)
|
|
191
197
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe CanvasSync::Jobs::SyncAccountsJob do
|
|
4
|
+
describe '#perform' do
|
|
5
|
+
before do
|
|
6
|
+
allow(CanvasSync::Jobs::SyncAccountsJob::ReportTask).to receive(:perform_later)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'syncs the root account and then invokes the report task' do
|
|
10
|
+
expect {
|
|
11
|
+
described_class.perform_now({})
|
|
12
|
+
}.to change { Account.count }.by(1)
|
|
13
|
+
|
|
14
|
+
expect(a_request(:get, 'http://test.instructure.com/api/v1/accounts/self')).to have_been_made
|
|
15
|
+
expect(CanvasSync::Jobs::SyncAccountsJob::ReportTask).to have_received(:perform_later).with({})
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'uses account_id from the options when present' do
|
|
19
|
+
described_class.perform_now({ account_id: 42 })
|
|
20
|
+
|
|
21
|
+
expect(a_request(:get, 'http://test.instructure.com/api/v1/accounts/42')).to have_been_made
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'falls back to account_id from the batch context' do
|
|
25
|
+
set_batch_context(account_id: 7)
|
|
26
|
+
|
|
27
|
+
described_class.perform_now({})
|
|
28
|
+
|
|
29
|
+
expect(a_request(:get, 'http://test.instructure.com/api/v1/accounts/7')).to have_been_made
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'skips the root account sync when root_account is false' do
|
|
33
|
+
expect {
|
|
34
|
+
described_class.perform_now({ root_account: false })
|
|
35
|
+
}.not_to change { Account.count }
|
|
36
|
+
|
|
37
|
+
expect(a_request(:get, %r{/api/v1/accounts/})).not_to have_been_made
|
|
38
|
+
expect(CanvasSync::Jobs::SyncAccountsJob::ReportTask).to have_received(:perform_later)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -78,7 +78,9 @@ def open_canvas_fixture(name)
|
|
|
78
78
|
JSON.parse(data)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
# Mirrors the host-app hook CanvasSync.get_canvas_sync_client calls. It passes an
|
|
82
|
+
# account ID when one is configured, so this has to accept an optional argument.
|
|
83
|
+
def canvas_sync_client(account_id = nil)
|
|
82
84
|
Bearcat::Client.new(token: 'cool-token', prefix: 'http://test.instructure.com')
|
|
83
85
|
end
|
|
84
86
|
|
data/spec/support/fake_canvas.rb
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": 1,
|
|
3
|
+
"name": "Test Root Account",
|
|
4
|
+
"workflow_state": "active",
|
|
5
|
+
"parent_account_id": null,
|
|
6
|
+
"root_account_id": null,
|
|
7
|
+
"uuid": "abcDEF1234567890abcDEF1234567890abcDEF12",
|
|
8
|
+
"default_storage_quota_mb": 500,
|
|
9
|
+
"default_user_storage_quota_mb": 50,
|
|
10
|
+
"default_group_storage_quota_mb": 50,
|
|
11
|
+
"default_time_zone": "America/Denver"
|
|
12
|
+
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: canvas_sync
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.27.
|
|
4
|
+
version: 0.27.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Instructure CustomDev
|
|
@@ -577,6 +577,7 @@ files:
|
|
|
577
577
|
- spec/canvas_sync/jobs/job_spec.rb
|
|
578
578
|
- spec/canvas_sync/jobs/report_starter_spec.rb
|
|
579
579
|
- spec/canvas_sync/jobs/report_sync_task_spec.rb
|
|
580
|
+
- spec/canvas_sync/jobs/sync_accounts_job_spec.rb
|
|
580
581
|
- spec/canvas_sync/jobs/sync_admins_job_spec.rb
|
|
581
582
|
- spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb
|
|
582
583
|
- spec/canvas_sync/jobs/sync_roles_job_spec.rb
|
|
@@ -711,6 +712,7 @@ files:
|
|
|
711
712
|
- spec/internal/db/schema.rb
|
|
712
713
|
- spec/spec_helper.rb
|
|
713
714
|
- spec/support/fake_canvas.rb
|
|
715
|
+
- spec/support/fixtures/canvas_responses/account.json
|
|
714
716
|
- spec/support/fixtures/canvas_responses/admins.json
|
|
715
717
|
- spec/support/fixtures/canvas_responses/module.json
|
|
716
718
|
- spec/support/fixtures/canvas_responses/module_item.json
|
|
@@ -776,6 +778,7 @@ test_files:
|
|
|
776
778
|
- spec/canvas_sync/jobs/job_spec.rb
|
|
777
779
|
- spec/canvas_sync/jobs/report_starter_spec.rb
|
|
778
780
|
- spec/canvas_sync/jobs/report_sync_task_spec.rb
|
|
781
|
+
- spec/canvas_sync/jobs/sync_accounts_job_spec.rb
|
|
779
782
|
- spec/canvas_sync/jobs/sync_admins_job_spec.rb
|
|
780
783
|
- spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb
|
|
781
784
|
- spec/canvas_sync/jobs/sync_roles_job_spec.rb
|
|
@@ -910,6 +913,7 @@ test_files:
|
|
|
910
913
|
- spec/internal/db/schema.rb
|
|
911
914
|
- spec/spec_helper.rb
|
|
912
915
|
- spec/support/fake_canvas.rb
|
|
916
|
+
- spec/support/fixtures/canvas_responses/account.json
|
|
913
917
|
- spec/support/fixtures/canvas_responses/admins.json
|
|
914
918
|
- spec/support/fixtures/canvas_responses/module.json
|
|
915
919
|
- spec/support/fixtures/canvas_responses/module_item.json
|