actionpack 1.12.5 → 1.13.0
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.
- data/CHANGELOG +517 -15
- data/MIT-LICENSE +1 -1
- data/README +18 -20
- data/Rakefile +7 -4
- data/examples/address_book_controller.rb +3 -3
- data/examples/blog_controller.cgi +3 -3
- data/examples/debate_controller.cgi +5 -5
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions.rb +73 -311
- data/lib/action_controller/{deprecated_assertions.rb → assertions/deprecated_assertions.rb} +32 -8
- data/lib/action_controller/assertions/dom_assertions.rb +25 -0
- data/lib/action_controller/assertions/model_assertions.rb +12 -0
- data/lib/action_controller/assertions/response_assertions.rb +140 -0
- data/lib/action_controller/assertions/routing_assertions.rb +82 -0
- data/lib/action_controller/assertions/selector_assertions.rb +571 -0
- data/lib/action_controller/assertions/tag_assertions.rb +117 -0
- data/lib/action_controller/base.rb +334 -163
- data/lib/action_controller/benchmarking.rb +3 -6
- data/lib/action_controller/caching.rb +83 -22
- data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -7
- data/lib/action_controller/cgi_ext/cgi_methods.rb +167 -173
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +43 -22
- data/lib/action_controller/cgi_process.rb +50 -27
- data/lib/action_controller/components.rb +21 -25
- data/lib/action_controller/cookies.rb +10 -9
- data/lib/action_controller/{dependencies.rb → deprecated_dependencies.rb} +9 -27
- data/lib/action_controller/filters.rb +448 -225
- data/lib/action_controller/flash.rb +24 -20
- data/lib/action_controller/helpers.rb +2 -5
- data/lib/action_controller/integration.rb +40 -16
- data/lib/action_controller/layout.rb +11 -8
- data/lib/action_controller/macros/auto_complete.rb +3 -2
- data/lib/action_controller/macros/in_place_editing.rb +3 -2
- data/lib/action_controller/mime_responds.rb +41 -29
- data/lib/action_controller/mime_type.rb +68 -10
- data/lib/action_controller/pagination.rb +4 -3
- data/lib/action_controller/request.rb +22 -14
- data/lib/action_controller/rescue.rb +25 -22
- data/lib/action_controller/resources.rb +302 -0
- data/lib/action_controller/response.rb +20 -2
- data/lib/action_controller/response.rb.rej +17 -0
- data/lib/action_controller/routing.rb +1165 -567
- data/lib/action_controller/scaffolding.rb +30 -31
- data/lib/action_controller/session/active_record_store.rb +2 -0
- data/lib/action_controller/session/drb_store.rb +4 -0
- data/lib/action_controller/session/mem_cache_store.rb +4 -0
- data/lib/action_controller/session_management.rb +6 -9
- data/lib/action_controller/status_codes.rb +89 -0
- data/lib/action_controller/streaming.rb +6 -15
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +5 -5
- data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -2
- data/lib/action_controller/templates/rescues/routing_error.rhtml +4 -4
- data/lib/action_controller/templates/rescues/template_error.rhtml +1 -1
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +52 -30
- data/lib/action_controller/url_rewriter.rb +63 -29
- data/lib/action_controller/vendor/html-scanner/html/document.rb +1 -0
- data/lib/action_controller/vendor/html-scanner/html/node.rb +3 -4
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +822 -0
- data/lib/action_controller/verification.rb +22 -11
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +1 -1
- data/lib/action_view/base.rb +46 -43
- data/lib/action_view/compiled_templates.rb +1 -1
- data/lib/action_view/helpers/active_record_helper.rb +54 -17
- data/lib/action_view/helpers/asset_tag_helper.rb +97 -46
- data/lib/action_view/helpers/capture_helper.rb +1 -1
- data/lib/action_view/helpers/date_helper.rb +258 -136
- data/lib/action_view/helpers/debug_helper.rb +1 -1
- data/lib/action_view/helpers/deprecated_helper.rb +34 -0
- data/lib/action_view/helpers/form_helper.rb +75 -35
- data/lib/action_view/helpers/form_options_helper.rb +7 -5
- data/lib/action_view/helpers/form_tag_helper.rb +44 -6
- data/lib/action_view/helpers/java_script_macros_helper.rb +59 -46
- data/lib/action_view/helpers/javascript_helper.rb +71 -10
- data/lib/action_view/helpers/javascripts/controls.js +41 -23
- data/lib/action_view/helpers/javascripts/dragdrop.js +105 -76
- data/lib/action_view/helpers/javascripts/effects.js +293 -163
- data/lib/action_view/helpers/javascripts/prototype.js +897 -389
- data/lib/action_view/helpers/javascripts/prototype.js.rej +561 -0
- data/lib/action_view/helpers/number_helper.rb +111 -65
- data/lib/action_view/helpers/prototype_helper.rb +84 -109
- data/lib/action_view/helpers/scriptaculous_helper.rb +5 -0
- data/lib/action_view/helpers/tag_helper.rb +69 -16
- data/lib/action_view/helpers/text_helper.rb +149 -112
- data/lib/action_view/helpers/url_helper.rb +200 -107
- data/lib/action_view/template_error.rb +66 -42
- data/test/abstract_unit.rb +4 -2
- data/test/active_record_unit.rb +84 -56
- data/test/activerecord/active_record_assertions_test.rb +26 -18
- data/test/activerecord/active_record_store_test.rb +4 -36
- data/test/activerecord/pagination_test.rb +1 -6
- data/test/controller/action_pack_assertions_test.rb +230 -113
- data/test/controller/addresses_render_test.rb +2 -6
- data/test/controller/assert_select_test.rb +576 -0
- data/test/controller/base_test.rb +73 -3
- data/test/controller/caching_test.rb +228 -0
- data/test/controller/capture_test.rb +12 -10
- data/test/controller/cgi_test.rb +89 -12
- data/test/controller/components_test.rb +24 -2
- data/test/controller/content_type_test.rb +139 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +33 -25
- data/test/controller/deprecated_instance_variables_test.rb +48 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +60 -0
- data/test/controller/fake_controllers.rb +0 -1
- data/test/controller/filters_test.rb +301 -16
- data/test/controller/flash_test.rb +19 -2
- data/test/controller/helper_test.rb +2 -2
- data/test/controller/integration_test.rb +154 -0
- data/test/controller/layout_test.rb +115 -1
- data/test/controller/mime_responds_test.rb +94 -0
- data/test/controller/mime_type_test.rb +9 -0
- data/test/controller/new_render_test.rb +161 -11
- data/test/controller/raw_post_test.rb +52 -15
- data/test/controller/redirect_test.rb +27 -14
- data/test/controller/render_test.rb +76 -29
- data/test/controller/request_test.rb +55 -4
- data/test/controller/resources_test.rb +274 -0
- data/test/controller/routing_test.rb +1533 -824
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +9 -1
- data/test/controller/session_management_test.rb +51 -0
- data/test/controller/test_test.rb +113 -29
- data/test/controller/url_rewriter_test.rb +86 -17
- data/test/controller/verification_test.rb +19 -17
- data/test/controller/webservice_test.rb +0 -7
- data/test/fixtures/content_type/render_default_content_types_for_respond_to.rhtml +1 -0
- data/test/fixtures/content_type/render_default_for_rhtml.rhtml +1 -0
- data/test/fixtures/content_type/render_default_for_rjs.rjs +1 -0
- data/test/fixtures/content_type/render_default_for_rxml.rxml +1 -0
- data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +1 -0
- data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +1 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/test/_hello.rxml +1 -0
- data/test/fixtures/test/hello_world_container.rxml +3 -0
- data/test/fixtures/topic.rb +2 -2
- data/test/template/active_record_helper_test.rb +83 -12
- data/test/template/asset_tag_helper_test.rb +75 -95
- data/test/template/compiled_templates_test.rb +1 -0
- data/test/template/date_helper_test.rb +873 -181
- data/test/template/deprecated_helper_test.rb +36 -0
- data/test/template/deprecated_instance_variables_test.rb +43 -0
- data/test/template/form_helper_test.rb +77 -1
- data/test/template/form_options_helper_test.rb +4 -0
- data/test/template/form_tag_helper_test.rb +66 -2
- data/test/template/java_script_macros_helper_test.rb +4 -1
- data/test/template/javascript_helper_test.rb +29 -0
- data/test/template/number_helper_test.rb +63 -27
- data/test/template/prototype_helper_test.rb +77 -34
- data/test/template/tag_helper_test.rb +34 -6
- data/test/template/text_helper_test.rb +69 -34
- data/test/template/url_helper_test.rb +168 -16
- data/test/testing_sandbox.rb +7 -22
- metadata +66 -20
- data/filler.txt +0 -50
- data/lib/action_controller/code_generation.rb +0 -235
- data/lib/action_controller/vendor/xml_simple.rb +0 -1019
- data/test/controller/caching_filestore.rb +0 -74
- data/test/fixtures/application_root/app/controllers/a_class_that_contains_a_controller/poorly_placed_controller.rb +0 -7
- data/test/fixtures/application_root/app/controllers/module_that_holds_controllers/nested_controller.rb +0 -3
- data/test/fixtures/application_root/app/models/a_class_that_contains_a_controller.rb +0 -7
- data/test/fixtures/dont_load.rb +0 -3
@@ -161,6 +161,33 @@ class NewRenderTestController < ActionController::Base
|
|
161
161
|
render :text => "How's there? #{render_to_string("test/list")}"
|
162
162
|
end
|
163
163
|
|
164
|
+
def render_to_string_with_assigns
|
165
|
+
@before = "i'm before the render"
|
166
|
+
render_to_string :text => "foo"
|
167
|
+
@after = "i'm after the render"
|
168
|
+
render :action => "test/hello_world"
|
169
|
+
end
|
170
|
+
|
171
|
+
def render_to_string_with_partial
|
172
|
+
@partial_only = render_to_string :partial => "partial_only"
|
173
|
+
@partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") }
|
174
|
+
render :action => "test/hello_world"
|
175
|
+
end
|
176
|
+
|
177
|
+
def render_to_string_with_exception
|
178
|
+
render_to_string :file => "exception that will not be caught - this will certainly not work", :use_full_path => true
|
179
|
+
end
|
180
|
+
|
181
|
+
def render_to_string_with_caught_exception
|
182
|
+
@before = "i'm before the render"
|
183
|
+
begin
|
184
|
+
render_to_string :file => "exception that will be caught- hope my future instance vars still work!", :use_full_path => true
|
185
|
+
rescue
|
186
|
+
end
|
187
|
+
@after = "i'm after the render"
|
188
|
+
render :action => "test/hello_world"
|
189
|
+
end
|
190
|
+
|
164
191
|
def accessing_params_in_template
|
165
192
|
render :inline => "Hello: <%= params[:name] %>"
|
166
193
|
end
|
@@ -187,6 +214,11 @@ class NewRenderTestController < ActionController::Base
|
|
187
214
|
render :text => "hello"
|
188
215
|
redirect_to :action => "double_render"
|
189
216
|
end
|
217
|
+
|
218
|
+
def render_to_string_and_render
|
219
|
+
@stuff = render_to_string :text => "here is some cached stuff"
|
220
|
+
render :text => "Hi web users! #{@stuff}"
|
221
|
+
end
|
190
222
|
|
191
223
|
def rendering_with_conflicting_local_vars
|
192
224
|
@name = "David"
|
@@ -202,6 +234,30 @@ class NewRenderTestController < ActionController::Base
|
|
202
234
|
render :template => "test/hello_world.rxml"
|
203
235
|
end
|
204
236
|
|
237
|
+
def head_with_location_header
|
238
|
+
head :location => "/foo"
|
239
|
+
end
|
240
|
+
|
241
|
+
def head_with_symbolic_status
|
242
|
+
head :status => params[:status].intern
|
243
|
+
end
|
244
|
+
|
245
|
+
def head_with_integer_status
|
246
|
+
head :status => params[:status].to_i
|
247
|
+
end
|
248
|
+
|
249
|
+
def head_with_string_status
|
250
|
+
head :status => params[:status]
|
251
|
+
end
|
252
|
+
|
253
|
+
def head_with_custom_header
|
254
|
+
head :x_custom_header => "something"
|
255
|
+
end
|
256
|
+
|
257
|
+
def head_with_status_code_first
|
258
|
+
head :forbidden, :x_custom_header => "something"
|
259
|
+
end
|
260
|
+
|
205
261
|
helper NewRenderTestHelper
|
206
262
|
helper do
|
207
263
|
def rjs_helper_method(value)
|
@@ -263,6 +319,11 @@ class NewRenderTestController < ActionController::Base
|
|
263
319
|
render :action => "content_for", :layout => "yield"
|
264
320
|
end
|
265
321
|
|
322
|
+
def render_content_type_from_body
|
323
|
+
response.content_type = Mime::RSS
|
324
|
+
render :text => "hello world!"
|
325
|
+
end
|
326
|
+
|
266
327
|
def rescue_action(e) raise end
|
267
328
|
|
268
329
|
private
|
@@ -393,18 +454,26 @@ class NewRenderTest < Test::Unit::TestCase
|
|
393
454
|
ActionController::Base.protected_variables_cache = nil
|
394
455
|
|
395
456
|
get :hello_world
|
396
|
-
|
457
|
+
assert !assigns.include?('request'), 'request should not be in assigns'
|
397
458
|
|
398
459
|
ActionController::Base.view_controller_internals = true
|
399
460
|
ActionController::Base.protected_variables_cache = nil
|
400
461
|
|
401
462
|
get :hello_world
|
402
|
-
|
463
|
+
assert assigns.include?('request'), 'request should be in assigns'
|
464
|
+
assert_deprecated 'request' do
|
465
|
+
assert_kind_of ActionController::AbstractRequest, assigns['request']
|
466
|
+
end
|
467
|
+
assert_not_deprecated do
|
468
|
+
assert_kind_of ActionController::AbstractRequest, @response.template.request
|
469
|
+
assert_kind_of ActionController::AbstractRequest, assigns['_request']
|
470
|
+
end
|
403
471
|
|
472
|
+
ensure
|
404
473
|
ActionController::Base.view_controller_internals = view_internals_old_value
|
405
474
|
ActionController::Base.protected_variables_cache = nil
|
406
475
|
end
|
407
|
-
|
476
|
+
|
408
477
|
def test_render_xml
|
409
478
|
get :render_xml_hello
|
410
479
|
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
|
@@ -429,17 +498,17 @@ EOS
|
|
429
498
|
|
430
499
|
def test_render_rjs_with_default
|
431
500
|
get :delete_with_js
|
432
|
-
assert_equal %!
|
501
|
+
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
433
502
|
end
|
434
503
|
|
435
504
|
def test_render_rjs_template_explicitly
|
436
505
|
get :render_js_with_explicit_template
|
437
|
-
assert_equal %!
|
506
|
+
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
438
507
|
end
|
439
508
|
|
440
509
|
def test_rendering_rjs_action_explicitly
|
441
510
|
get :render_js_with_explicit_action_template
|
442
|
-
assert_equal %!
|
511
|
+
assert_equal %!Element.remove("person");\nnew Effect.Highlight(\"project-4\",{});!, @response.body
|
443
512
|
end
|
444
513
|
|
445
514
|
def test_layout_rendering
|
@@ -483,9 +552,31 @@ EOS
|
|
483
552
|
end
|
484
553
|
|
485
554
|
def test_render_to_string
|
486
|
-
get :hello_in_a_string
|
555
|
+
assert_not_deprecated { get :hello_in_a_string }
|
487
556
|
assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body
|
488
557
|
end
|
558
|
+
|
559
|
+
def test_render_to_string_doesnt_break_assigns
|
560
|
+
get :render_to_string_with_assigns
|
561
|
+
assert_equal "i'm before the render", assigns(:before)
|
562
|
+
assert_equal "i'm after the render", assigns(:after)
|
563
|
+
end
|
564
|
+
|
565
|
+
def test_render_to_string_partial
|
566
|
+
get :render_to_string_with_partial
|
567
|
+
assert_equal "only partial", assigns(:partial_only)
|
568
|
+
assert_equal "Hello: david", assigns(:partial_with_locals)
|
569
|
+
end
|
570
|
+
|
571
|
+
def test_bad_render_to_string_still_throws_exception
|
572
|
+
assert_raises(ActionController::MissingTemplate) { get :render_to_string_with_exception }
|
573
|
+
end
|
574
|
+
|
575
|
+
def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
|
576
|
+
assert_nothing_raised { get :render_to_string_with_caught_exception }
|
577
|
+
assert_equal "i'm before the render", assigns(:before)
|
578
|
+
assert_equal "i'm after the render", assigns(:after)
|
579
|
+
end
|
489
580
|
|
490
581
|
def test_nested_rendering
|
491
582
|
get :hello_world
|
@@ -503,7 +594,7 @@ EOS
|
|
503
594
|
end
|
504
595
|
|
505
596
|
def test_render_with_explicit_template
|
506
|
-
get :render_with_explicit_template
|
597
|
+
assert_deprecated(/render/) { get :render_with_explicit_template }
|
507
598
|
assert_response :success
|
508
599
|
end
|
509
600
|
|
@@ -518,6 +609,12 @@ EOS
|
|
518
609
|
def test_render_and_redirect
|
519
610
|
assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect }
|
520
611
|
end
|
612
|
+
|
613
|
+
# specify the one exception to double render rule - render_to_string followed by render
|
614
|
+
def test_render_to_string_and_render
|
615
|
+
get :render_to_string_and_render
|
616
|
+
assert_equal("Hi web users! here is some cached stuff", @response.body)
|
617
|
+
end
|
521
618
|
|
522
619
|
def test_rendering_with_conflicting_local_vars
|
523
620
|
get :rendering_with_conflicting_local_vars
|
@@ -572,20 +669,20 @@ EOS
|
|
572
669
|
def test_update_page
|
573
670
|
get :update_page
|
574
671
|
assert_template nil
|
575
|
-
assert_equal 'text/javascript; charset=
|
672
|
+
assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type']
|
576
673
|
assert_equal 2, @response.body.split($/).length
|
577
674
|
end
|
578
675
|
|
579
676
|
def test_update_page_with_instance_variables
|
580
677
|
get :update_page_with_instance_variables
|
581
678
|
assert_template nil
|
582
|
-
assert_equal 'text/javascript; charset=
|
679
|
+
assert_equal 'text/javascript; charset=utf-8', @response.headers['Content-Type']
|
583
680
|
assert_match /balance/, @response.body
|
584
681
|
assert_match /\$37/, @response.body
|
585
682
|
end
|
586
683
|
|
587
684
|
def test_yield_content_for
|
588
|
-
get :yield_content_for
|
685
|
+
assert_not_deprecated { get :yield_content_for }
|
589
686
|
assert_equal "<title>Putting stuff in the title!</title>\n\nGreat stuff!\n", @response.body
|
590
687
|
end
|
591
688
|
|
@@ -597,4 +694,57 @@ EOS
|
|
597
694
|
get :hello_world_from_rxml_using_action
|
598
695
|
assert_equal "<html>\n <p>Hello</p>\n</html>\n", @response.body
|
599
696
|
end
|
697
|
+
|
698
|
+
|
699
|
+
def test_head_with_location_header
|
700
|
+
get :head_with_location_header
|
701
|
+
assert @response.body.blank?
|
702
|
+
assert_equal "/foo", @response.headers["Location"]
|
703
|
+
assert_response :ok
|
704
|
+
end
|
705
|
+
|
706
|
+
def test_head_with_custom_header
|
707
|
+
get :head_with_custom_header
|
708
|
+
assert @response.body.blank?
|
709
|
+
assert_equal "something", @response.headers["X-Custom-Header"]
|
710
|
+
assert_response :ok
|
711
|
+
end
|
712
|
+
|
713
|
+
def test_head_with_symbolic_status
|
714
|
+
get :head_with_symbolic_status, :status => "ok"
|
715
|
+
assert_equal "200 OK", @response.headers["Status"]
|
716
|
+
assert_response :ok
|
717
|
+
|
718
|
+
get :head_with_symbolic_status, :status => "not_found"
|
719
|
+
assert_equal "404 Not Found", @response.headers["Status"]
|
720
|
+
assert_response :not_found
|
721
|
+
|
722
|
+
ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
|
723
|
+
get :head_with_symbolic_status, :status => status.to_s
|
724
|
+
assert_equal code, @response.response_code
|
725
|
+
assert_response status
|
726
|
+
end
|
727
|
+
end
|
728
|
+
|
729
|
+
def test_head_with_integer_status
|
730
|
+
ActionController::StatusCodes::STATUS_CODES.each do |code, message|
|
731
|
+
get :head_with_integer_status, :status => code.to_s
|
732
|
+
assert_equal message, @response.message
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
def test_head_with_string_status
|
737
|
+
get :head_with_string_status, :status => "404 Eat Dirt"
|
738
|
+
assert_equal 404, @response.response_code
|
739
|
+
assert_equal "Eat Dirt", @response.message
|
740
|
+
assert_response :not_found
|
741
|
+
end
|
742
|
+
|
743
|
+
def test_head_with_status_code_first
|
744
|
+
get :head_with_status_code_first
|
745
|
+
assert_equal 403, @response.response_code
|
746
|
+
assert_equal "Forbidden", @response.message
|
747
|
+
assert_equal "something", @response.headers["X-Custom-Header"]
|
748
|
+
assert_response :forbidden
|
749
|
+
end
|
600
750
|
end
|
@@ -5,27 +5,64 @@ require File.dirname(__FILE__) + '/../../lib/action_controller/cgi_ext/raw_post_
|
|
5
5
|
|
6
6
|
class RawPostDataTest < Test::Unit::TestCase
|
7
7
|
def setup
|
8
|
+
ENV.delete('RAW_POST_DATA')
|
9
|
+
@request_body = 'a=1'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_post_with_urlencoded_body
|
13
|
+
ENV['REQUEST_METHOD'] = 'POST'
|
14
|
+
ENV['CONTENT_TYPE'] = ' apPlication/x-Www-form-urlEncoded; charset=utf-8'
|
15
|
+
assert_equal ['1'], cgi_params['a']
|
16
|
+
assert_has_raw_post_data
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_post_with_empty_content_type_treated_as_urlencoded
|
8
20
|
ENV['REQUEST_METHOD'] = 'POST'
|
9
21
|
ENV['CONTENT_TYPE'] = ''
|
10
|
-
|
22
|
+
assert_equal ['1'], cgi_params['a']
|
23
|
+
assert_has_raw_post_data
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_post_with_unrecognized_content_type_reads_body_but_doesnt_parse_params
|
27
|
+
ENV['REQUEST_METHOD'] = 'POST'
|
28
|
+
ENV['CONTENT_TYPE'] = 'foo/bar'
|
29
|
+
assert cgi_params.empty?
|
30
|
+
assert_has_raw_post_data
|
11
31
|
end
|
12
32
|
|
13
|
-
def
|
14
|
-
|
33
|
+
def test_put_with_urlencoded_body
|
34
|
+
ENV['REQUEST_METHOD'] = 'PUT'
|
35
|
+
ENV['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
|
36
|
+
assert_equal ['1'], cgi_params['a']
|
37
|
+
assert_has_raw_post_data
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_put_with_empty_content_type_ignores_body
|
41
|
+
ENV['REQUEST_METHOD'] = 'PUT'
|
42
|
+
ENV['CONTENT_TYPE'] = ''
|
43
|
+
assert cgi_params.empty?
|
44
|
+
assert_has_raw_post_data
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_put_with_unrecognized_content_type_ignores_body
|
48
|
+
ENV['REQUEST_METHOD'] = 'PUT'
|
49
|
+
ENV['CONTENT_TYPE'] = 'foo/bar'
|
50
|
+
assert cgi_params.empty?
|
51
|
+
assert_has_raw_post_data
|
15
52
|
end
|
16
53
|
|
17
54
|
private
|
18
|
-
def
|
19
|
-
old_stdin = $stdin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
55
|
+
def cgi_params
|
56
|
+
old_stdin, $stdin = $stdin, StringIO.new(@request_body.dup)
|
57
|
+
ENV['CONTENT_LENGTH'] = $stdin.size.to_s
|
58
|
+
CGI.new.params
|
59
|
+
ensure
|
60
|
+
$stdin = old_stdin
|
61
|
+
end
|
62
|
+
|
63
|
+
def assert_has_raw_post_data(expected_body = @request_body)
|
64
|
+
assert_not_nil ENV['RAW_POST_DATA']
|
65
|
+
assert ENV['RAW_POST_DATA'].frozen?
|
66
|
+
assert_equal expected_body, ENV['RAW_POST_DATA']
|
30
67
|
end
|
31
68
|
end
|
@@ -45,52 +45,60 @@ class RedirectTest < Test::Unit::TestCase
|
|
45
45
|
|
46
46
|
def test_simple_redirect
|
47
47
|
get :simple_redirect
|
48
|
-
|
48
|
+
assert_response :redirect
|
49
|
+
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
|
49
50
|
end
|
50
51
|
|
51
52
|
def test_redirect_with_method_reference_and_parameters
|
52
|
-
get :method_redirect
|
53
|
-
|
53
|
+
assert_deprecated(/redirect_to/) { get :method_redirect }
|
54
|
+
assert_response :redirect
|
55
|
+
assert_equal "http://test.host/redirect/dashboard/1?message=hello", redirect_to_url
|
54
56
|
end
|
55
57
|
|
56
58
|
def test_simple_redirect_using_options
|
57
59
|
get :host_redirect
|
60
|
+
assert_response :redirect
|
58
61
|
assert_redirected_to :action => "other_host", :only_path => false, :host => 'other.test.host'
|
59
62
|
end
|
60
63
|
|
61
64
|
def test_redirect_error_with_pretty_diff
|
62
65
|
get :host_redirect
|
66
|
+
assert_response :redirect
|
63
67
|
begin
|
64
68
|
assert_redirected_to :action => "other_host", :only_path => true
|
65
69
|
rescue Test::Unit::AssertionFailedError => err
|
66
70
|
redirection_msg, diff_msg = err.message.scan(/<\{[^\}]+\}>/).collect { |s| s[2..-3] }
|
67
|
-
assert_match %r(
|
68
|
-
assert_match %r(
|
69
|
-
assert_match %r(
|
70
|
-
assert_match %r(
|
71
|
-
assert_match %r(
|
71
|
+
assert_match %r("only_path"=>false), redirection_msg
|
72
|
+
assert_match %r("host"=>"other.test.host"), redirection_msg
|
73
|
+
assert_match %r("action"=>"other_host"), redirection_msg
|
74
|
+
assert_match %r("only_path"=>true), diff_msg
|
75
|
+
assert_match %r("host"=>"other.test.host"), diff_msg
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
75
79
|
def test_module_redirect
|
76
80
|
get :module_redirect
|
77
|
-
|
81
|
+
assert_response :redirect
|
82
|
+
assert_redirected_to "http://test.host/module_test/module_redirect/hello_world"
|
78
83
|
end
|
79
84
|
|
80
85
|
def test_module_redirect_using_options
|
81
86
|
get :module_redirect
|
87
|
+
assert_response :redirect
|
82
88
|
assert_redirected_to :controller => 'module_test/module_redirect', :action => 'hello_world'
|
83
89
|
end
|
84
90
|
|
85
91
|
def test_redirect_with_assigns
|
86
92
|
get :redirect_with_assigns
|
93
|
+
assert_response :redirect
|
87
94
|
assert_equal "world", assigns["hello"]
|
88
95
|
end
|
89
96
|
|
90
97
|
def test_redirect_to_back
|
91
98
|
@request.env["HTTP_REFERER"] = "http://www.example.com/coming/from"
|
92
99
|
get :redirect_to_back
|
93
|
-
|
100
|
+
assert_response :redirect
|
101
|
+
assert_equal "http://www.example.com/coming/from", redirect_to_url
|
94
102
|
end
|
95
103
|
|
96
104
|
def test_redirect_to_back_with_no_referer
|
@@ -117,26 +125,31 @@ module ModuleTest
|
|
117
125
|
|
118
126
|
def test_simple_redirect
|
119
127
|
get :simple_redirect
|
120
|
-
|
128
|
+
assert_response :redirect
|
129
|
+
assert_equal "http://test.host/module_test/module_redirect/hello_world", redirect_to_url
|
121
130
|
end
|
122
131
|
|
123
132
|
def test_redirect_with_method_reference_and_parameters
|
124
|
-
get :method_redirect
|
125
|
-
|
133
|
+
assert_deprecated(/redirect_to/) { get :method_redirect }
|
134
|
+
assert_response :redirect
|
135
|
+
assert_equal "http://test.host/module_test/module_redirect/dashboard/1?message=hello", redirect_to_url
|
126
136
|
end
|
127
137
|
|
128
138
|
def test_simple_redirect_using_options
|
129
139
|
get :host_redirect
|
140
|
+
assert_response :redirect
|
130
141
|
assert_redirected_to :action => "other_host", :only_path => false, :host => 'other.test.host'
|
131
142
|
end
|
132
143
|
|
133
144
|
def test_module_redirect
|
134
145
|
get :module_redirect
|
135
|
-
|
146
|
+
assert_response :redirect
|
147
|
+
assert_equal "http://test.host/redirect/hello_world", redirect_to_url
|
136
148
|
end
|
137
149
|
|
138
150
|
def test_module_redirect_using_options
|
139
151
|
get :module_redirect
|
152
|
+
assert_response :redirect
|
140
153
|
assert_redirected_to :controller => 'redirect', :action => "hello_world"
|
141
154
|
end
|
142
155
|
end
|