public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
verify :redirect_to => :back should redirect to the referrer. [#280 
state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Amos King (author)
Thu May 29 16:49:44 -0700 2008
lifo (committer)
Tue Jun 17 10:31:27 -0700 2008
commit  b99c1c939cd2329dad6d16a9dfeafdecdd5a412d
tree    6c1e2ddafd5fbbdbb478240387b87d03330e4201
parent  4d83e9d737a703b3634d0163599bdbede0500c31
...
116
117
118
119
 
120
121
122
...
116
117
118
 
119
120
121
122
0
@@ -116,7 +116,7 @@ module ActionController #:nodoc:
0
     end
0
     
0
     def apply_redirect_to(redirect_to_option) # :nodoc:
0
-      redirect_to_option.is_a?(Symbol) ? self.send!(redirect_to_option) : redirect_to_option
0
+      (redirect_to_option.is_a?(Symbol) && redirect_to_option != :back) ? self.send!(redirect_to_option) : redirect_to_option
0
     end
0
     
0
     def apply_remaining_actions(options) # :nodoc:
...
21
22
23
24
 
25
26
27
 
28
29
30
...
39
40
41
 
 
 
42
43
44
45
 
46
47
48
...
70
71
72
73
 
74
75
76
77
 
78
79
80
...
86
87
88
89
 
90
91
92
93
 
 
 
 
 
94
95
96
97
 
98
99
100
...
109
110
111
112
 
 
 
 
 
 
 
 
 
 
 
113
114
115
...
209
210
211
212
 
213
214
215
216
217
 
218
219
220
221
222
 
223
224
225
226
227
 
228
229
230
231
232
 
233
234
235
236
237
 
238
239
240
241
242
 
243
244
245
246
247
248
249
 
250
251
252
...
21
22
23
 
24
25
26
 
27
28
29
30
...
39
40
41
42
43
44
45
46
47
 
48
49
50
51
...
73
74
75
 
76
77
78
79
 
80
81
82
83
...
89
90
91
 
92
93
94
95
 
96
97
98
99
100
101
102
103
 
104
105
106
107
...
116
117
118
 
119
120
121
122
123
124
125
126
127
128
129
130
131
132
...
226
227
228
 
229
230
231
232
233
 
234
235
236
237
238
 
239
240
241
242
243
 
244
245
246
247
248
 
249
250
251
252
253
 
254
255
256
257
258
 
259
260
261
262
263
264
265
 
266
267
268
269
0
@@ -21,10 +21,10 @@ class VerificationTest < Test::Unit::TestCase
0
 
0
     verify :only => :guarded_by_method, :method => :post,
0
            :redirect_to => { :action => "unguarded" }
0
-           
0
+
0
     verify :only => :guarded_by_xhr, :xhr => true,
0
            :redirect_to => { :action => "unguarded" }
0
-           
0
+
0
     verify :only => :guarded_by_not_xhr, :xhr => false,
0
            :redirect_to => { :action => "unguarded" }
0
 
0
@@ -39,10 +39,13 @@ class VerificationTest < Test::Unit::TestCase
0
 
0
     verify :only => :no_default_action, :params => "santa"
0
 
0
+    verify :only => :guarded_with_back, :method => :post,
0
+           :redirect_to => :back
0
+
0
     def guarded_one
0
       render :text => "#{params[:one]}"
0
     end
0
-    
0
+
0
     def guarded_one_for_named_route_test
0
       render :text => "#{params[:one]}"
0
     end
0
@@ -70,11 +73,11 @@ class VerificationTest < Test::Unit::TestCase
0
     def guarded_by_method
0
       render :text => "#{request.method}"
0
     end
0
-    
0
+
0
     def guarded_by_xhr
0
       render :text => "#{request.xhr?}"
0
     end
0
-    
0
+
0
     def guarded_by_not_xhr
0
       render :text => "#{request.xhr?}"
0
     end
0
@@ -86,15 +89,19 @@ class VerificationTest < Test::Unit::TestCase
0
     def two_redirects
0
       render :nothing => true
0
     end
0
-    
0
+
0
     def must_be_post
0
       render :text => "Was a post!"
0
     end
0
-    
0
+
0
+    def guarded_with_back
0
+      render :text => "#{params[:one]}"
0
+    end
0
+
0
     def no_default_action
0
       # Will never run
0
     end
0
-    
0
+
0
     protected
0
       def rescue_action(e) raise end
0
 
0
@@ -109,7 +116,17 @@ class VerificationTest < Test::Unit::TestCase
0
     @response   = ActionController::TestResponse.new
0
     ActionController::Routing::Routes.add_named_route :foo, '/foo', :controller => 'test', :action => 'foo'
0
   end
0
-  
0
+
0
+  def test_using_symbol_back_with_no_referrer
0
+    assert_raise(ActionController::RedirectBackError) { get :guarded_with_back }
0
+  end
0
+
0
+  def test_using_symbol_back_redirects_to_referrer
0
+    @request.env["HTTP_REFERER"] = "/foo"
0
+    get :guarded_with_back
0
+    assert_redirected_to '/foo'
0
+  end
0
+
0
   def test_no_deprecation_warning_for_named_route
0
     assert_not_deprecated do
0
       get :guarded_one_for_named_route_test, :two => "not one"
0
@@ -209,44 +226,44 @@ class VerificationTest < Test::Unit::TestCase
0
     get :guarded_by_method
0
     assert_redirected_to :action => "unguarded"
0
   end
0
-  
0
+
0
   def test_guarded_by_xhr_with_prereqs
0
     xhr :post, :guarded_by_xhr
0
     assert_equal "true", @response.body
0
   end
0
-    
0
+
0
   def test_guarded_by_xhr_without_prereqs
0
     get :guarded_by_xhr
0
     assert_redirected_to :action => "unguarded"
0
   end
0
-  
0
+
0
   def test_guarded_by_not_xhr_with_prereqs
0
     get :guarded_by_not_xhr
0
     assert_equal "false", @response.body
0
   end
0
-    
0
+
0
   def test_guarded_by_not_xhr_without_prereqs
0
     xhr :post, :guarded_by_not_xhr
0
     assert_redirected_to :action => "unguarded"
0
   end
0
-  
0
+
0
   def test_guarded_post_and_calls_render_succeeds
0
     post :must_be_post
0
     assert_equal "Was a post!", @response.body
0
   end
0
-    
0
+
0
   def test_default_failure_should_be_a_bad_request
0
     post :no_default_action
0
     assert_response :bad_request
0
   end
0
-    
0
+
0
   def test_guarded_post_and_calls_render_fails_and_sets_allow_header
0
     get :must_be_post
0
     assert_response 405
0
     assert_equal "Must be post", @response.body
0
     assert_equal "POST", @response.headers["Allow"]
0
   end
0
-  
0
+
0
   def test_second_redirect
0
     assert_nothing_raised { get :two_redirects }
0
   end

Comments