Skip to content

Commit

Permalink
Merge #299
Browse files Browse the repository at this point in the history
299: Properly clean up indexes after test suite runs r=ellnix a=ellnix

# Pull Request

## Related issue
Fixes #298 

## PR checklist
Please check if your PR fulfills the following requirements:
- [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [X] Have you read the contributing guidelines?
- [X] Have you made sure that the title is accurate and descriptive of the changes?


Co-authored-by: ellnix <103502144+ellnix@users.noreply.github.com>
  • Loading branch information
meili-bors[bot] and ellnix authored Nov 3, 2023
2 parents 7fff94d + 7aa05a2 commit ef5d96c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}

safe_index_list.each do |index|
MeiliSearch::Rails.client.delete_index(index.uid)
MeiliSearch::Rails.client.delete_index(index)
end
end
end
10 changes: 6 additions & 4 deletions spec/support/2_method_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# A unique prefix for your test run in local or CI
SAFE_INDEX_PREFIX = "rails_#{SecureRandom.hex(8)}".freeze

def indexes
@indexes ||= {}
end

# avoid concurrent access to the same index in local or CI
def safe_index_uid(name)
"#{SAFE_INDEX_PREFIX}_#{name}"
indexes[name] ||= "#{SAFE_INDEX_PREFIX}_#{name}"
end

# get a list of safe indexes in local or CI
def safe_index_list
list = MeiliSearch::Rails.client.indexes['results']
list = list.select { |index| index.uid.include?(SAFE_INDEX_PREFIX) }
list.sort_by { |index| index.primary_key || '' }
indexes.values.flat_map { |safe_idx| [safe_idx, "#{safe_idx}_test"] }
end
2 changes: 1 addition & 1 deletion spec/support/active_record_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class Post < ActiveRecord::Base

include MeiliSearch::Rails

meilisearch synchronous: true do
meilisearch index_uid: safe_index_uid('Post'), synchronous: true do
attribute :comments do
comments.map(&:body)
end
Expand Down

0 comments on commit ef5d96c

Please sign in to comment.