public
Rubygem
Description: Most awesome pagination solution for Ruby
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
Click here to lend your support to: will_paginate and make a donation at www.pledgie.com !
Rename WillPaginate::Collection#page_count to #total_pages for consistency. If 
you implemented this interface, change your implementation accordingly.
Mislav Marohnić (author)
Thu Apr 03 20:16:48 -0700 2008
commit  9158a472c6a515e1902c67f626ea2a62ec3d9312
tree    9f4066ebb7922e6da46773882feb4ab600e063b2
parent  3f770b7c414d2dfdca8c83cc5d85ecc4ddf1f083
...
22
23
24
25
 
26
27
28
...
69
70
71
72
73
74
75
76
77
78
79
80
81
 
82
83
84
85
86
87
88
89
90
91
...
97
98
99
100
 
101
102
103
...
22
23
24
 
25
26
27
28
...
69
70
71
 
 
 
 
 
72
73
74
75
 
76
77
78
79
80
81
82
 
83
84
85
...
91
92
93
 
94
95
96
97
0
@@ -22,7 +22,7 @@ module WillPaginate
0
   # solutions: see +create+.
0
   #
0
   class Collection < Array
0
-    attr_reader :current_page, :per_page, :total_entries
0
+    attr_reader :current_page, :per_page, :total_entries, :total_pages
0
 
0
     # Arguments to this constructor are the current page number, per-page limit
0
     # and the total number of entries. The last argument is optional because it
0
@@ -69,23 +69,17 @@ module WillPaginate
0
       pager
0
     end
0
 
0
-    # The total number of pages.
0
-    def page_count
0
-      @total_pages
0
-    end
0
-
0
     # Helper method that is true when someone tries to fetch a page with a
0
     # larger number than the last page. Can be used in combination with flashes
0
     # and redirecting.
0
     def out_of_bounds?
0
-      current_page > page_count
0
+      current_page > total_pages
0
     end
0
 
0
     # Current offset of the paginated collection. If we're on the first page,
0
     # it is always 0. If we're on the 2nd page and there are 30 entries per page,
0
     # the offset is 30. This property is useful if you want to render ordinals
0
     # besides your records: simply start with offset + 1.
0
-    #
0
     def offset
0
       (current_page - 1) * per_page
0
     end
0
@@ -97,7 +91,7 @@ module WillPaginate
0
 
0
     # current_page + 1 or nil if there is no next page
0
     def next_page
0
-      current_page < page_count ? (current_page + 1) : nil
0
+      current_page < total_pages ? (current_page + 1) : nil
0
     end
0
 
0
     def total_entries=(number)
...
88
89
90
91
 
92
93
94
...
234
235
236
237
 
238
239
240
...
88
89
90
 
91
92
93
94
...
234
235
236
 
237
238
239
240
0
@@ -88,7 +88,7 @@ module WillPaginate
0
           "forget to specify the collection object for will_paginate?" unless collection
0
       end
0
       # early exit if there is nothing to render
0
-      return nil unless collection.page_count > 1
0
+      return nil unless collection.total_pages > 1
0
       options = options.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options
0
       # create the renderer instance
0
       renderer_class = options[:renderer].to_s.constantize
0
@@ -234,7 +234,7 @@ module WillPaginate
0
     end
0
 
0
     def total_pages
0
-      @collection.page_count
0
+      @collection.total_pages
0
     end
0
 
0
     def param_name
...
50
51
52
53
 
54
55
56
57
 
58
59
60
...
96
97
98
99
 
100
101
102
...
104
105
106
 
 
 
 
 
107
108
109
...
50
51
52
 
53
54
55
56
 
57
58
59
60
...
96
97
98
 
99
100
101
102
...
104
105
106
107
108
109
110
111
112
113
114
0
@@ -50,11 +50,11 @@ class ArrayPaginationTest < Test::Unit::TestCase
0
     end
0
 
0
     assert_equal entries, collection
0
-    assert_respond_to_all collection, %w(page_count each offset size current_page per_page total_entries)
0
+    assert_respond_to_all collection, %w(total_pages each offset size current_page per_page total_entries)
0
     assert_kind_of Array, collection
0
     assert_instance_of Array, collection.entries
0
     assert_equal 3, collection.offset
0
-    assert_equal 4, collection.page_count
0
+    assert_equal 4, collection.total_pages
0
     assert !collection.out_of_bounds?
0
   end
0
 
0
@@ -96,7 +96,7 @@ class ArrayPaginationTest < Test::Unit::TestCase
0
     bad_input = [0, -1, nil, '', 'Schnitzel']
0
 
0
     bad_input.each do |bad|
0
-      assert_raise(WillPaginate::InvalidPage) { create(bad) }
0
+      assert_raise(WillPaginate::InvalidPage) { create bad }
0
     end
0
   end
0
 
0
@@ -104,6 +104,11 @@ class ArrayPaginationTest < Test::Unit::TestCase
0
     assert_raise(ArgumentError) { create(1, -1) }
0
   end
0
 
0
+  def test_page_count_was_removed
0
+    assert_raise(NoMethodError) { create.page_count }
0
+    # It's `total_pages` now.
0
+  end
0
+
0
   private
0
     def create(page = 2, limit = 5, total = nil, &block)
0
       if block_given?
...
16
17
18
19
 
20
21
22
23
24
25
 
26
27
28
...
41
42
43
44
 
45
46
47
48
49
 
50
51
52
53
54
 
55
56
57
58
59
60
61
 
62
63
64
65
66
67
68
 
69
70
71
...
16
17
18
 
19
20
21
22
23
24
 
25
26
27
28
...
41
42
43
 
44
45
46
47
48
 
49
50
51
52
53
 
54
55
56
57
58
59
60
 
61
62
63
64
65
66
67
 
68
69
70
71
0
@@ -16,13 +16,13 @@ class FinderTest < ActiveRecordTestCase
0
     assert_equal 1, entries.current_page
0
     assert_nil entries.previous_page
0
     assert_nil entries.next_page
0
-    assert_equal 1, entries.page_count
0
+    assert_equal 1, entries.total_pages
0
     assert_equal 4, entries.size
0
     
0
     entries = Topic.paginate :page => 2
0
     assert_equal 2, entries.current_page
0
     assert_equal 1, entries.previous_page
0
-    assert_equal 1, entries.page_count
0
+    assert_equal 1, entries.total_pages
0
     assert entries.empty?
0
   end
0
 
0
@@ -41,31 +41,31 @@ class FinderTest < ActiveRecordTestCase
0
   def test_paginate_with_per_page
0
     entries = Topic.paginate :page => 1, :per_page => 1
0
     assert_equal 1, entries.size
0
-    assert_equal 4, entries.page_count
0
+    assert_equal 4, entries.total_pages
0
 
0
     # Developer class has explicit per_page at 10
0
     entries = Developer.paginate :page => 1
0
     assert_equal 10, entries.size
0
-    assert_equal 2, entries.page_count
0
+    assert_equal 2, entries.total_pages
0
 
0
     entries = Developer.paginate :page => 1, :per_page => 5
0
     assert_equal 11, entries.total_entries
0
     assert_equal 5, entries.size
0
-    assert_equal 3, entries.page_count
0
+    assert_equal 3, entries.total_pages
0
   end
0
   
0
   def test_paginate_with_order
0
     entries = Topic.paginate :page => 1, :order => 'created_at desc'
0
     expected = [topics(:futurama), topics(:harvey_birdman), topics(:rails), topics(:ar)].reverse
0
     assert_equal expected, entries.to_a
0
-    assert_equal 1, entries.page_count
0
+    assert_equal 1, entries.total_pages
0
   end
0
   
0
   def test_paginate_with_conditions
0
     entries = Topic.paginate :page => 1, :conditions => ["created_at > ?", 30.minutes.ago]
0
     expected = [topics(:rails), topics(:ar)]
0
     assert_equal expected, entries.to_a
0
-    assert_equal 1, entries.page_count
0
+    assert_equal 1, entries.total_pages
0
   end
0
 
0
   def test_paginate_with_include_and_conditions
...
189
190
191
192
 
193
194
195
...
204
205
206
207
 
208
209
210
...
189
190
191
 
192
193
194
195
...
204
205
206
 
207
208
209
210
0
@@ -189,7 +189,7 @@ class PaginationTest < Test::Unit::TestCase
0
   def test_no_pagination
0
     get :list_developers, :per_page => 12
0
     entries = assigns :developers
0
-    assert_equal 1, entries.page_count
0
+    assert_equal 1, entries.total_pages
0
     assert_equal 11, entries.size
0
 
0
     assert_equal '', @response.body
0
@@ -204,7 +204,7 @@ class PaginationTest < Test::Unit::TestCase
0
   uses_mocha 'helper internals' do
0
     def test_collection_name_can_be_guessed
0
       collection = mock
0
-      collection.expects(:page_count).returns(1)
0
+      collection.expects(:total_pages).returns(1)
0
       get :guess_collection_name, {}, :wp => collection
0
     end
0
   end

Comments