workarea-core 3.4.29 → 3.4.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/workarea/bulk_action/product_edit.rb +6 -6
- data/app/models/workarea/search/admin.rb +11 -1
- data/app/models/workarea/search/admin/pricing_discount.rb +1 -1
- data/app/models/workarea/search/storefront/product/categories.rb +1 -1
- data/app/models/workarea/user/password_reset.rb +3 -1
- data/app/queries/workarea/search/pagination.rb +4 -1
- 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 +18 -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/process_import.rb +3 -3
- data/config/initializers/15_endpoint_monitoring.rb +6 -3
- data/lib/tasks/search.rake +10 -4
- data/lib/workarea/changelog.rake +1 -1
- data/lib/workarea/core.rb +3 -0
- data/lib/workarea/core/engine.rb +3 -4
- 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/queues_pauser.rb +26 -0
- data/lib/workarea/version.rb +1 -1
- data/test/integration/workarea/monitoring_integration_test.rb +10 -5
- 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/models/workarea/user/password_reset_test.rb +12 -4
- data/test/queries/workarea/search/pagination_test.rb +9 -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/workarea-core.gemspec +3 -3
- metadata +13 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 314c6ea37c26a932c59db1704e58543674eaf44df1751825d2141a7466c9069a
|
4
|
+
data.tar.gz: fc6e14cb1bb9c8cfc0d4d2c884847b30bba2c7a9bb62cbc15b722abbb71f90e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4970592a6e9a7bfee84f97b2bd5f9a3ad8d361f76af3c7ba537d870bb23f714e1aff417c6ed1e2694d65b0b0be993753fce7a34b9f18557900ece6dcfa90f9b6
|
7
|
+
data.tar.gz: 05cf391954ee8613ff48071f7f66ea68178e78f07b41a91ab545de6ed22f53feb721d11f56014aa21dd3e0d365c5aafc1839b142cbeaaa4f4a65a4d787a5a025
|
@@ -36,15 +36,15 @@ module Workarea
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def apply_details!(product)
|
39
|
-
HashUpdate
|
40
|
-
.new(adds: add_details, removes: remove_details)
|
41
|
-
.
|
39
|
+
product.details = HashUpdate
|
40
|
+
.new(original: product.details, adds: add_details, removes: remove_details)
|
41
|
+
.result
|
42
42
|
end
|
43
43
|
|
44
44
|
def apply_filters!(product)
|
45
|
-
HashUpdate
|
46
|
-
.new(adds: add_filters, removes: remove_filters)
|
47
|
-
.
|
45
|
+
product.filters = HashUpdate
|
46
|
+
.new(original: product.filters, adds: add_filters, removes: remove_filters)
|
47
|
+
.result
|
48
48
|
end
|
49
49
|
|
50
50
|
def apply_pricing!(product)
|
@@ -18,7 +18,17 @@ module Workarea
|
|
18
18
|
aggs: {
|
19
19
|
type: {
|
20
20
|
terms: { field: 'facets.type', size: Workarea.config.jump_to_type_limit },
|
21
|
-
aggs: {
|
21
|
+
aggs: {
|
22
|
+
top: {
|
23
|
+
top_hits: {
|
24
|
+
size: Workarea.config.jump_to_results_per_type,
|
25
|
+
sort: [
|
26
|
+
{ _score: { order: 'desc' } },
|
27
|
+
{ updated_at: { order: 'desc' } }
|
28
|
+
]
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
22
32
|
}
|
23
33
|
}
|
24
34
|
}
|
@@ -13,7 +13,7 @@ module Workarea
|
|
13
13
|
if category.product_rules.present?
|
14
14
|
document = {
|
15
15
|
id: category.id,
|
16
|
-
query: Categorization.new(rules: category.product_rules).query
|
16
|
+
query: Workarea::Search::Categorization.new(rules: category.product_rules).query
|
17
17
|
}
|
18
18
|
|
19
19
|
Storefront.current_index.save(document, type: 'category')
|
@@ -4,7 +4,7 @@ module Workarea
|
|
4
4
|
include ApplicationDocument
|
5
5
|
include UrlToken
|
6
6
|
|
7
|
-
belongs_to :user, class_name: 'Workarea::User'
|
7
|
+
belongs_to :user, class_name: 'Workarea::User', index: true
|
8
8
|
|
9
9
|
index(
|
10
10
|
{ created_at: 1 },
|
@@ -14,6 +14,8 @@ module Workarea
|
|
14
14
|
def self.setup!(email)
|
15
15
|
user = User.find_by_email(email)
|
16
16
|
return nil unless user
|
17
|
+
|
18
|
+
where(user_id: user.id).destroy_all
|
17
19
|
create!(user: user)
|
18
20
|
end
|
19
21
|
|
@@ -7,7 +7,10 @@ module Workarea
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def per_page
|
10
|
-
params[:per_page].
|
10
|
+
return Workarea.config.per_page if params[:per_page].blank?
|
11
|
+
|
12
|
+
tmp = params[:per_page].to_i
|
13
|
+
tmp > 0 ? tmp : Workarea.config.per_page
|
11
14
|
end
|
12
15
|
|
13
16
|
def size
|
@@ -6,22 +6,26 @@ module Workarea
|
|
6
6
|
uri = URI.parse(request_url)
|
7
7
|
url = "#{uri.scheme}://#{uri.host}"
|
8
8
|
url += ":#{uri.port}" unless uri.port.in? [80, 443]
|
9
|
+
id = "direct_upload_#{url}"
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
response = begin
|
12
|
+
Workarea.s3.get_bucket_cors(Configuration::S3.bucket)
|
13
|
+
rescue Excon::Error::NotFound
|
14
|
+
Excon::Response.new(body: { 'CORSConfiguration' => [] })
|
15
|
+
end
|
12
16
|
|
13
|
-
response = Workarea.s3.get_bucket_cors(Configuration::S3.bucket)
|
14
17
|
cors = response.data[:body]
|
15
|
-
|
16
|
-
|
17
|
-
'
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
|
19
|
+
unless cors['CORSConfiguration'].pluck('ID').include?(id)
|
20
|
+
cors['CORSConfiguration'] << {
|
21
|
+
'ID' => id,
|
22
|
+
'AllowedMethod' => 'PUT',
|
23
|
+
'AllowedOrigin' => url,
|
24
|
+
'AllowedHeader' => '*'
|
25
|
+
}
|
26
|
+
|
27
|
+
Workarea.s3.put_bucket_cors(Configuration::S3.bucket, cors)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
attr_reader :type, :filename
|
@@ -5,13 +5,30 @@ module Workarea
|
|
5
5
|
parsed.map(&:to_s).map(&:strip).reject(&:blank?) if parsed.present?
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize(adds: [], updates: [], removes: [])
|
8
|
+
def initialize(original: {}, adds: [], updates: [], removes: [])
|
9
|
+
@original = original
|
9
10
|
@adds = Array(adds).flatten.each_slice(2).to_a
|
10
11
|
@updates = Array(updates).flatten.each_slice(2).to_a
|
11
12
|
@removes = Array(removes).flatten
|
12
13
|
end
|
13
14
|
|
15
|
+
def result
|
16
|
+
apply_to(@original.deep_dup)
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO v3.6 remove this method, doesn't work when the field is localized
|
20
|
+
# @deprecated
|
14
21
|
def apply(hash)
|
22
|
+
warn <<~eos
|
23
|
+
[DEPRECATION] `HashUpdate#apply` is deprecated and will be removed in
|
24
|
+
version 3.6.0. Please use `HashUpdate#result` instead.
|
25
|
+
eos
|
26
|
+
apply_to(hash)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def apply_to(hash)
|
15
32
|
@adds.each do |tuple|
|
16
33
|
key, value = *tuple
|
17
34
|
hash[key] = self.class.parse_values(value)
|
@@ -14,9 +14,10 @@ module Workarea
|
|
14
14
|
def perform_by_models(products)
|
15
15
|
return if products.blank?
|
16
16
|
|
17
|
-
|
17
|
+
Search::Storefront.bulk do
|
18
|
+
Search::ProductEntries.new(products).map(&:as_bulk_document)
|
19
|
+
end
|
18
20
|
|
19
|
-
Search::Storefront.bulk(documents)
|
20
21
|
products.each { |p| p.set(last_indexed_at: Time.current) }
|
21
22
|
end
|
22
23
|
end
|
@@ -18,11 +18,11 @@ module Workarea
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def perform_by_models(searches)
|
21
|
-
|
22
|
-
|
21
|
+
Search::Storefront.bulk do
|
22
|
+
searches.map do |model|
|
23
|
+
Search::Storefront::Search.new(model).as_bulk_document
|
24
|
+
end
|
23
25
|
end
|
24
|
-
|
25
|
-
Search::Storefront.bulk(documents)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -17,11 +17,11 @@ module Workarea
|
|
17
17
|
import.process!
|
18
18
|
|
19
19
|
ensure
|
20
|
-
if import
|
20
|
+
if import&.error?
|
21
21
|
Admin::DataFileMailer.import_error(id).deliver_now
|
22
|
-
elsif import
|
22
|
+
elsif import&.failure?
|
23
23
|
Admin::DataFileMailer.import_failure(id).deliver_now
|
24
|
-
|
24
|
+
elsif import.present?
|
25
25
|
Admin::DataFileMailer.import(id).deliver_now
|
26
26
|
end
|
27
27
|
end
|
@@ -3,7 +3,8 @@
|
|
3
3
|
#
|
4
4
|
Easymon::Repository.add(
|
5
5
|
'mongodb',
|
6
|
-
Workarea::Monitoring::MongoidCheck.new
|
6
|
+
Workarea::Monitoring::MongoidCheck.new,
|
7
|
+
:critical
|
7
8
|
)
|
8
9
|
|
9
10
|
#
|
@@ -11,7 +12,8 @@ Easymon::Repository.add(
|
|
11
12
|
#
|
12
13
|
Easymon::Repository.add(
|
13
14
|
'elasticsearch',
|
14
|
-
Workarea::Monitoring::ElasticsearchCheck.new
|
15
|
+
Workarea::Monitoring::ElasticsearchCheck.new,
|
16
|
+
:critical
|
15
17
|
)
|
16
18
|
|
17
19
|
#
|
@@ -21,7 +23,8 @@ Easymon::Repository.add(
|
|
21
23
|
"redis",
|
22
24
|
Easymon::RedisCheck.new(
|
23
25
|
Workarea::Configuration::Redis.persistent.to_h
|
24
|
-
)
|
26
|
+
),
|
27
|
+
:critical
|
25
28
|
)
|
26
29
|
|
27
30
|
#
|
data/lib/tasks/search.rake
CHANGED
@@ -12,7 +12,9 @@ namespace :workarea do
|
|
12
12
|
require 'sidekiq/testing/inline' unless ENV['INLINE'] == 'false'
|
13
13
|
puts 'Indexing admin...'
|
14
14
|
|
15
|
-
Workarea::
|
15
|
+
Workarea::QueuesPauser.with_paused_queues do
|
16
|
+
Workarea::Search::Admin.reset_indexes!
|
17
|
+
end
|
16
18
|
|
17
19
|
Mongoid.models.each do |klass|
|
18
20
|
next unless Workarea::Search::Admin.for(klass.first).present?
|
@@ -32,8 +34,10 @@ namespace :workarea do
|
|
32
34
|
require 'sidekiq/testing/inline' unless ENV['INLINE'] == 'false'
|
33
35
|
puts 'Indexing storefront...'
|
34
36
|
|
35
|
-
Workarea::
|
36
|
-
|
37
|
+
Workarea::QueuesPauser.with_paused_queues do
|
38
|
+
Workarea::Search::Storefront.reset_indexes!
|
39
|
+
Workarea::Search::Storefront.ensure_dynamic_mappings
|
40
|
+
end
|
37
41
|
|
38
42
|
# This code finds all unique filters for products so we can index a sample
|
39
43
|
# product for each to ensure the dynamic mappings get created.
|
@@ -79,7 +83,9 @@ namespace :workarea do
|
|
79
83
|
require 'sidekiq/testing/inline' unless ENV['INLINE'] == 'false'
|
80
84
|
puts 'Indexing help...'
|
81
85
|
|
82
|
-
Workarea::
|
86
|
+
Workarea::QueuesPauser.with_paused_queues do
|
87
|
+
Workarea::Search::Help.reset_indexes!
|
88
|
+
end
|
83
89
|
|
84
90
|
Workarea::Help::Article.all.each_by(100) do |help_article|
|
85
91
|
Workarea::Search::Help.new(help_article).save
|
data/lib/workarea/changelog.rake
CHANGED
data/lib/workarea/core.rb
CHANGED
@@ -126,6 +126,8 @@ require 'workarea/ext/freedom_patches/country'
|
|
126
126
|
require 'workarea/ext/freedom_patches/net_http_ssl_connection'
|
127
127
|
require 'workarea/ext/freedom_patches/dragonfly_job_fetch_url'
|
128
128
|
require 'workarea/ext/freedom_patches/dragonfly_callable_url_host'
|
129
|
+
require 'workarea/ext/freedom_patches/mongoid_localized_defaults'
|
130
|
+
require 'workarea/ext/freedom_patches/i18n_js'
|
129
131
|
require 'workarea/ext/mongoid/list_field'
|
130
132
|
require 'workarea/ext/mongoid/each_by'
|
131
133
|
require 'workarea/ext/mongoid/except'
|
@@ -206,6 +208,7 @@ require 'workarea/cache'
|
|
206
208
|
require 'workarea/scheduled_jobs'
|
207
209
|
require 'workarea/string_id'
|
208
210
|
require 'workarea/mail_interceptor'
|
211
|
+
require 'workarea/queues_pauser'
|
209
212
|
|
210
213
|
#
|
211
214
|
# Engines
|
data/lib/workarea/core/engine.rb
CHANGED
@@ -118,13 +118,12 @@ db.getSiblingDB("admin").runCommand( { setParameter: 1, notablescan: 0 } )
|
|
118
118
|
**************************************************
|
119
119
|
⛔️ WARNING: Dragonfly is configured to use the filesystem.
|
120
120
|
|
121
|
-
This means all
|
121
|
+
This means all Dragonfly assets (assets, product images, etc.) will be stored
|
122
122
|
locally and not accessible to all servers within your environment.
|
123
123
|
|
124
124
|
We recommend using S3 when running in a live environment by setting
|
125
|
-
WORKAREA_S3_REGION and WORKAREA_S3_BUCKET_NAME in your environment variables
|
126
|
-
|
127
|
-
are present.
|
125
|
+
WORKAREA_S3_REGION and WORKAREA_S3_BUCKET_NAME in your environment variables,
|
126
|
+
and setting `Workarea.config.asset_store = :s3` in an initializer.
|
128
127
|
**************************************************
|
129
128
|
eos
|
130
129
|
end
|
@@ -44,22 +44,27 @@ module Workarea
|
|
44
44
|
|
45
45
|
def save(document, options = {})
|
46
46
|
options = options.merge(type: type)
|
47
|
-
|
47
|
+
current_index.save(document, options)
|
48
48
|
end
|
49
49
|
|
50
|
-
def bulk(documents, options = {})
|
50
|
+
def bulk(documents = [], options = {})
|
51
51
|
options = options.merge(type: type)
|
52
|
-
|
52
|
+
|
53
|
+
if block_given?
|
54
|
+
I18n.for_each_locale { current_index.bulk(Array.wrap(yield), options) }
|
55
|
+
else
|
56
|
+
current_index.bulk(documents, options)
|
57
|
+
end
|
53
58
|
end
|
54
59
|
|
55
60
|
def update(document, options = {})
|
56
61
|
options = options.merge(type: type)
|
57
|
-
|
62
|
+
current_index.update(document, options)
|
58
63
|
end
|
59
64
|
|
60
65
|
def delete(id, options = {})
|
61
66
|
options = options.merge(type: type)
|
62
|
-
|
67
|
+
current_index.delete(id, options)
|
63
68
|
end
|
64
69
|
|
65
70
|
def count(query = nil, options = {})
|
@@ -97,12 +102,14 @@ module Workarea
|
|
97
102
|
end
|
98
103
|
|
99
104
|
def save(options = {})
|
100
|
-
|
101
|
-
|
105
|
+
I18n.for_each_locale do
|
106
|
+
document = as_document.merge(Serializer.serialize(model))
|
107
|
+
self.class.save(document, options)
|
108
|
+
end
|
102
109
|
end
|
103
110
|
|
104
111
|
def destroy(options = {})
|
105
|
-
self.class.delete(id, options)
|
112
|
+
I18n.for_each_locale { self.class.delete(id, options) }
|
106
113
|
end
|
107
114
|
end
|
108
115
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module I18n
|
2
|
+
module JS
|
3
|
+
class FallbackLocales
|
4
|
+
# i18n-js uses just the second part of this check out-of-the-box. This
|
5
|
+
# causes the I18n fallbacks to get autoloaded without the developer
|
6
|
+
# knowing.
|
7
|
+
#
|
8
|
+
# This surfaces in tests. System or integration tests will do this check
|
9
|
+
# for compiling assets, then I18n fallbacks get autoloaded. So this shows
|
10
|
+
# as some tests not having fallbacks if they run before one of those tests
|
11
|
+
# or magically having fallbacks if they run after one of those types of
|
12
|
+
# tests.
|
13
|
+
#
|
14
|
+
# Adding the `respond_to?` check doesn't cause autoload, but will return
|
15
|
+
# `true` if fallbacks are enabled. Retain the original check because we
|
16
|
+
# want the current I18n::JS backend to be checked, once fallbacks are
|
17
|
+
# `require`d `I18n.respond_to?(:fallbacks)` will always return `true`.
|
18
|
+
#
|
19
|
+
# See also: https://github.com/fnando/i18n-js/blob/master/lib/i18n/js/fallback_locales.rb#L49-L58
|
20
|
+
#
|
21
|
+
def using_i18n_fallbacks_module?
|
22
|
+
I18n.respond_to?(:fallbacks) &&
|
23
|
+
I18n::JS.backend.class.included_modules.include?(I18n::Backend::Fallbacks)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Fields
|
3
|
+
module LocalizedDefaults
|
4
|
+
def create_accessors(name, meth, options = {})
|
5
|
+
super
|
6
|
+
|
7
|
+
if options[:localize]
|
8
|
+
field = fields[name]
|
9
|
+
|
10
|
+
define_method meth do |*args|
|
11
|
+
result = super(*args)
|
12
|
+
return result unless result.nil?
|
13
|
+
|
14
|
+
default_name = field.send(:default_name)
|
15
|
+
return send(default_name) if respond_to?(default_name)
|
16
|
+
|
17
|
+
field.default_val
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ClassMethods.prepend(LocalizedDefaults)
|
24
|
+
end
|
25
|
+
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
@@ -3,27 +3,32 @@ require 'test_helper'
|
|
3
3
|
module Workarea
|
4
4
|
class MonitoringIntegrationTest < Workarea::IntegrationTest
|
5
5
|
def test_monitors_the_mongodb_status
|
6
|
-
get workarea.easymon_path
|
6
|
+
get workarea.easymon_path + '/mongodb'
|
7
7
|
assert_includes(response.body, 'Up')
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_monitors_the_redis_status
|
11
|
-
get workarea.easymon_path
|
11
|
+
get workarea.easymon_path + '/redis'
|
12
12
|
assert_includes(response.body, 'Up')
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_monitors_the_elasticsearch_status
|
16
|
-
get workarea.easymon_path
|
16
|
+
get workarea.easymon_path + '/elasticsearch'
|
17
17
|
assert_includes(response.body, 'Up')
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_monitors_the_sidekiq_queue_status
|
21
|
-
get workarea.easymon_path
|
21
|
+
get workarea.easymon_path + '/sidekiq-queue'
|
22
22
|
assert_includes(response.body, 'Low')
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_monitors_for_load_balancing
|
26
|
-
get workarea.easymon_path
|
26
|
+
get workarea.easymon_path + '/load-balancing'
|
27
|
+
assert_includes(response.body, 'Up')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_critical_endpoint
|
31
|
+
get workarea.easymon_path + "/critical"
|
27
32
|
assert_includes(response.body, 'Up')
|
28
33
|
end
|
29
34
|
end
|
@@ -67,6 +67,26 @@ module Workarea
|
|
67
67
|
assert_equal({ 'id' => '1' }, results.first['_source'])
|
68
68
|
end
|
69
69
|
|
70
|
+
def test_bulk_with_block
|
71
|
+
set_locales(available: [:en, :es], default: :en, current: :en)
|
72
|
+
Foo.bulk { { id: I18n.locale.to_s, bulk_action: 'index' } }
|
73
|
+
|
74
|
+
find_results = -> do
|
75
|
+
Foo
|
76
|
+
.current_index
|
77
|
+
.search({ query: { match_all: {} } }, type: 'foo')
|
78
|
+
.dig('hits', 'hits')
|
79
|
+
end
|
80
|
+
|
81
|
+
I18n.locale = :en
|
82
|
+
assert(1, Foo.count)
|
83
|
+
assert_equal({ 'id' => 'en' }, find_results.call.first['_source'])
|
84
|
+
|
85
|
+
I18n.locale = :es
|
86
|
+
assert(1, Foo.count)
|
87
|
+
assert_equal({ 'id' => 'es' }, find_results.call.first['_source'])
|
88
|
+
end
|
89
|
+
|
70
90
|
def test_update
|
71
91
|
Foo.save(id: '1')
|
72
92
|
Foo.update(id: '1', foo: 'bar')
|
@@ -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
|
@@ -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
|
@@ -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.with_config do |config|
|
24
33
|
config.per_page = 30
|
@@ -408,6 +408,22 @@ module Workarea
|
|
408
408
|
assert(result[:raw].present?)
|
409
409
|
assert_kind_of(Float, result[:raw]['_score'])
|
410
410
|
end
|
411
|
+
|
412
|
+
def test_locale
|
413
|
+
# No simple way to run this test without fallbacks or localized fields
|
414
|
+
return unless Workarea.config.localized_active_fields
|
415
|
+
|
416
|
+
set_locales(available: [:en, :es], default: :en, current: :en)
|
417
|
+
Search::Storefront.reset_indexes!
|
418
|
+
|
419
|
+
product = create_product(active_translations: { 'en' => true, 'es' => false })
|
420
|
+
|
421
|
+
I18n.locale = :es
|
422
|
+
assert_equal([], ProductSearch.new(q: '*').results.pluck(:model))
|
423
|
+
|
424
|
+
I18n.locale = :en
|
425
|
+
assert_equal([product], ProductSearch.new(q: '*').results.pluck(:model))
|
426
|
+
end
|
411
427
|
end
|
412
428
|
end
|
413
429
|
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
|
data/workarea-core.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_dependency 'mongoid-tree', '~> 2.1.0'
|
25
25
|
s.add_dependency 'mongoid-sample', '~> 0.1.0'
|
26
26
|
s.add_dependency 'elasticsearch', '~> 5.0.1'
|
27
|
-
s.add_dependency 'kaminari', '~>
|
27
|
+
s.add_dependency 'kaminari', '~> 1.2.1'
|
28
28
|
s.add_dependency 'kaminari-mongoid', '~> 0.1.2'
|
29
29
|
s.add_dependency 'activemerchant', '~> 1.52'
|
30
30
|
s.add_dependency 'dragonfly', '~> 1.1.2'
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.add_dependency 'sidekiq-cron', '~> 0.6.3'
|
33
33
|
s.add_dependency 'sidekiq-unique-jobs', '~> 6.0.6'
|
34
34
|
s.add_dependency 'sidekiq-throttled', '~> 0.8.2'
|
35
|
-
s.add_dependency 'geocoder', '~> 1.
|
35
|
+
s.add_dependency 'geocoder', '~> 1.6.3'
|
36
36
|
s.add_dependency 'redis-rails', '~> 5.0.0'
|
37
37
|
s.add_dependency 'redis-rack-cache', '~> 2.2.0'
|
38
38
|
s.add_dependency 'easymon', '~> 1.4.0'
|
@@ -65,7 +65,7 @@ Gem::Specification.new do |s|
|
|
65
65
|
s.add_dependency 'chart-horizontalbar-rails', '~> 1.0.4' # TODO remove v4
|
66
66
|
s.add_dependency 'select2-rails', '~> 4.0.3'
|
67
67
|
s.add_dependency 'wysihtml-rails', '~> 0.6.0.beta2'
|
68
|
-
s.add_dependency 'rack-attack', '~>
|
68
|
+
s.add_dependency 'rack-attack', '~> 6.3.1'
|
69
69
|
s.add_dependency 'jquery-livetype-rails', '~> 0.1.0' # TODO remove v4
|
70
70
|
s.add_dependency 'redcarpet', '~> 3.4.0'
|
71
71
|
s.add_dependency 'jquery-unique-clone-rails', '~> 1.0.0'
|
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.4.
|
4
|
+
version: 3.4.34
|
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-
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 1.2.1
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 1.2.1
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: kaminari-mongoid
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -268,14 +268,14 @@ dependencies:
|
|
268
268
|
requirements:
|
269
269
|
- - "~>"
|
270
270
|
- !ruby/object:Gem::Version
|
271
|
-
version: 1.
|
271
|
+
version: 1.6.3
|
272
272
|
type: :runtime
|
273
273
|
prerelease: false
|
274
274
|
version_requirements: !ruby/object:Gem::Requirement
|
275
275
|
requirements:
|
276
276
|
- - "~>"
|
277
277
|
- !ruby/object:Gem::Version
|
278
|
-
version: 1.
|
278
|
+
version: 1.6.3
|
279
279
|
- !ruby/object:Gem::Dependency
|
280
280
|
name: redis-rails
|
281
281
|
requirement: !ruby/object:Gem::Requirement
|
@@ -730,14 +730,14 @@ dependencies:
|
|
730
730
|
requirements:
|
731
731
|
- - "~>"
|
732
732
|
- !ruby/object:Gem::Version
|
733
|
-
version:
|
733
|
+
version: 6.3.1
|
734
734
|
type: :runtime
|
735
735
|
prerelease: false
|
736
736
|
version_requirements: !ruby/object:Gem::Requirement
|
737
737
|
requirements:
|
738
738
|
- - "~>"
|
739
739
|
- !ruby/object:Gem::Version
|
740
|
-
version:
|
740
|
+
version: 6.3.1
|
741
741
|
- !ruby/object:Gem::Dependency
|
742
742
|
name: jquery-livetype-rails
|
743
743
|
requirement: !ruby/object:Gem::Requirement
|
@@ -1855,7 +1855,9 @@ files:
|
|
1855
1855
|
- lib/workarea/ext/freedom_patches/dragonfly_job_fetch_url.rb
|
1856
1856
|
- lib/workarea/ext/freedom_patches/float.rb
|
1857
1857
|
- lib/workarea/ext/freedom_patches/global_id.rb
|
1858
|
+
- lib/workarea/ext/freedom_patches/i18n_js.rb
|
1858
1859
|
- lib/workarea/ext/freedom_patches/money.rb
|
1860
|
+
- lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
|
1859
1861
|
- lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb
|
1860
1862
|
- lib/workarea/ext/freedom_patches/net_http_ssl_connection.rb
|
1861
1863
|
- lib/workarea/ext/freedom_patches/routes_reloader.rb
|
@@ -1893,6 +1895,7 @@ files:
|
|
1893
1895
|
- lib/workarea/ping_home_base.rb
|
1894
1896
|
- lib/workarea/plugin.rb
|
1895
1897
|
- lib/workarea/plugin/asset_appends_helper.rb
|
1898
|
+
- lib/workarea/queues_pauser.rb
|
1896
1899
|
- lib/workarea/robots.rb
|
1897
1900
|
- lib/workarea/routes_constraints/redirect.rb
|
1898
1901
|
- lib/workarea/routes_constraints/super_admin.rb
|
@@ -2006,6 +2009,7 @@ files:
|
|
2006
2009
|
- test/lib/workarea/ext/freedom_patches/country_test.rb
|
2007
2010
|
- test/lib/workarea/ext/freedom_patches/dragonfly_callable_url_host_test.rb
|
2008
2011
|
- test/lib/workarea/ext/freedom_patches/global_id_test.rb
|
2012
|
+
- test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb
|
2009
2013
|
- test/lib/workarea/ext/freedom_patches/mongoid_simple_tags_test.rb
|
2010
2014
|
- test/lib/workarea/ext/mongoid/audit_log_entry_test.rb
|
2011
2015
|
- test/lib/workarea/ext/mongoid/each_by_test.rb
|
@@ -2609,7 +2613,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
2609
2613
|
- !ruby/object:Gem::Version
|
2610
2614
|
version: '0'
|
2611
2615
|
requirements: []
|
2612
|
-
rubygems_version: 3.0.
|
2616
|
+
rubygems_version: 3.0.3
|
2613
2617
|
signing_key:
|
2614
2618
|
specification_version: 4
|
2615
2619
|
summary: Core of the Workarea Commerce Platform
|