workarea-core 3.4.26 → 3.4.27

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: 565180173a33822af9ccf9869c938b7a279aa4af98d302d5eb294ae92a64ddcd
4
- data.tar.gz: 7e8a3f3affcb68255b2015abbc0215b07e074d4678f4ac5e949fd790f78a8497
3
+ metadata.gz: 4b85629d6e742d6d704d618e8467136a4d4b8fbb8bf6e5c9fba3a4fcd5b29f3c
4
+ data.tar.gz: 50316244efeff6bc792599bd4001e78e0a34778ea72f2b4360ff2b34e55b5dfb
5
5
  SHA512:
6
- metadata.gz: 233b6a7ea863877f716e809c348c921155fbf868db0a462bbcc57fe540aebe0008f44dc1a58d9fface1d04deb5bc0450938c8f53941a393246e5b9fffc3373a7
7
- data.tar.gz: db0b7774e57ef6c9f59e3c171c998a53400fc316500fd246ab1aadffc604bb473292edcc3371b7a06a42fa087a1bd5f0fddd50b8c974e50f55b7a48903116582
6
+ metadata.gz: 1384ce4d2f5d8e18ad3ffeec708f593ae86b871b2a92d84fab9fc3b758f8b7efe7cb99322730f432359eb1b11532a2ae7a38bb7230bc81faa16b1bc4fc55a43b
7
+ data.tar.gz: 63083fc48278f299668d9541ddd342689f14116a8158a3adf0d73644b8f23e9fdb091911cff97f59cd6b7f5009083e7c22ef65b5fc7d5da6bfd5e09c431a7079
@@ -10,18 +10,17 @@ module Workarea
10
10
  redis_key = "cors_#{url.optionize}"
11
11
  return if Workarea.redis.get(redis_key) == 'true'
12
12
 
13
- Workarea.s3.put_bucket_cors(
14
- Configuration::S3.bucket,
15
- 'CORSConfiguration' => [
16
- {
17
- 'ID' => "direct_upload_#{url}",
18
- 'AllowedMethod' => 'PUT',
19
- 'AllowedOrigin' => url,
20
- 'AllowedHeader' => '*'
21
- }
22
- ]
23
- )
24
-
13
+ response = Workarea.s3.get_bucket_cors(Configuration::S3.bucket)
14
+ cors = response.data[:body]
15
+ cors['CORSConfiguration'] << {
16
+ 'ID' => "direct_upload_#{url}",
17
+ 'AllowedMethod' => 'PUT',
18
+ 'AllowedOrigin' => url,
19
+ 'AllowedHeader' => '*'
20
+ }
21
+ cors['CORSConfiguration'].uniq!
22
+
23
+ Workarea.s3.put_bucket_cors(Configuration::S3.bucket, cors)
25
24
  Workarea.redis.set(redis_key, 'true')
26
25
  end
27
26
 
@@ -7,6 +7,54 @@ module Sidekiq
7
7
  class InvalidConfiguration < RuntimeError; end
8
8
 
9
9
  class << self
10
+ # The list of workers that perform Sidekiq callbacks. Used for checking
11
+ # whether one of them need to be fired off after a callback happens.
12
+ #
13
+ # @private
14
+ # @return [Array<Class>]
15
+ #
16
+ def workers
17
+ caching_classes? ? workers_list : workers_list.map(&:constantize)
18
+ end
19
+
20
+ # Add a {Class} to the list of workers to check when running callbacks.
21
+ #
22
+ # @private
23
+ # @param [Class] worker
24
+ #
25
+ def add_worker(klass)
26
+ if caching_classes?
27
+ workers_list << klass
28
+ elsif !workers_list.include?(klass.name)
29
+ workers_list << klass.name
30
+ end
31
+ end
32
+
33
+ # Whether Rails is caching classes, which matters when checking workers to
34
+ # run by comparing the worker's configuration with the model running the
35
+ # callback.
36
+ #
37
+ # When we aren't caching classes, we need to use the fully qualified
38
+ # constant name to decide since the classes could have been reloaded due
39
+ # to code changes.
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def caching_classes?
44
+ ::Rails.application.config.cache_classes
45
+ end
46
+
47
+ # Convenience reference to the tracked list of workers in the Rails config
48
+ #
49
+ # @private
50
+ # @return [Array<String,Class>]
51
+ #
52
+ def workers_list
53
+ config = ::Rails.application.config
54
+ config.sidekiq_callbacks_workers = [] unless config.respond_to?(:sidekiq_callbacks_workers)
55
+ config.sidekiq_callbacks_workers
56
+ end
57
+
10
58
  # Permanently or temporarily enable callback workers. If
11
59
  # no workers are given, it will enable all callback
12
60
  # workers during the execution of the block or globally if no
@@ -148,7 +196,7 @@ module Sidekiq
148
196
  # finds a problem.
149
197
  #
150
198
  def assert_valid_config!
151
- Sidekiq::CallbacksWorker.workers.each do |worker|
199
+ Sidekiq::Callbacks.workers.each do |worker|
152
200
  if (worker.enqueue_on.values.flatten & [:find, 'find']).any?
153
201
  raise(
154
202
  InvalidConfiguration,
@@ -161,7 +209,7 @@ module Sidekiq
161
209
  private
162
210
 
163
211
  def set_workers(workers, action)
164
- workers = Sidekiq::CallbacksWorker.workers if workers.blank?
212
+ workers = Sidekiq::Callbacks.workers if workers.blank?
165
213
 
166
214
  if !block_given?
167
215
  workers.each(&action)
@@ -197,7 +245,7 @@ module Sidekiq
197
245
  private
198
246
 
199
247
  def _enqueue_callback_workers(kind)
200
- Sidekiq::CallbacksWorker.workers.select(&:enabled?).each do |worker|
248
+ Sidekiq::Callbacks.workers.select(&:enabled?).each do |worker|
201
249
  worker.callbacks.each do |klass, callbacks|
202
250
  if _perform_callback_worker?(klass, callbacks, kind, worker)
203
251
  args = worker.find_callback_args(self)
@@ -219,7 +267,7 @@ module Sidekiq
219
267
  end
220
268
 
221
269
  def _is_a_callback_type_match?(model_class)
222
- return is_a?(model_class) if ::Rails.application.config.cache_classes
270
+ return is_a?(model_class) if Sidekiq::Callbacks.caching_classes?
223
271
 
224
272
  # This is a funny way of doing the same check as `is_a?`.
225
273
  #
@@ -4,15 +4,17 @@ module Sidekiq
4
4
  module CallbacksWorker
5
5
  extend ActiveSupport::Concern
6
6
 
7
- mattr_accessor :workers
8
- self.workers = []
9
-
10
7
  included do
11
8
  thread_cattr_accessor :enabled, :inlined
12
- CallbacksWorker.workers << self
9
+ Sidekiq::Callbacks.add_worker(self)
13
10
  end
14
11
 
15
12
  class_methods do
13
+ # @deprecated TODO remove this in v3.6
14
+ def workers
15
+ Sidekiq::Callbacks.workers
16
+ end
17
+
16
18
  def enabled?
17
19
  enabled.nil? || !!enabled
18
20
  end
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 4
5
- PATCH = 26
5
+ PATCH = 27
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -1,3 +1,4 @@
1
+ //= require workarea/core/modules/environment
1
2
  //= require workarea/core/modules/url
2
3
  //= require workarea/core/modules/form_submitting_controls
3
4
 
@@ -47,6 +47,14 @@ module Workarea
47
47
  end
48
48
 
49
49
  def test_ensure_cors
50
+ response = mock('Excon::Response')
51
+ response.expects(:data)
52
+ .times(3)
53
+ .returns(body: { 'CORSConfiguration' => [] })
54
+ Workarea.s3.expects(:get_bucket_cors)
55
+ .times(3)
56
+ .with(Configuration::S3.bucket)
57
+ .returns(response)
50
58
  Workarea.s3.expects(:put_bucket_cors).with(
51
59
  Configuration::S3.bucket,
52
60
  'CORSConfiguration' => [
@@ -61,6 +69,12 @@ module Workarea
61
69
  Workarea.s3.expects(:put_bucket_cors).with(
62
70
  Configuration::S3.bucket,
63
71
  'CORSConfiguration' => [
72
+ {
73
+ 'ID' => "direct_upload_http://test.host",
74
+ 'AllowedMethod' => 'PUT',
75
+ 'AllowedOrigin' => 'http://test.host',
76
+ 'AllowedHeader' => '*'
77
+ },
64
78
  {
65
79
  'ID' => "direct_upload_http://localhost:3000",
66
80
  'AllowedMethod' => 'PUT',
@@ -72,6 +86,18 @@ module Workarea
72
86
  Workarea.s3.expects(:put_bucket_cors).with(
73
87
  Configuration::S3.bucket,
74
88
  'CORSConfiguration' => [
89
+ {
90
+ 'ID' => "direct_upload_http://test.host",
91
+ 'AllowedMethod' => 'PUT',
92
+ 'AllowedOrigin' => 'http://test.host',
93
+ 'AllowedHeader' => '*'
94
+ },
95
+ {
96
+ 'ID' => "direct_upload_http://localhost:3000",
97
+ 'AllowedMethod' => 'PUT',
98
+ 'AllowedOrigin' => 'http://localhost:3000',
99
+ 'AllowedHeader' => '*'
100
+ },
75
101
  {
76
102
  'ID' => "direct_upload_https://example.com",
77
103
  'AllowedMethod' => 'PUT',
@@ -81,7 +107,6 @@ module Workarea
81
107
  ]
82
108
  ).returns(true)
83
109
 
84
-
85
110
  assert(DirectUpload.ensure_cors!('http://test.host/admin/content_assets'))
86
111
  assert_equal('true', Workarea.redis.get('cors_http_test_host'))
87
112
  assert(DirectUpload.ensure_cors!('http://localhost:3000/admin/content_assets'))
@@ -133,6 +133,9 @@ module Sidekiq
133
133
  end
134
134
  end
135
135
 
136
+ class TestTrackingWorkerOne; end
137
+ class TestTrackingWorkerTwo; end
138
+
136
139
  setup :setup_sidekiq
137
140
  teardown :teardown_sidekiq
138
141
 
@@ -429,5 +432,24 @@ module Sidekiq
429
432
 
430
433
  assert(Worker.enabled?)
431
434
  end
435
+
436
+ def test_tracking_workers
437
+ current_workers = ::Rails.application.config.sidekiq_callbacks_workers
438
+ ::Rails.application.config.sidekiq_callbacks_workers = []
439
+
440
+ Sidekiq::Callbacks.add_worker(TestTrackingWorkerOne)
441
+ assert_includes(Sidekiq::Callbacks.workers, TestTrackingWorkerOne)
442
+
443
+ current_cache_classes = ::Rails.application.config.cache_classes
444
+ ::Rails.application.config.cache_classes = false
445
+ ::Rails.application.config.sidekiq_callbacks_workers = []
446
+
447
+ Sidekiq::Callbacks.add_worker(TestTrackingWorkerTwo)
448
+ assert_includes(Sidekiq::Callbacks.workers, TestTrackingWorkerTwo)
449
+
450
+ ensure
451
+ ::Rails.application.config.sidekiq_callbacks_workers = current_workers
452
+ ::Rails.application.config.cache_classes = current_cache_classes
453
+ end
432
454
  end
433
455
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.26
4
+ version: 3.4.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Crouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2020-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -882,22 +882,22 @@ dependencies:
882
882
  name: minitest
883
883
  requirement: !ruby/object:Gem::Requirement
884
884
  requirements:
885
- - - "~>"
886
- - !ruby/object:Gem::Version
887
- version: 5.10.3
888
885
  - - ">="
889
886
  - !ruby/object:Gem::Version
890
887
  version: 5.10.1
888
+ - - "~>"
889
+ - !ruby/object:Gem::Version
890
+ version: 5.10.3
891
891
  type: :runtime
892
892
  prerelease: false
893
893
  version_requirements: !ruby/object:Gem::Requirement
894
894
  requirements:
895
- - - "~>"
896
- - !ruby/object:Gem::Version
897
- version: 5.10.3
898
895
  - - ">="
899
896
  - !ruby/object:Gem::Version
900
897
  version: 5.10.1
898
+ - - "~>"
899
+ - !ruby/object:Gem::Version
900
+ version: 5.10.3
901
901
  - !ruby/object:Gem::Dependency
902
902
  name: countries
903
903
  requirement: !ruby/object:Gem::Requirement
@@ -2609,7 +2609,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2609
2609
  - !ruby/object:Gem::Version
2610
2610
  version: '0'
2611
2611
  requirements: []
2612
- rubygems_version: 3.1.2
2612
+ rubygems_version: 3.0.6
2613
2613
  signing_key:
2614
2614
  specification_version: 4
2615
2615
  summary: Core of the Workarea Commerce Platform