Skip to content

Commit 54e8edc

Browse files
committed
Speed up various tests
Use insert_all instead of running callbacks, remove unnecessary awaits.
1 parent d582b98 commit 54e8edc

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

spec/model_methods_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
it 'uses the specified scope' do
99
TestUtil.reset_colors!
1010

11-
Color.create!(name: 'red', short_name: 'r3', hex: 3)
12-
Color.create!(name: 'red', short_name: 'r1', hex: 1)
13-
Color.create!(name: 'purple', short_name: 'p')
14-
15-
Color.clear_index!(true)
11+
Color.insert_all([
12+
{ name: 'red', short_name: 'r3', hex: 3 },
13+
{ name: 'red', short_name: 'r1', hex: 1 },
14+
{ name: 'purple', short_name: 'p', hex: 4 }
15+
])
1616

1717
Color.where(name: 'red').reindex!(3, true)
1818
expect(Color.search('').size).to eq(2)
1919

20-
Color.clear_index!(true)
21-
Color.where(id: Color.first.id).reindex!(3, true)
20+
Color.clear_index!
21+
Color.where(name: 'purple').reindex!(3, true)
2222
expect(Color.search('').size).to eq(1)
2323
end
2424
end
@@ -66,6 +66,7 @@
6666
)
6767
end
6868

69+
# No need to await since Book is synchronous
6970
expect(Book.search('Frankenstein')).to be_one
7071
end
7172
end
@@ -77,6 +78,7 @@
7778
_blue = Color.create!(name: 'blue', short_name: 'blu', hex: 0x0000FF)
7879
_black = Color.create!(name: 'black', short_name: 'bla', hex: 0x000000)
7980

81+
# No need to await since Color is synchronous
8082
json = Color.raw_search('')
8183
Color.index_documents Color.limit(1), true # reindex last color, `limit` is incompatible with the reindex! method
8284
expect(json['hits'].count).to eq(Color.raw_search('')['hits'].count)

spec/ms_clean_up_job_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'spec_helper'
2+
require 'support/models/restaurant'
3+
require 'support/models/book'
24

35
RSpec.describe 'MeiliSearch::Rails::MSCleanUpJob' do
46
include ActiveJob::TestHelper
@@ -9,10 +11,6 @@ def clean_up_indexes
911

1012
def create_indexed_record
1113
record
12-
13-
indexes.each do |index|
14-
index.wait_for_task(index.tasks['results'].last['uid'])
15-
end
1614
end
1715

1816
subject(:clean_up) { MeiliSearch::Rails::MSCleanUpJob }

spec/safe_index_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
genres = %w[Legend Fiction Crime].cycle
99
authors = %w[A B C].cycle
1010

11-
5.times do
12-
Book.create! name: Faker::Book.title, author: authors.next, genre: genres.next
13-
end
11+
Book.insert_all(Array.new(5) { { name: Faker::Book.title, author: authors.next, genre: genres.next } })
12+
Book.reindex!
1413

1514
expect do
1615
Book.index.facet_search('genre', 'Fic', filter: 'author = A')

0 commit comments

Comments
 (0)