From 14d114ce1dbbf7b70c71ace7d328b18177bbea82 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 19 Jan 2009 13:56:22 -0500 Subject: [PATCH] Ensure the previous pages params aren't passed through redirect --- lib/webrat/core/session.rb | 2 +- .../rails/app/controllers/webrat_controller.rb | 15 +++++++++++++-- .../views/webrat/before_redirect_form.html.erb | 7 +++++++ spec/integration/rails/config/routes.rb | 6 +++++- .../rails/test/integration/webrat_test.rb | 11 +++++++++++ 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 spec/integration/rails/app/views/webrat/before_redirect_form.html.erb diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index e0096fc..8010436 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -112,7 +112,7 @@ For example: @http_method = http_method @data = data - request_page(response_location, :get, data) if internal_redirect? + request_page(response_location, :get, {}) if internal_redirect? return response end diff --git a/spec/integration/rails/app/controllers/webrat_controller.rb b/spec/integration/rails/app/controllers/webrat_controller.rb index 94ffb76..890e6d8 100644 --- a/spec/integration/rails/app/controllers/webrat_controller.rb +++ b/spec/integration/rails/app/controllers/webrat_controller.rb @@ -12,13 +12,24 @@ class WebratController < ApplicationController def submit render :text => "OK" end - + def internal_redirect - redirect_to :submit + redirect_to submit_path end def external_redirect redirect_to "http://google.com" end + def before_redirect_form + end + + def redirect_to_show_params + redirect_to show_params_path(:custom_param => "123") + end + + def show_params + render :text => params.to_json + end + end \ No newline at end of file diff --git a/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb b/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb new file mode 100644 index 0000000..55f6577 --- /dev/null +++ b/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb @@ -0,0 +1,7 @@ +<% form_tag redirect_to_show_params_path do %> + + + <%= submit_tag "Test" %> +<% end %> \ No newline at end of file diff --git a/spec/integration/rails/config/routes.rb b/spec/integration/rails/config/routes.rb index 31a6c75..5c179ea 100644 --- a/spec/integration/rails/config/routes.rb +++ b/spec/integration/rails/config/routes.rb @@ -3,7 +3,11 @@ ActionController::Routing::Routes.draw do |map| webrat.submit "/submit", :action => "submit" webrat.internal_redirect "/internal_redirect", :action => "internal_redirect" webrat.external_redirect "/external_redirect", :action => "external_redirect" - + + webrat.before_redirect_form "/before_redirect_form", :action => "before_redirect_form" + webrat.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params" + webrat.show_params "/show_params", :action => "show_params" + webrat.root :action => "form" end end diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb index f31ac24..3427fbc 100644 --- a/spec/integration/rails/test/integration/webrat_test.rb +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -21,8 +21,19 @@ class WebratTest < ActionController::IntegrationTest assert field_labeled("Prefilled").value, "text" end + test "should not carry params through redirects" do + visit before_redirect_form_path + fill_in "Text field", :with => "value" + click_button + + assert response.body !~ /value/ + assert response.body =~ /custom_param/ + end + test "should follow internal redirects" do visit internal_redirect_path + + assert !response.redirect? assert response.body.include?("OK") end