Skip to content

Commit 3f46ded

Browse files
Merge #406
406: Refactor multi search specs r=ellnix a=ellnix - These tests were particularly slow, this is about a 50% reduction in time to complete (as reported by rspec). - In addition refactored to clean up deprecation warnings from test output Co-authored-by: ellnix <[email protected]>
2 parents b5d918f + 8b4e067 commit 3f46ded

File tree

2 files changed

+72
-59
lines changed

2 files changed

+72
-59
lines changed

.rubocop_todo.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-03-08 11:51:39 UTC using RuboCop version 1.27.0.
3+
# on 2025-03-14 19:22:00 UTC using RuboCop version 1.27.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -30,13 +30,6 @@ Layout/EmptyLinesAroundModuleBody:
3030
Exclude:
3131
- 'lib/meilisearch-rails.rb'
3232

33-
# Offense count: 2
34-
# This cop supports safe auto-correction (--auto-correct).
35-
# Configuration parameters: IndentationWidth.
36-
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
37-
Layout/FirstArrayElementIndentation:
38-
EnforcedStyle: consistent
39-
4033
# Offense count: 1
4134
# This cop supports safe auto-correction (--auto-correct).
4235
# Configuration parameters: EnforcedStyle.
@@ -146,7 +139,7 @@ RSpec/ContextWording:
146139
- 'spec/options_spec.rb'
147140
- 'spec/system/tech_shop_spec.rb'
148141

149-
# Offense count: 57
142+
# Offense count: 61
150143
# Configuration parameters: CountAsOne.
151144
RSpec/ExampleLength:
152145
Max: 16
@@ -174,7 +167,7 @@ RSpec/MultipleDescribes:
174167
Exclude:
175168
- 'spec/search_spec.rb'
176169

177-
# Offense count: 2
170+
# Offense count: 3
178171
RSpec/NestedGroups:
179172
Max: 4
180173

@@ -184,12 +177,12 @@ RSpec/VerifiedDoubles:
184177
Exclude:
185178
- 'spec/configuration_spec.rb'
186179

187-
# Offense count: 1
180+
# Offense count: 3
188181
# Configuration parameters: ForbiddenMethods, AllowedMethods.
189182
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
190183
Rails/SkipsModelValidations:
191184
Exclude:
192-
- 'spec/settings_spec.rb'
185+
- 'spec/multi_search_spec.rb'
193186

194187
# Offense count: 2
195188
# This cop supports safe auto-correction (--auto-correct).
@@ -247,7 +240,7 @@ Style/StringLiterals:
247240
Exclude:
248241
- 'spec/ms_clean_up_job_spec.rb'
249242

250-
# Offense count: 15
243+
# Offense count: 16
251244
# This cop supports safe auto-correction (--auto-correct).
252245
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
253246
# URISchemes: http, https

spec/multi_search_spec.rb

Lines changed: 66 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,37 @@
44
require 'support/models/color'
55

66
describe 'multi-search' do
7-
def reset_indexes
7+
before do
88
[Book, Color, Product].each do |klass|
99
klass.delete_all
10-
klass.clear_index!(true)
10+
klass.clear_index!
1111
end
12-
end
1312

14-
before do
15-
reset_indexes
16-
17-
Product.create! name: 'palm pixi plus', href: 'ebay', tags: ['terrible']
18-
Product.create! name: 'lg vortex', href: 'ebay', tags: ['decent']
19-
Product.create! name: 'palmpre', href: 'ebay', tags: ['discontinued', 'worst phone ever']
13+
Product.insert_all([
14+
{ name: 'palm pixi plus', href: 'ebay', tags: ['terrible'] },
15+
{ name: 'lg vortex', href: 'ebay', tags: ['decent'] },
16+
{ name: 'palmpre', href: 'ebay', tags: ['discontinued', 'worst phone ever'] }
17+
])
2018
Product.reindex!
2119

22-
Color.create! name: 'blue', short_name: 'blu', hex: 0x0000FF
23-
Color.create! name: 'black', short_name: 'bla', hex: 0x000000
24-
Color.create! name: 'green', short_name: 'gre', hex: 0x00FF00
25-
26-
Book.create! name: 'Steve Jobs', author: 'Walter Isaacson'
27-
Book.create! name: 'Moby Dick', author: 'Herman Melville'
20+
Color.insert_all([
21+
{ name: 'blue', short_name: 'blu', hex: 0x0000FF },
22+
{ name: 'black', short_name: 'bla', hex: 0x000000 },
23+
{ name: 'green', short_name: 'gre', hex: 0x00FF00 }
24+
])
25+
Color.reindex!
26+
27+
Book.insert_all([
28+
{ name: 'Steve Jobs', author: 'Walter Isaacson' },
29+
{ name: 'Moby Dick', author: 'Herman Melville' }
30+
])
31+
Book.reindex!
2832
end
2933

30-
let!(:palm_pixi_plus) { Product.find_by name: 'palm pixi plus' }
31-
let!(:steve_jobs) { Book.find_by name: 'Steve Jobs' }
32-
let!(:blue) { Color.find_by name: 'blue' }
33-
let!(:black) { Color.find_by name: 'black' }
34+
let(:palm_pixi_plus) { Product.find_by name: 'palm pixi plus' }
35+
let(:steve_jobs) { Book.find_by name: 'Steve Jobs' }
36+
let(:blue) { Color.find_by name: 'blue' }
37+
let(:black) { Color.find_by name: 'black' }
3438

3539
context 'with class keys' do
3640
it 'returns ORM records' do
@@ -40,8 +44,10 @@ def reset_indexes
4044
Color => { q: 'bl' }
4145
)
4246

43-
expect(results).to contain_exactly(
44-
steve_jobs, palm_pixi_plus, blue, black
47+
expect(results.to_h).to match(
48+
Book => [steve_jobs],
49+
Product => [palm_pixi_plus],
50+
Color => contain_exactly(blue, black)
4551
)
4652
end
4753
end
@@ -65,11 +71,13 @@ def reset_indexes
6571
'colors' => { q: 'bl', index_uid: Color.index.uid }
6672
)
6773

68-
expect(results).to contain_exactly(
69-
a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs'),
70-
a_hash_including('name' => 'palm pixi plus'),
71-
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
72-
a_hash_including('name' => 'black', 'short_name' => 'bla')
74+
expect(results.to_h).to match(
75+
'books' => [a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs')],
76+
'products' => [a_hash_including('name' => 'palm pixi plus')],
77+
'colors' => contain_exactly(
78+
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
79+
a_hash_including('name' => 'black', 'short_name' => 'bla')
80+
)
7381
)
7482
end
7583

@@ -82,10 +90,10 @@ def reset_indexes
8290
'nature_colors' => { q: 'green', index_uid: index_uid }
8391
)
8492

85-
expect(results).to contain_exactly(
86-
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
87-
a_hash_including('name' => 'black', 'short_name' => 'bla'),
88-
a_hash_including('name' => 'green', 'short_name' => 'gre')
93+
expect(results.to_h).to match(
94+
'bright_colors' => [a_hash_including('name' => 'blue', 'short_name' => 'blu')],
95+
'dark_colors' => [a_hash_including('name' => 'black', 'short_name' => 'bla')],
96+
'nature_colors' => [a_hash_including('name' => 'green', 'short_name' => 'gre')]
8997
)
9098
end
9199

@@ -97,8 +105,10 @@ def reset_indexes
97105
'colors' => { q: 'bl', index_uid: Color.index.uid, class_name: 'Color' }
98106
)
99107

100-
expect(results).to contain_exactly(
101-
steve_jobs, palm_pixi_plus, blue, black
108+
expect(results.to_h).to match(
109+
'books' => [steve_jobs],
110+
'products' => [palm_pixi_plus],
111+
'colors' => contain_exactly(blue, black)
102112
)
103113
end
104114
end
@@ -113,11 +123,13 @@ def reset_indexes
113123
Color.index.uid => { q: 'bl' }
114124
)
115125

116-
expect(results).to contain_exactly(
117-
a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs'),
118-
a_hash_including('name' => 'palm pixi plus'),
119-
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
120-
a_hash_including('name' => 'black', 'short_name' => 'bla')
126+
expect(results.to_h).to match(
127+
Book.index.uid => [a_hash_including('author' => 'Walter Isaacson', 'name' => 'Steve Jobs')],
128+
Product.index.uid.to_sym => [a_hash_including('name' => 'palm pixi plus')],
129+
Color.index.uid => contain_exactly(
130+
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
131+
a_hash_including('name' => 'black', 'short_name' => 'bla')
132+
)
121133
)
122134
end
123135

@@ -129,8 +141,10 @@ def reset_indexes
129141
Color.index.uid => { q: 'bl', class_name: 'Color' }
130142
)
131143

132-
expect(results).to contain_exactly(
133-
steve_jobs, palm_pixi_plus, blue, black
144+
expect(results.to_h).to match(
145+
Book.index.uid => [steve_jobs],
146+
Product.index.uid.to_sym => [palm_pixi_plus],
147+
Color.index.uid => contain_exactly(blue, black)
134148
)
135149
end
136150

@@ -154,10 +168,13 @@ def reset_indexes
154168
Color.index.uid => { q: 'bl' }
155169
)
156170

157-
expect(results).to contain_exactly(
158-
steve_jobs, palm_pixi_plus,
159-
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
160-
a_hash_including('name' => 'black', 'short_name' => 'bla')
171+
expect(results.to_h).to match(
172+
Book => [steve_jobs],
173+
Product.index_uid => [palm_pixi_plus],
174+
Color.index.uid => contain_exactly(
175+
a_hash_including('name' => 'blue', 'short_name' => 'blu'),
176+
a_hash_including('name' => 'black', 'short_name' => 'bla')
177+
)
161178
)
162179
end
163180
end
@@ -172,9 +189,12 @@ def reset_indexes
172189
Color.index.uid => { q: 'bl', page: 1, 'hitsPerPage' => '1' }
173190
)
174191

175-
expect(results).to contain_exactly(
176-
steve_jobs, palm_pixi_plus,
177-
a_hash_including('name' => 'black', 'short_name' => 'bla')
192+
expect(results.to_h).to match(
193+
Book => [steve_jobs],
194+
Product => [palm_pixi_plus],
195+
Color.index_uid => contain_exactly(
196+
a_hash_including('name' => 'black', 'short_name' => 'bla')
197+
)
178198
)
179199

180200
Meilisearch::Rails.configuration[:pagination_backend] = nil

0 commit comments

Comments
 (0)