Skip to content

Commit

Permalink
Refactor CleanUpJob spec for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix committed Jan 10, 2024
1 parent 083d1e2 commit 91437f1
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions spec/ms_clean_up_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
RSpec.describe 'MeiliSearch::Rails::MSCleanUpJob' do
include ActiveJob::TestHelper

subject(:job) { MeiliSearch::Rails::MSCleanUpJob }
def clean_up_indexes
indexes.each(&:delete_all_documents)
end

def create_indexed_record
record

indexes.each do |index|
index.wait_for_task(index.tasks['results'].last['uid'])
end
end

subject(:record) do
subject(:clean_up) { MeiliSearch::Rails::MSCleanUpJob }

let(:record) do
Book.create name: "Moby Dick", author: "Herman Mellville",
premium: false, released: true
end
Expand All @@ -21,16 +33,11 @@
end

it 'removes record from all indexes' do
indexes.each(&:delete_all_documents)

record
clean_up_indexes

indexes.each do |index|
index.wait_for_task(index.tasks['results'].first['uid'])
expect(index.search('*')['hits']).to be_one
end
create_indexed_record

job.perform_now(record_entries)
clean_up.perform_now(record_entries)

indexes.each do |index|
expect(index.search('*')['hits']).to be_empty
Expand All @@ -45,17 +52,21 @@
description: "Mexican chicken restaurant in Albuquerque, New Mexico.")
end

let(:indexes) { [Restaurant.index] }

it 'successfully deletes its document in the index' do
record
Restaurant.index.wait_for_task(Restaurant.index.tasks['results'].first['uid'])
expect(Restaurant.index.search("Pollos")['hits']).to be_one
clean_up_indexes

create_indexed_record

record.delete # does not run callbacks, unlike #destroy

job.perform_later(record_entries)
clean_up.perform_later(record_entries)
expect { perform_enqueued_jobs }.not_to raise_error

expect(Restaurant.index.search("Pollos")['hits']).to be_empty
indexes.each do |index|
expect(index.search('*')['hits']).to be_empty
end
end
end
end

0 comments on commit 91437f1

Please sign in to comment.