Permalink
Browse files

current_page? returns false for non-GET requests

  • Loading branch information...
1 parent 6f3c699 commit fddf7ea1c1e520f33fa26fe340f3fc107bcc95c8 @avakhov avakhov committed Sep 2, 2011
Showing with 16 additions and 2 deletions.
  1. +8 −0 actionpack/lib/action_view/helpers/url_helper.rb
  2. +8 −2 actionpack/test/template/url_helper_test.rb
@@ -569,13 +569,21 @@ def mail_to(email_address, name = nil, html_options = {})
#
# current_page?(:controller => 'library', :action => 'checkout')
# # => false
+ #
+ # Let's say we're in the <tt>/products</tt> action with method POST in case of invalid product.
+ #
+ # current_page?(:controller => 'product', :action => 'index')
+ # # => false
+ #
def current_page?(options)
unless request
raise "You cannot use helpers that need to determine the current " \
"page unless your view context provides a Request object " \
"in a #request method"
end
+ return false unless request.get?
+
url_string = url_for(options)
# We ignore any extra parameters in the request_uri if the
@@ -304,8 +304,8 @@ def test_link_to_if
assert_equal "Showing", link_to_if(false, "Showing", url_hash)
end
- def request_for_url(url)
- env = Rack::MockRequest.env_for("http://www.example.com#{url}")
+ def request_for_url(url, opts = {})
+ env = Rack::MockRequest.env_for("http://www.example.com#{url}", opts)
ActionDispatch::Request.new(env)
end
@@ -329,6 +329,12 @@ def test_current_page_with_params_that_match
assert current_page?("http://www.example.com/?order=desc&page=1")
end
+ def test_current_page_with_not_get_verb
+ @request = request_for_url("/events", :method => :post)
+
+ assert !current_page?('/events')
+ end
+
def test_link_unless_current
@request = request_for_url("/")

0 comments on commit fddf7ea

Please sign in to comment.