canvas_sync 0.27.12 → 0.27.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0cb609547db9a99f1706791e88585c33a02d1d23d0163550ca042fe7a6fc6c2
4
- data.tar.gz: 16685b41f9bbea87d8c3df59e26ede34d1de8d087204727d0a62af4b8ccdc1de
3
+ metadata.gz: 465e968a497bd2dc0bbba5d978bc37a42257122f74132e2f9d7a72c4ed7f9082
4
+ data.tar.gz: 113288ee3a4bea44ba48d837f917f111e8e0bb9de2f8e43c0d5e30eb78aa0361
5
5
  SHA512:
6
- metadata.gz: 7815652b4cfdf053ee6f30e8546af592bf60c4e0c21538667d3608d8dd90557f3b4543552a6ea901a0d2027073fe764f06a014afba5ab72004e50b1fc10da325
7
- data.tar.gz: 7db6393f537f9f585086166baf39f988da1f146e0cbf79ada0a7e015734f7e139757593e344940e65160add7efc8090638b1990a1e575ff772ee53c7949f00d5
6
+ metadata.gz: 2afe2d77cc726e26bdce33058d89bfd279f890dd5832c30c33575960387111f309ac15f6f2632406861cb1f3a4e34ce0ff16509612bb987f3e96974ceabc327b
7
+ data.tar.gz: 3c926ea08522792eae8fd6daaafcc343888aed77b55e943d1fca08a8ddf174d01db1fc26ebe786cd613eab18dc0d9d15221a2fe739a5a46d4dda4e626e48f498
@@ -27,12 +27,15 @@ module CanvasSync
27
27
  class << self
28
28
  def from_context
29
29
  report_batch = JobBatches::Batch.current
30
- base_context = report_batch&.parent&.context
31
30
  state = report_batch&.context
32
- return nil unless state.present?
31
+
32
+ # Only a report Batch carries :report_class. Any other Batch in the chain inherits a
33
+ # context from its parents, so check for the key itself rather than asking whether the
34
+ # context is present.
35
+ return nil if state.nil? || state[:report_class].blank?
33
36
 
34
37
  cls = state[:report_class].constantize
35
- cls.new(state[:report_options], base_context, state)
38
+ cls.new(state[:report_options], report_batch.parent&.context, state)
36
39
  end
37
40
 
38
41
  def perform_later(options)
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.27.12".freeze
2
+ VERSION = "0.27.13".freeze
3
3
  end
@@ -86,6 +86,30 @@ RSpec.describe CanvasSync::Jobs::ReportSyncTask do
86
86
  end
87
87
 
88
88
  describe ".from_context" do
89
+ # Stands in for JobBatches::ContextHash, which reads keys via #[] but routes every other Hash
90
+ # method through #flatten. Flattening loads (and locks down) the whole ancestor chain, so
91
+ # from_context has to stay on #[] - anything else costs the Batch the ability to record its
92
+ # own progress later in the job.
93
+ class FlattenTattlingContext
94
+ attr_reader :flatten_count
95
+
96
+ def initialize(hash)
97
+ @hash = hash.with_indifferent_access
98
+ @flatten_count = 0
99
+ end
100
+
101
+ def [](key)
102
+ @hash[key]
103
+ end
104
+
105
+ def flatten
106
+ @flatten_count += 1
107
+ @hash
108
+ end
109
+
110
+ delegate_missing_to :flatten
111
+ end
112
+
89
113
  it "reconstructs task from batch context" do
90
114
  stub_batch_context({ canvas_term_id: 1 })
91
115
  allow(CanvasSync::JobBatches::Batch.current).to receive(:context)
@@ -96,6 +120,38 @@ RSpec.describe CanvasSync::Jobs::ReportSyncTask do
96
120
  expect(task).to be_a(SyncSpecsTask)
97
121
  expect(task.options).to eq({ include_all: true })
98
122
  end
123
+
124
+ it "returns nil when the context belongs to a non-report Batch" do
125
+ # A Batch elsewhere in the sync chain inherits a context from its parents, so the context is
126
+ # populated - it just has no :report_class.
127
+ stub_batch_context({ canvas_term_id: 1 })
128
+ allow(CanvasSync::JobBatches::Batch.current).to receive(:context)
129
+ .and_return({ sync_batch_id: 42, account_id: 'self' }.with_indifferent_access)
130
+
131
+ expect(CanvasSync::Jobs::ReportSyncTask.from_context).to be_nil
132
+ end
133
+
134
+ it "returns nil when there is no current Batch" do
135
+ allow(CanvasSync::JobBatches::Batch).to receive(:current).and_return(nil)
136
+
137
+ expect(CanvasSync::Jobs::ReportSyncTask.from_context).to be_nil
138
+ end
139
+
140
+ it "does not flatten the context, for a report Batch or any other" do
141
+ report_context = FlattenTattlingContext.new(
142
+ report_class: 'SyncSpecsTask', report_options: { include_all: true }
143
+ )
144
+ other_context = FlattenTattlingContext.new(sync_batch_id: 42)
145
+
146
+ [report_context, other_context].each do |context|
147
+ stub_batch_context({ canvas_term_id: 1 })
148
+ allow(CanvasSync::JobBatches::Batch.current).to receive(:context).and_return(context)
149
+
150
+ CanvasSync::Jobs::ReportSyncTask.from_context
151
+
152
+ expect(context.flatten_count).to eq(0)
153
+ end
154
+ end
99
155
  end
100
156
 
101
157
  describe described_class::StarterJob do
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.12
4
+ version: 0.27.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure CustomDev
@@ -413,14 +413,14 @@ dependencies:
413
413
  requirements:
414
414
  - - "~>"
415
415
  - !ruby/object:Gem::Version
416
- version: 0.2.0
416
+ version: 0.2.1
417
417
  type: :runtime
418
418
  prerelease: false
419
419
  version_requirements: !ruby/object:Gem::Requirement
420
420
  requirements:
421
421
  - - "~>"
422
422
  - !ruby/object:Gem::Version
423
- version: 0.2.0
423
+ version: 0.2.1
424
424
  email:
425
425
  - pseng@instructure.com
426
426
  executables: []