workarea-core 3.4.30 → 3.4.31
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/search/storefront/product/categories.rb +1 -1
- data/app/models/workarea/user/password_reset.rb +3 -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/lib/workarea/core.rb +1 -0
- data/lib/workarea/elasticsearch/document.rb +15 -8
- data/lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb +25 -0
- data/lib/workarea/version.rb +1 -1
- 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/product_search_test.rb +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 299de23bea1f758a6c81b220df516b433a75b8d68feed5317ed1bc83a2a4bac9
|
4
|
+
data.tar.gz: 826455dd3ea5fe721feb372936ac4a6b169ae7c3256ce98cee94f1b3c1fd19ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b612026e5219dbefac87be6a897a43cff75b2fa045d62af44ef9bac1d27ef658e5c8c38cc25526bb52898841ee3b71d43caf89450e641d1c60ef68b1c7d65fe5
|
7
|
+
data.tar.gz: 336720cc69f36b67ee3706d424df574e04459a55221aa6e04dec7c09b920d6763f5983d5aef7bfeb778535c8c5b288a4ea48e8c18eeeaff39017245e1ba9e5d5
|
@@ -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
|
|
@@ -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
|
|
data/lib/workarea/core.rb
CHANGED
@@ -126,6 +126,7 @@ 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'
|
129
130
|
require 'workarea/ext/mongoid/list_field'
|
130
131
|
require 'workarea/ext/mongoid/each_by'
|
131
132
|
require 'workarea/ext/mongoid/except'
|
@@ -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,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
|
data/lib/workarea/version.rb
CHANGED
@@ -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
|
@@ -408,6 +408,19 @@ 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
|
+
set_locales(available: [:en, :es], default: :en, current: :en)
|
414
|
+
Search::Storefront.reset_indexes!
|
415
|
+
|
416
|
+
product = create_product(active_translations: { 'en' => true, 'es' => false })
|
417
|
+
|
418
|
+
I18n.locale = :es
|
419
|
+
assert_equal([], ProductSearch.new(q: '*').results.pluck(:model))
|
420
|
+
|
421
|
+
I18n.locale = :en
|
422
|
+
assert_equal([product], ProductSearch.new(q: '*').results.pluck(:model))
|
423
|
+
end
|
411
424
|
end
|
412
425
|
end
|
413
426
|
end
|
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.31
|
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-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -1856,6 +1856,7 @@ files:
|
|
1856
1856
|
- lib/workarea/ext/freedom_patches/float.rb
|
1857
1857
|
- lib/workarea/ext/freedom_patches/global_id.rb
|
1858
1858
|
- lib/workarea/ext/freedom_patches/money.rb
|
1859
|
+
- lib/workarea/ext/freedom_patches/mongoid_localized_defaults.rb
|
1859
1860
|
- lib/workarea/ext/freedom_patches/mongoid_simple_tags.rb
|
1860
1861
|
- lib/workarea/ext/freedom_patches/net_http_ssl_connection.rb
|
1861
1862
|
- lib/workarea/ext/freedom_patches/routes_reloader.rb
|
@@ -2006,6 +2007,7 @@ files:
|
|
2006
2007
|
- test/lib/workarea/ext/freedom_patches/country_test.rb
|
2007
2008
|
- test/lib/workarea/ext/freedom_patches/dragonfly_callable_url_host_test.rb
|
2008
2009
|
- test/lib/workarea/ext/freedom_patches/global_id_test.rb
|
2010
|
+
- test/lib/workarea/ext/freedom_patches/mongoid_localized_defaults_test.rb
|
2009
2011
|
- test/lib/workarea/ext/freedom_patches/mongoid_simple_tags_test.rb
|
2010
2012
|
- test/lib/workarea/ext/mongoid/audit_log_entry_test.rb
|
2011
2013
|
- test/lib/workarea/ext/mongoid/each_by_test.rb
|