workarea-core 3.5.15 → 3.5.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/workarea/current_tracking.rb +4 -2
  3. data/app/controllers/workarea/impersonation.rb +4 -2
  4. data/app/mailers/workarea/application_mailer.rb +4 -1
  5. data/app/middleware/workarea/application_middleware.rb +5 -2
  6. data/app/models/workarea/checkout.rb +7 -7
  7. data/app/models/workarea/data_file/csv.rb +9 -1
  8. data/app/models/workarea/inquiry.rb +2 -1
  9. data/app/models/workarea/inventory/sku.rb +2 -2
  10. data/app/models/workarea/metrics/user.rb +24 -8
  11. data/app/models/workarea/order.rb +10 -0
  12. data/app/models/workarea/order/item.rb +4 -4
  13. data/app/models/workarea/payment.rb +1 -6
  14. data/app/models/workarea/search/admin/inventory_sku.rb +5 -1
  15. data/app/models/workarea/shipping/service.rb +12 -5
  16. data/app/models/workarea/tax/rate.rb +3 -1
  17. data/app/queries/workarea/search/admin_search.rb +4 -0
  18. data/app/queries/workarea/search/admin_sorting.rb +1 -1
  19. data/config/initializers/00_configuration.rb +23 -8
  20. data/config/initializers/22_session_store.rb +1 -1
  21. data/config/locales/en.yml +3 -0
  22. data/lib/generators/workarea/install/install_generator.rb +13 -0
  23. data/lib/generators/workarea/install/templates/initializer.rb.erb +1 -13
  24. data/lib/tasks/cache.rake +3 -33
  25. data/lib/tasks/help.rake +4 -43
  26. data/lib/tasks/insights.rake +3 -35
  27. data/lib/tasks/migrate.rake +3 -96
  28. data/lib/tasks/search.rake +6 -68
  29. data/lib/tasks/services.rake +4 -54
  30. data/lib/workarea/configuration.rb +11 -2
  31. data/lib/workarea/configuration/administrable_options.rb +1 -5
  32. data/lib/workarea/core/engine.rb +4 -0
  33. data/lib/workarea/tasks/cache.rb +43 -0
  34. data/lib/workarea/tasks/help.rb +55 -0
  35. data/lib/workarea/tasks/insights.rb +47 -0
  36. data/lib/workarea/tasks/migrate.rb +106 -0
  37. data/lib/workarea/tasks/search.rb +105 -0
  38. data/lib/workarea/tasks/services.rb +71 -0
  39. data/lib/workarea/version.rb +1 -1
  40. data/lib/workarea/visit.rb +8 -1
  41. data/test/generators/workarea/install_generator_test.rb +6 -2
  42. data/test/integration/workarea/authentication_test.rb +2 -1
  43. data/test/mailers/workarea/application_mailer_test.rb +10 -0
  44. data/test/models/workarea/checkout_test.rb +57 -0
  45. data/test/models/workarea/data_file/import_test.rb +40 -0
  46. data/test/models/workarea/order/item_test.rb +9 -0
  47. data/test/models/workarea/shipping/service_test.rb +26 -0
  48. data/test/queries/workarea/search/admin_search_test.rb +10 -0
  49. data/workarea-core.gemspec +1 -1
  50. metadata +10 -4
@@ -2,7 +2,7 @@ module Workarea
2
2
  module VERSION
3
3
  MAJOR = 3
4
4
  MINOR = 5
5
- PATCH = 15
5
+ PATCH = 20
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
@@ -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
 
@@ -81,5 +79,11 @@ module Workarea
81
79
  def test_favicon
82
80
  assert_no_file 'public/favicon.ico'
83
81
  end
82
+
83
+ def test_development_mailer_port
84
+ assert_file 'config/environments/development.rb' do |file|
85
+ assert_match(%(config.action_mailer.default_url_options = { port: 3000 }), file)
86
+ end
87
+ end
84
88
  end
85
89
  end
@@ -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
@@ -21,5 +21,15 @@ module Workarea
21
21
  assert_equal([changed_email], changed_mail.from)
22
22
  end
23
23
  end
24
+
25
+ def test_default_url_options
26
+ @current_options = Rails.application.config.action_mailer.default_url_options.deep_dup
27
+ Rails.application.config.action_mailer.default_url_options = { port: 12345 }
28
+
29
+ assert_equal(12345, ApplicationMailer.new.default_url_options[:port])
30
+
31
+ ensure
32
+ Rails.application.config.action_mailer.default_url_options = @current_options
33
+ end
24
34
  end
25
35
  end
@@ -51,6 +51,63 @@ module Workarea
51
51
  refute_equal(payment_id, checkout.payment.object_id)
52
52
  end
53
53
 
54
+ def test_update
55
+ create_shipping_service
56
+ checkout = Checkout.new(@order)
57
+
58
+ checkout.start_as(:guest)
59
+
60
+ refute(
61
+ checkout.update(
62
+ email: 'test@workarea.com',
63
+ shipping_address: {
64
+ last_name: 'Crouse',
65
+ street: '22 S. 3rd St.',
66
+ street_2: 'Second Floor',
67
+ city: 'Philadelphia',
68
+ region: 'PA',
69
+ postal_code: '19106',
70
+ country: 'US'
71
+ },
72
+ billing_address: {
73
+ first_name: 'Ben',
74
+ street: '22 S. 3rd St.',
75
+ street_2: 'Second Floor',
76
+ city: 'Philadelphia',
77
+ region: 'PA',
78
+ postal_code: '19106',
79
+ country: 'US'
80
+ }
81
+ )
82
+ )
83
+
84
+ assert(
85
+ checkout.update(
86
+ email: 'test@workarea.com',
87
+ shipping_address: {
88
+ first_name: 'Ben',
89
+ last_name: 'Crouse',
90
+ street: '22 S. 3rd St.',
91
+ street_2: 'Second Floor',
92
+ city: 'Philadelphia',
93
+ region: 'PA',
94
+ postal_code: '19106',
95
+ country: 'US'
96
+ },
97
+ billing_address: {
98
+ first_name: 'Ben',
99
+ last_name: 'Crouse',
100
+ street: '22 S. 3rd St.',
101
+ street_2: 'Second Floor',
102
+ city: 'Philadelphia',
103
+ region: 'PA',
104
+ postal_code: '19106',
105
+ country: 'US'
106
+ }
107
+ )
108
+ )
109
+ end
110
+
54
111
  def test_continue_as
55
112
  checkout = Checkout.new(@order)
56
113
  checkout.continue_as(@user)
@@ -132,6 +132,46 @@ module Workarea
132
132
  refute(import.error?)
133
133
  assert(import.successful?)
134
134
  end
135
+
136
+ def test_csv_embedded_changes_for_release
137
+ release = create_release
138
+ product = create_product(
139
+ name: 'Foo',
140
+ variants: [{ sku: '1', name: 'Bar' }, { sku: '2', name: 'Baz' }]
141
+ )
142
+ product.name = 'Foo Changed'
143
+ product.variants.first.name = 'Bar Changed'
144
+
145
+ import = create_import(
146
+ model_type: product.class.name,
147
+ file: create_tempfile(Csv.new.serialize(product), extension: 'csv'),
148
+ file_type: 'csv',
149
+ release_id: release.id
150
+ )
151
+
152
+ assert_equal('csv', import.file_type)
153
+ assert_nothing_raised { import.process! }
154
+
155
+ product.reload
156
+ assert_equal('Foo', product.name)
157
+ assert_equal('Bar', product.variants.first.name)
158
+ assert_equal('Baz', product.variants.second.name)
159
+
160
+ Release.with_current(release) do
161
+ product.reload
162
+ assert_equal('Foo Changed', product.name)
163
+ assert_equal('Bar Changed', product.variants.first.name)
164
+ assert_equal('Baz', product.variants.second.name)
165
+ end
166
+
167
+ import.reload
168
+ assert_equal(2, import.total)
169
+ assert_equal(2, import.succeeded)
170
+ assert_equal(0, import.failed)
171
+ assert(import.complete?)
172
+ refute(import.error?)
173
+ assert(import.successful?)
174
+ end
135
175
  end
136
176
  end
137
177
  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: []),
@@ -91,7 +91,7 @@ Gem::Specification.new do |s|
91
91
  s.add_dependency 'loofah', '~> 2.3.1'
92
92
  s.add_dependency 'referer-parser', '~> 0.3.0'
93
93
  s.add_dependency 'serviceworker-rails', '~> 0.5.5'
94
- s.add_dependency 'chartkick', '~> 3.3.0'
94
+ s.add_dependency 'chartkick', '~> 3.4.0'
95
95
  s.add_dependency 'browser', '~> 2.6.1'
96
96
  s.add_dependency 'puma', '>= 4.3.1'
97
97
  s.add_dependency 'rack' , '>= 2.1.4'
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.15
4
+ version: 3.5.20
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-07-07 00:00:00.000000000 Z
11
+ date: 2020-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -1100,14 +1100,14 @@ dependencies:
1100
1100
  requirements:
1101
1101
  - - "~>"
1102
1102
  - !ruby/object:Gem::Version
1103
- version: 3.3.0
1103
+ version: 3.4.0
1104
1104
  type: :runtime
1105
1105
  prerelease: false
1106
1106
  version_requirements: !ruby/object:Gem::Requirement
1107
1107
  requirements:
1108
1108
  - - "~>"
1109
1109
  - !ruby/object:Gem::Version
1110
- version: 3.3.0
1110
+ version: 3.4.0
1111
1111
  - !ruby/object:Gem::Dependency
1112
1112
  name: browser
1113
1113
  requirement: !ruby/object:Gem::Requirement
@@ -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