elastic_record 4.1.4 → 4.1.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a164c34c1dc47a0290401edc67c7b1e38d296cdb
|
4
|
+
data.tar.gz: 26045f57baec0c90aca634cc853794e1782b1abd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a03d0a53928c5ff59653eaa3e7cd00d414cbdb7244e533541426612b233a0fe90abe27b903f391664c1fa3763c42923245d3c2cb54f4c19d521632686d64102
|
7
|
+
data.tar.gz: 84348d5ad734efc2a9a350fc16d58d890e6d2e7765e7841c0d9d857ee99e031a8b4acd76cb9c530c2b84dc164054e5e346d61723f73e2b06553703c05d0e8f9f
|
data/elastic_record.gemspec
CHANGED
@@ -54,7 +54,7 @@ module ElasticRecord
|
|
54
54
|
def index_record(record, index_name: alias_name)
|
55
55
|
unless disabled
|
56
56
|
index_document(
|
57
|
-
record.
|
57
|
+
record.try(:id),
|
58
58
|
record.as_search_document,
|
59
59
|
doctype: record.doctype,
|
60
60
|
index_name: index_name
|
@@ -65,7 +65,7 @@ module ElasticRecord
|
|
65
65
|
def update_record(record, index_name: alias_name)
|
66
66
|
unless disabled
|
67
67
|
update_document(
|
68
|
-
record.
|
68
|
+
record.id,
|
69
69
|
record.as_partial_update_document,
|
70
70
|
doctype: record.doctype,
|
71
71
|
index_name: index_name
|
@@ -84,11 +84,16 @@ module ElasticRecord
|
|
84
84
|
path = "/#{index_name}/#{doctype.name}/#{id}"
|
85
85
|
path << "?parent=#{parent}" if parent
|
86
86
|
|
87
|
-
|
87
|
+
if id
|
88
|
+
connection.json_put path, document
|
89
|
+
else
|
90
|
+
connection.json_post path, document
|
91
|
+
end
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
95
|
def update_document(id, document, doctype: model.doctype, parent: nil, index_name: alias_name)
|
96
|
+
raise "Cannot update a document with empty id" if id.blank?
|
92
97
|
params = {doc: document, doc_as_upsert: true}
|
93
98
|
|
94
99
|
if batch = current_bulk_batch
|
@@ -1,5 +1,19 @@
|
|
1
1
|
class Warehouse
|
2
|
-
|
2
|
+
class << self
|
3
|
+
def base_class
|
4
|
+
self
|
5
|
+
end
|
6
|
+
end
|
3
7
|
|
4
|
-
|
8
|
+
include ActiveModel::Model
|
9
|
+
include ElasticRecord::Model
|
10
|
+
|
11
|
+
attr_accessor :id, :name
|
12
|
+
alias_method :as_json, :as_search_document
|
13
|
+
|
14
|
+
elastic_index.load_from_source = true
|
15
|
+
|
16
|
+
def as_search_document
|
17
|
+
{ name: name }
|
18
|
+
end
|
5
19
|
end
|
@@ -16,6 +16,17 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Test
|
|
16
16
|
refute index.record_exists?('7')
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_index_record_without_id
|
20
|
+
index = Warehouse.elastic_index
|
21
|
+
without_deferring(index) do
|
22
|
+
warehouse = Warehouse.new(name: 'Amazon')
|
23
|
+
result = index.index_record(warehouse)
|
24
|
+
|
25
|
+
assert index.record_exists?(result['_id'])
|
26
|
+
refute index.record_exists?('xyz')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
def test_index_document
|
20
31
|
index.index_document('abc', color: 'red')
|
21
32
|
|
@@ -23,12 +34,26 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Test
|
|
23
34
|
refute index.record_exists?('xyz')
|
24
35
|
end
|
25
36
|
|
37
|
+
def test_index_document_without_id
|
38
|
+
index = Warehouse.elastic_index
|
39
|
+
without_deferring(index) do
|
40
|
+
result = index.index_document(nil, name: 'red')
|
41
|
+
|
42
|
+
assert index.record_exists?(result['_id'])
|
43
|
+
refute index.record_exists?('xyz')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
26
47
|
def test_update_document
|
27
48
|
index.index_document('abc', warehouse_id: '5', color: 'red')
|
28
49
|
index.update_document('abc', color: 'blue')
|
29
50
|
|
30
51
|
expected = {'warehouse_id' => '5', 'color' => 'blue'}
|
31
52
|
assert_equal expected, index.get('abc', Widget.doctype)['_source']
|
53
|
+
|
54
|
+
assert_raises RuntimeError do
|
55
|
+
index.update_document(nil, color: 'blue')
|
56
|
+
end
|
32
57
|
end
|
33
58
|
|
34
59
|
def test_delete_document
|
@@ -94,7 +119,7 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Test
|
|
94
119
|
end
|
95
120
|
|
96
121
|
def test_bulk_error
|
97
|
-
without_deferring do
|
122
|
+
without_deferring(index) do
|
98
123
|
begin
|
99
124
|
index.bulk do
|
100
125
|
index.index_document '5', color: 'green'
|
@@ -109,7 +134,7 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Test
|
|
109
134
|
end
|
110
135
|
|
111
136
|
def test_bulk_inheritence
|
112
|
-
without_deferring do
|
137
|
+
without_deferring(index) do
|
113
138
|
index.bulk do
|
114
139
|
InheritedWidget.elastic_index.index_document '5', color: 'green'
|
115
140
|
|
@@ -124,7 +149,7 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Test
|
|
124
149
|
|
125
150
|
private
|
126
151
|
|
127
|
-
def without_deferring
|
152
|
+
def without_deferring(index)
|
128
153
|
index.disable_deferring!
|
129
154
|
yield
|
130
155
|
index.reset
|
@@ -43,16 +43,16 @@ class ElasticRecord::RelationTest < MiniTest::Test
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_to_a_from_source
|
46
|
-
|
47
|
-
|
46
|
+
warehouses = [Warehouse.new(name: 'Amazon'), Warehouse.new(name: 'Walmart')]
|
47
|
+
result = Warehouse.elastic_index.bulk_add(warehouses)
|
48
48
|
|
49
|
-
|
49
|
+
array = Warehouse.elastic_relation.to_a
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
assert_equal 2, array.size
|
52
|
+
assert array.first.is_a?(Warehouse)
|
53
|
+
names = array.map(&:name)
|
54
|
+
assert_includes names, 'Amazon'
|
55
|
+
assert_includes names, 'Walmart'
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_delete_all
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infogroup
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-09-
|
12
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arelastic
|