File tree 2 files changed +14
-5
lines changed
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -18,11 +18,14 @@ def initialize(array, options)
18
18
end
19
19
20
20
def self . create ( results , total_hits , options = { } )
21
- offset = ( ( options [ :page ] - 1 ) * options [ :per_page ] )
22
- total_hits = 0 if total_hits . nil?
23
- offset = 0 if offset . nil?
24
- limit = 0 if options [ :per_page ] . nil?
25
- array = new results , limit : limit , offset : offset , total_count : total_hits
21
+ unless MeiliSearch ::Rails . active?
22
+ total_hits = 0
23
+ options [ :page ] = 1
24
+ options [ :per_page ] = 1
25
+ end
26
+
27
+ offset = ( options [ :page ] - 1 ) * options [ :per_page ]
28
+ array = new results , limit : options [ :per_page ] , offset : offset , total_count : total_hits
26
29
27
30
if array . empty? && !results . empty?
28
31
# since Kaminari 0.16.0, you need to pad the results with nil values so it matches the offset param
Original file line number Diff line number Diff line change 70
70
it 'respects max_total_hits' do
71
71
expect ( Restaurant . search ( '*' ) . count ) . to eq ( 2 )
72
72
end
73
+
74
+ it 'correctly forwards parameters' do
75
+ # Kaminari only makes current_page available if
76
+ # limit and offset have been passed
77
+ expect ( Restaurant . search ( '*' ) . current_page ) . to eq ( 1 )
78
+ end
73
79
end
You can’t perform that action at this time.
0 commit comments