workarea-core 3.5.4 → 3.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8490f36459db38d3440f85a679bbc51aec0fe302563068a715fc51e78e130ab0
4
- data.tar.gz: ba46602137e05b884f87a0169a75a896b9e7c7cb2601ce25130fac421dbd5a27
3
+ metadata.gz: d47e5bfba5ae31a8628b66da9818d40cc49adb0e3428b0449bddb3a414bc0efc
4
+ data.tar.gz: 4336935901cbd99fedf36de8e62ee3d1f842b143bed0d79e0b253be3419c97c2
5
5
  SHA512:
6
- metadata.gz: c4188e1edfb091422a9a871dfcd4819d7732e110bf45262d00c59ef532ebce574a64b8ab0e2c097c9a1442432de90b11dbf6acb3d419ca8b9e43da4e46e4b726
7
- data.tar.gz: 24700c5024b1bbde51a34eca0108ddf71a2caa8cf8edaed22fd5041a51a109b5e7854f8c7a323b103b20ee99536f5b67fb697cdcb1685d50a09d13ff47134cae
6
+ metadata.gz: 22c46296fa0ad6e75263909fe7793134219c05122077f2d6d58a1f4a493e425861f7051bbbb5684984bb34f7f0c9f80151fd44c9e8eb7b79868ccd2a8304a576
7
+ data.tar.gz: 11bea33230c8001e5d2f8841729b065600bd89d6faa22be3d5cf5183dfe4e065739cce4b52f664f3edacbe010ed5ddd87c78ef0d32bafdfe4de90d7638dff272
@@ -96,7 +96,7 @@ module Workarea
96
96
  # @return [Workarea::Content::BlockType]
97
97
  #
98
98
  def type
99
- Workarea.config.content_block_types.detect { |bt| bt.id == type_id }
99
+ Configuration::ContentBlocks.types.detect { |bt| bt.id == type_id }
100
100
  end
101
101
 
102
102
  def type=(value)
@@ -25,7 +25,7 @@ module Workarea
25
25
 
26
26
  def block_type
27
27
  return unless type_id.present?
28
- Workarea.config.content_block_types.detect { |bt| bt.id == type_id.to_sym }
28
+ Configuration::ContentBlocks.types.detect { |bt| bt.id == type_id.to_sym }
29
29
  end
30
30
 
31
31
  def typecast_data!
@@ -19,7 +19,7 @@ module Workarea
19
19
  # @return [Workarea::Content::BlockType, nil]
20
20
  #
21
21
  def self.find(id)
22
- Workarea.config.content_block_types.detect { |bt| bt.id == id }
22
+ Configuration::ContentBlocks.types.detect { |bt| bt.id == id }
23
23
  end
24
24
 
25
25
  def initialize(name)
@@ -12,7 +12,7 @@ module Workarea
12
12
  existing.instance_eval(&block) if block_given?
13
13
  else
14
14
  block_type.instance_eval(&block) if block_given?
15
- Workarea.config.content_block_types.push(block_type)
15
+ Configuration::ContentBlocks.types.push(block_type)
16
16
  end
17
17
  end
18
18
  end
@@ -59,7 +59,7 @@ module Workarea
59
59
  # @return [Workarea::Content::BlockType]
60
60
  #
61
61
  def type
62
- Workarea.config.content_block_types.detect { |bt| bt.id == type_id }
62
+ Configuration::ContentBlocks.types.detect { |bt| bt.id == type_id }
63
63
  end
64
64
  end
65
65
  end
@@ -13,11 +13,11 @@ module Workarea
13
13
  end
14
14
 
15
15
  def medium_match?(referrer)
16
- medium.to_s.strip.casecmp?(referrer.medium)
16
+ medium.present? && medium.to_s.strip.casecmp?(referrer.medium.to_s)
17
17
  end
18
18
 
19
19
  def source_match?(referrer)
20
- source.any? { |s| s.strip.casecmp?(referrer.source) }
20
+ source.any? { |s| s.present? && s.to_s.strip.casecmp?(referrer.source.to_s) }
21
21
  end
22
22
 
23
23
  def url_match?(referrer)
@@ -73,7 +73,7 @@ module Workarea
73
73
  # If loaded with `.only` this might be missing
74
74
  return if attribute_missing?(:active_segment_ids)
75
75
 
76
- CurrentSegments.has_segmented_content! if active_segment_ids.any?
76
+ CurrentSegments.has_segmented_content! if active_segment_ids.present?
77
77
  end
78
78
  end
79
79
  end
@@ -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
@@ -3,6 +3,14 @@ module Workarea
3
3
  module ContentBlocks
4
4
  extend self
5
5
 
6
+ def types
7
+ @types ||= []
8
+ end
9
+
10
+ def types=(values)
11
+ @types = values
12
+ end
13
+
6
14
  def building_blocks
7
15
  @building_blocks ||= []
8
16
  end
@@ -11,6 +19,14 @@ module Workarea
11
19
  building_blocks.each do |block|
12
20
  Content::BlockTypeDefinition.define(&block)
13
21
  end
22
+
23
+ # TODO remove in v3.6, this exists to help with a backwards incompatible
24
+ # patch to fix copying of Workarea.config in multisite.
25
+ Workarea.config.content_block_types = types
26
+ Workarea.deprecation.deprecate_methods(
27
+ AdministrableOptions,
28
+ content_block_types: 'use Configuration::ContentBlocks.types instead'
29
+ )
14
30
  end
15
31
  end
16
32
  end
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 5
5
- PATCH = 4
5
+ PATCH = 5
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
8
8
 
@@ -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
 
@@ -5,7 +5,7 @@ module Workarea
5
5
  class BlockNameTest < TestCase
6
6
  def test_not_erroring_for_configured_blocks
7
7
  assert_nothing_raised do
8
- Workarea.config.content_block_types.each do |type|
8
+ Configuration::ContentBlocks.types.each do |type|
9
9
  block = Block.new(type: type, data: type.defaults)
10
10
  BlockName.new(block).to_s
11
11
  end
@@ -13,7 +13,7 @@ module Workarea
13
13
  end
14
14
 
15
15
  def test_name_is_human_readable
16
- Workarea.config.content_block_types.each do |type|
16
+ Configuration::ContentBlocks.types.each do |type|
17
17
  block = Block.new(type: type, data: type.defaults)
18
18
  name = BlockName.new(block).to_s
19
19
 
@@ -7,12 +7,12 @@ module Workarea
7
7
  teardown :restore_config
8
8
 
9
9
  def reset_config
10
- @current = Workarea.config.content_block_types
11
- Workarea.config.content_block_types = []
10
+ @current = Configuration::ContentBlocks.types
11
+ Configuration::ContentBlocks.types = []
12
12
  end
13
13
 
14
14
  def restore_config
15
- Workarea.config.content_block_types = @current
15
+ Configuration::ContentBlocks.types = @current
16
16
  end
17
17
 
18
18
  def test_constructs_a_list_of_blocks_based_on_the_dsl
@@ -39,8 +39,8 @@ module Workarea
39
39
  end
40
40
  end
41
41
 
42
- assert_equal(2, Workarea.config.content_block_types.length)
43
- results = Workarea.config.content_block_types
42
+ assert_equal(2, Configuration::ContentBlocks.types.length)
43
+ results = Configuration::ContentBlocks.types
44
44
 
45
45
  assert_equal('Foo', results.first.name)
46
46
  assert_equal('workarea/admin/content_block_types/custom_foo_icon', results.first.icon)
@@ -122,7 +122,7 @@ module Workarea
122
122
  end
123
123
  end
124
124
 
125
- result = Workarea.config.content_block_types.first
125
+ result = Configuration::ContentBlocks.types.first
126
126
 
127
127
  assert_equal('Foo', result.name)
128
128
  assert_equal(5, result.fieldsets.length)
@@ -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.5.4
4
+ version: 3.5.5
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
@@ -896,22 +896,22 @@ dependencies:
896
896
  name: minitest
897
897
  requirement: !ruby/object:Gem::Requirement
898
898
  requirements:
899
- - - "~>"
900
- - !ruby/object:Gem::Version
901
- version: 5.10.3
902
899
  - - ">="
903
900
  - !ruby/object:Gem::Version
904
901
  version: 5.10.1
902
+ - - "~>"
903
+ - !ruby/object:Gem::Version
904
+ version: 5.10.3
905
905
  type: :runtime
906
906
  prerelease: false
907
907
  version_requirements: !ruby/object:Gem::Requirement
908
908
  requirements:
909
- - - "~>"
910
- - !ruby/object:Gem::Version
911
- version: 5.10.3
912
909
  - - ">="
913
910
  - !ruby/object:Gem::Version
914
911
  version: 5.10.1
912
+ - - "~>"
913
+ - !ruby/object:Gem::Version
914
+ version: 5.10.3
915
915
  - !ruby/object:Gem::Dependency
916
916
  name: countries
917
917
  requirement: !ruby/object:Gem::Requirement
@@ -2718,7 +2718,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2718
2718
  - !ruby/object:Gem::Version
2719
2719
  version: '0'
2720
2720
  requirements: []
2721
- rubygems_version: 3.1.2
2721
+ rubygems_version: 3.0.6
2722
2722
  signing_key:
2723
2723
  specification_version: 4
2724
2724
  summary: Core of the Workarea Commerce Platform