Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8429

Show
Ignore:
Timestamp:
12/17/07 00:39:19 (9 months ago)
Author:
david
Message:

Added delete_via_redirect and put_via_redirect to integration testing (closes #10497) [philodespotos]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r8426 r8429  
    11*2.0.2* (December 16th, 2007) 
     2 
     3* Added delete_via_redirect and put_via_redirect to integration testing #10497 [philodespotos] 
    24 
    35* Allow headers['Accept'] to be set by hand when calling xml_http_request #10461 [BMorearty] 
  • trunk/actionpack/lib/action_controller/integration.rb

    r8426 r8429  
    122122      end 
    123123 
    124       # Performs a GET request, following any subsequent redirect. Note tha
    125       # the redirects are followed until the response is not a redirect--this 
    126       # means you may run into an infinite loop if your redirect loops back to 
    127       # itself. Headers are treated in the same way as #get
    128       def get_via_redirect(path, args={}, headers = {}
    129         get path, args, headers 
     124      # Performs a request using the specified method, following any subsequen
     125      # redirect. Note that the redirects are followed until the response is 
     126      # not a redirect--this means you may run into an infinite loop if your 
     127      # redirect loops back to itself
     128      def request_via_redirect(http_method, path, parameters = nil, headers = nil
     129        send(http_method, path, parameters, headers) 
    130130        follow_redirect! while redirect? 
    131131        status 
    132132      end 
    133133 
    134       # Performs a POST request, following any subsequent redirect. This is 
    135       # vulnerable to infinite loops, the same as #get_via_redirect. Headers are 
    136       # treated in the same way as #get. 
    137       def post_via_redirect(path, args={}, headers = {}) 
    138         post path, args, headers 
    139         follow_redirect! while redirect? 
    140         status 
     134      # Performs a GET request, following any subsequent redirect. 
     135      # See #request_via_redirect() for more information. 
     136      def get_via_redirect(path, parameters = nil, headers = nil) 
     137        request_via_redirect(:get, path, parameters, headers) 
     138      end 
     139 
     140      # Performs a POST request, following any subsequent redirect. 
     141      # See #request_via_redirect() for more information. 
     142      def post_via_redirect(path, parameters = nil, headers = nil) 
     143        request_via_redirect(:post, path, parameters, headers) 
     144      end 
     145 
     146      # Performs a PUT request, following any subsequent redirect. 
     147      # See #request_via_redirect() for more information. 
     148      def put_via_redirect(path, parameters = nil, headers = nil) 
     149        request_via_redirect(:put, path, parameters, headers) 
     150      end 
     151 
     152      # Performs a DELETE request, following any subsequent redirect. 
     153      # See #request_via_redirect() for more information. 
     154      def delete_via_redirect(path, parameters = nil, headers = nil) 
     155        request_via_redirect(:delete, path, parameters, headers) 
    141156      end 
    142157 
  • trunk/actionpack/test/controller/integration_test.rb

    r8426 r8429  
    5050  end 
    5151 
    52   def test_get_via_redirect 
    53     path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 
    54  
    55     @session.expects(:get).with(path,args,headers) 
    56  
     52  def test_request_via_redirect_uses_given_method 
     53    path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"} 
     54    @session.expects(:put).with(path, args, headers) 
     55    @session.stubs(:redirect?).returns(false) 
     56    @session.request_via_redirect(:put, path, args, headers) 
     57  end 
     58 
     59  def test_request_via_redirect_follows_redirects 
     60    path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"} 
    5761    @session.stubs(:redirect?).returns(true, true, false) 
    5862    @session.expects(:follow_redirect!).times(2) 
    59  
     63    @session.request_via_redirect(:get, path, args, headers) 
     64  end 
     65 
     66  def test_request_via_redirect_returns_status 
     67    path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue"} 
     68    @session.stubs(:redirect?).returns(false) 
    6069    @session.stubs(:status).returns(200) 
    61     assert_equal 200, @session.get_via_redirect(path, args, headers) 
     70    assert_equal 200, @session.request_via_redirect(:get, path, args, headers) 
     71  end 
     72 
     73  def test_get_via_redirect 
     74    path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 
     75    @session.expects(:request_via_redirect).with(:get, path, args, headers) 
     76    @session.get_via_redirect(path, args, headers) 
    6277  end 
    6378 
    6479  def test_post_via_redirect 
    6580    path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 
    66  
    67     @session.expects(:post).with(path,args,headers) 
    68  
    69     @session.stubs(:redirect?).returns(true, true, false) 
    70     @session.expects(:follow_redirect!).times(2) 
    71  
    72     @session.stubs(:status).returns(200) 
    73     assert_equal 200, @session.post_via_redirect(path, args, headers) 
     81    @session.expects(:request_via_redirect).with(:post, path, args, headers) 
     82    @session.post_via_redirect(path, args, headers) 
     83  end 
     84 
     85  def test_put_via_redirect 
     86    path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 
     87    @session.expects(:request_via_redirect).with(:put, path, args, headers) 
     88    @session.put_via_redirect(path, args, headers) 
     89  end 
     90 
     91  def test_delete_via_redirect 
     92    path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" } 
     93    @session.expects(:request_via_redirect).with(:delete, path, args, headers) 
     94    @session.delete_via_redirect(path, args, headers) 
    7495  end 
    7596