Skip to content

Commit 385b278

Browse files
meili-bors[bot]ellnix
andauthoredFeb 5, 2025··
Merge #385
385: Fix will_paginate crash when Meilisearch disabled r=ellnix a=ellnix # Pull Request ## Related issue Fixes #382 Using `Meilisearch::Rails.active?` as an alternative to checking that the objects being replaced are actually `NullObject`. For an alternative solution see #383 The advantage of this approach is that NullObject remains opaque and requires no special treatment, and the logic is much easier to follow (in my opinion). Co-authored-by: ellnix <ellnix@disroot.org>
2 parents 5c408f1 + d3cce03 commit 385b278

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed
 

‎lib/meilisearch/rails/pagination/will_paginate.rb

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module Rails
1010
module Pagination
1111
class WillPaginate
1212
def self.create(results, total_hits, options = {})
13+
unless MeiliSearch::Rails.active?
14+
total_hits = 0
15+
options[:page] = 1
16+
options[:per_page] = 1
17+
end
18+
1319
::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
1420
pager.replace results
1521
end

‎spec/pagination/will_paginate_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,15 @@
4242
it 'respects max_total_hits' do
4343
expect(Movie.search('*').count).to eq(5)
4444
end
45+
46+
it 'does not crash when meilisearch is disabled' do
47+
MeiliSearch::Rails.configuration[:active] = false
48+
49+
expect do
50+
Movie.search ''
51+
end.not_to raise_error
52+
53+
ensure
54+
MeiliSearch::Rails.configuration[:active] = true
55+
end
4556
end

0 commit comments

Comments
 (0)
Please sign in to comment.