workarea-core 3.5.8 → 3.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/workarea/application_controller.rb +0 -5
- data/app/controllers/workarea/authentication.rb +6 -0
- data/app/helpers/workarea/i18n_helper.rb +1 -1
- data/app/middleware/workarea/application_middleware.rb +18 -0
- data/app/models/workarea/bulk_action/product_edit.rb +6 -6
- data/app/models/workarea/order.rb +3 -3
- 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 +2 -2
- data/app/models/workarea/search/storefront/product.rb +11 -2
- data/app/models/workarea/user/password_reset.rb +3 -1
- data/app/queries/workarea/product_releases.rb +6 -0
- data/app/queries/workarea/search/pagination.rb +4 -1
- data/app/queries/workarea/search/product_entries.rb +7 -5
- data/app/queries/workarea/search/storefront_search.rb +1 -1
- data/app/services/workarea/direct_upload.rb +17 -13
- data/app/services/workarea/hash_update.rb +15 -1
- data/app/workers/workarea/bulk_index_admin.rb +1 -1
- data/app/workers/workarea/bulk_index_products.rb +3 -2
- data/app/workers/workarea/bulk_index_searches.rb +4 -4
- data/app/workers/workarea/index_category_changes.rb +16 -3
- data/app/workers/workarea/process_import.rb +3 -3
- data/app/workers/workarea/reindex_release.rb +42 -0
- data/app/workers/workarea/synchronize_user_metrics.rb +12 -2
- data/lib/tasks/search.rake +10 -4
- data/lib/workarea/cache.rb +1 -1
- data/lib/workarea/changelog.rake +1 -1
- data/lib/workarea/core.rb +3 -0
- data/lib/workarea/elasticsearch/document.rb +15 -8
- data/lib/workarea/ext/freedom_patches/i18n_js.rb +27 -0
- data/lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb +25 -0
- data/lib/workarea/geolocation.rb +1 -9
- data/lib/workarea/queues_pauser.rb +26 -0
- data/lib/workarea/version.rb +1 -1
- data/lib/workarea/visit.rb +8 -1
- data/lib/workarea/warnings.rb +3 -4
- data/test/helpers/workarea/i18n_helper_test.rb +2 -0
- data/test/integration/workarea/authentication_test.rb +10 -0
- data/test/integration/workarea/cache_varies_integration_test.rb +31 -0
- data/test/lib/workarea/elasticsearch/document_test.rb +20 -0
- data/test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb +25 -0
- data/test/lib/workarea/geolocation_test.rb +3 -3
- data/test/models/workarea/releasable_test.rb +13 -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/models/workarea/segment/rules/geolocation_test.rb +9 -7
- data/test/models/workarea/user/password_reset_test.rb +12 -4
- data/test/queries/workarea/search/category_browse_test.rb +23 -0
- data/test/queries/workarea/search/pagination_test.rb +9 -0
- data/test/queries/workarea/search/product_entries_test.rb +11 -0
- data/test/queries/workarea/search/product_search_test.rb +16 -0
- data/test/services/workarea/direct_upload_test.rb +20 -3
- data/test/services/workarea/hash_update_test.rb +12 -12
- data/test/workers/workarea/process_import_test.rb +6 -0
- data/test/workers/workarea/reindex_release_test.rb +81 -0
- data/workarea-core.gemspec +4 -3
- metadata +29 -9
- data/test/queries/workarea/product_releases_test.rb +0 -56
@@ -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
|
-
|
98
|
-
|
97
|
+
refute_includes(location.names, 'US')
|
98
|
+
refute_includes(location.names, 'USA')
|
99
99
|
assert_includes(location.names, 'United States of America')
|
100
|
-
|
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')
|
@@ -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
|
@@ -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
|
@@ -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(
|
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
|
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
|
-
|
11
|
+
2.times do
|
12
|
+
PasswordReset.setup!(user.email)
|
12
13
|
|
13
|
-
|
14
|
-
|
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
|
@@ -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
|
@@ -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.config.per_page = 30
|
24
33
|
assert_equal(0, Paginate.new(page: 1).from)
|
@@ -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,22 @@ 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
|
+
# No simple way to run this test without fallbacks or localized fields
|
431
|
+
return unless Workarea.config.localized_active_fields
|
432
|
+
|
433
|
+
set_locales(available: [:en, :es], default: :en, current: :en)
|
434
|
+
Search::Storefront.reset_indexes!
|
435
|
+
|
436
|
+
product = create_product(active_translations: { 'en' => true, 'es' => false })
|
437
|
+
|
438
|
+
I18n.locale = :es
|
439
|
+
assert_equal([], ProductSearch.new(q: '*').results.pluck(:model))
|
440
|
+
|
441
|
+
I18n.locale = :en
|
442
|
+
assert_equal([product], ProductSearch.new(q: '*').results.pluck(:model))
|
443
|
+
end
|
428
444
|
end
|
429
445
|
end
|
430
446
|
end
|
@@ -108,11 +108,28 @@ 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
|
-
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_ensure_cors_with_no_existing_configuration
|
116
|
+
Workarea.s3.expects(:get_bucket_cors)
|
117
|
+
.raises(Excon::Errors::NotFound.new('CORS configuration does not exist'))
|
118
|
+
|
119
|
+
|
120
|
+
Workarea.s3.expects(:put_bucket_cors).with(
|
121
|
+
Configuration::S3.bucket,
|
122
|
+
'CORSConfiguration' => [
|
123
|
+
{
|
124
|
+
'ID' => "direct_upload_http://test.host",
|
125
|
+
'AllowedMethod' => 'PUT',
|
126
|
+
'AllowedOrigin' => 'http://test.host',
|
127
|
+
'AllowedHeader' => '*'
|
128
|
+
}
|
129
|
+
]
|
130
|
+
).returns(true)
|
131
|
+
|
132
|
+
assert(DirectUpload.ensure_cors!('http://test.host/admin/content_assets'))
|
116
133
|
end
|
117
134
|
|
118
135
|
private
|
@@ -2,23 +2,23 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Workarea
|
4
4
|
class HashUpdateTest < TestCase
|
5
|
-
def
|
6
|
-
|
5
|
+
def test_result
|
6
|
+
original = { 'foo' => 'bar' }
|
7
7
|
|
8
|
-
HashUpdate.new(adds: %w(key value)).
|
9
|
-
assert_equal(%w(value),
|
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)).
|
12
|
-
assert_equal(%w(baz),
|
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)).
|
15
|
-
refute_includes(
|
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 ']).
|
18
|
-
assert_equal(%w(one two),
|
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 ']).
|
21
|
-
assert_equal(%w(one two three),
|
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
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class ReindexReleaseTest < TestCase
|
5
|
+
include TestCase::SearchIndexing
|
6
|
+
|
7
|
+
setup :set_product
|
8
|
+
|
9
|
+
def set_product
|
10
|
+
@product = create_product(name: 'Foo')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_reschedule
|
14
|
+
a = create_release(name: 'A', publish_at: 1.week.from_now)
|
15
|
+
b = create_release(name: 'B', publish_at: 2.weeks.from_now)
|
16
|
+
c = create_release(name: 'C', publish_at: 4.weeks.from_now)
|
17
|
+
|
18
|
+
b.as_current { @product.update!(name: 'Bar') }
|
19
|
+
IndexProduct.perform(@product)
|
20
|
+
|
21
|
+
a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
22
|
+
b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
23
|
+
c.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
24
|
+
|
25
|
+
# Changing publish_at via `update` causes the release to publish due to Sidekiq inline
|
26
|
+
previous_publish_at = b.publish_at
|
27
|
+
b.set(publish_at: 5.weeks.from_now)
|
28
|
+
|
29
|
+
Sidekiq::Callbacks.enable(IndexProduct) { ReindexRelease.new.perform(b.id, previous_publish_at, b.publish_at) }
|
30
|
+
|
31
|
+
a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
32
|
+
b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
33
|
+
c.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_removing_from_schedule
|
37
|
+
a = create_release(name: 'A', publish_at: 1.week.from_now)
|
38
|
+
b = create_release(name: 'B', publish_at: 2.weeks.from_now)
|
39
|
+
c = create_release(name: 'C', publish_at: 4.weeks.from_now)
|
40
|
+
|
41
|
+
b.as_current { @product.update!(name: 'Bar') }
|
42
|
+
IndexProduct.perform(@product)
|
43
|
+
|
44
|
+
a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
45
|
+
b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
46
|
+
c.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
47
|
+
|
48
|
+
# Changing publish_at via `update` causes the release to publish due to Sidekiq inline
|
49
|
+
previous_publish_at = b.publish_at
|
50
|
+
b.set(publish_at: nil)
|
51
|
+
|
52
|
+
Sidekiq::Callbacks.enable(IndexProduct) { ReindexRelease.new.perform(b.id, previous_publish_at, nil) }
|
53
|
+
|
54
|
+
a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
55
|
+
b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
56
|
+
c.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_adding_to_schedule
|
60
|
+
a = create_release(name: 'A', publish_at: 1.week.from_now)
|
61
|
+
b = create_release(name: 'B')
|
62
|
+
c = create_release(name: 'C', publish_at: 4.weeks.from_now)
|
63
|
+
|
64
|
+
b.as_current { @product.update!(name: 'Bar') }
|
65
|
+
IndexProduct.perform(@product)
|
66
|
+
|
67
|
+
a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
68
|
+
b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
69
|
+
c.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
70
|
+
|
71
|
+
# Changing publish_at via `update` causes the release to publish due to Sidekiq inline
|
72
|
+
b.set(publish_at: 2.weeks.from_now)
|
73
|
+
|
74
|
+
Sidekiq::Callbacks.enable(IndexProduct) { ReindexRelease.new.perform(b.id, nil, b.publish_at) }
|
75
|
+
|
76
|
+
a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
77
|
+
b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
78
|
+
c.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|