actionpack 2.3.2 → 2.3.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (117) hide show
  1. data/CHANGELOG +5 -0
  2. data/Rakefile +10 -9
  3. data/lib/action_controller.rb +2 -7
  4. data/lib/action_controller/assertions/response_assertions.rb +11 -3
  5. data/lib/action_controller/base.rb +7 -2
  6. data/lib/action_controller/caching.rb +1 -1
  7. data/lib/action_controller/caching/actions.rb +9 -1
  8. data/lib/action_controller/caching/sweeper.rb +45 -0
  9. data/lib/action_controller/caching/sweeping.rb +0 -42
  10. data/lib/action_controller/failsafe.rb +40 -6
  11. data/lib/action_controller/flash.rb +11 -3
  12. data/lib/action_controller/http_authentication.rb +5 -2
  13. data/lib/action_controller/integration.rb +5 -12
  14. data/lib/action_controller/middlewares.rb +0 -1
  15. data/lib/action_controller/reloader.rb +34 -3
  16. data/lib/action_controller/request.rb +6 -2
  17. data/lib/action_controller/response.rb +2 -2
  18. data/lib/action_controller/routing/route_set.rb +2 -1
  19. data/lib/action_controller/streaming.rb +1 -1
  20. data/lib/action_controller/test_process.rb +9 -1
  21. data/lib/action_pack/version.rb +1 -1
  22. data/lib/action_view/helpers.rb +1 -1
  23. data/lib/action_view/helpers/asset_tag_helper.rb +21 -9
  24. data/lib/action_view/helpers/date_helper.rb +2 -2
  25. data/lib/action_view/helpers/form_helper.rb +25 -12
  26. data/lib/action_view/helpers/form_options_helper.rb +2 -0
  27. data/lib/action_view/helpers/form_tag_helper.rb +10 -4
  28. data/lib/action_view/helpers/number_helper.rb +1 -1
  29. data/lib/action_view/helpers/prototype_helper.rb +7 -7
  30. data/lib/action_view/helpers/scriptaculous_helper.rb +5 -5
  31. data/lib/action_view/helpers/text_helper.rb +3 -3
  32. data/lib/action_view/helpers/url_helper.rb +1 -1
  33. data/lib/action_view/paths.rb +1 -1
  34. data/lib/action_view/template.rb +22 -33
  35. data/test/abstract_unit.rb +1 -1
  36. data/test/activerecord/active_record_store_test.rb +3 -3
  37. data/test/controller/action_pack_assertions_test.rb +27 -0
  38. data/test/controller/caching_test.rb +39 -0
  39. data/test/controller/cookie_test.rb +10 -0
  40. data/test/controller/dispatcher_test.rb +9 -7
  41. data/test/controller/failsafe_test.rb +60 -0
  42. data/test/controller/filter_params_test.rb +2 -1
  43. data/test/controller/flash_test.rb +6 -1
  44. data/test/controller/http_digest_authentication_test.rb +34 -3
  45. data/test/controller/integration_test.rb +31 -3
  46. data/test/controller/redirect_test.rb +4 -1
  47. data/test/controller/reloader_test.rb +97 -0
  48. data/test/controller/render_test.rb +19 -9
  49. data/test/controller/request/multipart_params_parsing_test.rb +1 -62
  50. data/test/controller/request/test_request_test.rb +35 -0
  51. data/test/controller/request/url_encoded_params_parsing_test.rb +0 -38
  52. data/test/controller/request_test.rb +218 -230
  53. data/test/controller/resources_test.rb +8 -0
  54. data/test/controller/routing_test.rb +21 -0
  55. data/test/controller/send_file_test.rb +1 -1
  56. data/test/controller/session/cookie_store_test.rb +9 -32
  57. data/test/controller/test_test.rb +8 -0
  58. data/test/fixtures/failsafe/500.html +1 -0
  59. data/test/template/active_record_helper_test.rb +1 -1
  60. data/test/template/asset_tag_helper_test.rb +46 -0
  61. data/test/template/form_helper_test.rb +117 -6
  62. data/test/template/form_options_helper_test.rb +22 -0
  63. data/test/template/form_tag_helper_test.rb +23 -6
  64. data/test/template/prototype_helper_test.rb +11 -11
  65. data/test/template/template_test.rb +32 -0
  66. metadata +20 -63
  67. data/lib/action_controller/rewindable_input.rb +0 -28
  68. data/lib/action_controller/vendor/rack-1.0/rack.rb +0 -89
  69. data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +0 -22
  70. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +0 -37
  71. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +0 -37
  72. data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +0 -58
  73. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +0 -124
  74. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +0 -51
  75. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +0 -55
  76. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +0 -40
  77. data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +0 -480
  78. data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +0 -63
  79. data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +0 -36
  80. data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +0 -49
  81. data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +0 -61
  82. data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +0 -45
  83. data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +0 -29
  84. data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +0 -23
  85. data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +0 -85
  86. data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +0 -153
  87. data/lib/action_controller/vendor/rack-1.0/rack/file.rb +0 -88
  88. data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +0 -48
  89. data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +0 -61
  90. data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +0 -8
  91. data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +0 -89
  92. data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +0 -55
  93. data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +0 -84
  94. data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +0 -59
  95. data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +0 -8
  96. data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +0 -18
  97. data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +0 -67
  98. data/lib/action_controller/vendor/rack-1.0/rack/head.rb +0 -19
  99. data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +0 -462
  100. data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +0 -65
  101. data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +0 -16
  102. data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +0 -27
  103. data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +0 -204
  104. data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +0 -160
  105. data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +0 -57
  106. data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +0 -64
  107. data/lib/action_controller/vendor/rack-1.0/rack/request.rb +0 -241
  108. data/lib/action_controller/vendor/rack-1.0/rack/response.rb +0 -179
  109. data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +0 -142
  110. data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +0 -91
  111. data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +0 -109
  112. data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +0 -100
  113. data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +0 -349
  114. data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +0 -106
  115. data/lib/action_controller/vendor/rack-1.0/rack/static.rb +0 -38
  116. data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +0 -55
  117. data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +0 -392
@@ -67,6 +67,15 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
67
67
  assert_equal 'SuperSecret', credentials[:realm]
68
68
  end
69
69
 
70
+ test "authentication request with nil credentials" do
71
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => nil, :password => nil)
72
+ get :index
73
+
74
+ assert_response :unauthorized
75
+ assert_equal "HTTP Digest: Access denied.\n", @response.body, "Authentication didn't fail for request"
76
+ assert_not_equal 'Hello Secret', @response.body, "Authentication didn't fail for request"
77
+ end
78
+
70
79
  test "authentication request with invalid password" do
71
80
  @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'foo')
72
81
  get :display
@@ -151,6 +160,21 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
151
160
  assert_equal 'Definitely Maybe', @response.body
152
161
  end
153
162
 
163
+ test "authentication request with _method" do
164
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => 'pretty', :password => 'please', :method => :post)
165
+ @request.env['rack.methodoverride.original_method'] = 'POST'
166
+ put :display
167
+
168
+ assert_response :success
169
+ assert assigns(:logged_in)
170
+ assert_equal 'Definitely Maybe', @response.body
171
+ end
172
+
173
+ test "validate_digest_response should fail with nil returning password_procedure" do
174
+ @request.env['HTTP_AUTHORIZATION'] = encode_credentials(:username => nil, :password => nil)
175
+ assert !ActionController::HttpAuthentication::Digest.validate_digest_response(@request, "SuperSecret"){nil}
176
+ end
177
+
154
178
  private
155
179
 
156
180
  def encode_credentials(options)
@@ -161,15 +185,22 @@ class HttpDigestAuthenticationTest < ActionController::TestCase
161
185
  # to prevent tampering of timestamp
162
186
  ActionController::Base.session_options[:secret] = "session_options_secret"
163
187
 
164
- # Perform unauthenticated GET to retrieve digest parameters to use on subsequent request
165
- get :index
188
+ # Perform unauthenticated request to retrieve digest parameters to use on subsequent request
189
+ method = options.delete(:method) || 'GET'
190
+
191
+ case method.to_s.upcase
192
+ when 'GET'
193
+ get :index
194
+ when 'POST'
195
+ post :index
196
+ end
166
197
 
167
198
  assert_response :unauthorized
168
199
 
169
200
  credentials = decode_credentials(@response.headers['WWW-Authenticate'])
170
201
  credentials.merge!(options)
171
202
  credentials.reverse_merge!(:uri => "#{@request.env['REQUEST_URI']}")
172
- ActionController::HttpAuthentication::Digest.encode_credentials("GET", credentials, password, options[:password_is_ha1])
203
+ ActionController::HttpAuthentication::Digest.encode_credentials(method, credentials, password, options[:password_is_ha1])
173
204
  end
174
205
 
175
206
  def decode_credentials(header)
@@ -2,7 +2,7 @@ require 'abstract_unit'
2
2
 
3
3
  class SessionTest < Test::Unit::TestCase
4
4
  StubApp = lambda { |env|
5
- [200, {"Content-Type" => "text/html", "Content-Length" => "13"}, "Hello, World!"]
5
+ [200, {"Content-Type" => "text/html", "Content-Length" => "13"}, ["Hello, World!"]]
6
6
  }
7
7
 
8
8
  def setup
@@ -240,6 +240,14 @@ class IntegrationProcessTest < ActionController::IntegrationTest
240
240
  render :text => "foo: #{params[:foo]}", :status => 200
241
241
  end
242
242
 
243
+ def post_with_multiparameter_params
244
+ render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}", :status => 200
245
+ end
246
+
247
+ def multipart_post_with_multiparameter_params
248
+ render :text => "foo(1i): #{params[:"foo(1i)"]}, foo(2i): #{params[:"foo(2i)"]}, filesize: #{params[:file].size}", :status => 200
249
+ end
250
+
243
251
  def post
244
252
  render :text => "Created", :status => 201
245
253
  end
@@ -255,6 +263,8 @@ class IntegrationProcessTest < ActionController::IntegrationTest
255
263
  end
256
264
  end
257
265
 
266
+ FILES_DIR = File.dirname(__FILE__) + '/../fixtures/multipart'
267
+
258
268
  def test_get
259
269
  with_test_route_set do
260
270
  get '/get'
@@ -360,6 +370,24 @@ class IntegrationProcessTest < ActionController::IntegrationTest
360
370
  end
361
371
  end
362
372
 
373
+ def test_post_with_multiparameter_attribute_parameters
374
+ with_test_route_set do
375
+ post '/post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz"
376
+
377
+ assert_equal 200, status
378
+ assert_equal "foo(1i): bar, foo(2i): baz", response.body
379
+ end
380
+ end
381
+
382
+ def test_multipart_post_with_multiparameter_attribute_parameters
383
+ with_test_route_set do
384
+ post '/multipart_post_with_multiparameter_params', :"foo(1i)" => "bar", :"foo(2i)" => "baz", :file => fixture_file_upload(FILES_DIR + "/mona_lisa.jpg", "image/jpg")
385
+
386
+ assert_equal 200, status
387
+ assert_equal "foo(1i): bar, foo(2i): baz, filesize: 159528", response.body
388
+ end
389
+ end
390
+
363
391
  def test_head
364
392
  with_test_route_set do
365
393
  head '/get'
@@ -389,9 +417,9 @@ class MetalTest < ActionController::IntegrationTest
389
417
  class Poller
390
418
  def self.call(env)
391
419
  if env["PATH_INFO"] =~ /^\/success/
392
- [200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, "Hello World!"]
420
+ [200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, ["Hello World!"]]
393
421
  else
394
- [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, '']
422
+ [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
395
423
  end
396
424
  end
397
425
  end
@@ -235,7 +235,10 @@ class RedirectTest < ActionController::TestCase
235
235
 
236
236
  def test_redirect_with_partial_params
237
237
  get :module_redirect
238
- assert_redirected_to :action => 'hello_world'
238
+
239
+ assert_deprecated do
240
+ assert_redirected_to :action => 'hello_world'
241
+ end
239
242
  end
240
243
 
241
244
  def test_redirect_to_nil
@@ -0,0 +1,97 @@
1
+ require 'abstract_unit'
2
+
3
+ class ReloaderTests < ActiveSupport::TestCase
4
+ Reloader = ActionController::Reloader
5
+ Dispatcher = ActionController::Dispatcher
6
+
7
+ class MyBody < Array
8
+ def initialize(&block)
9
+ @on_close = block
10
+ end
11
+
12
+ def foo
13
+ "foo"
14
+ end
15
+
16
+ def bar
17
+ "bar"
18
+ end
19
+
20
+ def close
21
+ @on_close.call if @on_close
22
+ end
23
+ end
24
+
25
+ def setup_and_return_body(app = lambda { })
26
+ Dispatcher.expects(:reload_application)
27
+ reloader = Reloader.new(app)
28
+ headers, status, body = reloader.call({ })
29
+ body
30
+ end
31
+
32
+ def test_it_reloads_the_application_before_the_request
33
+ Dispatcher.expects(:reload_application)
34
+ reloader = Reloader.new(lambda {
35
+ [200, { "Content-Type" => "text/html" }, [""]]
36
+ })
37
+ reloader.call({ })
38
+ end
39
+
40
+ def test_returned_body_object_always_responds_to_close
41
+ body = setup_and_return_body(lambda {
42
+ [200, { "Content-Type" => "text/html" }, [""]]
43
+ })
44
+ assert body.respond_to?(:close)
45
+ end
46
+
47
+ def test_returned_body_object_behaves_like_underlying_object
48
+ body = setup_and_return_body(lambda {
49
+ b = MyBody.new
50
+ b << "hello"
51
+ b << "world"
52
+ [200, { "Content-Type" => "text/html" }, b]
53
+ })
54
+ assert_equal 2, body.size
55
+ assert_equal "hello", body[0]
56
+ assert_equal "world", body[1]
57
+ assert_equal "foo", body.foo
58
+ assert_equal "bar", body.bar
59
+ end
60
+
61
+ def test_it_calls_close_on_underlying_object_when_close_is_called_on_body
62
+ close_called = false
63
+ body = setup_and_return_body(lambda {
64
+ b = MyBody.new do
65
+ close_called = true
66
+ end
67
+ [200, { "Content-Type" => "text/html" }, b]
68
+ })
69
+ body.close
70
+ assert close_called
71
+ end
72
+
73
+ def test_returned_body_object_responds_to_all_methods_supported_by_underlying_object
74
+ body = setup_and_return_body(lambda {
75
+ [200, { "Content-Type" => "text/html" }, MyBody.new]
76
+ })
77
+ assert body.respond_to?(:size)
78
+ assert body.respond_to?(:each)
79
+ assert body.respond_to?(:foo)
80
+ assert body.respond_to?(:bar)
81
+ end
82
+
83
+ def test_it_doesnt_clean_up_the_application_after_call
84
+ Dispatcher.expects(:cleanup_application).never
85
+ body = setup_and_return_body(lambda {
86
+ [200, { "Content-Type" => "text/html" }, MyBody.new]
87
+ })
88
+ end
89
+
90
+ def test_it_cleans_up_the_application_when_close_is_called_on_body
91
+ Dispatcher.expects(:cleanup_application)
92
+ body = setup_and_return_body(lambda {
93
+ [200, { "Content-Type" => "text/html" }, MyBody.new]
94
+ })
95
+ body.close
96
+ end
97
+ end
@@ -193,20 +193,24 @@ class TestController < ActionController::Base
193
193
  render :inline => "<%= controller_name %>"
194
194
  end
195
195
 
196
+ def render_json_nil
197
+ render :json => nil
198
+ end
199
+
196
200
  def render_json_hello_world
197
- render :json => {:hello => 'world'}.to_json
201
+ render :json => ActiveSupport::JSON.encode(:hello => 'world')
198
202
  end
199
203
 
200
204
  def render_json_hello_world_with_callback
201
- render :json => {:hello => 'world'}.to_json, :callback => 'alert'
205
+ render :json => ActiveSupport::JSON.encode(:hello => 'world'), :callback => 'alert'
202
206
  end
203
207
 
204
208
  def render_json_with_custom_content_type
205
- render :json => {:hello => 'world'}.to_json, :content_type => 'text/javascript'
209
+ render :json => ActiveSupport::JSON.encode(:hello => 'world'), :content_type => 'text/javascript'
206
210
  end
207
211
 
208
212
  def render_symbol_json
209
- render :json => {:hello => 'world'}.to_json
213
+ render :json => ActiveSupport::JSON.encode(:hello => 'world')
210
214
  end
211
215
 
212
216
  def render_json_with_render_to_string
@@ -886,33 +890,39 @@ class RenderTest < ActionController::TestCase
886
890
  assert_equal "The secret is in the sauce\n", @response.body
887
891
  end
888
892
 
893
+ def test_render_json_nil
894
+ get :render_json_nil
895
+ assert_equal 'null', @response.body
896
+ assert_equal 'application/json', @response.content_type
897
+ end
898
+
889
899
  def test_render_json
890
900
  get :render_json_hello_world
891
- assert_equal '{"hello": "world"}', @response.body
901
+ assert_equal '{"hello":"world"}', @response.body
892
902
  assert_equal 'application/json', @response.content_type
893
903
  end
894
904
 
895
905
  def test_render_json_with_callback
896
906
  get :render_json_hello_world_with_callback
897
- assert_equal 'alert({"hello": "world"})', @response.body
907
+ assert_equal 'alert({"hello":"world"})', @response.body
898
908
  assert_equal 'application/json', @response.content_type
899
909
  end
900
910
 
901
911
  def test_render_json_with_custom_content_type
902
912
  get :render_json_with_custom_content_type
903
- assert_equal '{"hello": "world"}', @response.body
913
+ assert_equal '{"hello":"world"}', @response.body
904
914
  assert_equal 'text/javascript', @response.content_type
905
915
  end
906
916
 
907
917
  def test_render_symbol_json
908
918
  get :render_symbol_json
909
- assert_equal '{"hello": "world"}', @response.body
919
+ assert_equal '{"hello":"world"}', @response.body
910
920
  assert_equal 'application/json', @response.content_type
911
921
  end
912
922
 
913
923
  def test_render_json_with_render_to_string
914
924
  get :render_json_with_render_to_string
915
- assert_equal '{"hello": "partial html"}', @response.body
925
+ assert_equal '{"hello":"partial html"}', @response.body
916
926
  assert_equal 'application/json', @response.content_type
917
927
  end
918
928
 
@@ -96,7 +96,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
96
96
 
97
97
  # Ruby CGI doesn't handle multipart/mixed for us.
98
98
  files = params['files']
99
- assert_kind_of String, files
99
+ assert_kind_of Tempfile, files
100
100
  files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding)
101
101
  assert_equal 19756, files.size
102
102
  end
@@ -133,46 +133,6 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
133
133
  end
134
134
  end
135
135
 
136
- # The lint wrapper is used in integration tests
137
- # instead of a normal StringIO class
138
- InputWrapper = Rack::Lint::InputWrapper
139
-
140
- test "parses unwindable stream" do
141
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
142
- params = parse_multipart('large_text_file')
143
- assert_equal %w(file foo), params.keys.sort
144
- assert_equal 'bar', params['foo']
145
- end
146
-
147
- test "uploads and reads file with unwindable input" do
148
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
149
-
150
- with_test_routing do
151
- post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
152
- assert_equal "File: Hello", response.body
153
- end
154
- end
155
-
156
- test "passes through rack middleware and uploads file" do
157
- with_muck_middleware do
158
- with_test_routing do
159
- post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
160
- assert_equal "File: Hello", response.body
161
- end
162
- end
163
- end
164
-
165
- test "passes through rack middleware and uploads file with unwindable input" do
166
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
167
-
168
- with_muck_middleware do
169
- with_test_routing do
170
- post '/read', :uploaded_data => fixture_file_upload(FIXTURE_PATH + "/hello.txt", "text/plain")
171
- assert_equal "File: Hello", response.body
172
- end
173
- end
174
- end
175
-
176
136
  private
177
137
  def fixture(name)
178
138
  File.open(File.join(FIXTURE_PATH, name), 'rb') do |file|
@@ -199,25 +159,4 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
199
159
  yield
200
160
  end
201
161
  end
202
-
203
- class MuckMiddleware
204
- def initialize(app)
205
- @app = app
206
- end
207
-
208
- def call(env)
209
- req = Rack::Request.new(env)
210
- req.params # Parse params
211
- @app.call(env)
212
- end
213
- end
214
-
215
- def with_muck_middleware
216
- original_middleware = ActionController::Dispatcher.middleware
217
- middleware = original_middleware.dup
218
- middleware.insert_after ActionController::RewindableInput, MuckMiddleware
219
- ActionController::Dispatcher.middleware = middleware
220
- yield
221
- ActionController::Dispatcher.middleware = original_middleware
222
- end
223
162
  end
@@ -0,0 +1,35 @@
1
+ require 'abstract_unit'
2
+ require 'stringio'
3
+
4
+ class ActionController::TestRequestTest < ActiveSupport::TestCase
5
+
6
+ def setup
7
+ @request = ActionController::TestRequest.new
8
+ end
9
+
10
+ def test_test_request_has_session_options_initialized
11
+ assert @request.session_options
12
+ end
13
+
14
+ Rack::Session::Abstract::ID::DEFAULT_OPTIONS.each_key do |option|
15
+ test "test_rack_default_session_options_#{option}_exists_in_session_options_and_is_default" do
16
+ assert_equal(Rack::Session::Abstract::ID::DEFAULT_OPTIONS[option],
17
+ @request.session_options[option],
18
+ "Missing rack session default option #{option} in request.session_options")
19
+ end
20
+ test "test_rack_default_session_options_#{option}_exists_in_session_options" do
21
+ assert(@request.session_options.has_key?(option),
22
+ "Missing rack session option #{option} in request.session_options")
23
+ end
24
+ end
25
+
26
+ def test_session_id_exists_by_default
27
+ assert_not_nil(@request.session_options[:id])
28
+ end
29
+
30
+ def test_session_id_different_on_each_call
31
+ prev_id =
32
+ assert_not_equal(@request.session_options[:id], ActionController::TestRequest.new.session_options[:id])
33
+ end
34
+
35
+ end
@@ -126,45 +126,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
126
126
  assert_parses expected, query
127
127
  end
128
128
 
129
- test "passes through rack middleware and parses params" do
130
- with_muck_middleware do
131
- assert_parses({ "a" => { "b" => "c" } }, "a[b]=c")
132
- end
133
- end
134
-
135
- # The lint wrapper is used in integration tests
136
- # instead of a normal StringIO class
137
- InputWrapper = Rack::Lint::InputWrapper
138
-
139
- test "passes through rack middleware and parses params with unwindable input" do
140
- InputWrapper.any_instance.stubs(:rewind).raises(Errno::ESPIPE)
141
- with_muck_middleware do
142
- assert_parses({ "a" => { "b" => "c" } }, "a[b]=c")
143
- end
144
- end
145
-
146
129
  private
147
- class MuckMiddleware
148
- def initialize(app)
149
- @app = app
150
- end
151
-
152
- def call(env)
153
- req = Rack::Request.new(env)
154
- req.params # Parse params
155
- @app.call(env)
156
- end
157
- end
158
-
159
- def with_muck_middleware
160
- original_middleware = ActionController::Dispatcher.middleware
161
- middleware = original_middleware.dup
162
- middleware.insert_after ActionController::RewindableInput, MuckMiddleware
163
- ActionController::Dispatcher.middleware = middleware
164
- yield
165
- ActionController::Dispatcher.middleware = original_middleware
166
- end
167
-
168
130
  def with_test_routing
169
131
  with_routing do |set|
170
132
  set.draw do |map|