Skip to content

Commit

Permalink
Fixed a bug where the #total_count raises an exception
Browse files Browse the repository at this point in the history
fixes #849
  • Loading branch information
yuki24 committed Jan 13, 2017
1 parent b8757b7 commit 01ec38a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kaminari-core/lib/kaminari/models/page_scope_methods.rb
Expand Up @@ -5,7 +5,7 @@ module PageScopeMethods
# 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?
Expand Down
Expand Up @@ -84,6 +84,10 @@ class ActiveRecordRelationMethodsTest < ActiveSupport::TestCase
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

0 comments on commit 01ec38a

Please sign in to comment.