1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

Fixed a bug where the #total_count raises an exception

fixes #849
This commit is contained in:
Yuki Nishijima 2017-01-13 04:26:43 +00:00
parent b8757b7f0a
commit 01ec38a1ca
2 changed files with 5 additions and 1 deletions

View file

@ -5,7 +5,7 @@ module Kaminari
# Model.page(3).per(10)
def per(num, max_per_page: nil)
max_per_page ||= ((defined?(@_max_per_page) && @_max_per_page) || self.max_per_page)
@_per = num || default_per_page
@_per = (num || default_per_page).to_i
if (n = num.to_i) < 0 || !(/^\d/ =~ num.to_s)
self
elsif n.zero?

View file

@ -84,6 +84,10 @@ if defined? ActiveRecord
test "throw an exception when calculating total_count when the query includes column aliases used by a group-by clause" do
assert_equal 3, Book.joins(authorships: :user).select("users.name as author_name").group('users.name').page(1).total_count
end
test 'total_count is calculable with page 1 per "5" (the string)' do
assert_equal 7, User.page(1).per('5').load.total_count
end
end
end
end