Added reloads method to reload the page (note: it may resubmit forms)

This commit is contained in:
Kamal Fariz Mahyuddin 2008-03-08 14:13:38 +08:00 committed by Bryan Helmkamp
parent 407617b0be
commit 7ee7bae757
3 changed files with 45 additions and 8 deletions

View File

@ -1,5 +1,6 @@
== Trunk == Trunk
* Added reloads method to reload the page (Patch from Kamal Fariz Mahyuddi)
* Prevent making a request if clicking on local anchor link (Patch from Kamal Fariz Mahyuddi) * Prevent making a request if clicking on local anchor link (Patch from Kamal Fariz Mahyuddi)
* Serialize empty text field values just like browsers (Patch from Kamal Fariz Mahyuddi) * Serialize empty text field values just like browsers (Patch from Kamal Fariz Mahyuddi)
* Added clicks_link_within(selector, link_text), allowing restricting link search * Added clicks_link_within(selector, link_text), allowing restricting link search

View File

@ -185,6 +185,15 @@ module ActionController
`open tmp/#{filename}` `open tmp/#{filename}`
end end
# Reloads the last page requested. Note that this will resubmit forms
# and their data.
#
# Example:
# reloads
def reloads
request_page(*@last_request_args) if defined?(@last_request_args) && @last_request_args
end
protected # Methods you could call, but probably shouldn't protected # Methods you could call, but probably shouldn't
def authenticity_token_value(onclick) def authenticity_token_value(onclick)
@ -313,6 +322,7 @@ module ActionController
def request_page(method, url, data = {}) # :nodoc: def request_page(method, url, data = {}) # :nodoc:
debug_log "REQUESTING PAGE: #{method.to_s.upcase} #{url} with #{data.inspect}" debug_log "REQUESTING PAGE: #{method.to_s.upcase} #{url} with #{data.inspect}"
@current_url = url @current_url = url
@last_request_args = [method, url, data]
self.send "#{method}_via_redirect", @current_url, data || {} self.send "#{method}_via_redirect", @current_url, data || {}
if response.body =~ /Exception caught/ || response.body.blank? if response.body =~ /Exception caught/ || response.body.blank?

26
test/reloads_test.rb Normal file
View File

@ -0,0 +1,26 @@
require File.dirname(__FILE__) + "/helper"
RAILS_ROOT = "." unless defined?(RAILS_ROOT)
class ReloadsTest < Test::Unit::TestCase
def setup
@session = ActionController::Integration::Session.new
@session.stubs(:assert_response)
@session.stubs(:get_via_redirect)
@response = mock
@session.stubs(:response).returns(@response)
@response.stubs(:body).returns("")
end
def test_should_reload_the_page
@session.expects(:get_via_redirect).with("/", {}).times(2)
@session.visits("/")
@session.reloads
end
def test_should_not_request_page_if_not_visited_any_page
@session.expects(:get_via_redirect).never
@session.reloads
end
end