workarea-core 3.5.13 → 3.5.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/workarea/impersonation.rb +2 -1
  3. data/app/mailers/workarea/application_mailer.rb +4 -1
  4. data/app/middleware/workarea/application_middleware.rb +5 -2
  5. data/app/models/workarea/checkout.rb +7 -7
  6. data/app/models/workarea/data_file/csv.rb +9 -1
  7. data/app/models/workarea/inquiry.rb +2 -1
  8. data/app/models/workarea/inventory/sku.rb +2 -2
  9. data/app/models/workarea/metrics/user.rb +24 -8
  10. data/app/models/workarea/order.rb +10 -0
  11. data/app/models/workarea/payment.rb +1 -6
  12. data/app/models/workarea/search/storefront/category_query.rb +1 -1
  13. data/app/queries/workarea/search/admin_search.rb +4 -0
  14. data/app/queries/workarea/search/admin_sorting.rb +1 -1
  15. data/app/services/workarea/index_release_schedule_previews.rb +37 -0
  16. data/app/workers/workarea/index_release_schedule_change.rb +32 -0
  17. data/app/workers/workarea/publish_release.rb +1 -0
  18. data/config/initializers/00_configuration.rb +3 -2
  19. data/config/locales/en.yml +2 -0
  20. data/lib/generators/workarea/install/install_generator.rb +13 -0
  21. data/lib/generators/workarea/install/templates/initializer.rb.erb +1 -13
  22. data/lib/tasks/cache.rake +3 -33
  23. data/lib/tasks/help.rake +4 -43
  24. data/lib/tasks/insights.rake +3 -35
  25. data/lib/tasks/migrate.rake +3 -96
  26. data/lib/tasks/search.rake +6 -68
  27. data/lib/tasks/services.rake +4 -54
  28. data/lib/workarea/configuration.rb +11 -2
  29. data/lib/workarea/configuration/administrable_options.rb +1 -5
  30. data/lib/workarea/core.rb +1 -0
  31. data/lib/workarea/core/engine.rb +4 -0
  32. data/lib/workarea/ext/jbuilder/jbuilder_cache.rb +29 -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/test/generators/workarea/install_generator_test.rb +6 -2
  41. data/test/mailers/workarea/application_mailer_test.rb +10 -0
  42. data/test/models/workarea/checkout_test.rb +57 -0
  43. data/test/models/workarea/data_file/import_test.rb +40 -0
  44. data/test/models/workarea/search/storefront/category_query_test.rb +11 -0
  45. data/test/queries/workarea/search/admin_search_test.rb +10 -0
  46. data/test/services/workarea/index_release_schedule_previews_test.rb +28 -0
  47. data/test/workers/workarea/{reindex_release_test.rb → index_release_schedule_change_test.rb} +30 -4
  48. data/test/workers/workarea/publish_release_test.rb +24 -0
  49. data/workarea-core.gemspec +2 -2
  50. metadata +17 -8
  51. data/app/workers/workarea/reindex_release.rb +0 -42
@@ -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
@@ -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
@@ -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: []),
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class IndexReleaseSchedulePreviewsTest < TestCase
5
+ def test_affected_releases
6
+ release = create_release
7
+ results = IndexReleaseSchedulePreviews.new(release: release).affected_releases
8
+ assert_equal([release], results)
9
+
10
+ a = create_release(publish_at: 1.week.from_now)
11
+ b = create_release(publish_at: 2.weeks.from_now)
12
+ c = create_release(publish_at: 4.weeks.from_now)
13
+ assert_equal([a, b, c], IndexReleaseSchedulePreviews.new.affected_releases)
14
+
15
+ results = IndexReleaseSchedulePreviews
16
+ .new(starts_at: 3.days.from_now, ends_at: 17.days.from_now)
17
+ .affected_releases
18
+
19
+ assert_equal([a, b], results)
20
+
21
+ results = IndexReleaseSchedulePreviews
22
+ .new(release: release, starts_at: 3.days.from_now, ends_at: 10.days.from_now)
23
+ .affected_releases
24
+
25
+ assert_equal([a, release], results)
26
+ end
27
+ end
28
+ end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Workarea
4
- class ReindexReleaseTest < TestCase
4
+ class IndexReleaseScheduleChangeTest < TestCase
5
5
  include TestCase::SearchIndexing
6
6
 
7
7
  setup :set_product
@@ -26,7 +26,9 @@ module Workarea
26
26
  previous_publish_at = b.publish_at
27
27
  b.set(publish_at: 5.weeks.from_now)
28
28
 
29
- Sidekiq::Callbacks.enable(IndexProduct) { ReindexRelease.new.perform(b.id, previous_publish_at, b.publish_at) }
29
+ Sidekiq::Callbacks.enable(IndexProduct) do
30
+ IndexReleaseScheduleChange.new.perform(b.id, previous_publish_at, b.publish_at)
31
+ end
30
32
 
31
33
  a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
32
34
  b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
@@ -49,7 +51,9 @@ module Workarea
49
51
  previous_publish_at = b.publish_at
50
52
  b.set(publish_at: nil)
51
53
 
52
- Sidekiq::Callbacks.enable(IndexProduct) { ReindexRelease.new.perform(b.id, previous_publish_at, nil) }
54
+ Sidekiq::Callbacks.enable(IndexProduct) do
55
+ IndexReleaseScheduleChange.new.perform(b.id, previous_publish_at, nil)
56
+ end
53
57
 
54
58
  a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
55
59
  b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
@@ -71,11 +75,33 @@ module Workarea
71
75
  # Changing publish_at via `update` causes the release to publish due to Sidekiq inline
72
76
  b.set(publish_at: 2.weeks.from_now)
73
77
 
74
- Sidekiq::Callbacks.enable(IndexProduct) { ReindexRelease.new.perform(b.id, nil, b.publish_at) }
78
+ Sidekiq::Callbacks.enable(IndexProduct) do
79
+ IndexReleaseScheduleChange.new.perform(b.id, nil, b.publish_at)
80
+ end
75
81
 
76
82
  a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
77
83
  b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
78
84
  c.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
79
85
  end
86
+
87
+ def test_destroyed
88
+ a = create_release(name: 'A', publish_at: 1.week.from_now)
89
+ b = create_release(name: 'B', publish_at: 2.weeks.from_now)
90
+ c = create_release(name: 'C', publish_at: 4.weeks.from_now)
91
+
92
+ b.as_current { @product.update!(name: 'Bar') }
93
+ IndexProduct.perform(@product)
94
+
95
+ a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
96
+ b.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
97
+ c.as_current { assert_equal([@product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
98
+
99
+ Sidekiq::Callbacks.enable(IndexReleaseScheduleChange, IndexProduct) do
100
+ b.destroy
101
+ end
102
+
103
+ a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
104
+ c.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
105
+ end
80
106
  end
81
107
  end
@@ -2,6 +2,8 @@ require 'test_helper'
2
2
 
3
3
  module Workarea
4
4
  class PublishReleaseTest < TestCase
5
+ include TestCase::SearchIndexing
6
+
5
7
  def test_publishes_the_release
6
8
  release = create_release
7
9
  PublishRelease.new.perform(release.id)
@@ -16,5 +18,27 @@ module Workarea
16
18
  assert_equal(1, Mongoid::AuditLog::Entry.count)
17
19
  assert(Mongoid::AuditLog::Entry.first.modifier.system?)
18
20
  end
21
+
22
+ def test_reindexes_release_schedule
23
+ product = create_product(name: 'Foo')
24
+
25
+ a = create_release(publish_at: 1.week.from_now)
26
+ b = create_release(publish_at: 2.weeks.from_now)
27
+ c = create_release(publish_at: 4.weeks.from_now)
28
+
29
+ b.as_current { product.update!(name: 'Bar') }
30
+ IndexProduct.perform(product)
31
+
32
+ assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model))
33
+ a.as_current { assert_empty(Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
34
+ b.as_current { assert_equal([product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
35
+ c.as_current { assert_equal([product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
36
+
37
+ Sidekiq::Callbacks.enable(IndexProduct) { PublishRelease.new.perform(b.id) }
38
+
39
+ assert_equal([product], Search::ProductSearch.new(q: 'bar').results.pluck(:model))
40
+ a.as_current { assert_equal([product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
41
+ c.as_current { assert_equal([product], Search::ProductSearch.new(q: 'bar').results.pluck(:model)) }
42
+ end
19
43
  end
20
44
  end
@@ -91,10 +91,10 @@ 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
- s.add_dependency 'rack', '>= 2.0.8'
97
+ s.add_dependency 'rack' , '>= 2.1.4'
98
98
 
99
99
  # HACK for vendoring active_shipping
100
100
  s.add_dependency 'active_utils', '~> 3.3.1'
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.13
4
+ version: 3.5.18
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-06-11 00:00:00.000000000 Z
11
+ date: 2020-09-01 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
@@ -1142,14 +1142,14 @@ dependencies:
1142
1142
  requirements:
1143
1143
  - - ">="
1144
1144
  - !ruby/object:Gem::Version
1145
- version: 2.0.8
1145
+ version: 2.1.4
1146
1146
  type: :runtime
1147
1147
  prerelease: false
1148
1148
  version_requirements: !ruby/object:Gem::Requirement
1149
1149
  requirements:
1150
1150
  - - ">="
1151
1151
  - !ruby/object:Gem::Version
1152
- version: 2.0.8
1152
+ version: 2.1.4
1153
1153
  - !ruby/object:Gem::Dependency
1154
1154
  name: active_utils
1155
1155
  requirement: !ruby/object:Gem::Requirement
@@ -1734,6 +1734,7 @@ files:
1734
1734
  - app/services/workarea/direct_upload/product_image.rb
1735
1735
  - app/services/workarea/export_report.rb
1736
1736
  - app/services/workarea/hash_update.rb
1737
+ - app/services/workarea/index_release_schedule_previews.rb
1737
1738
  - app/services/workarea/inventory_adjustment.rb
1738
1739
  - app/services/workarea/login.rb
1739
1740
  - app/services/workarea/new_discount.rb
@@ -1771,6 +1772,7 @@ files:
1771
1772
  - app/workers/workarea/index_product.rb
1772
1773
  - app/workers/workarea/index_product_children.rb
1773
1774
  - app/workers/workarea/index_product_rule.rb
1775
+ - app/workers/workarea/index_release_schedule_change.rb
1774
1776
  - app/workers/workarea/index_search_customizations.rb
1775
1777
  - app/workers/workarea/index_skus.rb
1776
1778
  - app/workers/workarea/keep_product_index_fresh.rb
@@ -1785,7 +1787,6 @@ files:
1785
1787
  - app/workers/workarea/publish_bulk_action.rb
1786
1788
  - app/workers/workarea/publish_release.rb
1787
1789
  - app/workers/workarea/redirect_navigable_slugs.rb
1788
- - app/workers/workarea/reindex_release.rb
1789
1790
  - app/workers/workarea/save_metrics.rb
1790
1791
  - app/workers/workarea/save_order_cancellation_metrics.rb
1791
1792
  - app/workers/workarea/save_order_metrics.rb
@@ -1945,6 +1946,7 @@ files:
1945
1946
  - lib/workarea/ext/freedom_patches/string.rb
1946
1947
  - lib/workarea/ext/freedom_patches/uri.rb
1947
1948
  - lib/workarea/ext/jbuilder/jbuilder_append_partials.rb
1949
+ - lib/workarea/ext/jbuilder/jbuilder_cache.rb
1948
1950
  - lib/workarea/ext/mongoid/audit_log_entry.decorator
1949
1951
  - lib/workarea/ext/mongoid/each_by.rb
1950
1952
  - lib/workarea/ext/mongoid/embedded_children.rb
@@ -1988,6 +1990,12 @@ files:
1988
1990
  - lib/workarea/string_id.rb
1989
1991
  - lib/workarea/svg_asset_finder.rb
1990
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
1991
1999
  - lib/workarea/url_token.rb
1992
2000
  - lib/workarea/validators/email_validator.rb
1993
2001
  - lib/workarea/validators/ip_address_validator.rb
@@ -2442,6 +2450,7 @@ files:
2442
2450
  - test/services/workarea/direct_upload_test.rb
2443
2451
  - test/services/workarea/export_report_test.rb
2444
2452
  - test/services/workarea/hash_update_test.rb
2453
+ - test/services/workarea/index_release_schedule_previews_test.rb
2445
2454
  - test/services/workarea/inventory_adjustment_test.rb
2446
2455
  - test/services/workarea/login_test.rb
2447
2456
  - test/services/workarea/order_merge_test.rb
@@ -2474,6 +2483,7 @@ files:
2474
2483
  - test/workers/workarea/index_payment_transactions_test.rb
2475
2484
  - test/workers/workarea/index_product_rule_test.rb
2476
2485
  - test/workers/workarea/index_product_test.rb
2486
+ - test/workers/workarea/index_release_schedule_change_test.rb
2477
2487
  - test/workers/workarea/index_skus_test.rb
2478
2488
  - test/workers/workarea/keep_product_index_fresh_test.rb
2479
2489
  - test/workers/workarea/mark_discounts_as_redeemed_test.rb
@@ -2484,7 +2494,6 @@ files:
2484
2494
  - test/workers/workarea/publish_bulk_action_test.rb
2485
2495
  - test/workers/workarea/publish_release_test.rb
2486
2496
  - test/workers/workarea/redirect_navigable_slugs_test.rb
2487
- - test/workers/workarea/reindex_release_test.rb
2488
2497
  - test/workers/workarea/save_order_metrics_test.rb
2489
2498
  - test/workers/workarea/save_user_order_details_test.rb
2490
2499
  - test/workers/workarea/send_refund_email_test.rb
@@ -1,42 +0,0 @@
1
- module Workarea
2
- class ReindexRelease
3
- include Sidekiq::Worker
4
- include Sidekiq::CallbacksWorker
5
-
6
- sidekiq_options(
7
- enqueue_on: {
8
- Release => :save,
9
- only_if: -> { publish_at_changed? },
10
- with: -> { [id, publish_at_was, publish_at] }
11
- },
12
- queue: 'high'
13
- )
14
-
15
- def perform(id, previous_publish_at, new_publish_at)
16
- rescheduled_release = Release.find(id)
17
- earlier, later = if previous_publish_at.present? && new_publish_at.present?
18
- [previous_publish_at, new_publish_at].sort
19
- elsif previous_publish_at.present?
20
- [previous_publish_at, nil]
21
- else
22
- [new_publish_at, nil]
23
- end
24
-
25
- affected_releases = Release.scheduled(after: earlier, before: later).includes(:changesets).to_a
26
- affected_releases += [rescheduled_release]
27
- affected_releases.uniq!
28
-
29
- affected_models = affected_releases.flat_map(&:changesets).flat_map(&:releasable)
30
-
31
- affected_releases.each do |release|
32
- affected_models.each do |releasable|
33
- Search::Storefront.new(releasable.in_release(release)).destroy
34
-
35
- # Different models have different indexing workers, running callbacks
36
- # ensures the appropriate worker is triggered
37
- releasable.run_callbacks(:save_release_changes)
38
- end
39
- end
40
- end
41
- end
42
- end