~nchohan/appscale/GAE1.4.0-namespaces

« back to all changes in this revision

Viewing changes to AppLoadBalancer/vendor/rails/actionpack/test/controller/verification_test.rb

  • Committer: Chris Bunch
  • Date: 2009-11-16 18:37:46 UTC
  • mto: This revision was merged to the branch mainline in revision 303.
  • Revision ID: chris@magna-carta-20091116183746-1sqxle515itjf6si
added fix for create_user on load balancer

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'abstract_unit'
 
2
 
 
3
class VerificationTest < ActionController::TestCase
 
4
  class TestController < ActionController::Base
 
5
    verify :only => :guarded_one, :params => "one",
 
6
           :add_flash => { :error => 'unguarded' },
 
7
           :redirect_to => { :action => "unguarded" }
 
8
 
 
9
    verify :only => :guarded_two, :params => %w( one two ),
 
10
           :redirect_to => { :action => "unguarded" }
 
11
 
 
12
    verify :only => :guarded_with_flash, :params => "one",
 
13
           :add_flash => { :notice => "prereqs failed" },
 
14
           :redirect_to => { :action => "unguarded" }
 
15
 
 
16
    verify :only => :guarded_in_session, :session => "one",
 
17
           :redirect_to => { :action => "unguarded" }
 
18
 
 
19
    verify :only => [:multi_one, :multi_two], :session => %w( one two ),
 
20
           :redirect_to => { :action => "unguarded" }
 
21
 
 
22
    verify :only => :guarded_by_method, :method => :post,
 
23
           :redirect_to => { :action => "unguarded" }
 
24
 
 
25
    verify :only => :guarded_by_xhr, :xhr => true,
 
26
           :redirect_to => { :action => "unguarded" }
 
27
 
 
28
    verify :only => :guarded_by_not_xhr, :xhr => false,
 
29
           :redirect_to => { :action => "unguarded" }
 
30
 
 
31
    before_filter :unconditional_redirect, :only => :two_redirects
 
32
    verify :only => :two_redirects, :method => :post,
 
33
           :redirect_to => { :action => "unguarded" }
 
34
 
 
35
    verify :only => :must_be_post, :method => :post, :render => { :status => 405, :text => "Must be post" }, :add_headers => { "Allow" => "POST" }
 
36
 
 
37
    verify :only => :guarded_one_for_named_route_test, :params => "one",
 
38
           :redirect_to => :foo_url
 
39
 
 
40
    verify :only => :no_default_action, :params => "santa"
 
41
 
 
42
    verify :only => :guarded_with_back, :method => :post,
 
43
           :redirect_to => :back
 
44
 
 
45
    def guarded_one
 
46
      render :text => "#{params[:one]}"
 
47
    end
 
48
 
 
49
    def guarded_one_for_named_route_test
 
50
      render :text => "#{params[:one]}"
 
51
    end
 
52
 
 
53
    def guarded_with_flash
 
54
      render :text => "#{params[:one]}"
 
55
    end
 
56
 
 
57
    def guarded_two
 
58
      render :text => "#{params[:one]}:#{params[:two]}"
 
59
    end
 
60
 
 
61
    def guarded_in_session
 
62
      render :text => "#{session["one"]}"
 
63
    end
 
64
 
 
65
    def multi_one
 
66
      render :text => "#{session["one"]}:#{session["two"]}"
 
67
    end
 
68
 
 
69
    def multi_two
 
70
      render :text => "#{session["two"]}:#{session["one"]}"
 
71
    end
 
72
 
 
73
    def guarded_by_method
 
74
      render :text => "#{request.method}"
 
75
    end
 
76
 
 
77
    def guarded_by_xhr
 
78
      render :text => "#{request.xhr?}"
 
79
    end
 
80
 
 
81
    def guarded_by_not_xhr
 
82
      render :text => "#{request.xhr?}"
 
83
    end
 
84
 
 
85
    def unguarded
 
86
      render :text => "#{params[:one]}"
 
87
    end
 
88
 
 
89
    def two_redirects
 
90
      render :nothing => true
 
91
    end
 
92
 
 
93
    def must_be_post
 
94
      render :text => "Was a post!"
 
95
    end
 
96
 
 
97
    def guarded_with_back
 
98
      render :text => "#{params[:one]}"
 
99
    end
 
100
 
 
101
    def no_default_action
 
102
      # Will never run
 
103
    end
 
104
 
 
105
    protected
 
106
      def rescue_action(e) raise end
 
107
 
 
108
      def unconditional_redirect
 
109
        redirect_to :action => "unguarded"
 
110
      end
 
111
  end
 
112
 
 
113
  def setup
 
114
    @controller = TestController.new
 
115
    @request    = ActionController::TestRequest.new
 
116
    @response   = ActionController::TestResponse.new
 
117
    ActionController::Routing::Routes.add_named_route :foo, '/foo', :controller => 'test', :action => 'foo'
 
118
  end
 
119
 
 
120
  def test_using_symbol_back_with_no_referrer
 
121
    assert_raise(ActionController::RedirectBackError) { get :guarded_with_back }
 
122
  end
 
123
 
 
124
  def test_using_symbol_back_redirects_to_referrer
 
125
    @request.env["HTTP_REFERER"] = "/foo"
 
126
    get :guarded_with_back
 
127
    assert_redirected_to '/foo'
 
128
  end
 
129
 
 
130
  def test_no_deprecation_warning_for_named_route
 
131
    assert_not_deprecated do
 
132
      get :guarded_one_for_named_route_test, :two => "not one"
 
133
      assert_redirected_to '/foo'
 
134
    end
 
135
  end
 
136
 
 
137
  def test_guarded_one_with_prereqs
 
138
    get :guarded_one, :one => "here"
 
139
    assert_equal "here", @response.body
 
140
  end
 
141
 
 
142
  def test_guarded_one_without_prereqs
 
143
    get :guarded_one
 
144
    assert_redirected_to :action => "unguarded"
 
145
    assert_equal 'unguarded', flash[:error]
 
146
  end
 
147
 
 
148
  def test_guarded_with_flash_with_prereqs
 
149
    get :guarded_with_flash, :one => "here"
 
150
    assert_equal "here", @response.body
 
151
    assert flash.empty?
 
152
  end
 
153
 
 
154
  def test_guarded_with_flash_without_prereqs
 
155
    get :guarded_with_flash
 
156
    assert_redirected_to :action => "unguarded"
 
157
    assert_equal "prereqs failed", flash[:notice]
 
158
  end
 
159
 
 
160
  def test_guarded_two_with_prereqs
 
161
    get :guarded_two, :one => "here", :two => "there"
 
162
    assert_equal "here:there", @response.body
 
163
  end
 
164
 
 
165
  def test_guarded_two_without_prereqs_one
 
166
    get :guarded_two, :two => "there"
 
167
    assert_redirected_to :action => "unguarded"
 
168
  end
 
169
 
 
170
  def test_guarded_two_without_prereqs_two
 
171
    get :guarded_two, :one => "here"
 
172
    assert_redirected_to :action => "unguarded"
 
173
  end
 
174
 
 
175
  def test_guarded_two_without_prereqs_both
 
176
    get :guarded_two
 
177
    assert_redirected_to :action => "unguarded"
 
178
  end
 
179
 
 
180
  def test_unguarded_with_params
 
181
    get :unguarded, :one => "here"
 
182
    assert_equal "here", @response.body
 
183
  end
 
184
 
 
185
  def test_unguarded_without_params
 
186
    get :unguarded
 
187
    assert_equal "", @response.body
 
188
  end
 
189
 
 
190
  def test_guarded_in_session_with_prereqs
 
191
    get :guarded_in_session, {}, "one" => "here"
 
192
    assert_equal "here", @response.body
 
193
  end
 
194
 
 
195
  def test_guarded_in_session_without_prereqs
 
196
    get :guarded_in_session
 
197
    assert_redirected_to :action => "unguarded"
 
198
  end
 
199
 
 
200
  def test_multi_one_with_prereqs
 
201
    get :multi_one, {}, "one" => "here", "two" => "there"
 
202
    assert_equal "here:there", @response.body
 
203
  end
 
204
 
 
205
  def test_multi_one_without_prereqs
 
206
    get :multi_one
 
207
    assert_redirected_to :action => "unguarded"
 
208
  end
 
209
 
 
210
  def test_multi_two_with_prereqs
 
211
    get :multi_two, {}, "one" => "here", "two" => "there"
 
212
    assert_equal "there:here", @response.body
 
213
  end
 
214
 
 
215
  def test_multi_two_without_prereqs
 
216
    get :multi_two
 
217
    assert_redirected_to :action => "unguarded"
 
218
  end
 
219
 
 
220
  def test_guarded_by_method_with_prereqs
 
221
    post :guarded_by_method
 
222
    assert_equal "post", @response.body
 
223
  end
 
224
 
 
225
  def test_guarded_by_method_without_prereqs
 
226
    get :guarded_by_method
 
227
    assert_redirected_to :action => "unguarded"
 
228
  end
 
229
 
 
230
  def test_guarded_by_xhr_with_prereqs
 
231
    xhr :post, :guarded_by_xhr
 
232
    assert_equal "true", @response.body
 
233
  end
 
234
 
 
235
  def test_guarded_by_xhr_without_prereqs
 
236
    get :guarded_by_xhr
 
237
    assert_redirected_to :action => "unguarded"
 
238
  end
 
239
 
 
240
  def test_guarded_by_not_xhr_with_prereqs
 
241
    get :guarded_by_not_xhr
 
242
    assert_equal "false", @response.body
 
243
  end
 
244
 
 
245
  def test_guarded_by_not_xhr_without_prereqs
 
246
    xhr :post, :guarded_by_not_xhr
 
247
    assert_redirected_to :action => "unguarded"
 
248
  end
 
249
 
 
250
  def test_guarded_post_and_calls_render_succeeds
 
251
    post :must_be_post
 
252
    assert_equal "Was a post!", @response.body
 
253
  end
 
254
 
 
255
  def test_default_failure_should_be_a_bad_request
 
256
    post :no_default_action
 
257
    assert_response :bad_request
 
258
  end
 
259
 
 
260
  def test_guarded_post_and_calls_render_fails_and_sets_allow_header
 
261
    get :must_be_post
 
262
    assert_response 405
 
263
    assert_equal "Must be post", @response.body
 
264
    assert_equal "POST", @response.headers["Allow"]
 
265
  end
 
266
 
 
267
  def test_second_redirect
 
268
    assert_nothing_raised { get :two_redirects }
 
269
  end
 
270
end