From 9d46d6029cf321b8cde0d06925180c75c6b5339b Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Fri, 12 Apr 2019 13:02:02 -0400 Subject: [PATCH] Fixes the inconsistency in the #first_page method --- kaminari-core/lib/kaminari/models/page_scope_methods.rb | 2 +- kaminari-core/test/models/active_record/scopes_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kaminari-core/lib/kaminari/models/page_scope_methods.rb b/kaminari-core/lib/kaminari/models/page_scope_methods.rb index d5ac025..b5deadb 100644 --- a/kaminari-core/lib/kaminari/models/page_scope_methods.rb +++ b/kaminari-core/lib/kaminari/models/page_scope_methods.rb @@ -75,7 +75,7 @@ module Kaminari # First page of the collection? def first_page? - current_page == 1 + !out_of_range? && (current_page == 1) end # Last page of the collection? diff --git a/kaminari-core/test/models/active_record/scopes_test.rb b/kaminari-core/test/models/active_record/scopes_test.rb index d852844..585227b 100644 --- a/kaminari-core/test/models/active_record/scopes_test.rb +++ b/kaminari-core/test/models/active_record/scopes_test.rb @@ -340,6 +340,12 @@ if defined? ActiveRecord test 'not on first page' do assert_false model_class.page(5).per(10).first_page? end + + test 'on first page with no record' do + model_class.delete_all + + assert_false model_class.page(1).first_page? + end end sub_test_case '#last_page?' do