workarea-core 3.5.17 → 3.5.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/workarea/current_tracking.rb +6 -2
  3. data/app/controllers/workarea/impersonation.rb +4 -2
  4. data/app/middleware/workarea/application_middleware.rb +5 -2
  5. data/app/models/workarea/metrics/user.rb +18 -8
  6. data/app/models/workarea/order/item.rb +4 -4
  7. data/app/models/workarea/release.rb +8 -0
  8. data/app/models/workarea/search/admin/inventory_sku.rb +5 -1
  9. data/app/models/workarea/search/storefront.rb +1 -5
  10. data/app/models/workarea/search/storefront/product.rb +1 -14
  11. data/app/models/workarea/shipping/service.rb +12 -5
  12. data/app/models/workarea/tax/rate.rb +3 -1
  13. data/app/queries/workarea/product_releases.rb +1 -11
  14. data/app/queries/workarea/search/admin_search.rb +4 -0
  15. data/app/queries/workarea/search/admin_sorting.rb +1 -1
  16. data/app/queries/workarea/search/product_entries.rb +12 -6
  17. data/app/workers/workarea/update_email.rb +33 -0
  18. data/config/initializers/00_configuration.rb +23 -8
  19. data/config/initializers/05_scheduled_jobs.rb +1 -1
  20. data/config/initializers/22_session_store.rb +1 -1
  21. data/config/locales/en.yml +1 -0
  22. data/lib/generators/workarea/install/templates/initializer.rb.erb +0 -12
  23. data/lib/tasks/cache.rake +3 -33
  24. data/lib/tasks/help.rake +4 -43
  25. data/lib/tasks/insights.rake +3 -35
  26. data/lib/tasks/migrate.rake +3 -96
  27. data/lib/tasks/search.rake +6 -68
  28. data/lib/tasks/services.rake +4 -54
  29. data/lib/workarea.rb +10 -0
  30. data/lib/workarea/changelog.rake +1 -1
  31. data/lib/workarea/configuration.rb +4 -3
  32. data/lib/workarea/configuration/administrable_options.rb +2 -1
  33. data/lib/workarea/core/engine.rb +4 -0
  34. data/lib/workarea/scheduled_jobs.rb +1 -1
  35. data/lib/workarea/tasks/cache.rb +43 -0
  36. data/lib/workarea/tasks/help.rb +55 -0
  37. data/lib/workarea/tasks/insights.rb +47 -0
  38. data/lib/workarea/tasks/migrate.rb +106 -0
  39. data/lib/workarea/tasks/search.rb +105 -0
  40. data/lib/workarea/tasks/services.rb +71 -0
  41. data/lib/workarea/version.rb +1 -1
  42. data/lib/workarea/visit.rb +8 -1
  43. data/lib/workarea/warnings.rb +1 -1
  44. data/test/generators/workarea/install_generator_test.rb +0 -2
  45. data/test/integration/workarea/authentication_test.rb +2 -1
  46. data/test/lib/workarea/scheduled_jobs_test.rb +1 -5
  47. data/test/models/workarea/data_file/csv_test.rb +2 -1
  48. data/test/models/workarea/metrics/user_test.rb +55 -52
  49. data/test/models/workarea/order/item_test.rb +9 -0
  50. data/test/models/workarea/shipping/service_test.rb +26 -0
  51. data/test/queries/workarea/search/admin_search_test.rb +10 -0
  52. data/test/workers/workarea/status_reporter_test.rb +3 -1
  53. data/test/workers/workarea/update_email_test.rb +39 -0
  54. metadata +10 -4
  55. data/app/workers/workarea/update_payment_profile_email.rb +0 -22
  56. data/test/workers/workarea/update_payment_profile_email_test.rb +0 -27
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 5
5
- PATCH = 17
5
+ PATCH = 22
6
6
  PRE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
8
8
 
@@ -6,7 +6,6 @@ module Workarea
6
6
  attr_writer :override_segments
7
7
 
8
8
  delegate :postal_code, :city, :subdivision, :region, :country, to: :geolocation
9
- delegate :admin?, to: :metrics
10
9
 
11
10
  def initialize(env)
12
11
  @env = env
@@ -25,6 +24,14 @@ module Workarea
25
24
  session[:user_id].present?
26
25
  end
27
26
 
27
+ def impersonating?
28
+ session[:admin_id].present?
29
+ end
30
+
31
+ def admin?
32
+ (logged_in? && impersonating?) || metrics.admin?
33
+ end
34
+
28
35
  def request
29
36
  @request ||= ActionDispatch::Request.new(env)
30
37
  end
@@ -26,7 +26,7 @@ find their preference.
26
26
 
27
27
  def check_mongo_notable_scan
28
28
  if (Rails.env.development? &&
29
- !Workarea.config.skip_service_connections &&
29
+ !Workarea.skip_services? &&
30
30
  Configuration::Mongoid.indexes_enforced?)
31
31
  warn <<~eos
32
32
  **************************************************
@@ -55,8 +55,6 @@ module Workarea
55
55
  assert_file 'config/initializers/workarea.rb' do |file|
56
56
  assert_match(%(config.site_name =), file)
57
57
  assert_match(%(config.host =), file)
58
- assert_match(%(config.email_to =), file)
59
- assert_match(%(config.email_from =), file)
60
58
  end
61
59
  end
62
60
 
@@ -3,8 +3,9 @@ require 'test_helper'
3
3
  module Workarea
4
4
  class AuthenticationTest < IntegrationTest
5
5
  class AuthenticationController < Workarea::ApplicationController
6
- include Authentication
7
6
  include HttpCaching
7
+ include Authentication
8
+ include Impersonation
8
9
  include Storefront::CurrentCheckout
9
10
 
10
11
  before_action :cache_page, only: :cached
@@ -15,12 +15,8 @@ module Workarea
15
15
  end
16
16
 
17
17
  def test_redis_not_available
18
- @_skip_services = Workarea.config.skip_service_connections
19
- Workarea.config.skip_service_connections = true
20
-
18
+ Workarea.stubs(skip_services?: true)
21
19
  assert_nil(ScheduledJobs.clean)
22
- ensure
23
- Workarea.config.skip_service_connections = @_skip_services
24
20
  end
25
21
  end
26
22
  end
@@ -309,7 +309,8 @@ module Workarea
309
309
  end
310
310
 
311
311
  def test_blank_rows_are_ignored
312
- model = Foo.new(id: nil)
312
+ model = Foo.new
313
+ Foo.fields.keys.each { |f| model.send("#{f}=", nil) }
313
314
 
314
315
  import = create_import(
315
316
  model_type: Foo.name,
@@ -134,7 +134,7 @@ module Workarea
134
134
  def test_merging_metrics
135
135
  freeze_time
136
136
 
137
- metrics = User.create!(
137
+ first = User.create!(
138
138
  first_order_at: 2.weeks.ago,
139
139
  last_order_at: 1.day.ago,
140
140
  orders: 2,
@@ -147,41 +147,43 @@ module Workarea
147
147
  purchased: { product_ids: ['qoo'], category_ids: ['quo'], search_ids: ['qux'] }
148
148
  )
149
149
 
150
- metrics.merge!(User.new)
151
- metrics.reload
152
- assert_equal(2.weeks.ago, metrics.first_order_at)
153
- assert_equal(1.day.ago, metrics.last_order_at)
154
- assert_equal(2, metrics.orders)
155
- assert_equal(100, metrics.revenue)
156
- assert_equal(-10, metrics.discounts)
157
- assert_equal(50, metrics.average_order_value)
158
- assert_equal(1, metrics.cancellations)
159
- assert_equal(-20, metrics.refund)
160
- assert_equal(['foo'], metrics.viewed.product_ids)
161
- assert_equal(['bar'], metrics.viewed.category_ids)
162
- assert_equal(['baz'], metrics.viewed.search_ids)
163
- assert_equal(['qoo'], metrics.purchased.product_ids)
164
- assert_equal(['quo'], metrics.purchased.category_ids)
165
- assert_equal(['qux'], metrics.purchased.search_ids)
166
-
167
- blank = User.create!(id: 'foo').tap { |u| u.merge!(metrics) }
168
- blank.reload
169
- assert_equal(2.weeks.ago, blank.first_order_at)
170
- assert_equal(1.day.ago, blank.last_order_at)
171
- assert_equal(2, blank.orders)
172
- assert_equal(100, blank.revenue)
173
- assert_equal(-10, blank.discounts)
174
- assert_equal(50, blank.average_order_value)
175
- assert_equal(1, blank.cancellations)
176
- assert_equal(-20, blank.refund)
177
- assert_equal(['foo'], blank.viewed.product_ids)
178
- assert_equal(['bar'], blank.viewed.category_ids)
179
- assert_equal(['baz'], blank.viewed.search_ids)
180
- assert_equal(['qoo'], blank.purchased.product_ids)
181
- assert_equal(['quo'], blank.purchased.category_ids)
182
- assert_equal(['qux'], blank.purchased.search_ids)
183
-
184
- existing = User.create!(
150
+ first.merge!(User.new)
151
+ first.reload
152
+ assert_equal(1, Metrics::User.count)
153
+ assert_equal(2.weeks.ago, first.first_order_at)
154
+ assert_equal(1.day.ago, first.last_order_at)
155
+ assert_equal(2, first.orders)
156
+ assert_equal(100, first.revenue)
157
+ assert_equal(-10, first.discounts)
158
+ assert_equal(50, first.average_order_value)
159
+ assert_equal(1, first.cancellations)
160
+ assert_equal(-20, first.refund)
161
+ assert_equal(['foo'], first.viewed.product_ids)
162
+ assert_equal(['bar'], first.viewed.category_ids)
163
+ assert_equal(['baz'], first.viewed.search_ids)
164
+ assert_equal(['qoo'], first.purchased.product_ids)
165
+ assert_equal(['quo'], first.purchased.category_ids)
166
+ assert_equal(['qux'], first.purchased.search_ids)
167
+
168
+ second = User.create!(id: 'foo').tap { |u| u.merge!(first) }
169
+ second.reload
170
+ assert_equal(1, Metrics::User.count)
171
+ assert_equal(2.weeks.ago, second.first_order_at)
172
+ assert_equal(1.day.ago, second.last_order_at)
173
+ assert_equal(2, second.orders)
174
+ assert_equal(100, second.revenue)
175
+ assert_equal(-10, second.discounts)
176
+ assert_equal(50, second.average_order_value)
177
+ assert_equal(1, second.cancellations)
178
+ assert_equal(-20, second.refund)
179
+ assert_equal(['foo'], second.viewed.product_ids)
180
+ assert_equal(['bar'], second.viewed.category_ids)
181
+ assert_equal(['baz'], second.viewed.search_ids)
182
+ assert_equal(['qoo'], second.purchased.product_ids)
183
+ assert_equal(['quo'], second.purchased.category_ids)
184
+ assert_equal(['qux'], second.purchased.search_ids)
185
+
186
+ third = User.create!(
185
187
  first_order_at: 3.weeks.ago,
186
188
  last_order_at: 3.weeks.ago,
187
189
  orders: 2,
@@ -191,22 +193,23 @@ module Workarea
191
193
  purchased: { product_ids: ['four'], category_ids: ['five'], search_ids: ['six'] }
192
194
  )
193
195
 
194
- existing.merge!(metrics)
195
- existing.reload
196
- assert_equal(3.weeks.ago, existing.first_order_at)
197
- assert_equal(1.day.ago, existing.last_order_at)
198
- assert_equal(4, existing.orders)
199
- assert_equal(220, existing.revenue)
200
- assert_equal(-10, existing.discounts)
201
- assert_equal(55, existing.average_order_value)
202
- assert_equal(1, existing.cancellations)
203
- assert_equal(-20, existing.refund)
204
- assert_equal(%w(one foo), existing.viewed.product_ids)
205
- assert_equal(%w(two bar), existing.viewed.category_ids)
206
- assert_equal(%w(three baz), existing.viewed.search_ids)
207
- assert_equal(%w(four qoo), existing.purchased.product_ids)
208
- assert_equal(%w(five quo), existing.purchased.category_ids)
209
- assert_equal(%w(six qux), existing.purchased.search_ids)
196
+ third.merge!(second)
197
+ third.reload
198
+ assert_equal(1, Metrics::User.count)
199
+ assert_equal(3.weeks.ago, third.first_order_at)
200
+ assert_equal(1.day.ago, third.last_order_at)
201
+ assert_equal(4, third.orders)
202
+ assert_equal(220, third.revenue)
203
+ assert_equal(-10, third.discounts)
204
+ assert_equal(55, third.average_order_value)
205
+ assert_equal(1, third.cancellations)
206
+ assert_equal(-20, third.refund)
207
+ assert_equal(%w(one foo), third.viewed.product_ids)
208
+ assert_equal(%w(two bar), third.viewed.category_ids)
209
+ assert_equal(%w(three baz), third.viewed.search_ids)
210
+ assert_equal(%w(four qoo), third.purchased.product_ids)
211
+ assert_equal(%w(five quo), third.purchased.category_ids)
212
+ assert_equal(%w(six qux), third.purchased.search_ids)
210
213
  end
211
214
  end
212
215
  end
@@ -55,6 +55,15 @@ module Workarea
55
55
  )
56
56
  assert(item.on_sale?)
57
57
  end
58
+
59
+ def test_fulfilled_by?
60
+ item.fulfillment = 'shipping'
61
+ assert(item.fulfilled_by?(:shipping))
62
+ assert(item.fulfilled_by?(:shipping, :download))
63
+ refute(item.fulfilled_by?(:download))
64
+ assert(item.shipping?)
65
+ refute(item.download?)
66
+ end
58
67
  end
59
68
  end
60
69
  end
@@ -35,6 +35,32 @@ module Workarea
35
35
  assert_equal(3.to_m, shipping_service.find_rate(7.to_m).price)
36
36
  assert_equal(2.to_m, shipping_service.find_rate(10.to_m).price)
37
37
  end
38
+
39
+ def test_find_tax_code
40
+ create_shipping_service(name: 'Ground', carrier: 'UPS', tax_code: '001')
41
+ create_shipping_service(name: 'Express', carrier: 'UPS', tax_code: nil)
42
+ Workarea.config.default_shipping_service_tax_code = nil
43
+
44
+ assert_equal('001', Service.find_tax_code('UPS', 'Ground'))
45
+ assert_nil(Service.find_tax_code('UPS', 'Express'))
46
+ assert_nil(Service.find_tax_code('FedEx', 'Express'))
47
+
48
+ Workarea.config.default_shipping_service_tax_code = '101'
49
+
50
+ assert_equal('001', Service.find_tax_code('UPS', 'Ground'))
51
+ assert_nil(Service.find_tax_code('UPS', 'Express'))
52
+ assert_equal('101', Service.find_tax_code('FedEx', 'Express'))
53
+ assert_equal('101', Service.find_tax_code('FedEx', 'Express'))
54
+
55
+ Workarea.config.default_shipping_service_tax_code = -> (carrier, name) do
56
+ carrier == 'FedEx' ? '101' : '001'
57
+ end
58
+
59
+ assert_equal('001', Service.find_tax_code('UPS', 'Ground'))
60
+ assert_nil(Service.find_tax_code('UPS', 'Express'))
61
+ assert_equal('101', Service.find_tax_code('FedEx', 'Express'))
62
+ assert_equal('001', Service.find_tax_code('DHL', 'Overnight'))
63
+ end
38
64
  end
39
65
  end
40
66
  end
@@ -81,6 +81,16 @@ module Workarea
81
81
  assert_equal(results.reverse, search.results)
82
82
  end
83
83
 
84
+ def test_default_sort_by_score
85
+ # Unlike other admin searches (primarily indexes), we want searching to
86
+ # default sort by score. Testing scores directly is unreliable so just
87
+ # do a simple check here.
88
+ assert_equal(
89
+ [{ _score: :desc }, { updated_at: :desc }],
90
+ AdminSearch.new.default_admin_sort
91
+ )
92
+ end
93
+
84
94
  def test_selected_sorting
85
95
  results = [
86
96
  create_product(name: 'A', variants: []),
@@ -12,8 +12,10 @@ module Workarea
12
12
 
13
13
  StatusReporter.new.perform
14
14
 
15
- assert(2, ActionMailer::Base.deliveries.count)
15
+ assert_equal(2, ActionMailer::Base.deliveries.count)
16
+
16
17
  delivery_emails = ActionMailer::Base.deliveries.map(&:to).flatten
18
+
17
19
  assert(delivery_emails.include?('foo@workarea.com'))
18
20
  assert(delivery_emails.include?('bar@workarea.com'))
19
21
  end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class UpdateEmailTest < TestCase
5
+ def test_updating_payment_profile
6
+ user = create_user(email: 'user@workarea.com')
7
+ profile = Payment::Profile.lookup(PaymentReference.new(user))
8
+
9
+ UpdateEmail.new.perform(user.id.to_s, 'email' => [nil, 'user@workarea.com'])
10
+ assert_equal(profile.reload.email, 'user@workarea.com')
11
+
12
+ UpdateEmail.new.perform(
13
+ user.id.to_s,
14
+ 'email' => ['user@workarea.com', 'test@workarea.com']
15
+ )
16
+ assert_equal(profile.reload.email, 'test@workarea.com')
17
+ end
18
+
19
+ def test_updating_metrics
20
+ user = create_user(email: 'user@workarea.com')
21
+ old_metrics = Metrics::User.find_or_initialize_by(id: 'user@workarea.com')
22
+ old_metrics.update!(orders: 3)
23
+
24
+ UpdateEmail.new.perform(user.id.to_s, 'email' => [nil, 'user@workarea.com'])
25
+ assert_equal(1, Metrics::User.count)
26
+ assert_equal(3, old_metrics.reload.orders)
27
+
28
+ new_metrics = Metrics::User.create!(id: 'test@workarea.com', orders: 1)
29
+
30
+ UpdateEmail.new.perform(
31
+ user.id.to_s,
32
+ 'email' => ['user@workarea.com', 'test@workarea.com']
33
+ )
34
+ assert_equal(1, Metrics::User.count)
35
+ assert_raises(Mongoid::Errors::DocumentNotFound) { old_metrics.reload }
36
+ assert_equal(4, new_metrics.reload.orders)
37
+ end
38
+ end
39
+ 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.17
4
+ version: 3.5.22
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-08-19 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -1795,7 +1795,7 @@ files:
1795
1795
  - app/workers/workarea/status_reporter.rb
1796
1796
  - app/workers/workarea/synchronize_user_metrics.rb
1797
1797
  - app/workers/workarea/update_elasticsearch_settings.rb
1798
- - app/workers/workarea/update_payment_profile_email.rb
1798
+ - app/workers/workarea/update_email.rb
1799
1799
  - app/workers/workarea/verify_scheduled_releases.rb
1800
1800
  - bin/rails
1801
1801
  - config/i18n-js.yml
@@ -1990,6 +1990,12 @@ files:
1990
1990
  - lib/workarea/string_id.rb
1991
1991
  - lib/workarea/svg_asset_finder.rb
1992
1992
  - lib/workarea/swappable_list.rb
1993
+ - lib/workarea/tasks/cache.rb
1994
+ - lib/workarea/tasks/help.rb
1995
+ - lib/workarea/tasks/insights.rb
1996
+ - lib/workarea/tasks/migrate.rb
1997
+ - lib/workarea/tasks/search.rb
1998
+ - lib/workarea/tasks/services.rb
1993
1999
  - lib/workarea/url_token.rb
1994
2000
  - lib/workarea/validators/email_validator.rb
1995
2001
  - lib/workarea/validators/ip_address_validator.rb
@@ -2493,7 +2499,7 @@ files:
2493
2499
  - test/workers/workarea/send_refund_email_test.rb
2494
2500
  - test/workers/workarea/status_reporter_test.rb
2495
2501
  - test/workers/workarea/synchronize_user_metrics_test.rb
2496
- - test/workers/workarea/update_payment_profile_email_test.rb
2502
+ - test/workers/workarea/update_email_test.rb
2497
2503
  - test/workers/workarea/verify_scheduled_releases_test.rb
2498
2504
  - vendor/active_shipping/.gitignore
2499
2505
  - vendor/active_shipping/.travis.yml
@@ -1,22 +0,0 @@
1
- module Workarea
2
- class UpdatePaymentProfileEmail
3
- include Sidekiq::Worker
4
- include Sidekiq::CallbacksWorker
5
-
6
- sidekiq_options(
7
- enqueue_on: { User => :update, with: -> { [id, changes] } }
8
- )
9
-
10
- def perform(id, changes)
11
- if changes['email'].present? && changes['email'].first.present?
12
- old_email = changes['email'].first
13
- new_email = changes['email'].last
14
-
15
- user = User.find(id)
16
- user.email = old_email # set old email so we lookup by old email value
17
-
18
- Payment::Profile.update_email(PaymentReference.new(user), new_email)
19
- end
20
- end
21
- end
22
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Workarea
4
- class UpdatePaymentProfileEmailTest < Workarea::TestCase
5
- setup do
6
- @user = create_user(email: 'user@workarea.com')
7
- @profile = Payment::Profile.lookup(PaymentReference.new(@user))
8
- @worker = UpdatePaymentProfileEmail.new
9
- end
10
-
11
- def test_updating_payment_profile_email_address
12
- @worker.perform(
13
- @user.id.to_s,
14
- 'email' => ['user@workarea.com', 'test@workarea.com']
15
- )
16
-
17
- @profile.reload
18
- assert_equal(@profile.email, 'test@workarea.com')
19
- end
20
-
21
- def test_skipping_update_if_email_change_is_nil
22
- @worker.perform(@user.id.to_s, 'email' => [nil, 'user@workarea.com'])
23
- @profile.reload
24
- assert_equal(@profile.email, 'user@workarea.com')
25
- end
26
- end
27
- end