Added reloads method to reload the page (note: it may resubmit forms)
This commit is contained in:
parent
407617b0be
commit
7ee7bae757
@ -1,5 +1,6 @@
|
||||
== 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)
|
||||
* Serialize empty text field values just like browsers (Patch from Kamal Fariz Mahyuddi)
|
||||
* Added clicks_link_within(selector, link_text), allowing restricting link search
|
||||
|
@ -179,11 +179,20 @@ module ActionController
|
||||
return unless File.exist?(RAILS_ROOT + "/tmp")
|
||||
|
||||
filename = "webrat-#{Time.now.to_i}.html"
|
||||
File.open(RAILS_ROOT + "/tmp/#{filename}", "w") do |f|
|
||||
f.write response.body
|
||||
end
|
||||
`open tmp/#{filename}`
|
||||
end
|
||||
File.open(RAILS_ROOT + "/tmp/#{filename}", "w") do |f|
|
||||
f.write response.body
|
||||
end
|
||||
`open tmp/#{filename}`
|
||||
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
|
||||
|
||||
@ -313,6 +322,7 @@ module ActionController
|
||||
def request_page(method, url, data = {}) # :nodoc:
|
||||
debug_log "REQUESTING PAGE: #{method.to_s.upcase} #{url} with #{data.inspect}"
|
||||
@current_url = url
|
||||
@last_request_args = [method, url, data]
|
||||
self.send "#{method}_via_redirect", @current_url, data || {}
|
||||
|
||||
if response.body =~ /Exception caught/ || response.body.blank?
|
||||
|
26
test/reloads_test.rb
Normal file
26
test/reloads_test.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user