paginator 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/paginator.rb +7 -2
- data/test/test_paginator.rb +16 -0
- metadata +1 -1
data/lib/paginator.rb
CHANGED
@@ -2,7 +2,7 @@ require 'forwardable'
|
|
2
2
|
|
3
3
|
class Paginator
|
4
4
|
|
5
|
-
VERSION = '1.0.
|
5
|
+
VERSION = '1.0.2'
|
6
6
|
|
7
7
|
class ArgumentError < ::ArgumentError; end
|
8
8
|
class MissingCountError < ArgumentError; end
|
@@ -52,7 +52,12 @@ class Paginator
|
|
52
52
|
# Retrieve page object by number
|
53
53
|
def page(number)
|
54
54
|
number = (n = number.to_i) > 0 ? n : 1
|
55
|
-
Page.new(self, number, lambda{
|
55
|
+
Page.new(self, number, lambda {
|
56
|
+
offset = (number - 1) * @per_page
|
57
|
+
args = [offset]
|
58
|
+
args << @per_page if @select.arity == 2
|
59
|
+
@select.call(*args)
|
60
|
+
})
|
56
61
|
end
|
57
62
|
|
58
63
|
# Page object
|
data/test/test_paginator.rb
CHANGED
@@ -72,5 +72,21 @@ class PaginatorTest < Test::Unit::TestCase
|
|
72
72
|
def test_number_of_pages
|
73
73
|
assert_equal 5, @pager.number_of_pages
|
74
74
|
end
|
75
|
+
|
76
|
+
def test_passing_block_to_initializer_with_arity_of_two_yields_per_page
|
77
|
+
pager = Paginator.new(20,2) do |offset,per_page|
|
78
|
+
assert_equal 2, per_page
|
79
|
+
end
|
80
|
+
pager.page(1).items
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_passing_block_to_initializer_with_arity_of_one_does_not_yield_per_page
|
84
|
+
pager = Paginator.new(20,2) do |offset|
|
85
|
+
assert_equal 0, offset
|
86
|
+
end
|
87
|
+
pager.page(1).items
|
88
|
+
end
|
89
|
+
|
90
|
+
|
75
91
|
|
76
92
|
end
|
metadata
CHANGED