Skip to content

Commit 96dd4a4

Browse files
meili-bors[bot]ellnixbrunoocasali
authored
Merge #408
408: Speed up tests r=brunoocasali a=ellnix In preparation for adding more tests, which itself is in preparation for some serious refactoring. Co-authored-by: ellnix <[email protected]> Co-authored-by: Bruno Casali <[email protected]>
2 parents c3fc3f1 + 9f01362 commit 96dd4a4

File tree

8 files changed

+21
-21
lines changed

8 files changed

+21
-21
lines changed

spec/model_methods_spec.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
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)
16-
11+
# rubocop:disable Rails/SkipsModelValidations
12+
Color.insert_all([
13+
{ name: 'red', short_name: 'r3', hex: 3 },
14+
{ name: 'red', short_name: 'r1', hex: 1 },
15+
{ name: 'purple', short_name: 'p', hex: 4 }
16+
])
17+
# rubocop:enable Rails/SkipsModelValidations
1718
Color.where(name: 'red').reindex!(3, true)
1819
expect(Color.search('').size).to eq(2)
1920

20-
Color.clear_index!(true)
21-
Color.where(id: Color.first.id).reindex!(3, true)
21+
Color.clear_index!
22+
Color.where(name: 'purple').reindex!(3, true)
2223
expect(Color.search('').size).to eq(1)
2324
end
2425
end
@@ -66,6 +67,7 @@
6667
)
6768
end
6869

70+
# No need to await since Book is synchronous
6971
expect(Book.search('Frankenstein')).to be_one
7072
end
7173
end
@@ -77,6 +79,7 @@
7779
_blue = Color.create!(name: 'blue', short_name: 'blu', hex: 0x0000FF)
7880
_black = Color.create!(name: 'black', short_name: 'bla', hex: 0x000000)
7981

82+
# No need to await since Color is synchronous
8083
json = Color.raw_search('')
8184
Color.index_documents Color.limit(1), true # reindex last color, `limit` is incompatible with the reindex! method
8285
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 } }) # rubocop:disable Rails/SkipsModelValidations
12+
Book.reindex!
1413

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

spec/support/models/animals.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def ms_id
3434

3535
module TestUtil
3636
def self.reset_animals!
37-
Cat.clear_index!(true)
37+
Cat.clear_index!
3838
Cat.delete_all
39-
Dog.clear_index!(true)
39+
Dog.clear_index!
4040
Dog.delete_all
4141
end
4242
end

spec/support/models/book.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def public?
3535

3636
module TestUtil
3737
def self.reset_books!
38-
Book.clear_index!(true)
38+
Book.clear_index!
3939
Book.index(safe_index_uid('BookAuthor')).delete_all_documents
4040
Book.index(safe_index_uid('Book')).delete_all_documents
4141
end

spec/support/models/color.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def will_save_change_to_short_name?
3939

4040
module TestUtil
4141
def self.reset_colors!
42-
Color.clear_index!(true)
42+
Color.clear_index!
4343
Color.delete_all
4444
end
4545
end

spec/support/models/movie.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Movie < ActiveRecord::Base
1515

1616
module TestUtil
1717
def self.reset_movies!
18-
Movie.clear_index!(true)
18+
Movie.clear_index!
1919
Movie.delete_all
2020
end
2121
end

spec/support/models/people.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def will_save_change_to_full_name?
2525

2626
module TestUtil
2727
def self.reset_people!
28-
People.clear_index!(true)
28+
People.clear_index!
2929
People.delete_all
3030
end
3131
end

0 commit comments

Comments
 (0)