elastic_record 1.1.4 → 1.1.5
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/Gemfile +3 -1
- data/Rakefile +2 -2
- data/elastic_record.gemspec +2 -2
- data/lib/elastic_record.rb +1 -0
- data/lib/elastic_record/callbacks.rb +13 -5
- data/lib/elastic_record/connection.rb +7 -8
- data/lib/elastic_record/errors.rb +10 -0
- data/lib/elastic_record/index/deferred.rb +7 -1
- data/lib/elastic_record/index/documents.rb +34 -17
- data/lib/elastic_record/index/manage.rb +8 -0
- data/lib/elastic_record/index/percolator.rb +16 -10
- data/lib/elastic_record/integration/active_record.rb +7 -0
- data/lib/elastic_record/integration/cassandra_object.rb +7 -0
- data/lib/elastic_record/model.rb +5 -10
- data/lib/elastic_record/railtie.rb +10 -0
- data/lib/elastic_record/relation.rb +26 -5
- data/lib/elastic_record/relation/batches.rb +4 -1
- data/lib/elastic_record/relation/finder_methods.rb +13 -3
- data/lib/elastic_record/relation/search_methods.rb +17 -0
- data/lib/elastic_record/relation/value_methods.rb +2 -2
- data/lib/elastic_record/searches_many.rb +1 -1
- data/lib/elastic_record/searches_many/association.rb +14 -10
- data/lib/elastic_record/searches_many/builder.rb +3 -3
- data/lib/elastic_record/searches_many/collection_proxy.rb +9 -3
- data/lib/elastic_record/searches_many/reflection.rb +4 -0
- data/test/elastic_record/callbacks_test.rb +65 -1
- data/test/elastic_record/config_test.rb +3 -3
- data/test/elastic_record/connection_test.rb +1 -1
- data/test/elastic_record/index/configurator_test.rb +1 -1
- data/test/elastic_record/index/documents_test.rb +23 -4
- data/test/elastic_record/index/manage_test.rb +1 -1
- data/test/elastic_record/index/mapping_test.rb +1 -1
- data/test/elastic_record/index/percolator_test.rb +1 -1
- data/test/elastic_record/index/settings_test.rb +1 -1
- data/test/elastic_record/index/warmer_test.rb +1 -1
- data/test/elastic_record/index_test.rb +1 -1
- data/test/elastic_record/integration/active_record_test.rb +39 -0
- data/test/elastic_record/log_subscriber_test.rb +11 -0
- data/test/elastic_record/lucene_test.rb +1 -1
- data/test/elastic_record/model_test.rb +1 -1
- data/test/elastic_record/railties/controller_runtime_test.rb +1 -1
- data/test/elastic_record/relation/admin_test.rb +13 -7
- data/test/elastic_record/relation/batches_test.rb +27 -1
- data/test/elastic_record/relation/delegation_test.rb +1 -1
- data/test/elastic_record/relation/finder_methods_test.rb +23 -8
- data/test/elastic_record/relation/merging_test.rb +1 -1
- data/test/elastic_record/relation/none_test.rb +1 -1
- data/test/elastic_record/relation/search_methods_test.rb +15 -2
- data/test/elastic_record/relation_test.rb +50 -3
- data/test/elastic_record/searches_many/association_test.rb +47 -0
- data/test/elastic_record/searches_many/autosave_test.rb +11 -10
- data/test/elastic_record/searches_many/collection_proxy_test.rb +1 -1
- data/test/elastic_record/searches_many/reflection_test.rb +7 -1
- data/test/elastic_record/searches_many_test.rb +11 -11
- data/test/elastic_record/searching_test.rb +1 -1
- data/test/helper.rb +19 -12
- data/test/support/models/option.rb +24 -0
- data/test/support/models/test_model.rb +22 -1
- data/test/support/models/warehouse.rb +2 -2
- data/test/support/models/widget.rb +4 -2
- data/test/support/query_counter.rb +56 -0
- metadata +10 -5
- data/lib/elastic_record/orm/active_record.rb +0 -7
data/test/helper.rb
CHANGED
@@ -4,30 +4,37 @@ Bundler.require
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
|
6
6
|
require 'support/connect'
|
7
|
+
require 'support/query_counter'
|
7
8
|
require 'support/models/test_model'
|
8
9
|
require 'support/models/warehouse'
|
9
10
|
require 'support/models/widget'
|
11
|
+
require 'support/models/option'
|
12
|
+
require 'pp'
|
10
13
|
|
11
|
-
ElasticRecord::Config.model_names = %w(Warehouse Widget)
|
14
|
+
ElasticRecord::Config.model_names = %w(Warehouse Widget Option)
|
12
15
|
|
13
16
|
FakeWeb.allow_net_connect = %r[^https?://127.0.0.1]
|
14
17
|
|
15
18
|
module MiniTest
|
16
|
-
class
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
class Unit
|
20
|
+
class TestCase
|
21
|
+
def setup
|
22
|
+
Widget._test_cache.clear
|
23
|
+
Option._test_cache.clear
|
20
24
|
|
21
|
-
|
25
|
+
FakeWeb.clean_registry
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
Widget.elastic_index.create_and_deploy if Widget.elastic_index.all_names.empty?
|
28
|
+
|
29
|
+
ElasticRecord::Config.models.each do |model|
|
30
|
+
model.elastic_index.enable_deferring!
|
31
|
+
end
|
25
32
|
end
|
26
|
-
end
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
34
|
+
def teardown
|
35
|
+
ElasticRecord::Config.models.each do |model|
|
36
|
+
model.elastic_index.reset_deferring!
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Option
|
2
|
+
include TestModel
|
3
|
+
|
4
|
+
define_attributes [:name, :widget_id]
|
5
|
+
|
6
|
+
searches_many :options
|
7
|
+
|
8
|
+
self.elastic_index.mapping[:properties].update(
|
9
|
+
name: {
|
10
|
+
type: 'multi_field',
|
11
|
+
fields: {
|
12
|
+
name: {type: 'string', index: 'not_analyzed'},
|
13
|
+
analyzed: {type: 'string', index: 'analyzed'}
|
14
|
+
}
|
15
|
+
},
|
16
|
+
widget_id: {
|
17
|
+
type: 'string', index: 'not_analyzed'
|
18
|
+
}
|
19
|
+
)
|
20
|
+
|
21
|
+
def widget=(other)
|
22
|
+
self.widget_id = other.id
|
23
|
+
end
|
24
|
+
end
|
@@ -11,11 +11,28 @@ module TestModel
|
|
11
11
|
|
12
12
|
include ElasticRecord::Model
|
13
13
|
include ElasticRecord::Callbacks
|
14
|
+
|
14
15
|
end
|
15
16
|
|
16
17
|
module ClassMethods
|
18
|
+
|
19
|
+
def _test_cache
|
20
|
+
@_test_cache ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def load_elastic_record_hits(*args)
|
24
|
+
find(*args)
|
25
|
+
end
|
26
|
+
|
17
27
|
def find(ids)
|
18
|
-
ids.map
|
28
|
+
ids.map do |id|
|
29
|
+
record = _test_cache.detect { |m| m.id.to_s == id.to_s }
|
30
|
+
record.nil? ? new(id: id, color: 'red') : record.clone
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def primary_key
|
35
|
+
'id'
|
19
36
|
end
|
20
37
|
|
21
38
|
def base_class
|
@@ -50,6 +67,10 @@ module TestModel
|
|
50
67
|
|
51
68
|
def initialize(attrs = {})
|
52
69
|
self.attributes = attrs
|
70
|
+
cloned = self.clone
|
71
|
+
cloned.id = cloned.id.to_s
|
72
|
+
self.class._test_cache.delete_if { |record| record.id == cloned.id }
|
73
|
+
self.class._test_cache << cloned
|
53
74
|
end
|
54
75
|
|
55
76
|
def attributes=(attrs)
|
@@ -5,9 +5,11 @@ class Widget
|
|
5
5
|
|
6
6
|
define_attributes [:name, :color, :warehouse_id]
|
7
7
|
|
8
|
+
searches_many :options
|
9
|
+
|
8
10
|
self.elastic_index.mapping[:properties].update(
|
9
11
|
name: {
|
10
|
-
type: 'multi_field',
|
12
|
+
type: 'multi_field',
|
11
13
|
fields: {
|
12
14
|
name: {type: 'string', index: 'not_analyzed'},
|
13
15
|
analyzed: {type: 'string', index: 'analyzed'}
|
@@ -36,4 +38,4 @@ class Widget
|
|
36
38
|
def warehouse=(other)
|
37
39
|
self.warehouse_id = other.id
|
38
40
|
end
|
39
|
-
end
|
41
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class ElasticSearchCounter
|
2
|
+
class << self
|
3
|
+
attr_accessor :ignored_elastic, :log, :log_all
|
4
|
+
def clear_log; self.log = []; self.log_all = []; end
|
5
|
+
end
|
6
|
+
|
7
|
+
self.clear_log
|
8
|
+
|
9
|
+
self.ignored_elastic = []
|
10
|
+
|
11
|
+
elastic_search_ignored = []
|
12
|
+
|
13
|
+
[elastic_search_ignored].each do |db_ignored_elastic|
|
14
|
+
ignored_elastic.concat db_ignored_elastic
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :ignore
|
18
|
+
|
19
|
+
def initialize(ignore = Regexp.union(self.class.ignored_elastic))
|
20
|
+
@ignore = ignore
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(name, start, finish, message_id, values)
|
24
|
+
self.class.log_all << values
|
25
|
+
self.class.log << values unless ignore =~ values[:request].path
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveSupport::Notifications.subscribe('request.elastic_record', ElasticSearchCounter.new)
|
30
|
+
|
31
|
+
module MiniTest
|
32
|
+
class Unit
|
33
|
+
class TestCase
|
34
|
+
def assert_queries(num = 1, options = {})
|
35
|
+
ignore_none = options.fetch(:ignore_none) { num == :any }
|
36
|
+
ElasticSearchCounter.clear_log
|
37
|
+
x = yield
|
38
|
+
the_log = ignore_none ? ElasticSearchCounter.log_all : ElasticSearchCounter.log
|
39
|
+
if num == :any
|
40
|
+
assert_operator the_log.size, :>=, 1, "1 or more queries expected, but none were executed."
|
41
|
+
else
|
42
|
+
queries = the_log.map { |event| " #{event[:request].method} #{event[:request].path} #{event[:request].body}\n" }.join("\n")
|
43
|
+
|
44
|
+
mesg = "#{the_log.size} instead of #{num} queries were executed.#{the_log.size == 0 ? '' : "\nQueries:\n#{queries}"}"
|
45
|
+
assert_equal num, the_log.size, mesg
|
46
|
+
end
|
47
|
+
|
48
|
+
x
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_no_queries(&block)
|
52
|
+
assert_queries(0, :ignore_none => true, &block)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
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: 1.1.
|
4
|
+
version: 1.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: 2013-
|
12
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arelastic
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.4.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.4.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activemodel
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/elastic_record/callbacks.rb
|
58
58
|
- lib/elastic_record/config.rb
|
59
59
|
- lib/elastic_record/connection.rb
|
60
|
+
- lib/elastic_record/errors.rb
|
60
61
|
- lib/elastic_record/index.rb
|
61
62
|
- lib/elastic_record/index/configurator.rb
|
62
63
|
- lib/elastic_record/index/deferred.rb
|
@@ -66,10 +67,11 @@ files:
|
|
66
67
|
- lib/elastic_record/index/percolator.rb
|
67
68
|
- lib/elastic_record/index/settings.rb
|
68
69
|
- lib/elastic_record/index/warmer.rb
|
70
|
+
- lib/elastic_record/integration/active_record.rb
|
71
|
+
- lib/elastic_record/integration/cassandra_object.rb
|
69
72
|
- lib/elastic_record/log_subscriber.rb
|
70
73
|
- lib/elastic_record/lucene.rb
|
71
74
|
- lib/elastic_record/model.rb
|
72
|
-
- lib/elastic_record/orm/active_record.rb
|
73
75
|
- lib/elastic_record/railtie.rb
|
74
76
|
- lib/elastic_record/railties/controller_runtime.rb
|
75
77
|
- lib/elastic_record/relation.rb
|
@@ -100,6 +102,7 @@ files:
|
|
100
102
|
- test/elastic_record/index/settings_test.rb
|
101
103
|
- test/elastic_record/index/warmer_test.rb
|
102
104
|
- test/elastic_record/index_test.rb
|
105
|
+
- test/elastic_record/integration/active_record_test.rb
|
103
106
|
- test/elastic_record/log_subscriber_test.rb
|
104
107
|
- test/elastic_record/lucene_test.rb
|
105
108
|
- test/elastic_record/model_test.rb
|
@@ -120,9 +123,11 @@ files:
|
|
120
123
|
- test/elastic_record/searching_test.rb
|
121
124
|
- test/helper.rb
|
122
125
|
- test/support/connect.rb
|
126
|
+
- test/support/models/option.rb
|
123
127
|
- test/support/models/test_model.rb
|
124
128
|
- test/support/models/warehouse.rb
|
125
129
|
- test/support/models/widget.rb
|
130
|
+
- test/support/query_counter.rb
|
126
131
|
homepage: http://github.com/data-axle/elastic_record
|
127
132
|
licenses:
|
128
133
|
- MIT
|