mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
current_page? returns false for non-GET requests
This commit is contained in:
@@ -569,6 +569,12 @@ module ActionView
|
||||
#
|
||||
# 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 " \
|
||||
@@ -576,6 +582,8 @@ module ActionView
|
||||
"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 @@ class UrlHelperTest < ActiveSupport::TestCase
|
||||
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 @@ class UrlHelperTest < ActiveSupport::TestCase
|
||||
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("/")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user