workarea-core 3.5.12 → 3.5.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/mailers/workarea/application_mailer.rb +4 -1
- data/app/models/workarea/checkout.rb +7 -7
- data/app/models/workarea/data_file/csv.rb +9 -1
- data/app/models/workarea/inquiry.rb +2 -1
- data/app/models/workarea/inventory/sku.rb +2 -2
- data/app/models/workarea/metrics/user.rb +24 -8
- data/app/models/workarea/order.rb +13 -3
- data/app/models/workarea/payment.rb +1 -6
- data/app/models/workarea/releasable.rb +3 -1
- data/app/models/workarea/release/changeset.rb +1 -0
- data/app/models/workarea/search/admin/pricing_discount.rb +1 -1
- data/app/models/workarea/search/storefront.rb +9 -1
- data/app/models/workarea/search/storefront/category_query.rb +1 -1
- data/app/models/workarea/search/storefront/product.rb +11 -2
- data/app/queries/workarea/product_releases.rb +6 -0
- data/app/services/workarea/direct_upload.rb +6 -1
- data/app/services/workarea/index_release_schedule_previews.rb +37 -0
- data/app/workers/workarea/index_category_changes.rb +16 -3
- data/app/workers/workarea/index_release_schedule_change.rb +32 -0
- data/app/workers/workarea/publish_release.rb +1 -0
- data/config/locales/en.yml +2 -0
- data/lib/generators/workarea/install/install_generator.rb +13 -0
- data/lib/generators/workarea/install/templates/initializer.rb.erb +1 -1
- data/lib/tasks/search.rake +10 -4
- data/lib/workarea/configuration.rb +11 -0
- data/lib/workarea/configuration/administrable_options.rb +1 -5
- data/lib/workarea/core.rb +2 -0
- data/lib/workarea/ext/jbuilder/jbuilder_cache.rb +29 -0
- data/lib/workarea/queues_pauser.rb +26 -0
- data/lib/workarea/version.rb +1 -1
- data/test/generators/workarea/install_generator_test.rb +6 -0
- data/test/mailers/workarea/application_mailer_test.rb +10 -0
- data/test/models/workarea/checkout_test.rb +57 -0
- data/test/models/workarea/data_file/import_test.rb +40 -0
- data/test/models/workarea/releasable_test.rb +13 -0
- data/test/models/workarea/search/storefront/category_query_test.rb +11 -0
- data/test/models/workarea/search/storefront/product_releases_test.rb +60 -0
- data/test/models/workarea/search/storefront_test.rb +13 -0
- data/test/queries/workarea/search/category_browse_test.rb +23 -0
- data/test/services/workarea/direct_upload_test.rb +20 -0
- data/test/services/workarea/index_release_schedule_previews_test.rb +28 -0
- data/test/workers/workarea/index_release_schedule_change_test.rb +107 -0
- data/test/workers/workarea/publish_release_test.rb +24 -0
- data/workarea-core.gemspec +6 -5
- metadata +33 -13
- data/test/queries/workarea/product_releases_test.rb +0 -56
data/lib/tasks/search.rake
CHANGED
@@ -16,7 +16,9 @@ namespace :workarea do
|
|
16
16
|
task admin: :environment do
|
17
17
|
setup
|
18
18
|
puts 'Indexing admin...'
|
19
|
-
Workarea::
|
19
|
+
Workarea::QueuesPauser.with_paused_queues do
|
20
|
+
Workarea::Search::Admin.reset_indexes!
|
21
|
+
end
|
20
22
|
|
21
23
|
Mongoid.models.each do |klass|
|
22
24
|
next unless Workarea::Search::Admin.for(klass.first).present?
|
@@ -36,8 +38,10 @@ namespace :workarea do
|
|
36
38
|
setup
|
37
39
|
puts 'Indexing storefront...'
|
38
40
|
|
39
|
-
Workarea::
|
40
|
-
|
41
|
+
Workarea::QueuesPauser.with_paused_queues do
|
42
|
+
Workarea::Search::Storefront.reset_indexes!
|
43
|
+
Workarea::Search::Storefront.ensure_dynamic_mappings
|
44
|
+
end
|
41
45
|
|
42
46
|
# This code finds all unique filters for products so we can index a sample
|
43
47
|
# product for each to ensure the dynamic mappings get created.
|
@@ -83,7 +87,9 @@ namespace :workarea do
|
|
83
87
|
setup
|
84
88
|
puts 'Indexing help...'
|
85
89
|
|
86
|
-
Workarea::
|
90
|
+
Workarea::QueuesPauser.with_paused_queues do
|
91
|
+
Workarea::Search::Help.reset_indexes!
|
92
|
+
end
|
87
93
|
|
88
94
|
Workarea::Help::Article.all.each_by(Workarea.config.bulk_index_batch_size) do |help_article|
|
89
95
|
Workarea::Search::Help.new(help_article).save
|
@@ -1297,6 +1297,17 @@ module Workarea
|
|
1297
1297
|
|
1298
1298
|
# The number of results that will show per-type in the admin jump to
|
1299
1299
|
config.jump_to_results_per_type = 5
|
1300
|
+
|
1301
|
+
# Attributes that will be sliced out of params and persisted on
|
1302
|
+
# the credit card tender during checkout.
|
1303
|
+
config.credit_card_attributes = %i[
|
1304
|
+
month
|
1305
|
+
year
|
1306
|
+
saved_card_id
|
1307
|
+
number
|
1308
|
+
cvv
|
1309
|
+
amount
|
1310
|
+
]
|
1300
1311
|
end
|
1301
1312
|
end
|
1302
1313
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Workarea
|
2
2
|
module Configuration
|
3
3
|
class AdministrableOptions < ActiveSupport::InheritableOptions
|
4
|
-
def
|
4
|
+
def [](name)
|
5
5
|
static_config = super
|
6
6
|
return static_config if static_config.present? || static_config.to_s == 'false'
|
7
7
|
return static_config unless check_fieldsets?(name)
|
@@ -9,10 +9,6 @@ module Workarea
|
|
9
9
|
Configuration::Admin.instance.send(name)
|
10
10
|
end
|
11
11
|
|
12
|
-
def respond_to_missing?(name, include_private)
|
13
|
-
true
|
14
|
-
end
|
15
|
-
|
16
12
|
private
|
17
13
|
|
18
14
|
def check_fieldsets?(name)
|
data/lib/workarea/core.rb
CHANGED
@@ -146,6 +146,7 @@ require 'workarea/ext/mongoid/find_ordered'
|
|
146
146
|
require 'workarea/ext/mongoid/embedded_children'
|
147
147
|
require 'workarea/ext/sprockets/ruby_processor'
|
148
148
|
require 'workarea/ext/jbuilder/jbuilder_append_partials'
|
149
|
+
require 'workarea/ext/jbuilder/jbuilder_cache'
|
149
150
|
|
150
151
|
if Rails.env.development?
|
151
152
|
require 'workarea/ext/freedom_patches/routes_reloader'
|
@@ -221,6 +222,7 @@ require 'workarea/mail_interceptor'
|
|
221
222
|
require 'workarea/visit'
|
222
223
|
require 'workarea/warnings'
|
223
224
|
require 'workarea/latest_version'
|
225
|
+
require 'workarea/queues_pauser'
|
224
226
|
|
225
227
|
#
|
226
228
|
# Engines
|
@@ -0,0 +1,29 @@
|
|
1
|
+
decorate JbuilderTemplate, with: :workarea do
|
2
|
+
def _cache_fragment_for(*)
|
3
|
+
return yield if workarea_admin?
|
4
|
+
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def _cache_key(*)
|
9
|
+
super.tap do |result|
|
10
|
+
result << workarea_cache_varies if workarea_cache_varies.present?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def workarea_admin?
|
17
|
+
@context&.controller&.current_user&.admin?
|
18
|
+
rescue ::RuntimeError
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
def workarea_cache_varies
|
23
|
+
workarea_request_env['workarea.cache_varies']
|
24
|
+
end
|
25
|
+
|
26
|
+
def workarea_request_env
|
27
|
+
@context.controller.request.env || {}
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Workarea
|
2
|
+
module QueuesPauser
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def pause_queues!
|
6
|
+
pauser = Sidekiq::Throttled::QueuesPauser.instance
|
7
|
+
queues.each { |queue| pauser.pause!(queue) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def resume_queues!
|
11
|
+
pauser = Sidekiq::Throttled::QueuesPauser.instance
|
12
|
+
queues.each { |queue| pauser.resume!(queue) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_paused_queues(&block)
|
16
|
+
pause_queues!
|
17
|
+
yield
|
18
|
+
ensure
|
19
|
+
resume_queues!
|
20
|
+
end
|
21
|
+
|
22
|
+
def queues
|
23
|
+
Configuration::Sidekiq.queues
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/workarea/version.rb
CHANGED
@@ -81,5 +81,11 @@ module Workarea
|
|
81
81
|
def test_favicon
|
82
82
|
assert_no_file 'public/favicon.ico'
|
83
83
|
end
|
84
|
+
|
85
|
+
def test_development_mailer_port
|
86
|
+
assert_file 'config/environments/development.rb' do |file|
|
87
|
+
assert_match(%(config.action_mailer.default_url_options = { port: 3000 }), file)
|
88
|
+
end
|
89
|
+
end
|
84
90
|
end
|
85
91
|
end
|
@@ -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
|
@@ -375,6 +375,19 @@ module Workarea
|
|
375
375
|
in_release = model.in_release(nil)
|
376
376
|
assert_equal('Foo', in_release.name)
|
377
377
|
refute_equal(in_release.object_id, model.object_id)
|
378
|
+
|
379
|
+
Mongoid::QueryCache.cache do
|
380
|
+
cached = Foo.find(model.id) # a find to ensure it's in the cache table
|
381
|
+
cached.name = 'Bar' # so the cache table's instance has a change
|
382
|
+
|
383
|
+
in_release = model.in_release(nil)
|
384
|
+
assert_equal('Foo', in_release.name)
|
385
|
+
refute_equal(in_release.object_id, model.object_id)
|
386
|
+
refute_equal(cached.object_id, model.object_id)
|
387
|
+
end
|
388
|
+
|
389
|
+
ensure
|
390
|
+
Mongoid::QueryCache.clear_cache
|
378
391
|
end
|
379
392
|
|
380
393
|
def test_skip_changeset
|
@@ -75,6 +75,17 @@ module Workarea
|
|
75
75
|
assert_equal([@category.id.to_s], CategoryQuery.find_by_product(@product))
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
def test_deleted_releases
|
80
|
+
release = create_release
|
81
|
+
release.as_current do
|
82
|
+
@category.product_rules.first.update!(value: 'bar')
|
83
|
+
end
|
84
|
+
|
85
|
+
release.destroy
|
86
|
+
CategoryQuery.new(@category).update
|
87
|
+
assert_equal([@category.id.to_s], CategoryQuery.find_by_product(@product))
|
88
|
+
end
|
78
89
|
end
|
79
90
|
end
|
80
91
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Search
|
5
|
+
class Storefront
|
6
|
+
class ProductReleasesTest < TestCase
|
7
|
+
def test_product_changes
|
8
|
+
product = create_product(name: 'Foo')
|
9
|
+
release_one = create_release
|
10
|
+
release_one.as_current { product.update!(name: 'Bar') }
|
11
|
+
|
12
|
+
assert_equal([release_one], Product.new(product).releases)
|
13
|
+
|
14
|
+
release_one.update!(publish_at: 1.day.from_now)
|
15
|
+
release_two = create_release(publish_at: 3.days.from_now)
|
16
|
+
assert_equal([release_one, release_two], Product.new(product).releases)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_featured_product_changes
|
20
|
+
product = create_product
|
21
|
+
category = create_category
|
22
|
+
|
23
|
+
release_one = create_release
|
24
|
+
release_one.as_current { category.update!(product_ids: [product.id]) }
|
25
|
+
assert_equal([release_one], Product.new(product).releases)
|
26
|
+
|
27
|
+
release_one.update!(publish_at: 1.day.from_now)
|
28
|
+
release_two = create_release(publish_at: 3.days.from_now)
|
29
|
+
assert_equal([release_one, release_two], Product.new(product).releases)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_variant_changes
|
33
|
+
product = create_product(variants: [{ sku: 'SKU' }])
|
34
|
+
release = create_release
|
35
|
+
release.as_current { product.variants.first.update!(details: { color: 'Red' }) }
|
36
|
+
assert_equal([release], Product.new(product).releases)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_pricing_changes
|
40
|
+
product = create_product(variants: [{ sku: 'SKU' }])
|
41
|
+
pricing = Pricing::Sku.find('SKU')
|
42
|
+
|
43
|
+
release = create_release
|
44
|
+
release.as_current { pricing.prices.first.update!(regular: 10_000) }
|
45
|
+
assert_equal([release], Product.new(product).releases)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_changesets_with_missing_releases
|
49
|
+
product = create_product(name: 'Foo')
|
50
|
+
release = create_release
|
51
|
+
release.as_current { product.update!(name: 'Bar') }
|
52
|
+
release.delete
|
53
|
+
|
54
|
+
assert_nil(product.reload.changesets.first.release)
|
55
|
+
assert_equal([], Product.new(product).releases)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -25,6 +25,19 @@ module Workarea
|
|
25
25
|
release.as_current { category.product_rules.first.update!(value: 'bar') }
|
26
26
|
assert_equal(2, Storefront.new(category).changesets.size)
|
27
27
|
end
|
28
|
+
|
29
|
+
def test_releases
|
30
|
+
category = create_category(name: 'Foo')
|
31
|
+
assert_empty(Storefront.new(category).as_document[:changeset_release_ids])
|
32
|
+
|
33
|
+
a = create_release(publish_at: 1.week.from_now)
|
34
|
+
a.as_current { category.update!(name: 'Bar') }
|
35
|
+
assert_equal([a.id], Storefront.new(category).as_document[:changeset_release_ids])
|
36
|
+
|
37
|
+
b = create_release(publish_at: 2.weeks.from_now)
|
38
|
+
assert_includes(Storefront.new(category).as_document[:changeset_release_ids], a.id)
|
39
|
+
assert_includes(Storefront.new(category).as_document[:changeset_release_ids], b.id)
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
30
43
|
end
|
@@ -382,6 +382,29 @@ module Workarea
|
|
382
382
|
refute_includes(result_ids, product_five.id)
|
383
383
|
end
|
384
384
|
end
|
385
|
+
|
386
|
+
def test_featured_product_changes_in_a_release
|
387
|
+
one = create_product
|
388
|
+
two = create_product
|
389
|
+
three = create_product(name: 'Foo', active: false)
|
390
|
+
category = create_category(product_ids: [one.id, two.id], product_rules: [])
|
391
|
+
release = create_release(publish_at: 1.week.from_now)
|
392
|
+
|
393
|
+
release.as_current do
|
394
|
+
three.update!(name: 'Bar', active: true, default_category_id: category.id)
|
395
|
+
category.update!(product_ids: [three.id, one.id, two.id])
|
396
|
+
search = CategoryBrowse.new(sort: %w(featured), category_ids: [category.id])
|
397
|
+
sorts = search.results.pluck(:raw).pluck('_source').pluck('sorts').pluck(category.id.to_s)
|
398
|
+
assert_equal([0, 1, 2], sorts)
|
399
|
+
end
|
400
|
+
|
401
|
+
release.as_current do
|
402
|
+
category.update!(product_ids: [one.id, two.id, three.id])
|
403
|
+
search = CategoryBrowse.new(sort: %w(featured), category_ids: [category.id])
|
404
|
+
sorts = search.results.pluck(:raw).pluck('_source').pluck('sorts').pluck(category.id.to_s)
|
405
|
+
assert_equal([0, 1, 2], sorts)
|
406
|
+
end
|
407
|
+
end
|
385
408
|
end
|
386
409
|
end
|
387
410
|
end
|