elasticsearch-persistence 0.1.6 → 0.1.7
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/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/examples/music/suggester.rb +4 -4
- data/examples/music/template.rb +2 -1
- data/lib/elasticsearch/persistence/model/store.rb +4 -1
- data/lib/elasticsearch/persistence/version.rb +1 -1
- data/test/integration/model/model_basic_test.rb +26 -1
- data/test/unit/model_store_test.rb +31 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55426b2295af55ae3c3c5e22b5db473b208b74a0
|
4
|
+
data.tar.gz: 86391c93cbec7a02acc48ddd1f42f01b48dff606
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a628a20d7500464ad4e810ef22269152a301a31508a6b0df11b22e0fdd7a67ce0607f58a675ccafaa9bdb04748d2aae829e9aeba2bae626c643a1cccf23f76d
|
7
|
+
data.tar.gz: 632053ca6192adbbaac8b2e6565043d658bf66a659db9fbf4341dbc89907a2526cc477493f1d324b33c9857ddd02e7e646ab566b07e1cbc5345ee00d1eda42c3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -616,7 +616,7 @@ Elasticsearch::Persistence.client = Elasticsearch::Client.new log: true
|
|
616
616
|
To set up a specific client for a specific model:
|
617
617
|
|
618
618
|
```ruby
|
619
|
-
Article.client = Elasticsearch::Client.new host: 'api.server.org'
|
619
|
+
Article.gateway.client = Elasticsearch::Client.new host: 'api.server.org'
|
620
620
|
```
|
621
621
|
|
622
622
|
You might want to do this during you application bootstrap process, e.g. in a Rails initializer.
|
data/examples/music/suggester.rb
CHANGED
@@ -12,19 +12,19 @@ class Suggester
|
|
12
12
|
body: {
|
13
13
|
artists: {
|
14
14
|
text: @term,
|
15
|
-
completion: { field: 'suggest_name' }
|
15
|
+
completion: { field: 'suggest_name', size: 25 }
|
16
16
|
},
|
17
17
|
members: {
|
18
18
|
text: @term,
|
19
|
-
completion: { field: 'suggest_member' }
|
19
|
+
completion: { field: 'suggest_member', size: 25 }
|
20
20
|
},
|
21
21
|
albums: {
|
22
22
|
text: @term,
|
23
|
-
completion: { field: 'suggest_title' }
|
23
|
+
completion: { field: 'suggest_title', size: 25 }
|
24
24
|
},
|
25
25
|
tracks: {
|
26
26
|
text: @term,
|
27
|
-
completion: { field: 'suggest_track' }
|
27
|
+
completion: { field: 'suggest_track', size: 25 }
|
28
28
|
}
|
29
29
|
}
|
30
30
|
end
|
data/examples/music/template.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# Usage:
|
18
18
|
# ------
|
19
19
|
#
|
20
|
-
# $ time rails new music --force --skip --skip-bundle --skip-active-record --template /
|
20
|
+
# $ time rails new music --force --skip --skip-bundle --skip-active-record --template https://raw.githubusercontent.com/elastic/elasticsearch-rails/master/elasticsearch-persistence/examples/music/template.rb
|
21
21
|
#
|
22
22
|
# =====================================================================================================
|
23
23
|
|
@@ -132,6 +132,7 @@ gem "quiet_assets"
|
|
132
132
|
gem "simple_form"
|
133
133
|
|
134
134
|
gem 'elasticsearch', git: 'git://github.com/elasticsearch/elasticsearch-ruby.git'
|
135
|
+
gem 'elasticsearch-model', git: 'git://github.com/elasticsearch/elasticsearch-rails.git', require: 'elasticsearch/model'
|
135
136
|
gem 'elasticsearch-persistence', git: 'git://github.com/elasticsearch/elasticsearch-rails.git', require: 'elasticsearch/persistence/model'
|
136
137
|
gem 'elasticsearch-rails', git: 'git://github.com/elasticsearch/elasticsearch-rails.git'
|
137
138
|
|
@@ -44,7 +44,10 @@ module Elasticsearch
|
|
44
44
|
# @return [Hash,FalseClass] The Elasticsearch response as a Hash or `false`
|
45
45
|
#
|
46
46
|
def save(options={})
|
47
|
-
|
47
|
+
unless options.delete(:validate) == false
|
48
|
+
return false unless valid?
|
49
|
+
end
|
50
|
+
|
48
51
|
run_callbacks :save do
|
49
52
|
options.update id: self.id
|
50
53
|
options.update index: self._index if self._index
|
@@ -51,7 +51,7 @@ module Elasticsearch
|
|
51
51
|
|
52
52
|
should "save and find the object" do
|
53
53
|
person = Person.new name: 'John Smith', birthday: Date.parse('1970-01-01')
|
54
|
-
person.save
|
54
|
+
assert person.save
|
55
55
|
|
56
56
|
assert_not_nil person.id
|
57
57
|
document = Person.find(person.id)
|
@@ -63,6 +63,20 @@ module Elasticsearch
|
|
63
63
|
assert_not_nil Elasticsearch::Persistence.client.get index: 'people', type: 'person', id: person.id
|
64
64
|
end
|
65
65
|
|
66
|
+
should "not save an invalid object" do
|
67
|
+
person = Person.new name: nil
|
68
|
+
assert ! person.save
|
69
|
+
end
|
70
|
+
|
71
|
+
should "save an invalid object with the :validate option" do
|
72
|
+
person = Person.new name: nil, salary: 100
|
73
|
+
assert person.save validate: false
|
74
|
+
|
75
|
+
assert_not_nil person.id
|
76
|
+
document = Person.find(person.id)
|
77
|
+
assert_equal 100, document.salary
|
78
|
+
end
|
79
|
+
|
66
80
|
should "delete the object" do
|
67
81
|
person = Person.create name: 'John Smith', birthday: Date.parse('1970-01-01')
|
68
82
|
|
@@ -129,6 +143,17 @@ module Elasticsearch
|
|
129
143
|
assert found.updated_at > updated_at, [found.updated_at, updated_at].inspect
|
130
144
|
end
|
131
145
|
|
146
|
+
should "find all instances" do
|
147
|
+
Person.create name: 'John Smith'
|
148
|
+
Person.create name: 'Mary Smith'
|
149
|
+
Person.gateway.refresh_index!
|
150
|
+
|
151
|
+
people = Person.all
|
152
|
+
|
153
|
+
assert_equal 2, people.total
|
154
|
+
assert_equal 2, people.size
|
155
|
+
end
|
156
|
+
|
132
157
|
should "find instances by search" do
|
133
158
|
Person.create name: 'John Smith'
|
134
159
|
Person.create name: 'Mary Smith'
|
@@ -80,10 +80,7 @@ class Elasticsearch::Persistence::ModelStoreTest < Test::Unit::TestCase
|
|
80
80
|
end
|
81
81
|
.returns({'_id' => 'abc123'})
|
82
82
|
|
83
|
-
assert ! subject.persisted?
|
84
|
-
|
85
83
|
assert subject.save
|
86
|
-
assert subject.persisted?
|
87
84
|
end
|
88
85
|
|
89
86
|
should "save the model and set the ID" do
|
@@ -108,6 +105,37 @@ class Elasticsearch::Persistence::ModelStoreTest < Test::Unit::TestCase
|
|
108
105
|
assert_equal Time.parse('2014-01-01T00:00:00Z'), subject.updated_at
|
109
106
|
end
|
110
107
|
|
108
|
+
should "not save an invalid model" do
|
109
|
+
@gateway
|
110
|
+
.expects(:save)
|
111
|
+
.never
|
112
|
+
|
113
|
+
subject.instance_eval do
|
114
|
+
def valid?; false; end;
|
115
|
+
end
|
116
|
+
|
117
|
+
assert ! subject.save
|
118
|
+
assert ! subject.persisted?
|
119
|
+
end
|
120
|
+
|
121
|
+
should "skip the validation with the :validate option" do
|
122
|
+
@gateway
|
123
|
+
.expects(:save)
|
124
|
+
.with do |object, options|
|
125
|
+
assert_equal subject, object
|
126
|
+
assert_equal nil, options[:id]
|
127
|
+
true
|
128
|
+
end
|
129
|
+
.returns({'_id' => 'abc123'})
|
130
|
+
|
131
|
+
subject.instance_eval do
|
132
|
+
def valid?; false; end;
|
133
|
+
end
|
134
|
+
|
135
|
+
assert subject.save validate: false
|
136
|
+
assert subject.persisted?
|
137
|
+
end
|
138
|
+
|
111
139
|
should "pass the options to gateway" do
|
112
140
|
@gateway
|
113
141
|
.expects(:save)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticsearch-persistence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karel Minarik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|