Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ User.page(2).prev_page #=> 1
User.page(1).first_page? #=> true
User.page(50).last_page? #=> true
User.page(100).out_of_range? #=> true
User.all.paginated? #=> false
User.page(1).paginated? #=> true
```

### The `per` Scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module ActiveRecordModelExtension
included do
include Kaminari::ConfigurationMethods

def self.paginated?
false
end

# Fetch the values at the specified page number
# Model.page(5)
eval <<-RUBY, nil, __FILE__, __LINE__ + 1
Expand Down
4 changes: 4 additions & 0 deletions kaminari-core/lib/kaminari/models/page_scope_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,9 @@ def last_page?
def out_of_range?
current_page > total_pages
end

def paginated?
limit_value.present?
end
end
end
14 changes: 14 additions & 0 deletions kaminari-core/test/models/active_record/scopes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,20 @@ def shutdown
end
end

sub_test_case '#paginated?' do
test 'before calling page' do
assert_false model_class.paginated?
end

test 'after calling page' do
assert_true model_class.page(1).paginated?
end

test 'after calling page and unscoping limit' do
assert_false model_class.page(1).unscope(:limit).paginated?
end
end

sub_test_case '#count' do
test 'page 1' do
assert_equal 25, model_class.page.count
Expand Down
Loading