workarea-core 3.4.28 → 3.4.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/workarea/bulk_action/product_edit.rb +6 -6
  3. data/app/models/workarea/search/admin.rb +39 -17
  4. data/app/models/workarea/search/storefront/product/categories.rb +1 -1
  5. data/app/models/workarea/user/password_reset.rb +3 -1
  6. data/app/queries/workarea/search/pagination.rb +4 -1
  7. data/app/queries/workarea/search/storefront_search.rb +1 -1
  8. data/app/services/workarea/direct_upload.rb +12 -13
  9. data/app/services/workarea/hash_update.rb +18 -1
  10. data/app/workers/workarea/bulk_index_admin.rb +1 -1
  11. data/app/workers/workarea/bulk_index_products.rb +3 -2
  12. data/app/workers/workarea/bulk_index_searches.rb +4 -4
  13. data/app/workers/workarea/process_import.rb +3 -3
  14. data/config/initializers/15_endpoint_monitoring.rb +6 -3
  15. data/lib/workarea/changelog.rake +1 -1
  16. data/lib/workarea/configuration.rb +6 -0
  17. data/lib/workarea/core.rb +2 -0
  18. data/lib/workarea/core/engine.rb +3 -4
  19. data/lib/workarea/elasticsearch/document.rb +15 -8
  20. data/lib/workarea/ext/freedom_patches/i18n_js.rb +27 -0
  21. data/lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb +25 -0
  22. data/lib/workarea/version.rb +1 -1
  23. data/test/integration/workarea/monitoring_integration_test.rb +10 -5
  24. data/test/lib/workarea/elasticsearch/document_test.rb +20 -0
  25. data/test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb +25 -0
  26. data/test/models/workarea/user/password_reset_test.rb +12 -4
  27. data/test/queries/workarea/search/pagination_test.rb +9 -0
  28. data/test/queries/workarea/search/product_search_test.rb +16 -0
  29. data/test/services/workarea/direct_upload_test.rb +0 -3
  30. data/test/services/workarea/hash_update_test.rb +12 -12
  31. data/test/workers/workarea/process_import_test.rb +6 -0
  32. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8439c1a91cb856c912b1d2e905b0febc658cfa4d8aa2e0d284783f52e4b02e0
4
- data.tar.gz: ec47357ec28e16a43e06dbbfa1ad1323767dae291c199d715d5241fa5d54d611
3
+ metadata.gz: 9380a926427872b88a127eeca3d80b734d8679e297cd691a409b2125d181b210
4
+ data.tar.gz: 37b763327a0a0f7eec7d34b4f744eae59580a8717f1e0bac3b4fadc830c62f61
5
5
  SHA512:
6
- metadata.gz: 1b7801af7aa2e4f98ac24a0e8f53fae358e0ebdbd8504766144c5dc6df7c0e478fd3c73fbf2b0996fb38ad131f72137466cecec2cfa8c6ee3ff0b098dce465df
7
- data.tar.gz: 0de8df6aae608882554a3280eaa2d6f473ac181c68b8356aa9bf4ac9fefc0443d98172c85af55e8de71f0ea96e0cb36acd2000b94b1ebbb9f3c46956b9c6b0f9
6
+ metadata.gz: 6da8af3694f295513a48512a0fd51f2309c04f33b400461dfb90727c8d4b083a7e291e0e66edb69ae23ba9a55a4f8eb5351b34434da153ed915bada8ccdabe7d
7
+ data.tar.gz: f15b4a14d8e5a44f0acbc71c2c780731b0f9b3c3f07c8223e5aa15ba5d9ad48f8a779d81a10dd33b2561503fff5da37f7478ed3dedb7cfd6bfee5e6931b47a37
@@ -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)
@@ -5,27 +5,49 @@ module Workarea
5
5
 
6
6
  def self.jump_to(params, size = Workarea.config.default_admin_jump_to_result_count)
7
7
  query = {
8
- query: {
9
- match_phrase_prefix: {
10
- jump_to_search_text: {
11
- query: params[:q],
12
- max_expansions: 10
8
+ aggs: {
9
+ grouped_by_type: {
10
+ filter: {
11
+ match_phrase_prefix: {
12
+ jump_to_search_text: {
13
+ query: params[:q],
14
+ max_expansions: 10
15
+ }
16
+ }
17
+ },
18
+ aggs: {
19
+ type: {
20
+ terms: { field: 'facets.type', size: Workarea.config.jump_to_type_limit },
21
+ aggs: {
22
+ top: {
23
+ top_hits: {
24
+ size: Workarea.config.jump_to_results_per_type,
25
+ sort: [
26
+ { _score: { order: 'desc' } },
27
+ { updated_at: { order: 'desc' } }
28
+ ]
29
+ }
30
+ }
31
+ }
32
+ }
13
33
  }
14
34
  }
15
- },
16
- size: size,
17
- sort: [{ jump_to_position: :asc }]
35
+ }
18
36
  }
19
37
 
20
- search(query)['hits']['hits'].map do |result|
21
- {
22
- label: result['_source']['jump_to_text'],
23
- type: result['_source']['facets']['type'],
24
- model_class: result['_source']['model_class'],
25
- route_helper: result['_source']['jump_to_route_helper'],
26
- to_param: result['_source']['jump_to_param']
27
- }
28
- end
38
+ aggregation = search(query)['aggregations']['grouped_by_type']['type']
39
+ aggregation['buckets']
40
+ .reduce([]) { |m, b| m + b['top']['hits']['hits'] }
41
+ .sort_by { |r| [r['_source']['jump_to_position'], r['_score']] }
42
+ .map do |result|
43
+ {
44
+ label: result['_source']['jump_to_text'],
45
+ type: result['_source']['facets']['type'],
46
+ model_class: result['_source']['model_class'],
47
+ route_helper: result['_source']['jump_to_route_helper'],
48
+ to_param: result['_source']['jump_to_param']
49
+ }
50
+ end
29
51
  end
30
52
 
31
53
  def self.for(model)
@@ -13,7 +13,7 @@ module Workarea
13
13
  if category.product_rules.present?
14
14
  document = {
15
15
  id: category.id,
16
- query: Categorization.new(rules: category.product_rules).query
16
+ query: Workarea::Search::Categorization.new(rules: category.product_rules).query
17
17
  }
18
18
 
19
19
  Storefront.current_index.save(document, type: 'category')
@@ -4,7 +4,7 @@ module Workarea
4
4
  include ApplicationDocument
5
5
  include UrlToken
6
6
 
7
- belongs_to :user, class_name: 'Workarea::User'
7
+ belongs_to :user, class_name: 'Workarea::User', index: true
8
8
 
9
9
  index(
10
10
  { created_at: 1 },
@@ -14,6 +14,8 @@ module Workarea
14
14
  def self.setup!(email)
15
15
  user = User.find_by_email(email)
16
16
  return nil unless user
17
+
18
+ where(user_id: user.id).destroy_all
17
19
  create!(user: user)
18
20
  end
19
21
 
@@ -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
 
@@ -6,22 +6,21 @@ module Workarea
6
6
  uri = URI.parse(request_url)
7
7
  url = "#{uri.scheme}://#{uri.host}"
8
8
  url += ":#{uri.port}" unless uri.port.in? [80, 443]
9
-
10
- redis_key = "cors_#{url.optionize}"
11
- return if Workarea.redis.get(redis_key) == 'true'
9
+ id = "direct_upload_#{url}"
12
10
 
13
11
  response = Workarea.s3.get_bucket_cors(Configuration::S3.bucket)
14
12
  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)
24
- Workarea.redis.set(redis_key, 'true')
13
+
14
+ unless cors['CORSConfiguration'].pluck('ID').include?(id)
15
+ cors['CORSConfiguration'] << {
16
+ 'ID' => id,
17
+ 'AllowedMethod' => 'PUT',
18
+ 'AllowedOrigin' => url,
19
+ 'AllowedHeader' => '*'
20
+ }
21
+
22
+ Workarea.s3.put_bucket_cors(Configuration::S3.bucket, cors)
23
+ end
25
24
  end
26
25
 
27
26
  attr_reader :type, :filename
@@ -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)
@@ -13,7 +13,7 @@ module Workarea
13
13
 
14
14
  def perform_by_models(models)
15
15
  return if models.empty?
16
- Workarea::Search::Admin.bulk(documents_for(models))
16
+ Workarea::Search::Admin.bulk { documents_for(models) }
17
17
  end
18
18
 
19
19
  private
@@ -14,9 +14,10 @@ module Workarea
14
14
  def perform_by_models(products)
15
15
  return if products.blank?
16
16
 
17
- documents = Search::ProductEntries.new(products).map(&:as_bulk_document)
17
+ Search::Storefront.bulk do
18
+ Search::ProductEntries.new(products).map(&:as_bulk_document)
19
+ end
18
20
 
19
- Search::Storefront.bulk(documents)
20
21
  products.each { |p| p.set(last_indexed_at: Time.current) }
21
22
  end
22
23
  end
@@ -18,11 +18,11 @@ module Workarea
18
18
  end
19
19
 
20
20
  def perform_by_models(searches)
21
- documents = searches.map do |model|
22
- Search::Storefront::Search.new(model).as_bulk_document
21
+ Search::Storefront.bulk do
22
+ searches.map do |model|
23
+ Search::Storefront::Search.new(model).as_bulk_document
24
+ end
23
25
  end
24
-
25
- Search::Storefront.bulk(documents)
26
26
  end
27
27
  end
28
28
 
@@ -17,11 +17,11 @@ module Workarea
17
17
  import.process!
18
18
 
19
19
  ensure
20
- if import.error?
20
+ if import&.error?
21
21
  Admin::DataFileMailer.import_error(id).deliver_now
22
- elsif import.failure?
22
+ elsif import&.failure?
23
23
  Admin::DataFileMailer.import_failure(id).deliver_now
24
- else
24
+ elsif import.present?
25
25
  Admin::DataFileMailer.import(id).deliver_now
26
26
  end
27
27
  end
@@ -3,7 +3,8 @@
3
3
  #
4
4
  Easymon::Repository.add(
5
5
  'mongodb',
6
- Workarea::Monitoring::MongoidCheck.new
6
+ Workarea::Monitoring::MongoidCheck.new,
7
+ :critical
7
8
  )
8
9
 
9
10
  #
@@ -11,7 +12,8 @@ Easymon::Repository.add(
11
12
  #
12
13
  Easymon::Repository.add(
13
14
  'elasticsearch',
14
- Workarea::Monitoring::ElasticsearchCheck.new
15
+ Workarea::Monitoring::ElasticsearchCheck.new,
16
+ :critical
15
17
  )
16
18
 
17
19
  #
@@ -21,7 +23,8 @@ Easymon::Repository.add(
21
23
  "redis",
22
24
  Easymon::RedisCheck.new(
23
25
  Workarea::Configuration::Redis.persistent.to_h
24
- )
26
+ ),
27
+ :critical
25
28
  )
26
29
 
27
30
  #
@@ -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
@@ -1283,6 +1283,12 @@ module Workarea
1283
1283
  'Workarea::Catalog::Category' => 7,
1284
1284
  'Workarea::Navigation::Menu' => 1_000
1285
1285
  }
1286
+
1287
+ # The max number of types of results that will show in the admin jump to
1288
+ config.jump_to_type_limit = 5
1289
+
1290
+ # The number of results that will show per-type in the admin jump to
1291
+ config.jump_to_results_per_type = 5
1286
1292
  end
1287
1293
  end
1288
1294
  end
@@ -126,6 +126,8 @@ require 'workarea/ext/freedom_patches/country'
126
126
  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
+ require 'workarea/ext/freedom_patches/mongoid_localized_defaults'
130
+ require 'workarea/ext/freedom_patches/i18n_js'
129
131
  require 'workarea/ext/mongoid/list_field'
130
132
  require 'workarea/ext/mongoid/each_by'
131
133
  require 'workarea/ext/mongoid/except'
@@ -118,13 +118,12 @@ db.getSiblingDB("admin").runCommand( { setParameter: 1, notablescan: 0 } )
118
118
  **************************************************
119
119
  ⛔️ WARNING: Dragonfly is configured to use the filesystem.
120
120
 
121
- This means all dragonfly assets (assets, product images, etc.) will be stored
121
+ This means all Dragonfly assets (assets, product images, etc.) will be stored
122
122
  locally and not accessible to all servers within your environment.
123
123
 
124
124
  We recommend using S3 when running in a live environment by setting
125
- WORKAREA_S3_REGION and WORKAREA_S3_BUCKET_NAME in your environment variables.
126
- Workarea will automatically configure Dragonfly to use S3 if those values
127
- are present.
125
+ WORKAREA_S3_REGION and WORKAREA_S3_BUCKET_NAME in your environment variables,
126
+ and setting `Workarea.config.asset_store = :s3` in an initializer.
128
127
  **************************************************
129
128
  eos
130
129
  end
@@ -44,22 +44,27 @@ module Workarea
44
44
 
45
45
  def save(document, options = {})
46
46
  options = options.merge(type: type)
47
- I18n.for_each_locale { current_index.save(document, options) }
47
+ current_index.save(document, options)
48
48
  end
49
49
 
50
- def bulk(documents, options = {})
50
+ def bulk(documents = [], options = {})
51
51
  options = options.merge(type: type)
52
- I18n.for_each_locale { current_index.bulk(documents, options) }
52
+
53
+ if block_given?
54
+ I18n.for_each_locale { current_index.bulk(Array.wrap(yield), options) }
55
+ else
56
+ current_index.bulk(documents, options)
57
+ end
53
58
  end
54
59
 
55
60
  def update(document, options = {})
56
61
  options = options.merge(type: type)
57
- I18n.for_each_locale { current_index.update(document, options) }
62
+ current_index.update(document, options)
58
63
  end
59
64
 
60
65
  def delete(id, options = {})
61
66
  options = options.merge(type: type)
62
- I18n.for_each_locale { current_index.delete(id, options) }
67
+ current_index.delete(id, options)
63
68
  end
64
69
 
65
70
  def count(query = nil, options = {})
@@ -97,12 +102,14 @@ module Workarea
97
102
  end
98
103
 
99
104
  def save(options = {})
100
- document = as_document.merge(Serializer.serialize(model))
101
- self.class.save(document, options)
105
+ I18n.for_each_locale do
106
+ document = as_document.merge(Serializer.serialize(model))
107
+ self.class.save(document, options)
108
+ end
102
109
  end
103
110
 
104
111
  def destroy(options = {})
105
- self.class.delete(id, options)
112
+ I18n.for_each_locale { self.class.delete(id, options) }
106
113
  end
107
114
  end
108
115
  end
@@ -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
@@ -0,0 +1,25 @@
1
+ module Mongoid
2
+ module Fields
3
+ module LocalizedDefaults
4
+ def create_accessors(name, meth, options = {})
5
+ super
6
+
7
+ if options[:localize]
8
+ field = fields[name]
9
+
10
+ define_method meth do |*args|
11
+ result = super(*args)
12
+ return result unless result.nil?
13
+
14
+ default_name = field.send(:default_name)
15
+ return send(default_name) if respond_to?(default_name)
16
+
17
+ field.default_val
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ ClassMethods.prepend(LocalizedDefaults)
24
+ end
25
+ end
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 4
5
- PATCH = 28
5
+ PATCH = 33
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -3,27 +3,32 @@ require 'test_helper'
3
3
  module Workarea
4
4
  class MonitoringIntegrationTest < Workarea::IntegrationTest
5
5
  def test_monitors_the_mongodb_status
6
- get workarea.easymon_path('mongodb')
6
+ get workarea.easymon_path + '/mongodb'
7
7
  assert_includes(response.body, 'Up')
8
8
  end
9
9
 
10
10
  def test_monitors_the_redis_status
11
- get workarea.easymon_path('redis')
11
+ get workarea.easymon_path + '/redis'
12
12
  assert_includes(response.body, 'Up')
13
13
  end
14
14
 
15
15
  def test_monitors_the_elasticsearch_status
16
- get workarea.easymon_path('elasticsearch')
16
+ get workarea.easymon_path + '/elasticsearch'
17
17
  assert_includes(response.body, 'Up')
18
18
  end
19
19
 
20
20
  def test_monitors_the_sidekiq_queue_status
21
- get workarea.easymon_path('sidekiq-queue')
21
+ get workarea.easymon_path + '/sidekiq-queue'
22
22
  assert_includes(response.body, 'Low')
23
23
  end
24
24
 
25
25
  def test_monitors_for_load_balancing
26
- get workarea.easymon_path('load-balancing')
26
+ get workarea.easymon_path + '/load-balancing'
27
+ assert_includes(response.body, 'Up')
28
+ end
29
+
30
+ def test_critical_endpoint
31
+ get workarea.easymon_path + "/critical"
27
32
  assert_includes(response.body, 'Up')
28
33
  end
29
34
  end
@@ -67,6 +67,26 @@ module Workarea
67
67
  assert_equal({ 'id' => '1' }, results.first['_source'])
68
68
  end
69
69
 
70
+ def test_bulk_with_block
71
+ set_locales(available: [:en, :es], default: :en, current: :en)
72
+ Foo.bulk { { id: I18n.locale.to_s, bulk_action: 'index' } }
73
+
74
+ find_results = -> do
75
+ Foo
76
+ .current_index
77
+ .search({ query: { match_all: {} } }, type: 'foo')
78
+ .dig('hits', 'hits')
79
+ end
80
+
81
+ I18n.locale = :en
82
+ assert(1, Foo.count)
83
+ assert_equal({ 'id' => 'en' }, find_results.call.first['_source'])
84
+
85
+ I18n.locale = :es
86
+ assert(1, Foo.count)
87
+ assert_equal({ 'id' => 'es' }, find_results.call.first['_source'])
88
+ end
89
+
70
90
  def test_update
71
91
  Foo.save(id: '1')
72
92
  Foo.update(id: '1', foo: 'bar')
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class MongoidLocalizedDefaultsTest < TestCase
5
+ class Foo
6
+ include Mongoid::Document
7
+
8
+ field :name, type: String, default: -> { 'foo' }, localize: true
9
+ field :config, type: Hash, default: { foo: 'bar' }, localize: true
10
+ end
11
+
12
+ def test_localized_defaults
13
+ set_locales(available: [:en, :es], default: :en, current: :en)
14
+
15
+ instance = Foo.new
16
+ assert_equal('foo', instance.name)
17
+ assert_equal({ foo: 'bar' }, instance.config)
18
+
19
+ I18n.locale = :es
20
+
21
+ assert_equal('foo', instance.name)
22
+ assert_equal({ foo: 'bar' }, instance.config)
23
+ end
24
+ end
25
+ end
@@ -4,14 +4,22 @@ module Workarea
4
4
  class User
5
5
  class PasswordResetTest < TestCase
6
6
  def user
7
- @user ||= create_user
7
+ @user ||= create_user(email: 'one@workarea.com')
8
8
  end
9
9
 
10
10
  def test_setup!
11
- PasswordReset.setup!(user.email)
11
+ 2.times do
12
+ PasswordReset.setup!(user.email)
12
13
 
13
- assert_equal(1, PasswordReset.count)
14
- assert_equal(user.id, PasswordReset.first.user_id)
14
+ assert_equal(1, PasswordReset.count)
15
+ assert_equal(user.id, PasswordReset.first.user_id)
16
+ end
17
+
18
+ two = create_user(email: 'two@workarea.com')
19
+ PasswordReset.setup!('two@workarea.com')
20
+
21
+ assert_equal(2, PasswordReset.count)
22
+ assert_equal(two.id, PasswordReset.last.user_id)
15
23
  end
16
24
 
17
25
  def test_complete
@@ -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
@@ -408,6 +408,22 @@ module Workarea
408
408
  assert(result[:raw].present?)
409
409
  assert_kind_of(Float, result[:raw]['_score'])
410
410
  end
411
+
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
+
416
+ set_locales(available: [:en, :es], default: :en, current: :en)
417
+ Search::Storefront.reset_indexes!
418
+
419
+ product = create_product(active_translations: { 'en' => true, 'es' => false })
420
+
421
+ I18n.locale = :es
422
+ assert_equal([], ProductSearch.new(q: '*').results.pluck(:model))
423
+
424
+ I18n.locale = :en
425
+ assert_equal([product], ProductSearch.new(q: '*').results.pluck(:model))
426
+ end
411
427
  end
412
428
  end
413
429
  end
@@ -108,11 +108,8 @@ module Workarea
108
108
  ).returns(true)
109
109
 
110
110
  assert(DirectUpload.ensure_cors!('http://test.host/admin/content_assets'))
111
- assert_equal('true', Workarea.redis.get('cors_http_test_host'))
112
111
  assert(DirectUpload.ensure_cors!('http://localhost:3000/admin/content_assets'))
113
- assert_equal('true', Workarea.redis.get('cors_http_localhost_3000'))
114
112
  assert(DirectUpload.ensure_cors!('https://example.com/admin/direct_uploads'))
115
- assert_equal('true', Workarea.redis.get('cors_https_example_com'))
116
113
  end
117
114
 
118
115
  private
@@ -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
@@ -53,5 +53,11 @@ module Workarea
53
53
  t('workarea.admin.data_file_mailer.import_failure.errors')
54
54
  )
55
55
  end
56
+
57
+ def test_perform_with_missing_import
58
+ assert_raises Mongoid::Errors::DocumentNotFound do
59
+ ProcessImport.new.perform('foo')
60
+ end
61
+ end
56
62
  end
57
63
  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.28
4
+ version: 3.4.33
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-03-03 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -1855,7 +1855,9 @@ 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
1860
+ - lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
1859
1861
  - lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb
1860
1862
  - lib/workarea/ext/freedom_patches/net_http_ssl_connection.rb
1861
1863
  - lib/workarea/ext/freedom_patches/routes_reloader.rb
@@ -2006,6 +2008,7 @@ files:
2006
2008
  - test/lib/workarea/ext/freedom_patches/country_test.rb
2007
2009
  - test/lib/workarea/ext/freedom_patches/dragonfly_callable_url_host_test.rb
2008
2010
  - test/lib/workarea/ext/freedom_patches/global_id_test.rb
2011
+ - test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb
2009
2012
  - test/lib/workarea/ext/freedom_patches/mongoid_simple_tags_test.rb
2010
2013
  - test/lib/workarea/ext/mongoid/audit_log_entry_test.rb
2011
2014
  - test/lib/workarea/ext/mongoid/each_by_test.rb
@@ -2609,7 +2612,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
2609
2612
  - !ruby/object:Gem::Version
2610
2613
  version: '0'
2611
2614
  requirements: []
2612
- rubygems_version: 3.0.6
2615
+ rubygems_version: 3.0.3
2613
2616
  signing_key:
2614
2617
  specification_version: 4
2615
2618
  summary: Core of the Workarea Commerce Platform