Skip to content

Commit

Permalink
Fix will_paginate crash when Meilisearch disabled
Browse files Browse the repository at this point in the history
When Meilisearch is disabled, NullObject is passed to will_paginate when
it expects integers.
  • Loading branch information
ellnix committed Jan 13, 2025
1 parent 1eaa408 commit e9cf005
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/meilisearch/rails/pagination/will_paginate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module Rails
module Pagination
class WillPaginate
def self.create(results, total_hits, options = {})
total_hits = 0 if Utilities.null_object?(total_hits)
options[:page] = 1 if Utilities.null_object?(options[:page])
options[:per_page] = 1 if Utilities.null_object?(options[:per_page])

::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
pager.replace results
end
Expand Down
4 changes: 4 additions & 0 deletions lib/meilisearch/rails/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def sequel_model?(model_class)
defined?(::Sequel::Model) && model_class < Sequel::Model
end

def null_object?(obj)
obj.is_a? NullObject
end

private

def constraint_passes?(record, constraint)
Expand Down

0 comments on commit e9cf005

Please sign in to comment.