workarea-core 3.4.31 → 3.4.32

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: 299de23bea1f758a6c81b220df516b433a75b8d68feed5317ed1bc83a2a4bac9
4
- data.tar.gz: 826455dd3ea5fe721feb372936ac4a6b169ae7c3256ce98cee94f1b3c1fd19ff
3
+ metadata.gz: 4efeb3ece9613f3cfad48795bd81db270c1c28a95c5c219f84f24d7416cdc111
4
+ data.tar.gz: 0e397d42f281689cf24607fa58b53a1abf0dd5f3118320d2b01764ae336aa7f6
5
5
  SHA512:
6
- metadata.gz: b612026e5219dbefac87be6a897a43cff75b2fa045d62af44ef9bac1d27ef658e5c8c38cc25526bb52898841ee3b71d43caf89450e641d1c60ef68b1c7d65fe5
7
- data.tar.gz: 336720cc69f36b67ee3706d424df574e04459a55221aa6e04dec7c09b920d6763f5983d5aef7bfeb778535c8c5b288a4ea48e8c18eeeaff39017245e1ba9e5d5
6
+ metadata.gz: 4d5d1be53ba4ab30d7e1ff3e25d4eb47081c3e97bb5e21686a18872f05c0e9894ec53b2803612e7887fa0da66ebc8a2c11cf1805ba14d5532c634e646d6e8cf8
7
+ data.tar.gz: 90e07d7eca3d3a7d9daa8064c0e85841d134098f436b7be7bcf1e599b06d7ba42504a3e314a2fe3058b37dda084745eb6c56fd206a885b3e57d906fbdb5dcaf5
@@ -36,15 +36,15 @@ module Workarea
36
36
  end
37
37
 
38
38
  def apply_details!(product)
39
- HashUpdate
40
- .new(adds: add_details, removes: remove_details)
41
- .apply(product.details)
39
+ product.details = HashUpdate
40
+ .new(original: product.details, adds: add_details, removes: remove_details)
41
+ .result
42
42
  end
43
43
 
44
44
  def apply_filters!(product)
45
- HashUpdate
46
- .new(adds: add_filters, removes: remove_filters)
47
- .apply(product.filters)
45
+ product.filters = HashUpdate
46
+ .new(original: product.filters, adds: add_filters, removes: remove_filters)
47
+ .result
48
48
  end
49
49
 
50
50
  def apply_pricing!(product)
@@ -7,7 +7,10 @@ module Workarea
7
7
  end
8
8
 
9
9
  def per_page
10
- params[:per_page].presence || Workarea.config.per_page
10
+ return Workarea.config.per_page if params[:per_page].blank?
11
+
12
+ tmp = params[:per_page].to_i
13
+ tmp > 0 ? tmp : Workarea.config.per_page
11
14
  end
12
15
 
13
16
  def size
@@ -4,7 +4,7 @@ module Workarea
4
4
  attr_reader :params
5
5
 
6
6
  def initialize(params)
7
- @params = params
7
+ @params = params.with_indifferent_access.except(:per_page)
8
8
  @used_middleware = []
9
9
  end
10
10
 
@@ -5,13 +5,30 @@ module Workarea
5
5
  parsed.map(&:to_s).map(&:strip).reject(&:blank?) if parsed.present?
6
6
  end
7
7
 
8
- def initialize(adds: [], updates: [], removes: [])
8
+ def initialize(original: {}, adds: [], updates: [], removes: [])
9
+ @original = original
9
10
  @adds = Array(adds).flatten.each_slice(2).to_a
10
11
  @updates = Array(updates).flatten.each_slice(2).to_a
11
12
  @removes = Array(removes).flatten
12
13
  end
13
14
 
15
+ def result
16
+ apply_to(@original.deep_dup)
17
+ end
18
+
19
+ # TODO v3.6 remove this method, doesn't work when the field is localized
20
+ # @deprecated
14
21
  def apply(hash)
22
+ warn <<~eos
23
+ [DEPRECATION] `HashUpdate#apply` is deprecated and will be removed in
24
+ version 3.6.0. Please use `HashUpdate#result` instead.
25
+ eos
26
+ apply_to(hash)
27
+ end
28
+
29
+ private
30
+
31
+ def apply_to(hash)
15
32
  @adds.each do |tuple|
16
33
  key, value = *tuple
17
34
  hash[key] = self.class.parse_values(value)
@@ -67,7 +67,7 @@ namespace :workarea do
67
67
  message << " #{line.strip}"
68
68
  end
69
69
  end
70
- message << " #{entry[:author]}\n"
70
+ message << "\n #{entry[:author]}\n"
71
71
  end
72
72
 
73
73
  # ensure and append to changelog
@@ -127,6 +127,7 @@ require 'workarea/ext/freedom_patches/net_http_ssl_connection'
127
127
  require 'workarea/ext/freedom_patches/dragonfly_job_fetch_url'
128
128
  require 'workarea/ext/freedom_patches/dragonfly_callable_url_host'
129
129
  require 'workarea/ext/freedom_patches/mongoid_localized_defaults'
130
+ require 'workarea/ext/freedom_patches/i18n_js'
130
131
  require 'workarea/ext/mongoid/list_field'
131
132
  require 'workarea/ext/mongoid/each_by'
132
133
  require 'workarea/ext/mongoid/except'
@@ -0,0 +1,27 @@
1
+ module I18n
2
+ module JS
3
+ class FallbackLocales
4
+ # i18n-js uses just the second part of this check out-of-the-box. This
5
+ # causes the I18n fallbacks to get autoloaded without the developer
6
+ # knowing.
7
+ #
8
+ # This surfaces in tests. System or integration tests will do this check
9
+ # for compiling assets, then I18n fallbacks get autoloaded. So this shows
10
+ # as some tests not having fallbacks if they run before one of those tests
11
+ # or magically having fallbacks if they run after one of those types of
12
+ # tests.
13
+ #
14
+ # Adding the `respond_to?` check doesn't cause autoload, but will return
15
+ # `true` if fallbacks are enabled. Retain the original check because we
16
+ # want the current I18n::JS backend to be checked, once fallbacks are
17
+ # `require`d `I18n.respond_to?(:fallbacks)` will always return `true`.
18
+ #
19
+ # See also: https://github.com/fnando/i18n-js/blob/master/lib/i18n/js/fallback_locales.rb#L49-L58
20
+ #
21
+ def using_i18n_fallbacks_module?
22
+ I18n.respond_to?(:fallbacks) &&
23
+ I18n::JS.backend.class.included_modules.include?(I18n::Backend::Fallbacks)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 4
5
- PATCH = 31
5
+ PATCH = 32
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -19,6 +19,15 @@ module Workarea
19
19
  assert_equal(1, Paginate.new(page: 'asdf').page)
20
20
  end
21
21
 
22
+ def test_per_page
23
+ assert_equal(Workarea.config.per_page, Paginate.new.per_page)
24
+ assert_equal(2, Paginate.new(per_page: 2).per_page)
25
+ assert_equal(Workarea.config.per_page, Paginate.new(per_page: -1).per_page)
26
+ assert_equal(Workarea.config.per_page, Paginate.new(per_page: 0).per_page)
27
+ assert_equal(3, Paginate.new(per_page: '3').per_page)
28
+ assert_equal(Workarea.config.per_page, Paginate.new(per_page: 'asdf').per_page)
29
+ end
30
+
22
31
  def test_from
23
32
  Workarea.with_config do |config|
24
33
  config.per_page = 30
@@ -410,6 +410,9 @@ module Workarea
410
410
  end
411
411
 
412
412
  def test_locale
413
+ # No simple way to run this test without fallbacks or localized fields
414
+ return unless Workarea.config.localized_active_fields
415
+
413
416
  set_locales(available: [:en, :es], default: :en, current: :en)
414
417
  Search::Storefront.reset_indexes!
415
418
 
@@ -2,23 +2,23 @@ require 'test_helper'
2
2
 
3
3
  module Workarea
4
4
  class HashUpdateTest < TestCase
5
- def test_apply
6
- hash = { 'foo' => 'bar' }
5
+ def test_result
6
+ original = { 'foo' => 'bar' }
7
7
 
8
- HashUpdate.new(adds: %w(key value)).apply(hash)
9
- assert_equal(%w(value), hash['key'])
8
+ result = HashUpdate.new(original: original, adds: %w(key value)).result
9
+ assert_equal(%w(value), result['key'])
10
10
 
11
- HashUpdate.new(updates: %w(foo baz)).apply(hash)
12
- assert_equal(%w(baz), hash['foo'])
11
+ result = HashUpdate.new(original: original, updates: %w(foo baz)).result
12
+ assert_equal(%w(baz), result['foo'])
13
13
 
14
- HashUpdate.new(removes: %w(foo)).apply(hash)
15
- refute_includes(hash.keys, 'foo')
14
+ result = HashUpdate.new(original: original, removes: %w(foo)).result
15
+ refute_includes(result.keys, 'foo')
16
16
 
17
- HashUpdate.new(adds: ['key', 'one, two ']).apply(hash)
18
- assert_equal(%w(one two), hash['key'])
17
+ result = HashUpdate.new(original: original, adds: ['key', 'one, two ']).result
18
+ assert_equal(%w(one two), result['key'])
19
19
 
20
- HashUpdate.new(updates: ['key', 'one, two, three ']).apply(hash)
21
- assert_equal(%w(one two three), hash['key'])
20
+ result = HashUpdate.new(original: original, updates: ['key', 'one, two, three ']).result
21
+ assert_equal(%w(one two three), result['key'])
22
22
  end
23
23
  end
24
24
  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.31
4
+ version: 3.4.32
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-04-15 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -1855,6 +1855,7 @@ files:
1855
1855
  - lib/workarea/ext/freedom_patches/dragonfly_job_fetch_url.rb
1856
1856
  - lib/workarea/ext/freedom_patches/float.rb
1857
1857
  - lib/workarea/ext/freedom_patches/global_id.rb
1858
+ - lib/workarea/ext/freedom_patches/i18n_js.rb
1858
1859
  - lib/workarea/ext/freedom_patches/money.rb
1859
1860
  - lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
1860
1861
  - lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb