public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://gitrdoc.com/brynary/webrat/tree/master/
Clone URL: git://github.com/brynary/webrat.git
Rails and Merb integration tests for following redirects
joshknowles (author)
Mon Dec 29 20:14:26 -0800 2008
commit  e19b1cc323e8df657a357bfeefe3f68745f80938
tree    93e84d96a94005ed0f23ace72e204070cae52f1f
parent  e77495bc04cacfb1e7684bd938a7c6d32545130f
...
110
111
112
113
 
114
115
116
...
110
111
112
 
113
114
115
116
0
@@ -110,7 +110,7 @@ For example:
0
       @http_method  = http_method
0
       @data         = data
0
 
0
-      request_page(response.location, :get, data) if redirect?
0
+      request_page(response.headers["Location"], :get, data) if redirect?
0
 
0
       return response
0
     end
...
42
43
44
45
46
47
48
49
50
51
52
...
59
60
61
62
63
64
65
66
67
68
...
42
43
44
 
 
 
 
 
45
46
47
...
54
55
56
 
 
 
 
57
58
59
0
@@ -42,11 +42,6 @@ module Webrat
0
         :params => (data && data.any?) ? data : nil, 
0
         :headers => headers,
0
         :method => method)
0
-      follow_redirect
0
-    end
0
-    
0
-    def follow_redirect
0
-      self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
0
     end
0
 
0
   end
0
@@ -59,10 +54,6 @@ module Merb #:nodoc:
0
         @_webrat_session ||= Webrat::MerbSession.new
0
         @_webrat_session.response = @_webrat_session.request(uri, env)
0
       end
0
-  
0
-      def follow_redirect
0
-        @_webrat_session.follow_redirect
0
-      end
0
     end
0
   end
0
 end
...
7
8
9
 
 
 
 
10
11
...
7
8
9
10
11
12
13
14
15
0
@@ -7,4 +7,8 @@ class Testing < Application
0
   def submit_form
0
   end
0
   
0
+  def redirect_to_root
0
+    redirect "/"
0
+  end
0
+  
0
 end
0
\ No newline at end of file
...
28
29
30
 
31
32
...
28
29
30
31
32
33
0
@@ -28,4 +28,5 @@
0
 Merb.logger.info("Compiling routes...")
0
 Merb::Router.prepare do
0
   match("/").to(:controller => "testing", :action => "show_form")
0
+  match("/redirect").to(:controller => "testing", :action => "redirect_to_root")
0
 end
0
\ No newline at end of file
...
5
6
7
8
 
9
10
11
...
13
14
15
16
 
 
 
 
 
17
18
...
5
6
7
 
8
9
10
11
...
13
14
15
 
16
17
18
19
20
21
22
0
@@ -5,7 +5,7 @@ describe "Webrat" do
0
     response = visit "/"
0
     response.should contain("Webrat Form")
0
   end
0
-  
0
+
0
   it "should submit forms" do
0
     visit "/"
0
     fill_in "Text field", :with => "Hello"
0
@@ -13,5 +13,9 @@ describe "Webrat" do
0
     select "January"
0
     click_button "Test"
0
   end
0
-  
0
+
0
+  it "should follow redirects" do
0
+    response = visit "/redirect"
0
+    response.should contain("Webrat Form")
0
+  end
0
 end
0
\ No newline at end of file
...
1
2
 
3
4
5
 
6
7
8
9
 
 
 
 
 
10
11
...
1
 
2
3
4
 
5
6
7
8
 
9
10
11
12
13
14
15
0
@@ -1,10 +1,14 @@
0
 class WebratController < ApplicationController
0
-  
0
+
0
   def form
0
   end
0
-  
0
+
0
   def submit
0
     render :text => "OK"
0
   end
0
-  
0
+
0
+  def redirect
0
+    redirect_to :submit
0
+  end
0
+
0
 end
0
\ No newline at end of file
...
1
2
3
4
 
 
 
 
5
6
...
1
2
 
 
3
4
5
6
7
8
0
@@ -1,6 +1,8 @@
0
 ActionController::Routing::Routes.draw do |map|
0
   map.with_options :controller => "webrat" do |webrat|
0
-    webrat.submit "/submit",  :action => "submit"
0
-    webrat.root               :action => "form"
0
+    webrat.submit   "/submit",    :action => "submit"
0
+    webrat.redirect "/redirect",  :action => "redirect"
0
+
0
+    webrat.root :action => "form"
0
   end
0
 end
...
6
7
8
9
 
10
11
12
...
14
15
16
 
 
 
 
 
17
...
6
7
8
 
9
10
11
12
...
14
15
16
17
18
19
20
21
22
0
@@ -6,7 +6,7 @@ class WebratTest < ActionController::IntegrationTest
0
     assert_tag "Webrat Form"
0
     assert response.body.include?("Webrat Form")
0
   end
0
-  
0
+
0
   test "should submit forms" do
0
     visit root_path
0
     fill_in "Text field", :with => "Hello"
0
@@ -14,4 +14,9 @@ class WebratTest < ActionController::IntegrationTest
0
     select "January"
0
     click_button "Test"
0
   end
0
+
0
+  test "should follow redirects" do
0
+    visit redirect_path
0
+    assert response.body.include?("OK")
0
+  end
0
 end
...
115
116
117
118
 
119
120
121
...
115
116
117
 
118
119
120
121
0
@@ -115,7 +115,7 @@ describe Webrat::Session do
0
 
0
     it "should follow redirects" do
0
       webrat_session.should_receive(:redirect?).twice.and_return(true, false)
0
-      webrat_session.response.should_receive(:location).once.and_return("/newurl")
0
+      webrat_session.response.should_receive(:headers).once.and_return({ "Location" => "/newurl" })
0
 
0
       webrat_session.request_page("/oldurl", :get, {})
0
 
...
33
34
35
36
 
37
38
39
...
33
34
35
 
36
37
38
39
0
@@ -33,7 +33,7 @@ describe "visit" do
0
 
0
   it "should follow redirects" do
0
     webrat_session.should_receive(:redirect?).twice.and_return(true, false)
0
-    webrat_session.response.should_receive(:location).once.and_return("/newurl")
0
+    webrat_session.response.should_receive(:headers).once.and_return({ "Location" => "/newurl" })
0
 
0
     visit("/oldurl")
0
 

Comments