From 17d0fb83aa8e257ecf887d3c9774f4289bee4458 Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Sun, 8 May 2016 22:23:36 +0000 Subject: [PATCH] Fixed a bug where the range of the records displayed on the last page doesn't match closes #718 --- lib/kaminari/helpers/action_view_extension.rb | 2 +- spec/helpers/action_view_extension_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/kaminari/helpers/action_view_extension.rb b/lib/kaminari/helpers/action_view_extension.rb index eaf0e0a..d438eca 100644 --- a/lib/kaminari/helpers/action_view_extension.rb +++ b/lib/kaminari/helpers/action_view_extension.rb @@ -95,7 +95,7 @@ module Kaminari t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count) else first = collection.offset_value + 1 - last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value + last = (sum = collection.offset_value + collection.limit_value) > collection.total_count ? collection.total_count : sum t('helpers.page_entries_info.more_pages.display_entries', :entry_name => entry_name, :first => first, :last => last, :total => collection.total_count) end.html_safe end diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb index 6a64dfc..415c659 100644 --- a/spec/helpers/action_view_extension_spec.rb +++ b/spec/helpers/action_view_extension_spec.rb @@ -209,6 +209,18 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(Rails) do it { should == 'Displaying members 26 - 50 of 50 in total' } end end + + describe 'the last page' do + before do + User.max_pages_per 4 + @users = User.page(4).per(10) + end + + after { User.max_pages_per nil } + + subject { helper.page_entries_info @users, :params => {:controller => 'users', :action => 'index'} } + it { should == 'Displaying users 31 - 40 of 50 in total' } + end end end context 'on a model with namespace' do