elastic_record 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'elastic_record'
5
- s.version = '0.8.1'
5
+ s.version = '0.8.2'
6
6
  s.summary = 'Use Elastic Search with your objects'
7
7
  s.description = 'Find your records with elastic search'
8
8
 
@@ -3,6 +3,7 @@ require 'elastic_record/relation/batches'
3
3
  require 'elastic_record/relation/delegation'
4
4
  require 'elastic_record/relation/finder_methods'
5
5
  require 'elastic_record/relation/merging'
6
+ require 'elastic_record/relation/none'
6
7
  require 'elastic_record/relation/search_methods'
7
8
 
8
9
  module ElasticRecord
@@ -0,0 +1,21 @@
1
+ module ElasticRecord
2
+ class Relation
3
+ module None
4
+ def to_a
5
+ []
6
+ end
7
+
8
+ def count
9
+ 0
10
+ end
11
+
12
+ def facets
13
+ {}
14
+ end
15
+
16
+ def as_elastic
17
+ {}
18
+ end
19
+ end
20
+ end
21
+ end
@@ -43,10 +43,6 @@ module ElasticRecord
43
43
  clone.filter!(*args)
44
44
  end
45
45
 
46
- def negate(*args)
47
- filter args.map { |arg| arelastic.filter.not arg }
48
- end
49
-
50
46
  def limit!(value)
51
47
  self.limit_value = value
52
48
  self
@@ -114,6 +110,10 @@ module ElasticRecord
114
110
  clone.extending!(*modules, &block)
115
111
  end
116
112
 
113
+ def none
114
+ extending(None)
115
+ end
116
+
117
117
  def as_elastic
118
118
  build_search.as_elastic
119
119
  end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ class ElasticRecord::Relation::NoneTest < MiniTest::Spec
4
+ def setup
5
+ super
6
+ Widget.elastic_index.reset
7
+ end
8
+
9
+ def test_none
10
+ none = Widget.elastic_relation.none
11
+
12
+ assert_equal 0, none.size
13
+ assert_equal 0, none.count
14
+ assert_equal [], none.to_a
15
+ end
16
+ end
@@ -57,24 +57,6 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
57
57
  assert_equal expected, relation.as_elastic['query']
58
58
  end
59
59
 
60
- def test_negate
61
- search = relation.negate("prefix" => {"name" => "Jo"})
62
-
63
- expected = {
64
- "constant_score" => {
65
- "filter" => {
66
- "not" => {
67
- "prefix" => {
68
- "name" => "Jo"
69
- }
70
- }
71
- }
72
- }
73
- }
74
-
75
- assert_equal expected, search.as_elastic['query']
76
- end
77
-
78
60
  def test_query_with_only_query
79
61
  relation.query!('foo')
80
62
 
@@ -210,6 +192,10 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
210
192
  assert_equal 'bar', relation.bar
211
193
  end
212
194
 
195
+ def test_none
196
+ assert_kind_of ElasticRecord::Relation::None, relation.none
197
+ end
198
+
213
199
  private
214
200
  def relation
215
201
  @relation ||= Widget.elastic_relation
@@ -2,6 +2,7 @@ require 'helper'
2
2
 
3
3
  class ElasticRecord::RelationTest < MiniTest::Spec
4
4
  def setup
5
+ super
5
6
  Widget.elastic_index.reset
6
7
  end
7
8
 
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: 0.8.1
4
+ version: 0.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -76,6 +76,7 @@ files:
76
76
  - lib/elastic_record/relation/delegation.rb
77
77
  - lib/elastic_record/relation/finder_methods.rb
78
78
  - lib/elastic_record/relation/merging.rb
79
+ - lib/elastic_record/relation/none.rb
79
80
  - lib/elastic_record/relation/search_methods.rb
80
81
  - lib/elastic_record/relation/value_methods.rb
81
82
  - lib/elastic_record/searching.rb
@@ -95,6 +96,7 @@ files:
95
96
  - test/elastic_record/relation/delegation_test.rb
96
97
  - test/elastic_record/relation/finder_methods_test.rb
97
98
  - test/elastic_record/relation/merging_test.rb
99
+ - test/elastic_record/relation/none_test.rb
98
100
  - test/elastic_record/relation/search_methods_test.rb
99
101
  - test/elastic_record/relation_test.rb
100
102
  - test/elastic_record/searching_test.rb