workarea-core 3.5.9 → 3.5.10

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: 277c3f21e9ad08940c1f72830fd89f066987b104d019cb45b670774dc31b91e2
4
- data.tar.gz: a256669db5f584453ad3103365446f5cb885bfa55bae6b68240b07782775b8aa
3
+ metadata.gz: 6b38c044efaff914d6bbbeff43668f4bef87e963f08df785e1afc1b23acb69ec
4
+ data.tar.gz: '087f5d99ee26408269f723973c8199679b21ce894a66657f98457ebb16bfdf0f'
5
5
  SHA512:
6
- metadata.gz: 97608d2f8240e4e21862d986599f8a6cbe4f5e461dc0bbb027203fff9d36b2d74f6477f27a9a652a893690146cfcaac3347bd0e263084f85af6438649d4a9c52
7
- data.tar.gz: 2affa2d8c642e5f47f690d29ccf01629efaaa41f2963d1b16b9a02a3e690ceb57a22447f0e9ebbf7552973de4b817f6d6f80154a76cca01bc8065e6bfa5620ed
6
+ metadata.gz: b90cfa898d74c2111b43b5ccc5bbef7dba02393184e6f6e4830ba50407bc32217e8f7df3aef7b69c3e990a1e8a9c7c5a4b060b032fe109591ddb8666bda5567d
7
+ data.tar.gz: 903fb77fce3abe0e67b553734b3511c03b31a0bc8b9cb73bfd04a2bfbfd72605a5cd711f9e4e0b2d044acf2d0158b3b39dfb2f39fd1951a599afe1b3d20b7b71
@@ -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,27 @@ 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
+ Workarea.deprecation.deprecate_methods(self.class, apply: :result)
23
+ apply_to(hash)
24
+ end
25
+
26
+ private
27
+
28
+ def apply_to(hash)
15
29
  @adds.each do |tuple|
16
30
  key, value = *tuple
17
31
  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
@@ -132,6 +132,7 @@ require 'workarea/ext/freedom_patches/active_support_duration'
132
132
  require 'workarea/ext/freedom_patches/premailer'
133
133
  require 'workarea/ext/freedom_patches/referer_parser'
134
134
  require 'workarea/ext/freedom_patches/mongoid_localized_defaults'
135
+ require 'workarea/ext/freedom_patches/i18n_js'
135
136
  require 'workarea/ext/mongoid/list_field'
136
137
  require 'workarea/ext/mongoid/each_by'
137
138
  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 = 5
5
- PATCH = 9
5
+ PATCH = 10
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
8
8
 
@@ -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.config.per_page = 30
24
33
  assert_equal(0, Paginate.new(page: 1).from)
@@ -427,6 +427,9 @@ module Workarea
427
427
  end
428
428
 
429
429
  def test_locale
430
+ # No simple way to run this test without fallbacks or localized fields
431
+ return unless Workarea.config.localized_active_fields
432
+
430
433
  set_locales(available: [:en, :es], default: :en, current: :en)
431
434
  Search::Storefront.reset_indexes!
432
435
 
@@ -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.5.9
4
+ version: 3.5.10
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
@@ -1919,6 +1919,7 @@ files:
1919
1919
  - lib/workarea/ext/freedom_patches/dragonfly_job_fetch_url.rb
1920
1920
  - lib/workarea/ext/freedom_patches/float.rb
1921
1921
  - lib/workarea/ext/freedom_patches/global_id.rb
1922
+ - lib/workarea/ext/freedom_patches/i18n_js.rb
1922
1923
  - lib/workarea/ext/freedom_patches/money.rb
1923
1924
  - lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
1924
1925
  - lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb