Skip to content

Commit

Permalink
Isolate pagination configuration in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix committed Nov 1, 2023
1 parent a2a9fbe commit 6394f2e
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,7 @@
describe 'Kaminari' do
before(:all) do
require 'kaminari'
MeiliSearch::Rails.configuration = { meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://127.0.0.1:7700'),
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'masterKey'), pagination_backend: :kaminari }
MeiliSearch::Rails.configuration[:pagination_backend] = :kaminari
Restaurant.clear_index!(true)

10.times do
Expand All @@ -701,6 +700,8 @@
Restaurant.reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true)
end

after(:all) { MeiliSearch::Rails.configuration[:pagination_backend] = nil }

it 'paginates' do
hits = Restaurant.search ''
expect(hits.total_count).to eq(Restaurant.raw_search('')['hits'].size)
Expand Down Expand Up @@ -745,17 +746,16 @@
describe 'Will_paginate' do
before(:all) do
require 'will_paginate'
MeiliSearch::Rails.configuration = {
meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://127.0.0.1:7700'),
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'masterKey'), pagination_backend: :will_paginate
}
MeiliSearch::Rails.configuration[:pagination_backend] = :will_paginate
Movie.clear_index!(true)

10.times { Movie.create(title: Faker::Movie.title) }

Movie.reindex!(MeiliSearch::Rails::IndexSettings::DEFAULT_BATCH_SIZE, true)
end

after(:all) { MeiliSearch::Rails.configuration[:pagination_backend] = nil }

it 'paginates' do
hits = Movie.search '', hits_per_page: 2
expect(hits.per_page).to eq(2)
Expand Down Expand Up @@ -789,13 +789,8 @@
end

describe 'with pagination by pagy' do
before(:all) do
MeiliSearch::Rails.configuration = {
meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://127.0.0.1:7700'),
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'masterKey'),
pagination_backend: :pagy
}
end
before(:all) { MeiliSearch::Rails.configuration[:pagination_backend] = :pagy }
after(:all) { MeiliSearch::Rails.configuration[:pagination_backend] = nil }

it 'has meaningful error when pagy is set as the pagination_backend' do
logger = double
Expand All @@ -811,8 +806,6 @@

describe 'attributes_to_crop' do
before(:all) do
# MeiliSearch::Rails.configuration = { meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://127.0.0.1:7700'),
# meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'masterKey') }
MeiliSearch::Rails.configuration[:per_environment] = false

10.times do
Expand Down Expand Up @@ -1077,7 +1070,7 @@
end
end

context 'when MeiliSearch calls are deactivated', focus: true do
context 'when MeiliSearch calls are deactivated' do
it 'is active by default' do
expect(MeiliSearch::Rails).to be_active
end
Expand Down

0 comments on commit 6394f2e

Please sign in to comment.