search_flip 3.8.0 → 4.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,8 @@ RSpec.describe SearchFlip::Index do
5
5
  subject { ProductIndex }
6
6
 
7
7
  methods = [
8
- :all, :profile, :where, :where_not, :filter, :range, :match_all, :match_none,
9
- :exists, :exists_not, :post_where, :post_where_not, :post_filter, :post_must,
8
+ :all, :profile, :where, :where_not, :filter, :range, :match_all, :exists,
9
+ :exists_not, :post_where, :post_where_not, :post_filter, :post_must,
10
10
  :post_must_not, :post_should, :post_range, :post_exists, :post_exists_not,
11
11
  :aggregate, :scroll, :source, :includes, :eager_load, :preload, :sort, :resort,
12
12
  :order, :reorder, :offset, :limit, :paginate, :page, :per, :search,
@@ -14,7 +14,7 @@ RSpec.describe SearchFlip::Index do
14
14
  :total_entries, :total_count, :terminate_after, :timeout, :records, :results,
15
15
  :must, :must_not, :should, :find_each_result,
16
16
  :find_results_in_batches, :preference, :search_type, :routing,
17
- :track_total_hits, :explain, :http_timeout
17
+ :track_total_hits, :explain
18
18
  ]
19
19
 
20
20
  methods.each do |method|
@@ -77,7 +77,7 @@ RSpec.describe SearchFlip::Index do
77
77
  include SearchFlip::Index
78
78
  end
79
79
 
80
- expect(klass.include_type_name?).to eq(klass.connection.distribution.nil? && klass.connection.version.to_i < 7)
80
+ expect(klass.include_type_name?).to eq(klass.connection.version.to_i < 7)
81
81
  end
82
82
 
83
83
  it "returns true if the type name is not equal to _doc" do
@@ -185,7 +185,7 @@ RSpec.describe SearchFlip::Index do
185
185
  end
186
186
 
187
187
  describe ".update_mapping" do
188
- if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
188
+ if TestIndex.connection.version.to_i >= 7
189
189
  context "without type name" do
190
190
  it "delegates to connection" do
191
191
  TestIndex.create_index
@@ -211,21 +211,11 @@ RSpec.describe SearchFlip::Index do
211
211
  mapping = { properties: { id: { type: "long" } } }
212
212
 
213
213
  allow(TestIndex).to receive(:mapping).and_return(mapping)
214
- allow(TestIndex.connection).to receive(:update_mapping)
214
+ allow(TestIndex.connection).to receive(:update_mapping).and_call_original
215
215
 
216
216
  TestIndex.update_mapping
217
217
 
218
- if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
219
- expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
220
- else
221
- expect(TestIndex.connection).to have_received(:update_mapping).with("test", mapping)
222
- end
223
- end
224
-
225
- it "updates the mapping" do
226
- TestIndex.create_index
227
-
228
- expect(TestIndex.update_mapping).to eq(true)
218
+ expect(TestIndex.connection).to have_received(:update_mapping).with("test", { "test" => mapping }, type_name: "test")
229
219
  end
230
220
  end
231
221
  end
@@ -245,7 +235,7 @@ RSpec.describe SearchFlip::Index do
245
235
  end
246
236
 
247
237
  describe ".get_mapping" do
248
- if TestIndex.connection.distribution || TestIndex.connection.version.to_i >= 7
238
+ if TestIndex.connection.version.to_i >= 7
249
239
  context "without type name" do
250
240
  it "delegates to connection" do
251
241
  allow(TestIndex).to receive(:include_type_name?).and_return(false)
@@ -268,22 +258,11 @@ RSpec.describe SearchFlip::Index do
268
258
  TestIndex.create_index
269
259
  TestIndex.update_mapping
270
260
 
271
- allow(TestIndex.connection).to receive(:get_mapping)
261
+ allow(TestIndex.connection).to receive(:get_mapping).and_call_original
272
262
 
273
263
  TestIndex.get_mapping
274
264
 
275
- if TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8
276
- expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
277
- else
278
- expect(TestIndex.connection).to have_received(:get_mapping).with("test")
279
- end
280
- end
281
-
282
- it "returns the mapping" do
283
- TestIndex.create_index
284
- TestIndex.update_mapping
285
-
286
- expect(TestIndex.get_mapping).to be_present
265
+ expect(TestIndex.connection).to have_received(:get_mapping).with("test", type_name: "test")
287
266
  end
288
267
  end
289
268
  end
@@ -340,7 +319,7 @@ RSpec.describe SearchFlip::Index do
340
319
 
341
320
  TestIndex.type_url
342
321
 
343
- expect(TestIndex.connection).to have_received(:type_url).with("test", TestIndex.connection.distribution.nil? && TestIndex.connection.version.to_i < 8 ? "test" : "_doc")
322
+ expect(TestIndex.connection).to have_received(:type_url).with("test", "test")
344
323
  end
345
324
  end
346
325
 
@@ -433,7 +412,7 @@ RSpec.describe SearchFlip::Index do
433
412
 
434
413
  products = create_list(:product, 2)
435
414
 
436
- if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
415
+ if ProductIndex.connection.version.to_i >= 5
437
416
  expect { ProductIndex.create products, {}, routing: "r1" }.to(change { ProductIndex.total_count }.by(2))
438
417
 
439
418
  expect(ProductIndex.get(products.first.id, routing: "r1")["_routing"]).to eq("r1")
@@ -447,7 +426,7 @@ RSpec.describe SearchFlip::Index do
447
426
  it "allows respects class options" do
448
427
  products = create_list(:product, 2)
449
428
 
450
- if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
429
+ if ProductIndex.connection.version.to_i >= 5
451
430
  allow(ProductIndex).to receive(:index_options).and_return(routing: "r1")
452
431
 
453
432
  expect { ProductIndex.create products }.to(change { ProductIndex.total_count }.by(2))
@@ -2,16 +2,6 @@ require File.expand_path("../spec_helper", __dir__)
2
2
 
3
3
  RSpec.describe SearchFlip::JSON do
4
4
  describe ".generate" do
5
- it "encodes timestamps correctly" do
6
- Timecop.freeze "2020-06-01 12:00:00 UTC" do
7
- expect(described_class.generate(timestamp: Time.now.utc)).to eq('{"timestamp":"2020-06-01T12:00:00.000Z"}')
8
- end
9
- end
10
-
11
- it "encodes bigdecimals as string" do
12
- expect(described_class.generate(value: BigDecimal(1))).to eq('{"value":"1.0"}')
13
- end
14
-
15
5
  it "delegates to Oj" do
16
6
  allow(Oj).to receive(:dump)
17
7
 
@@ -19,7 +9,7 @@ RSpec.describe SearchFlip::JSON do
19
9
 
20
10
  described_class.generate(payload)
21
11
 
22
- expect(Oj).to have_received(:dump).with(payload, mode: :custom, use_to_json: true, time_format: :xmlschema, bigdecimal_as_decimal: false)
12
+ expect(Oj).to have_received(:dump).with(payload, mode: :custom, use_to_json: true)
23
13
  end
24
14
 
25
15
  it "generates json" do
@@ -28,18 +18,14 @@ RSpec.describe SearchFlip::JSON do
28
18
  end
29
19
 
30
20
  describe ".parse" do
31
- it "returns the parsed json payload" do
32
- expect(described_class.parse('{"key":"value"}')).to eq("key" => "value")
33
- end
34
-
35
- it "delegates to JSON" do
36
- allow(JSON).to receive(:parse)
21
+ it "delegates to Oj" do
22
+ allow(Oj).to receive(:load)
37
23
 
38
24
  payload = '{"key":"value"}'
39
25
 
40
26
  described_class.parse(payload)
41
27
 
42
- expect(JSON).to have_received(:parse).with(payload)
28
+ expect(Oj).to have_received(:load).with(payload)
43
29
  end
44
30
  end
45
31
  end
@@ -7,7 +7,7 @@ RSpec.describe SearchFlip::NullInstrumenter do
7
7
  it "calls start" do
8
8
  allow(subject).to receive(:start)
9
9
 
10
- subject.instrument("name", { key: "value" }) { true }
10
+ subject.instrument("name", { key: "value" }) {}
11
11
 
12
12
  expect(subject).to have_received(:start)
13
13
  end
@@ -15,7 +15,7 @@ RSpec.describe SearchFlip::NullInstrumenter do
15
15
  it "calls finish" do
16
16
  allow(subject).to receive(:finish)
17
17
 
18
- subject.instrument("name", { key: "value" }) { true }
18
+ subject.instrument("name", { key: "value" }) {}
19
19
 
20
20
  expect(subject).to have_received(:finish)
21
21
  end
@@ -82,7 +82,7 @@ RSpec.describe SearchFlip::Response do
82
82
 
83
83
  ProductIndex.import products
84
84
 
85
- expect(ProductIndex.match_all.results.to_set(&:id)).to eq(products.to_set(&:id))
85
+ expect(ProductIndex.match_all.results.map(&:id).to_set).to eq(products.map(&:id).to_set)
86
86
  end
87
87
  end
88
88
 
@@ -126,7 +126,7 @@ RSpec.describe SearchFlip::Response do
126
126
 
127
127
  response = ProductIndex.match_all.response
128
128
 
129
- expect(response.ids.to_set).to eq(products.map(&:id).to_set(&:to_s))
129
+ expect(response.ids.to_set).to eq(products.map(&:id).map(&:to_s).to_set)
130
130
  expect(response.ids).to eq(response.raw_response["hits"]["hits"].map { |hit| hit["_id"] })
131
131
  end
132
132
  end
@@ -1,6 +1,29 @@
1
1
  require File.expand_path("../spec_helper", __dir__)
2
2
 
3
3
  RSpec.describe SearchFlip::Result do
4
+ describe ".convert" do
5
+ it "deeply converts hashes and arrays" do
6
+ result = described_class.convert("parent" => { "child" => [{ "key1" => "value" }, { "key2" => 3 }] })
7
+
8
+ expect(result.parent.child[0].key1).to eq("value")
9
+ expect(result.parent.child[1].key2).to eq(3)
10
+ end
11
+ end
12
+
13
+ describe "#method_missing" do
14
+ it "returns the value of the key equal to the message name" do
15
+ expect(described_class.convert("some_key" => "value").some_key).to eq("value")
16
+ expect(described_class.new.some_key).to be_nil
17
+ end
18
+ end
19
+
20
+ describe "#responds_to_missing?" do
21
+ it "returns true/false if the key equal to the message name is present or not" do
22
+ expect(described_class.convert("some_key" => nil).respond_to?(:some_key)).to eq(true)
23
+ expect(described_class.convert("some_key" => nil).respond_to?(:other_key)).to eq(false)
24
+ end
25
+ end
26
+
4
27
  describe ".from_hit" do
5
28
  it "adds a _hit key into _source and merges the hit keys into it" do
6
29
  result = SearchFlip::Result.from_hit("_score" => 1.0, "_source" => { "name" => "Some name" })
@@ -8,12 +31,6 @@ RSpec.describe SearchFlip::Result do
8
31
  expect(result).to eq("name" => "Some name", "_hit" => { "_score" => 1.0 })
9
32
  end
10
33
 
11
- it "allows deep method access" do
12
- result = SearchFlip::Result.from_hit("_source" => { "key1" => [{ "key2" => "value" }] })
13
-
14
- expect(result.key1[0].key2).to eq("value")
15
- end
16
-
17
34
  it "works with the _source being disabled" do
18
35
  result = SearchFlip::Result.from_hit("_id" => 1)
19
36
 
@@ -0,0 +1,28 @@
1
+ require File.expand_path("../spec_helper", __dir__)
2
+ require "search_flip/to_json"
3
+
4
+ RSpec.describe "to_json" do
5
+ it "uses the correct format for Time" do
6
+ Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
7
+ expect(Time.now.utc.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
8
+ end
9
+ end
10
+
11
+ it "uses the correct format for Date" do
12
+ Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
13
+ expect(Date.today.to_json).to eq("\"2018-01-01\"")
14
+ end
15
+ end
16
+
17
+ it "uses the correct format for DateTime" do
18
+ Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
19
+ expect(Time.now.utc.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
20
+ end
21
+ end
22
+
23
+ it "uses the correct format for TimeWithZone" do
24
+ Timecop.freeze Time.parse("2018-01-01 12:00:00 UTC") do
25
+ expect(Time.find_zone("UTC").now.to_json).to eq("\"2018-01-01T12:00:00.000000Z\"")
26
+ end
27
+ end
28
+ end
data/spec/spec_helper.rb CHANGED
@@ -16,8 +16,6 @@ RSpec.configure do |config|
16
16
  TestIndex.delete_index if TestIndex.index_exists?
17
17
  ProductIndex.match_all.delete
18
18
  Product.delete_all
19
- CommentIndex.match_all.delete
20
- Comment.delete_all
21
19
  end
22
20
  end
23
21
 
@@ -86,7 +84,7 @@ class CommentIndex
86
84
  include SearchFlip::Index
87
85
 
88
86
  def self.type_name
89
- connection.distribution.nil? && connection.version.to_i < 8 ? "comments" : "_doc"
87
+ "comments"
90
88
  end
91
89
 
92
90
  def self.index_name
@@ -113,7 +111,7 @@ class ProductIndex
113
111
  include SearchFlip::Index
114
112
 
115
113
  def self.mapping
116
- if ProductIndex.connection.distribution || ProductIndex.connection.version.to_i >= 5
114
+ if ProductIndex.connection.version.to_i >= 5
117
115
  {
118
116
  properties: {
119
117
  category: {
@@ -136,7 +134,7 @@ class ProductIndex
136
134
  end
137
135
 
138
136
  def self.type_name
139
- connection.distribution.nil? && connection.version.to_i < 8 ? "products" : "_doc"
137
+ "products"
140
138
  end
141
139
 
142
140
  def self.index_name
@@ -177,7 +175,7 @@ class TestIndex
177
175
  end
178
176
 
179
177
  def self.type_name
180
- connection.distribution.nil? && connection.version.to_i < 8 ? "test" : "_doc"
178
+ "test"
181
179
  end
182
180
 
183
181
  def self.index_name
metadata CHANGED
@@ -1,23 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.0
4
+ version: 4.0.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-19 00:00:00.000000000 Z
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: hashie
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-core
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '0'
20
- type: :runtime
34
+ type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
@@ -25,13 +39,69 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: http
42
+ name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
- type: :runtime
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_bot
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
35
105
  prerelease: false
36
106
  version_requirements: !ruby/object:Gem::Requirement
37
107
  requirements:
@@ -39,7 +109,49 @@ dependencies:
39
109
  - !ruby/object:Gem::Version
40
110
  version: '0'
41
111
  - !ruby/object:Gem::Dependency
42
- name: json
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: http
43
155
  requirement: !ruby/object:Gem::Requirement
44
156
  requirements:
45
157
  - - ">="
@@ -138,14 +250,12 @@ files:
138
250
  - spec/search_flip/null_instrumenter_spec.rb
139
251
  - spec/search_flip/response_spec.rb
140
252
  - spec/search_flip/result_spec.rb
253
+ - spec/search_flip/to_json_spec.rb
141
254
  - spec/spec_helper.rb
142
255
  homepage: https://github.com/mrkamel/search_flip
143
256
  licenses:
144
257
  - MIT
145
- metadata:
146
- homepage_uri: https://github.com/mrkamel/search_flip
147
- source_code_uri: https://github.com/mrkamel/search_flip
148
- changelog_uri: https://github.com/mrkamel/search_flip/blob/master/CHANGELOG.md
258
+ metadata: {}
149
259
  post_install_message: |
150
260
  Thanks for using search_flip!
151
261
  When upgrading to 3.x, please check out
@@ -160,12 +270,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
270
  version: '0'
161
271
  required_rubygems_version: !ruby/object:Gem::Requirement
162
272
  requirements:
163
- - - ">="
273
+ - - ">"
164
274
  - !ruby/object:Gem::Version
165
- version: '0'
275
+ version: 1.3.1
166
276
  requirements: []
167
- rubygems_version: 3.2.3
168
- signing_key:
277
+ rubygems_version: 3.0.3
278
+ signing_key:
169
279
  specification_version: 4
170
280
  summary: Full-Featured Elasticsearch Ruby Client with a Chainable DSL
171
- test_files: []
281
+ test_files:
282
+ - spec/delegate_matcher.rb
283
+ - spec/search_flip/aggregation_spec.rb
284
+ - spec/search_flip/aws_sigv4_plugin_spec.rb
285
+ - spec/search_flip/bulk_spec.rb
286
+ - spec/search_flip/connection_spec.rb
287
+ - spec/search_flip/criteria_spec.rb
288
+ - spec/search_flip/http_client_spec.rb
289
+ - spec/search_flip/index_spec.rb
290
+ - spec/search_flip/json_spec.rb
291
+ - spec/search_flip/model_spec.rb
292
+ - spec/search_flip/null_instrumenter_spec.rb
293
+ - spec/search_flip/response_spec.rb
294
+ - spec/search_flip/result_spec.rb
295
+ - spec/search_flip/to_json_spec.rb
296
+ - spec/spec_helper.rb