Skip to content
Browse files

Add support for page parameter in custom routes like "/foo/page/2"

  • Loading branch information...
1 parent fb38b83 commit 4d2da56949b66f838d932724ca40bf7f93627b1f @mislav mislav committed Apr 21, 2008
Showing with 30 additions and 7 deletions.
  1. +6 −0 CHANGELOG
  2. +1 −1 README.rdoc
  3. +1 −1 lib/will_paginate/view_helpers.rb
  4. +4 −4 test/lib/view_test_process.rb
  5. +18 −1 test/view_test.rb
View
6 CHANGELOG
@@ -1,3 +1,9 @@
+== 2.2.2, released 2008-04-21
+
+* Add support for page parameter in custom routes like "/foo/page/2"
+* Change output of "page_entries_info" on single-page collection and erraneous
+ output with empty collection as reported by Tim Chater
+
== 2.2.1, released 2008-04-08
* take less risky path when monkeypatching named_scope; fix that it no longer
View
2 README.rdoc
@@ -114,7 +114,7 @@ contributions or just simply awesome ideas:
Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
-Lourens Naudé, Rick Olson.
+Lourens Naudé, Rick Olson, Russell Norris.
== Usable pagination in the UI
View
2 lib/will_paginate/view_helpers.rb
@@ -280,7 +280,7 @@ def url_for(page)
end
url = @template.url_for(@url_params)
- @url_string = url.sub(/([?&]#{CGI.escape param_name}=)#{page}/, '\1@')
+ @url_string = url.sub(%r!([?&/]#{CGI.escape param_name}[=/])#{page}!, '\1@')
return url
end
@url_string.sub '@', page.to_s
View
8 test/lib/view_test_process.rb
@@ -5,15 +5,19 @@
WillPaginate.enable_actionpack
ActionController::Routing::Routes.draw do |map|
+ map.connect 'dummy/page/:page', :controller => 'dummy'
map.connect ':controller/:action/:id'
end
ActionController::Base.perform_caching = false
class DummyRequest
+ attr_accessor :symbolized_path_parameters
+
def initialize
@get = true
@params = {}
+ @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
end
def get?
@@ -24,10 +28,6 @@ def post
@get = false
end
- def symbolized_path_parameters
- { :controller => 'foo', :action => 'bar' }
- end
-
def relative_url_root
''
end
View
19 test/view_test.rb
@@ -220,6 +220,15 @@ def test_complex_custom_page_param
end
end
+ def test_custom_routing_page_param
+ @request.symbolized_path_parameters.update :controller => 'dummy', :action => nil
+ paginate :per_page => 2 do
+ assert_select 'a[href]', 6 do |links|
+ assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
+ end
+ end
+ end
+
## internal hardcore stuff ##
class LegacyCollection < WillPaginate::Collection
@@ -307,14 +316,22 @@ def validate_page_numbers expected, links, param_name = :page
})
end
- def assert_links_match pattern, links = nil
+ def assert_links_match pattern, links = nil, numbers = nil
links ||= assert_select 'div.pagination a[href]' do |elements|
elements
end
+
+ pages = [] if numbers
links.each do |el|
assert_match pattern, el['href']
+ if numbers
+ el['href'] =~ pattern
+ pages << $1.to_i
+ end
end
+
+ assert_equal pages, numbers, "page numbers don't match" if numbers
end
def assert_no_links_match pattern

0 comments on commit 4d2da56

Please sign in to comment.
Something went wrong with that request. Please try again.