elastic_searchable 0.6.8 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ module ElasticSearchable
|
|
19
19
|
# :json (optional) configure the json document to be indexed (see http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html#method-i-as_json for available options)
|
20
20
|
def elastic_searchable(options = {})
|
21
21
|
options.symbolize_keys!
|
22
|
-
self.elastic_options = options
|
22
|
+
self.elastic_options = options.merge(:unless => Array.wrap(options[:unless]).push(&:elasticsearch_offline?))
|
23
23
|
|
24
24
|
extend ElasticSearchable::Indexing::ClassMethods
|
25
25
|
extend ElasticSearchable::Queries
|
data/lib/elastic_searchable.rb
CHANGED
@@ -28,6 +28,18 @@ module ElasticSearchable
|
|
28
28
|
def logger
|
29
29
|
@@logger
|
30
30
|
end
|
31
|
+
|
32
|
+
# execute a block of work without reindexing objects
|
33
|
+
@@offline = false
|
34
|
+
def offline?
|
35
|
+
@@offline
|
36
|
+
end
|
37
|
+
def offline(&block)
|
38
|
+
@@offline = true
|
39
|
+
yield
|
40
|
+
ensure
|
41
|
+
@@offline = false
|
42
|
+
end
|
31
43
|
# perform a request to the elasticsearch server
|
32
44
|
# configuration:
|
33
45
|
# ElasticSearchable.base_uri 'host:port' controls where to send request to
|
@@ -66,6 +66,22 @@ class TestElasticSearchable < Test::Unit::TestCase
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
context 'Model.create within ElasticSearchable.offline block' do
|
70
|
+
setup do
|
71
|
+
Post.any_instance.expects(:update_index_on_create).never
|
72
|
+
ElasticSearchable.offline do
|
73
|
+
@post = Post.create :title => 'foo', :body => "bar"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
should 'not have triggered indexing behavior' do end #see expectations
|
77
|
+
should 'not have fired after_index callback' do
|
78
|
+
assert !@post.indexed?
|
79
|
+
end
|
80
|
+
should 'not have fired after_index_on_create callback' do
|
81
|
+
assert !@post.indexed_on_create?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
69
85
|
context 'with empty index when multiple database records' do
|
70
86
|
setup do
|
71
87
|
Post.delete_all
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_searchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|