workarea-core 3.5.8 → 3.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/workarea/application_controller.rb +0 -5
  3. data/app/controllers/workarea/authentication.rb +6 -0
  4. data/app/helpers/workarea/i18n_helper.rb +1 -1
  5. data/app/middleware/workarea/application_middleware.rb +18 -0
  6. data/app/models/workarea/search/storefront/category_query.rb +2 -2
  7. data/app/models/workarea/user/password_reset.rb +3 -1
  8. data/app/queries/workarea/search/product_entries.rb +7 -5
  9. data/app/workers/workarea/bulk_index_admin.rb +1 -1
  10. data/app/workers/workarea/bulk_index_products.rb +3 -2
  11. data/app/workers/workarea/bulk_index_searches.rb +4 -4
  12. data/app/workers/workarea/synchronize_user_metrics.rb +12 -2
  13. data/lib/workarea/cache.rb +1 -1
  14. data/lib/workarea/core.rb +1 -0
  15. data/lib/workarea/elasticsearch/document.rb +15 -8
  16. data/lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb +25 -0
  17. data/lib/workarea/geolocation.rb +1 -9
  18. data/lib/workarea/version.rb +1 -1
  19. data/test/helpers/workarea/i18n_helper_test.rb +2 -0
  20. data/test/integration/workarea/authentication_test.rb +10 -0
  21. data/test/integration/workarea/cache_varies_integration_test.rb +31 -0
  22. data/test/lib/workarea/elasticsearch/document_test.rb +20 -0
  23. data/test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb +25 -0
  24. data/test/lib/workarea/geolocation_test.rb +3 -3
  25. data/test/models/workarea/segment/rules/geolocation_test.rb +9 -7
  26. data/test/models/workarea/user/password_reset_test.rb +12 -4
  27. data/test/queries/workarea/search/product_entries_test.rb +11 -0
  28. data/test/queries/workarea/search/product_search_test.rb +13 -0
  29. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c2fa2d437187cdfa6f9630002c94d5822cc51f5befb62060e6fd219203d4285
4
- data.tar.gz: 2a9bb9faea3d1d1ed34cbf48938fcee9d1d2673ebcd3acf1cc976fda0370acd5
3
+ metadata.gz: 277c3f21e9ad08940c1f72830fd89f066987b104d019cb45b670774dc31b91e2
4
+ data.tar.gz: a256669db5f584453ad3103365446f5cb885bfa55bae6b68240b07782775b8aa
5
5
  SHA512:
6
- metadata.gz: 71f63a2c7b0d0824a173279e01c17ddcc10ea4ef7fb2a232874cd54198a867b5fb6cc3735673d7fe41223f1815e28fdc3794d820d25a74eea03d7f381b4e47eb
7
- data.tar.gz: fc5503c7cb0ee41b481c04cf3682b002e019e095c4a6a1e27c9279a40c78012c3712312e82e5c8c2878c5be680aca7137acb9d706af71bf6cf95c54c4112ec52
6
+ metadata.gz: 97608d2f8240e4e21862d986599f8a6cbe4f5e461dc0bbb027203fff9d36b2d74f6477f27a9a652a893690146cfcaac3347bd0e263084f85af6438649d4a9c52
7
+ data.tar.gz: 2affa2d8c642e5f47f690d29ccf01629efaaa41f2963d1b16b9a02a3e690ceb57a22447f0e9ebbf7552973de4b817f6d6f80154a76cca01bc8065e6bfa5620ed
@@ -7,7 +7,6 @@ module Workarea
7
7
 
8
8
  protect_from_forgery
9
9
 
10
- before_action :set_locale
11
10
  after_action :set_flash_header
12
11
 
13
12
  # Cache templates within the scope of a request for development
@@ -33,10 +32,6 @@ module Workarea
33
32
 
34
33
  private
35
34
 
36
- def set_locale
37
- I18n.locale = params[:locale] || I18n.default_locale
38
- end
39
-
40
35
  def set_flash_header
41
36
  messages = flash.map { |k, v| [k, ERB::Util.h(v)] }
42
37
  response.headers['X-Flash-Messages'] = Hash[messages].to_json
@@ -89,6 +89,12 @@ module Workarea
89
89
  else
90
90
  uri = URI.parse(params[:return_to])
91
91
 
92
+ if I18n.locale != I18n.default_locale
93
+ query_hash = Rack::Utils.parse_nested_query(uri.query)
94
+ query_hash['locale'] ||= I18n.locale
95
+ uri.query = query_hash.to_query
96
+ end
97
+
92
98
  if uri.fragment.present?
93
99
  "#{uri.request_uri}##{uri.fragment}"
94
100
  else
@@ -10,7 +10,7 @@ module Workarea
10
10
  result = ''
11
11
 
12
12
  params
13
- .except(:utf8, :controller, :action)
13
+ .except(:utf8, :controller, :action, :locale)
14
14
  .each_pair { |key, value| result << hidden_field_tag(key, value, id: nil) }
15
15
 
16
16
  result.html_safe
@@ -8,6 +8,7 @@ module Workarea
8
8
  request = Rack::Request.new(env)
9
9
  return @app.call(env) if request.path =~ /(jpe?g|png|ico|gif|css|js|svg)$/
10
10
 
11
+ set_locale(env, request)
11
12
  setup_environment(env, request)
12
13
  set_segment_request_headers(env)
13
14
  status, headers, body = @app.call(env)
@@ -16,6 +17,10 @@ module Workarea
16
17
  [status, headers, body]
17
18
  end
18
19
 
20
+ def set_locale(env, request)
21
+ I18n.locale = locale_from_request(env, request) || I18n.default_locale
22
+ end
23
+
19
24
  def setup_environment(env, request)
20
25
  env['workarea.visit'] = Visit.new(env)
21
26
  env['workarea.cache_varies'] = Cache::Varies.new(env['workarea.visit']).to_s
@@ -37,6 +42,19 @@ module Workarea
37
42
 
38
43
  private
39
44
 
45
+ def locale_from_request(env, request)
46
+ return request.params['locale'] if request.params['locale'].present?
47
+
48
+ env_with_method = env.merge(
49
+ method: request.params[Rack::MethodOverride::METHOD_OVERRIDE_PARAM_KEY].presence ||
50
+ request.request_method
51
+ )
52
+ Rails.application.routes.recognize_path(request.path, env_with_method)[:locale]
53
+
54
+ rescue ActionController::RoutingError
55
+ # Return nil since we can't get locale out of this request
56
+ end
57
+
40
58
  def normalize_segment_ids(visit)
41
59
  visit.applied_segments.map(&:id).sort.join(',')
42
60
  end
@@ -113,7 +113,7 @@ module Workarea
113
113
  id: category.id,
114
114
  release_id: 'live',
115
115
  changeset_release_ids: changesets.map(&:release_id).uniq,
116
- query: Categorization.new(rules: category.product_rules).query
116
+ query: Workarea::Search::Categorization.new(rules: category.product_rules).query
117
117
  }
118
118
 
119
119
  Storefront.current_index.save(document, type: 'category')
@@ -130,7 +130,7 @@ module Workarea
130
130
  document = {
131
131
  id: "#{category.id}-#{changeset.release_id}",
132
132
  release_id: changeset.release_id,
133
- query: Categorization.new(rules: category.product_rules).query
133
+ query: Workarea::Search::Categorization.new(rules: category.product_rules).query
134
134
  }
135
135
 
136
136
  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
 
@@ -17,15 +17,17 @@ module Workarea
17
17
  end
18
18
 
19
19
  def live_entries
20
- @live_entries ||= @products.flat_map do |product|
21
- index_entries_for(product.without_release)
20
+ @live_entries ||= @products.reduce([]) do |memo, product|
21
+ memo + Array.wrap(index_entries_for(product.without_release))
22
22
  end
23
23
  end
24
24
 
25
25
  def release_entries
26
- @release_entries ||= @products.flat_map do |product|
27
- ProductReleases.new(product).releases.map do |release|
28
- index_entries_for(product.in_release(release))
26
+ @release_entries ||= @products.reduce([]) do |results, product|
27
+ releases = ProductReleases.new(product).releases
28
+
29
+ results + releases.reduce([]) do |memo, release|
30
+ memo + Array.wrap(index_entries_for(product.in_release(release)))
29
31
  end
30
32
  end
31
33
  end
@@ -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
@@ -15,8 +15,9 @@ module Workarea
15
15
  return if products.blank?
16
16
  products = Array.wrap(products)
17
17
 
18
- documents = Search::ProductEntries.new(products).map(&:as_bulk_document)
19
- Search::Storefront.bulk(documents)
18
+ Search::Storefront.bulk do
19
+ Search::ProductEntries.new(products).map(&:as_bulk_document)
20
+ end
20
21
 
21
22
  Catalog::Product.in(id: products.map(&:id)).set(last_indexed_at: Time.current)
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
 
@@ -19,8 +19,18 @@ module Workarea
19
19
 
20
20
  def perform(id)
21
21
  user = User.find(id)
22
- metrics = Metrics::User.find_or_create_by(id: user.email)
23
- metrics.set(admin: user.admin?, tags: user.tags)
22
+
23
+ Metrics::User.collection.update_one(
24
+ { _id: user.email },
25
+ {
26
+ '$set' => {
27
+ admin: user.admin?,
28
+ tags: user.tags,
29
+ updated_at: Time.current.utc
30
+ }
31
+ },
32
+ upsert: true
33
+ )
24
34
  end
25
35
  end
26
36
  end
@@ -70,7 +70,7 @@ module Workarea
70
70
  end
71
71
 
72
72
  def to_s
73
- @to_s ||= @varies.map { |v| visit.instance_exec(&v).to_s }.join(':')
73
+ @to_s ||= ([I18n.locale] + @varies.map { |v| visit.instance_exec(&v).to_s }).join(':')
74
74
  end
75
75
  end
76
76
  end
@@ -131,6 +131,7 @@ require 'workarea/ext/freedom_patches/dragonfly_callable_url_host'
131
131
  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
+ require 'workarea/ext/freedom_patches/mongoid_localized_defaults'
134
135
  require 'workarea/ext/mongoid/list_field'
135
136
  require 'workarea/ext/mongoid/each_by'
136
137
  require 'workarea/ext/mongoid/except'
@@ -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,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
@@ -57,15 +57,7 @@ module Workarea
57
57
  end
58
58
 
59
59
  def names
60
- @names ||= [
61
- postal_code,
62
- city,
63
- region,
64
- subdivision&.name,
65
- country&.alpha2,
66
- country&.alpha3,
67
- country&.name
68
- ].reject(&:blank?)
60
+ @names ||= [postal_code, city, subdivision&.name, country&.name].reject(&:blank?)
69
61
  end
70
62
 
71
63
  private
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 5
5
- PATCH = 8
5
+ PATCH = 9
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
8
8
 
@@ -7,12 +7,14 @@ module Workarea
7
7
  params[:controller] = 'controller'
8
8
  params[:action] = 'action'
9
9
  params[:foo] = 'bar'
10
+ params[:locale] = 'es'
10
11
 
11
12
  assert_includes(switch_locale_fields, 'foo')
12
13
  assert_includes(switch_locale_fields, 'bar')
13
14
  refute_includes(switch_locale_fields, 'utf8')
14
15
  refute_includes(switch_locale_fields, 'controller')
15
16
  refute_includes(switch_locale_fields, 'action')
17
+ refute_includes(switch_locale_fields, 'locale')
16
18
  end
17
19
  end
18
20
  end
@@ -185,5 +185,15 @@ module Workarea
185
185
  get '/test_logout'
186
186
  refute(cookies[:email].present?)
187
187
  end
188
+
189
+ def test_ensures_locale_passthrough_for_return_to
190
+ set_locales(available: [:en, :es], default: :en, current: :en)
191
+
192
+ get '/login_required', params: { locale: 'es', return_to: '/blah?foo=bar' }
193
+ get '/test_login', params: { user_id: @user.id }
194
+ assert(response.redirect?)
195
+ assert_match('locale=es', response.location)
196
+ assert_match('foo=bar', response.location)
197
+ end
188
198
  end
189
199
  end
@@ -25,6 +25,10 @@ module Workarea
25
25
  render plain: session[:foo].presence || 'nil'
26
26
  end
27
27
 
28
+ def varies
29
+ render plain: request.env['workarea.cache_varies']
30
+ end
31
+
28
32
  def current_user
29
33
  nil
30
34
  end
@@ -34,6 +38,11 @@ module Workarea
34
38
  Rails.application.routes.prepend do
35
39
  post 'cache_varies_test_set_session', to: 'workarea/cache_varies_integration_test/caching#set_session'
36
40
  get 'cache_varies_test_foo', to: 'workarea/cache_varies_integration_test/caching#foo'
41
+
42
+ scope '(:locale)', constraints: Workarea::I18n.routes_constraint do
43
+ get 'cache_varies_test_varies', to: 'workarea/cache_varies_integration_test/caching#varies'
44
+ patch 'cache_varies_test_varies', to: 'workarea/cache_varies_integration_test/caching#varies'
45
+ end
37
46
  end
38
47
 
39
48
  Rails.application.reload_routes!
@@ -74,5 +83,27 @@ module Workarea
74
83
  assert_equal('baz', response.body)
75
84
  assert_equal('fresh', response.headers['X-Rack-Cache'])
76
85
  end
86
+
87
+ def test_varies_includes_locale
88
+ set_locales(available: [:en, :es], default: :en, current: :en)
89
+
90
+ get '/cache_varies_test_varies'
91
+ assert_includes(response.body, 'en')
92
+
93
+ get '/cache_varies_test_varies', params: { locale: 'es' }
94
+ assert_includes(response.body, 'es')
95
+
96
+ get '/es/cache_varies_test_varies'
97
+ assert_includes(response.body, 'es')
98
+
99
+ patch '/cache_varies_test_varies'
100
+ assert_includes(response.body, 'en')
101
+
102
+ patch '/cache_varies_test_varies', params: { locale: 'es' }
103
+ assert_includes(response.body, 'es')
104
+
105
+ patch '/es/cache_varies_test_varies'
106
+ assert_includes(response.body, 'es')
107
+ end
77
108
  end
78
109
  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
@@ -94,10 +94,10 @@ module Workarea
94
94
  'HTTP_GEOIP_POSTAL_CODE' => '19106'
95
95
  )
96
96
 
97
- assert_includes(location.names, 'US')
98
- assert_includes(location.names, 'USA')
97
+ refute_includes(location.names, 'US')
98
+ refute_includes(location.names, 'USA')
99
99
  assert_includes(location.names, 'United States of America')
100
- assert_includes(location.names, 'PA')
100
+ refute_includes(location.names, 'PA')
101
101
  assert_includes(location.names, 'Pennsylvania')
102
102
  assert_includes(location.names, 'Philadelphia')
103
103
  assert_includes(location.names, '19106')
@@ -7,12 +7,15 @@ module Workarea
7
7
  def test_qualifies?
8
8
  refute(Geolocation.new.qualifies?(create_visit))
9
9
 
10
- visit = create_visit('HTTP_GEOIP_REGION' => 'PA')
10
+ visit = create_visit(
11
+ 'HTTP_GEOIP_REGION' => 'PA',
12
+ 'HTTP_GEOIP_CITY_COUNTRY_CODE' => 'US'
13
+ )
11
14
  refute(Geolocation.new(locations: %w(NJ)).qualifies?(visit))
12
- assert(Geolocation.new(locations: %w(pa)).qualifies?(visit))
13
- assert(Geolocation.new(locations: %w(PA)).qualifies?(visit))
14
- assert(Geolocation.new(locations: %w(NJ PA)).qualifies?(visit))
15
- refute(Geolocation.new(locations: %w(NJ NY)).qualifies?(visit))
15
+ assert(Geolocation.new(locations: %w(us-pa)).qualifies?(visit))
16
+ assert(Geolocation.new(locations: %w(US-PA)).qualifies?(visit))
17
+ assert(Geolocation.new(locations: %w(US-NJ US-pa)).qualifies?(visit))
18
+ refute(Geolocation.new(locations: %w(US-NJ US-NY)).qualifies?(visit))
16
19
 
17
20
  visit = create_visit(
18
21
  'HTTP_GEOIP_REGION' => 'PA',
@@ -26,14 +29,13 @@ module Workarea
26
29
  assert(Geolocation.new(locations: %w(Philadelphia)).qualifies?(visit))
27
30
  assert(Geolocation.new(locations: %w(Philadelphia US)).qualifies?(visit))
28
31
  refute(Geolocation.new(locations: %w(Harrisburg)).qualifies?(visit))
29
- refute(Geolocation.new(locations: %w(Harrisburg PA)).qualifies?(visit))
32
+ refute(Geolocation.new(locations: %w(Harrisburg US-PA)).qualifies?(visit))
30
33
  assert(Geolocation.new(locations: %w(Philadelphia Harrisburg)).qualifies?(visit))
31
34
  refute(Geolocation.new(locations: %w(Pittsburgh Harrisburg)).qualifies?(visit))
32
35
 
33
36
  visit = create_visit('HTTP_GEOIP_CITY_COUNTRY_CODE' => 'US')
34
37
  refute(Geolocation.new(locations: %w(CA)).qualifies?(visit))
35
38
  assert(Geolocation.new(locations: %w(US)).qualifies?(visit))
36
- assert(Geolocation.new(locations: %w(USA)).qualifies?(visit))
37
39
  assert(Geolocation.new(locations: ['United States of America']).qualifies?(visit))
38
40
  assert(Geolocation.new(locations: %w(Philadelphia US)).qualifies?(visit))
39
41
  assert(Geolocation.new(locations: %w(US CA)).qualifies?(visit))
@@ -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
@@ -36,6 +36,17 @@ module Workarea
36
36
  assert_equal(release.id, results.first.release_id)
37
37
  refute_equal(product.object_id, results.first.model.object_id)
38
38
  end
39
+
40
+ def test_entry_flattening
41
+ products = Array.new(2) { create_product }
42
+ release = create_release
43
+ release.as_current { products.first.update!(name: 'Bar') }
44
+
45
+ instance = ProductEntries.new(products)
46
+ instance.stubs(:index_entries_for).returns([:foo, :bar])
47
+
48
+ assert_equal([:foo, :bar, :foo, :bar, :foo, :bar], instance.entries)
49
+ end
39
50
  end
40
51
  end
41
52
  end
@@ -425,6 +425,19 @@ module Workarea
425
425
  assert_equal([product], ProductSearch.new(q: '*').results.pluck(:model))
426
426
  end
427
427
  end
428
+
429
+ def test_locale
430
+ set_locales(available: [:en, :es], default: :en, current: :en)
431
+ Search::Storefront.reset_indexes!
432
+
433
+ product = create_product(active_translations: { 'en' => true, 'es' => false })
434
+
435
+ I18n.locale = :es
436
+ assert_equal([], ProductSearch.new(q: '*').results.pluck(:model))
437
+
438
+ I18n.locale = :en
439
+ assert_equal([product], ProductSearch.new(q: '*').results.pluck(:model))
440
+ end
428
441
  end
429
442
  end
430
443
  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.8
4
+ version: 3.5.9
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-31 00:00:00.000000000 Z
11
+ date: 2020-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -1920,6 +1920,7 @@ files:
1920
1920
  - lib/workarea/ext/freedom_patches/float.rb
1921
1921
  - lib/workarea/ext/freedom_patches/global_id.rb
1922
1922
  - lib/workarea/ext/freedom_patches/money.rb
1923
+ - lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
1923
1924
  - lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb
1924
1925
  - lib/workarea/ext/freedom_patches/net_http_ssl_connection.rb
1925
1926
  - lib/workarea/ext/freedom_patches/premailer.rb
@@ -2081,6 +2082,7 @@ files:
2081
2082
  - test/lib/workarea/ext/freedom_patches/dragonfly_callable_url_host_test.rb
2082
2083
  - test/lib/workarea/ext/freedom_patches/global_id_test.rb
2083
2084
  - test/lib/workarea/ext/freedom_patches/money_test.rb
2085
+ - test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb
2084
2086
  - test/lib/workarea/ext/freedom_patches/mongoid_simple_tags_test.rb
2085
2087
  - test/lib/workarea/ext/mongoid/audit_log_entry_test.rb
2086
2088
  - test/lib/workarea/ext/mongoid/each_by_test.rb