<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -8,7 +8,7 @@ module Webrat
   # A page load or form submission returned an unsuccessful response code (500-599)
   class PageLoadError &lt; WebratError
   end
-  
+
   def self.session_class
     case Webrat.configuration.mode
     when :rails
@@ -37,29 +37,29 @@ For example:
       STR
     end
   end
-  
+
   class Session
     extend Forwardable
     include Logging
     include SaveAndOpenPage
-    
+
     attr_reader :current_url
     attr_reader :elements
-    
+
     def initialize(context = nil) #:nodoc:
       @http_method     = :get
       @data            = {}
       @default_headers = {}
       @custom_headers  = {}
       @context         = context
-      
+
       reset
     end
-    
+
     def current_dom #:nodoc:
       current_scope.dom
     end
-    
+
     # For backwards compatibility -- removing in 1.0
     def current_page #:nodoc:
       page = OpenStruct.new
@@ -68,11 +68,11 @@ For example:
       page.data = @data
       page
     end
-    
+
     def doc_root #:nodoc:
       nil
     end
-    
+
     def header(key, value)
       @custom_headers[key] = value
     end
@@ -80,7 +80,7 @@ For example:
     def http_accept(mime_type)
       header('Accept', Webrat::MIME.mime_type(mime_type))
     end
-    
+
     def basic_auth(user, pass)
       encoded_login = [&quot;#{user}:#{pass}&quot;].pack(&quot;m*&quot;)
       header('HTTP_AUTHORIZATION', &quot;Basic #{encoded_login}&quot;)
@@ -103,28 +103,30 @@ For example:
 
       save_and_open_page if exception_caught? &amp;&amp; Webrat.configuration.open_error_files?
       raise PageLoadError.new(&quot;Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}&quot;) unless success_code?
-      
+
       reset
-      
+
       @current_url  = url
       @http_method  = http_method
       @data         = data
-      
+
+      request_page(response.location, :get, data) if response.redirect?
+
       return response
     end
-    
+
     def success_code? #:nodoc:
       (200..499).include?(response_code)
     end
-    
+
     def exception_caught? #:nodoc:
       response_body =~ /Exception caught/
     end
-    
+
     def current_scope #:nodoc:
       scopes.last || page_scope
     end
-    
+
     # Reloads the last page requested. Note that this will resubmit forms
     # and their data.
     def reloads
@@ -132,10 +134,10 @@ For example:
     end
 
     webrat_deprecate :reload, :reloads
-      
-    
+
+
     # Works like click_link, but only looks for the link text within a given selector
-    # 
+    #
     # Example:
     #   click_link_within &quot;#user_12&quot;, &quot;Vote&quot;
     def click_link_within(selector, link_text)
@@ -145,14 +147,14 @@ For example:
     end
 
     webrat_deprecate :clicks_link_within, :click_link_within
-    
+
     def within(selector)
       scopes.push(Scope.from_scope(self, current_scope, selector))
       ret = yield(current_scope)
       scopes.pop
       return ret
     end
-    
+
     # Issues a GET request for a page, follows any redirects, and verifies the final page
     # load was successful.
     #
@@ -161,7 +163,7 @@ For example:
     def visit(url = nil, http_method = :get, data = {})
       request_page(url, http_method, data)
     end
-    
+
     webrat_deprecate :visits, :visit
 
     # Subclasses can override this to show error messages without html
@@ -176,25 +178,25 @@ For example:
     def page_scope #:nodoc:
       @_page_scope ||= Scope.from_page(self, response, response_body)
     end
-    
+
     def dom
       page_scope.dom
     end
-    
+
     def xml_content_type?
       false
     end
-    
+
     def simulate
       return if Webrat.configuration.mode == :selenium
       yield
     end
-    
+
     def automate
       return unless Webrat.configuration.mode == :selenium
       yield
     end
-    
+
     def_delegators :current_scope, :fill_in,            :fills_in
     def_delegators :current_scope, :set_hidden_field
     def_delegators :current_scope, :submit_form
@@ -213,14 +215,14 @@ For example:
     def_delegators :current_scope, :field_by_xpath
     def_delegators :current_scope, :field_with_id
     def_delegators :current_scope, :select_option
-    
+
   private
-    
+
     def reset
       @elements     = {}
       @_scopes      = nil
       @_page_scope  = nil
     end
-    
+
   end
 end</diff>
      <filename>lib/webrat/core/session.rb</filename>
    </modified>
    <modified>
      <diff>@@ -50,10 +50,7 @@ module Webrat
 
     def do_request(http_method, url, data, headers) #:nodoc:
       update_protocol(url)
-
       integration_session.send(http_method, normalize_url(url), data, headers)
-      integration_session.follow_redirect_with_headers(headers) while integration_session.internal_redirect?
-      integration_session.status
     end
 
     # remove protocol, host and anchor
@@ -82,27 +79,6 @@ module Webrat
 end
 
 module ActionController #:nodoc:
-  module Integration #:nodoc:
-    class Session #:nodoc:
-      def internal_redirect?
-        redirect? &amp;&amp; response.redirect_url_match?(host)
-      end
-
-      def follow_redirect_with_headers(h = {})
-        raise &quot;Not a redirect! #{@status} #{@status_message}&quot; unless redirect?
-
-        h = Hash.new if h.nil?
-        h['HTTP_REFERER'] = request.url
-
-        location = headers[&quot;location&quot;]
-        location = location.first if location.is_a?(Array)
-        
-        get(location, {}, h)
-        status
-      end
-    end
-  end
-
   IntegrationTest.class_eval do
     include Webrat::Methods
     include Webrat::Matchers</diff>
      <filename>lib/webrat/rails.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,7 +11,6 @@ module Webrat
         path, data, headers = *args
         params = data.merge({:env =&gt; headers || {}})
         self.__send__(&quot;#{verb}_it&quot;, path, params)
-        get_it(@response.location, params) while @response.redirect?
       end
     end
   end</diff>
      <filename>lib/webrat/sinatra.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,33 +2,39 @@ module Webrat #:nodoc:
   def self.session_class #:nodoc:
     TestSession
   end
-  
+
   class TestSession &lt; Session #:nodoc:
     attr_accessor :response_body
     attr_writer :response_code
-    
+
     def doc_root
       File.expand_path(File.join(&quot;.&quot;, &quot;public&quot;))
     end
-    
+
     def response
-      @response ||= Object.new
+      @response ||= TestResponse.new
     end
-    
+
     def response_code
       @response_code || 200
     end
-    
-    def get(url, data)
+
+    def get(url, data, headers = nil)
+    end
+
+    def post(url, data, headers = nil)
     end
-    
-    def post(url, data)
+
+    def put(url, data, headers = nil)
     end
-    
-    def put(url, data)
+
+    def delete(url, data, headers = nil)
     end
-    
-    def delete(url, data)
+  end
+  
+  class TestResponse #:nodoc:
+    def redirect?
+      false
     end
   end
 end
\ No newline at end of file</diff>
      <filename>spec/fakes/test_session.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,47 +1,47 @@
 require File.expand_path(File.dirname(__FILE__) + &quot;/../../spec_helper&quot;)
 
 describe Webrat::Session do
-  
+
   it &quot;should not have a doc_root&quot; do
     session = Webrat::Session.new
     session.doc_root.should be_nil
   end
-  
+
   it &quot;should expose the current_dom&quot; do
     session = Webrat::Session.new
-    
+
     def session.response
       Object.new
     end
-    
+
     def session.response_body
       &quot;&lt;html&gt;&lt;/html&gt;&quot;
     end
-    
+
     session.should respond_to(:current_dom)
   end
-  
+
   it &quot;should open the page in the browser in MacOSX&quot; do
     session = Webrat::Session.new
     session.stub!(:ruby_platform =&gt; 'darwin')
     session.should_receive(:`).with(&quot;open path&quot;)
     session.open_in_browser(&quot;path&quot;)
   end
-  
+
   it &quot;should open the page in the browser in cygwin&quot; do
     session = Webrat::Session.new
     session.stub!(:ruby_platform =&gt; 'i386-cygwin')
     session.should_receive(:`).with(&quot;rundll32 url.dll,FileProtocolHandler path\\to\\file&quot;)
     session.open_in_browser(&quot;path/to/file&quot;)
   end
-  
+
   it &quot;should open the page in the browser in Win32&quot; do
     session = Webrat::Session.new
     session.stub!(:ruby_platform =&gt; 'win32')
     session.should_receive(:`).with(&quot;rundll32 url.dll,FileProtocolHandler path\\to\\file&quot;)
     session.open_in_browser(&quot;path/to/file&quot;)
   end
-  
+
   it &quot;should provide a current_page for backwards compatibility&quot; do
     session = Webrat::Session.new
     current_page = session.current_page
@@ -58,7 +58,7 @@ describe Webrat::Session do
 
   it &quot;should return a copy of the headers to be sent&quot; do
     session = Webrat::Session.new
-    session.instance_eval { 
+    session.instance_eval {
       @default_headers = {'HTTP_X_FORWARDED_FOR' =&gt; '192.168.1.1'}
       @custom_headers = {'Accept' =&gt; 'application/xml'}
     }
@@ -89,17 +89,17 @@ describe Webrat::Session do
     before(:each) do
       webrat_session = Webrat::Session.new
     end
-  
+
     it &quot;should raise an error if the request is not a success&quot; do
       webrat_session.stub!(:get)
       webrat_session.stub!(:response_body =&gt; &quot;Exception caught&quot;)
       webrat_session.stub!(:response_code =&gt; 500)
       webrat_session.stub!(:formatted_error =&gt; &quot;application error&quot;)
       webrat_session.stub!(:save_and_open_page)
-  
+
       lambda { webrat_session.request_page('some url', :get, {}) }.should raise_error(Webrat::PageLoadError)
     end
-    
+
     it &quot;should raise an error but not open if the request is not a success and config quashes save_and_open&quot; do
       Webrat.configure do |config|
         config.open_error_files = false
@@ -109,8 +109,17 @@ describe Webrat::Session do
       webrat_session.stub!(:response_code =&gt; 500)
       webrat_session.stub!(:formatted_error =&gt; &quot;application error&quot;)
       webrat_session.should_not_receive(:save_and_open_page)
-  
+
       lambda { webrat_session.request_page('some url', :get, {}) }.should raise_error(Webrat::PageLoadError)
     end
+
+    it &quot;should follow redirects&quot; do
+      webrat_session.response.should_receive(:redirect?).twice.and_return(true, false)
+      webrat_session.response.should_receive(:location).once.and_return(&quot;/newurl&quot;)
+
+      webrat_session.request_page(&quot;/oldurl&quot;, :get, {})
+
+      webrat_session.current_url.should == &quot;/newurl&quot;
+    end
   end
-end
+end
\ No newline at end of file</diff>
      <filename>spec/private/core/session_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,8 +6,6 @@ describe Webrat::RailsSession do
   before :each do
     Webrat.configuration.mode = :rails
     @integration_session = mock(&quot;integration_session&quot;)
-    @integration_session.stub!(:internal_redirect?)
-    @integration_session.stub!(:status)
   end
 
   it &quot;should delegate response_body to the session response body&quot; do
@@ -80,44 +78,6 @@ describe Webrat::RailsSession do
     end
   end
 
-  context &quot;following redirects&quot; do
-    it &quot;should use forward headers when following redirects&quot; do
-      @integration_session.stub!(:post)
-      @integration_session.stub!(:host)
-      @integration_session.stub!(:status)
-
-      @integration_session.should_receive(:internal_redirect?).twice.and_return(true, false)
-      @integration_session.should_receive(:follow_redirect_with_headers).with(&quot;headers&quot;)
-
-      rails_session = Webrat::RailsSession.new(@integration_session)
-      rails_session.post(&quot;url&quot;, &quot;data&quot;, &quot;headers&quot;)
-    end
-
-    it &quot;should follow internal redirects&quot; do
-      @integration_session.stub!(:get)
-      @integration_session.stub!(:host)
-      @integration_session.stub!(:status)
-
-      @integration_session.should_receive(:internal_redirect?).twice.and_return(true, false)
-      @integration_session.should_receive(:follow_redirect_with_headers)
-
-      rails_session = Webrat::RailsSession.new(@integration_session)
-      rails_session.get(&quot;url&quot;, &quot;data&quot;, &quot;headers&quot;)
-    end
-
-    it &quot;should not follow external redirects&quot; do
-      @integration_session.stub!(:get)
-      @integration_session.stub!(:host)
-      @integration_session.stub!(:status)
-
-      @integration_session.should_receive(:internal_redirect?).and_return(false)
-      @integration_session.should_not_receive(:follow_redirect_with_headers)
-
-      rails_session = Webrat::RailsSession.new(@integration_session)
-      rails_session.get(&quot;url&quot;, &quot;data&quot;, &quot;headers&quot;)
-    end
-  end
-
   it &quot;should provide a saved_page_dir&quot; do
     Webrat::RailsSession.new(mock(&quot;integration session&quot;)).should respond_to(:saved_page_dir)
   end
@@ -125,66 +85,4 @@ describe Webrat::RailsSession do
   it &quot;should provide a doc_root&quot; do
     Webrat::RailsSession.new(mock(&quot;integration session&quot;)).should respond_to(:doc_root)
   end
-end
-
-describe ActionController::Integration::Session do
-  before :each do
-    Webrat.configuration.mode = :rails
-    @integration_session = ActionController::Integration::Session.new
-    @integration_session.stub!(:request =&gt; mock(&quot;request&quot;, :url =&gt; &quot;http://source.url/&quot;))
-    @integration_session.stub!(:response =&gt; mock(&quot;response&quot;))
-  end
-
-  describe &quot;internal_redirect?&quot; do
-    it &quot;should return false if the response is not a redirect&quot; do
-      @integration_session.should_receive(:redirect?).and_return(false)
-      @integration_session.internal_redirect?.should == false
-    end
-
-    it &quot;should return false if the response was a redirect but the response location does not match the request host&quot; do
-      @integration_session.should_receive(:redirect?).and_return(true)
-      @integration_session.response.should_receive(:redirect_url_match?).and_return(false)
-      @integration_session.internal_redirect?.should == false
-    end
-
-    it &quot;should return true if the response is a redirect and the response location matches the request host&quot; do
-      @integration_session.should_receive(:redirect?).and_return(true)
-      @integration_session.response.should_receive(:redirect_url_match?).and_return(true)
-      @integration_session.internal_redirect?.should == true
-    end
-  end
-
-  describe &quot;follow_redirect_with_headers&quot; do
-    before do
-      Webrat.configuration.mode = :rails
-      @integration_session.stub!(:headers).and_return({ 'location' =&gt; [&quot;/&quot;]})
-      @integration_session.stub!(:redirect?).and_return true
-      @integration_session.stub!(:get)
-    end
-
-    it &quot;should raise an exception if response wasn't a redirect&quot; do
-      @integration_session.stub!(:redirect?).and_return false
-      lambda { @integration_session.follow_redirect_with_headers }.should raise_error
-    end
-
-    it &quot;should set the HTTP referer header&quot; do
-      headers = {}
-
-      @integration_session.follow_redirect_with_headers(headers)
-      headers[&quot;HTTP_REFERER&quot;].should == &quot;http://source.url/&quot;
-    end
-
-    it &quot;should GET the first location header&quot; do
-      @integration_session.stub!(&quot;headers&quot;).and_return({ 'location' =&gt; ['/target'] })
-
-      @integration_session.should_receive(:get).with(&quot;/target&quot;, {}, hash_including(&quot;headers&quot; =&gt; &quot;foo&quot;))
-
-      @integration_session.follow_redirect_with_headers({&quot;headers&quot; =&gt; &quot;foo&quot;})
-    end
-
-    it &quot;should return the status&quot; do
-      @integration_session.stub!(:status).and_return &quot;202&quot;
-      @integration_session.follow_redirect_with_headers.should == &quot;202&quot;
-    end
-  end
 end
\ No newline at end of file</diff>
      <filename>spec/private/rails/rails_session_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,11 +4,6 @@ describe Webrat::SinatraSession do
   before :each do
     Webrat.configuration.mode = :sinatra
     @sinatra_session = Webrat::SinatraSession.new
-
-    @response = mock(:response)
-    @response.stub!(:redirect?)
-
-    @sinatra_session.instance_variable_set(&quot;@response&quot;, @response)
   end
 
   it &quot;should delegate get to get_it&quot; do
@@ -30,14 +25,4 @@ describe Webrat::SinatraSession do
     @sinatra_session.should_receive(:delete_it).with(&quot;url&quot;, { :env =&gt; &quot;headers&quot; })
     @sinatra_session.delete(&quot;url&quot;, {}, &quot;headers&quot;)
   end
-
-  it &quot;should forward headers when following redirects&quot; do
-    @response.should_receive(:redirect?).twice.and_return(true, false)
-    @response.should_receive(:location).and_return(&quot;redirect url&quot;)
-
-    @sinatra_session.should_receive(:get_it).with(&quot;original url&quot;, { :env =&gt; &quot;headers&quot; })
-    @sinatra_session.should_receive(:get_it).with(&quot;redirect url&quot;, { :env =&gt; &quot;headers&quot; })
-
-    @sinatra_session.get(&quot;original url&quot;, {}, &quot;headers&quot;)
-  end
 end
\ No newline at end of file</diff>
      <filename>spec/private/sinatra/sinatra_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,22 +13,31 @@ describe &quot;visit&quot; do
     webrat_session.should_receive(:get).with(&quot;/&quot;, {})
     visit(&quot;/&quot;)
   end
-  
+
   it &quot;should assert valid response&quot; do
     webrat_session.response_code = 501
     lambda { visit(&quot;/&quot;) }.should raise_error(Webrat::PageLoadError)
   end
-  
+
   [200, 300, 400, 499].each do |status|
     it &quot;should consider the #{status} status code as success&quot; do
       webrat_session.response_code = status
       lambda { visit(&quot;/&quot;) }.should_not raise_error
     end
   end
-  
+
   it &quot;should require a visit before manipulating page&quot; do
     lambda { fill_in &quot;foo&quot;, :with =&gt; &quot;blah&quot; }.should raise_error(Webrat::WebratError)
   end
+
+  it &quot;should follow redirects&quot; do
+    webrat_session.response.should_receive(:redirect?).twice.and_return(true, false)
+    webrat_session.response.should_receive(:location).once.and_return(&quot;/newurl&quot;)
+
+    visit(&quot;/oldurl&quot;)
+
+    current_url.should == &quot;/newurl&quot;
+  end
 end
 
 describe &quot;visit with referer&quot; do
@@ -45,5 +54,5 @@ describe &quot;visit with referer&quot; do
     webrat_session.should_receive(:get).with(&quot;/&quot;, {}, {&quot;HTTP_REFERER&quot; =&gt; &quot;/old_url&quot;})
     visit(&quot;/&quot;)
   end
-  
+
 end</diff>
      <filename>spec/public/visit_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a56973854276e18545da4d89ff99ee73fabe8d9d</id>
    </parent>
  </parents>
  <author>
    <name>Josh Knowles</name>
    <email>joshknowles@gmail.com</email>
  </author>
  <url>http://github.com/brynary/webrat/commit/ce364d16638c6d6906b5c00ffdcb0374caed7f5b</url>
  <id>ce364d16638c6d6906b5c00ffdcb0374caed7f5b</id>
  <committed-date>2008-12-29T18:19:13-08:00</committed-date>
  <authored-date>2008-12-29T18:19:13-08:00</authored-date>
  <message>Refactor redirect support out of RailsSession &amp; SinatraSession and into Session#request_page</message>
  <tree>9bc450cf3a87ab9e0bcae5a82e1c3b65f3bd71fd</tree>
  <committer>
    <name>Josh Knowles</name>
    <email>joshknowles@gmail.com</email>
  </committer>
</commit>
