actionpack 1.13.6 → 2.0.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 +1400 -20
- data/MIT-LICENSE +1 -1
- data/README +5 -5
- data/RUNNING_UNIT_TESTS +4 -5
- data/Rakefile +5 -6
- data/install.rb +2 -2
- data/lib/action_controller.rb +11 -15
- data/lib/action_controller/assertions.rb +12 -25
- data/lib/action_controller/assertions/dom_assertions.rb +18 -4
- data/lib/action_controller/assertions/model_assertions.rb +8 -1
- data/lib/action_controller/assertions/response_assertions.rb +35 -12
- data/lib/action_controller/assertions/routing_assertions.rb +56 -12
- data/lib/action_controller/assertions/selector_assertions.rb +105 -38
- data/lib/action_controller/assertions/tag_assertions.rb +28 -15
- data/lib/action_controller/base.rb +318 -250
- data/lib/action_controller/benchmarking.rb +33 -29
- data/lib/action_controller/caching.rb +130 -64
- data/lib/action_controller/cgi_ext.rb +16 -0
- data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
- data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
- data/lib/action_controller/cgi_ext/session.rb +73 -0
- data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
- data/lib/action_controller/cgi_process.rb +34 -57
- data/lib/action_controller/components.rb +19 -36
- data/lib/action_controller/cookies.rb +10 -9
- data/lib/action_controller/dispatcher.rb +195 -0
- data/lib/action_controller/filters.rb +35 -34
- data/lib/action_controller/flash.rb +30 -35
- data/lib/action_controller/helpers.rb +121 -47
- data/lib/action_controller/http_authentication.rb +126 -0
- data/lib/action_controller/integration.rb +105 -101
- data/lib/action_controller/layout.rb +59 -47
- data/lib/action_controller/mime_responds.rb +57 -68
- data/lib/action_controller/mime_type.rb +43 -80
- data/lib/action_controller/mime_types.rb +20 -0
- data/lib/action_controller/polymorphic_routes.rb +88 -0
- data/lib/action_controller/record_identifier.rb +91 -0
- data/lib/action_controller/request.rb +553 -88
- data/lib/action_controller/request_forgery_protection.rb +126 -0
- data/lib/action_controller/request_profiler.rb +138 -0
- data/lib/action_controller/rescue.rb +185 -69
- data/lib/action_controller/resources.rb +211 -172
- data/lib/action_controller/response.rb +49 -8
- data/lib/action_controller/routing.rb +359 -236
- data/lib/action_controller/routing_optimisation.rb +119 -0
- data/lib/action_controller/session/active_record_store.rb +3 -2
- data/lib/action_controller/session/cookie_store.rb +161 -0
- data/lib/action_controller/session/mem_cache_store.rb +9 -16
- data/lib/action_controller/session_management.rb +17 -8
- data/lib/action_controller/streaming.rb +6 -3
- data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
- data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
- data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
- data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
- data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
- data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
- data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
- data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
- data/lib/action_controller/test_case.rb +53 -0
- data/lib/action_controller/test_process.rb +59 -46
- data/lib/action_controller/url_rewriter.rb +48 -24
- data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
- data/lib/action_controller/verification.rb +27 -21
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +4 -4
- data/lib/action_view.rb +2 -3
- data/lib/action_view/base.rb +218 -63
- data/lib/action_view/compiled_templates.rb +1 -2
- data/lib/action_view/helpers/active_record_helper.rb +35 -17
- data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
- data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
- data/lib/action_view/helpers/benchmark_helper.rb +12 -5
- data/lib/action_view/helpers/cache_helper.rb +29 -0
- data/lib/action_view/helpers/capture_helper.rb +97 -63
- data/lib/action_view/helpers/date_helper.rb +295 -35
- data/lib/action_view/helpers/debug_helper.rb +6 -2
- data/lib/action_view/helpers/form_helper.rb +354 -111
- data/lib/action_view/helpers/form_options_helper.rb +171 -109
- data/lib/action_view/helpers/form_tag_helper.rb +332 -76
- data/lib/action_view/helpers/javascript_helper.rb +35 -11
- data/lib/action_view/helpers/javascripts/controls.js +484 -354
- data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
- data/lib/action_view/helpers/javascripts/effects.js +396 -364
- data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
- data/lib/action_view/helpers/number_helper.rb +84 -60
- data/lib/action_view/helpers/prototype_helper.rb +419 -43
- data/lib/action_view/helpers/record_identification_helper.rb +20 -0
- data/lib/action_view/helpers/record_tag_helper.rb +59 -0
- data/lib/action_view/helpers/sanitize_helper.rb +223 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
- data/lib/action_view/helpers/tag_helper.rb +69 -39
- data/lib/action_view/helpers/text_helper.rb +221 -148
- data/lib/action_view/helpers/url_helper.rb +283 -165
- data/lib/action_view/partials.rb +134 -62
- data/lib/action_view/template_error.rb +4 -12
- data/lib/actionpack.rb +1 -0
- data/test/abstract_unit.rb +21 -1
- data/test/action_view_test.rb +26 -0
- data/test/active_record_unit.rb +12 -20
- data/test/activerecord/active_record_store_test.rb +2 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
- data/test/controller/action_pack_assertions_test.rb +21 -152
- data/test/controller/addresses_render_test.rb +2 -7
- data/test/controller/assert_select_test.rb +120 -14
- data/test/controller/base_test.rb +11 -13
- data/test/controller/caching_test.rb +125 -5
- data/test/controller/capture_test.rb +23 -16
- data/test/controller/cgi_test.rb +66 -391
- data/test/controller/components_test.rb +31 -42
- data/test/controller/content_type_test.rb +1 -1
- data/test/controller/cookie_test.rb +42 -14
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
- data/test/controller/dispatcher_test.rb +123 -0
- data/test/controller/fake_models.rb +5 -0
- data/test/controller/filters_test.rb +44 -7
- data/test/controller/flash_test.rb +46 -2
- data/test/controller/fragment_store_setting_test.rb +10 -8
- data/test/controller/helper_test.rb +19 -2
- data/test/controller/html-scanner/document_test.rb +124 -0
- data/test/controller/html-scanner/node_test.rb +69 -0
- data/test/controller/html-scanner/sanitizer_test.rb +250 -0
- data/test/controller/html-scanner/tag_node_test.rb +239 -0
- data/test/controller/html-scanner/text_node_test.rb +51 -0
- data/test/controller/html-scanner/tokenizer_test.rb +125 -0
- data/test/controller/http_authentication_test.rb +54 -0
- data/test/controller/integration_test.rb +12 -26
- data/test/controller/layout_test.rb +64 -12
- data/test/controller/mime_responds_test.rb +193 -38
- data/test/controller/mime_type_test.rb +30 -8
- data/test/controller/new_render_test.rb +104 -22
- data/test/controller/polymorphic_routes_test.rb +98 -0
- data/test/controller/record_identifier_test.rb +103 -0
- data/test/controller/redirect_test.rb +120 -18
- data/test/controller/render_test.rb +195 -45
- data/test/controller/request_forgery_protection_test.rb +217 -0
- data/test/controller/request_test.rb +545 -27
- data/test/controller/rescue_test.rb +501 -0
- data/test/controller/resources_test.rb +258 -132
- data/test/controller/routing_test.rb +502 -106
- data/test/controller/selector_test.rb +5 -5
- data/test/controller/send_file_test.rb +17 -7
- data/test/controller/session/cookie_store_test.rb +246 -0
- data/test/controller/session/mem_cache_store_test.rb +182 -0
- data/test/controller/session_fixation_test.rb +8 -11
- data/test/controller/session_management_test.rb +7 -7
- data/test/controller/test_test.rb +150 -38
- data/test/controller/url_rewriter_test.rb +87 -12
- data/test/controller/verification_test.rb +11 -0
- data/test/controller/view_paths_test.rb +137 -0
- data/test/controller/webservice_test.rb +11 -75
- data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
- data/test/fixtures/db_definitions/sqlite.sql +2 -1
- data/test/fixtures/developer.rb +2 -0
- data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
- data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
- data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
- data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
- data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
- data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/bracketed_param +5 -0
- data/test/fixtures/override/test/hello_world.erb +1 -0
- data/test/fixtures/override2/layouts/test/sub.erb +1 -0
- data/test/fixtures/post_test/layouts/post.html.erb +1 -0
- data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
- data/test/fixtures/post_test/post/index.html.erb +1 -0
- data/test/fixtures/post_test/post/index.iphone.erb +1 -0
- data/test/fixtures/post_test/super_post/index.html.erb +1 -0
- data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
- data/test/fixtures/public/404.html +1 -0
- data/test/fixtures/public/500.html +1 -0
- data/test/fixtures/public/javascripts/application.js +0 -1
- data/test/fixtures/public/javascripts/bank.js +1 -0
- data/test/fixtures/public/javascripts/robber.js +1 -0
- data/test/fixtures/public/stylesheets/bank.css +1 -0
- data/test/fixtures/public/stylesheets/robber.css +1 -0
- data/test/fixtures/replies.yml +2 -0
- data/test/fixtures/reply.rb +2 -1
- data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
- data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
- data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
- data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
- data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
- data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
- data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
- data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
- data/test/fixtures/test/_hash_greeting.erb +1 -0
- data/test/fixtures/test/_hash_object.erb +2 -0
- data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
- data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
- data/test/fixtures/test/_partial.erb +1 -0
- data/test/fixtures/test/_partial.html.erb +1 -0
- data/test/fixtures/test/_partial.js.erb +1 -0
- data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
- data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
- data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
- data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
- data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
- data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
- data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
- data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
- data/test/fixtures/test/content_for_concatenated.erb +3 -0
- data/test/fixtures/test/content_for_with_parameter.erb +2 -0
- data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
- data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.builder +1 -0
- data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
- data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
- data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
- data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
- data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
- data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
- data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
- data/test/fixtures/test/list.erb +1 -0
- data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
- data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
- data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
- data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
- data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
- data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
- data/test/fixtures/topic.rb +1 -1
- data/test/template/active_record_helper_test.rb +67 -20
- data/test/template/asset_tag_helper_test.rb +222 -54
- data/test/template/atom_feed_helper_test.rb +101 -0
- data/test/template/benchmark_helper_test.rb +2 -2
- data/test/template/compiled_templates_test.rb +76 -32
- data/test/template/date_helper_test.rb +125 -9
- data/test/template/form_helper_test.rb +326 -33
- data/test/template/form_options_helper_test.rb +822 -15
- data/test/template/form_tag_helper_test.rb +96 -30
- data/test/template/javascript_helper_test.rb +61 -13
- data/test/template/number_helper_test.rb +12 -11
- data/test/template/prototype_helper_test.rb +185 -24
- data/test/template/sanitize_helper_test.rb +49 -0
- data/test/template/scriptaculous_helper_test.rb +9 -3
- data/test/template/tag_helper_test.rb +13 -2
- data/test/template/text_helper_test.rb +38 -52
- data/test/template/url_helper_test.rb +216 -46
- metadata +144 -116
- data/examples/.htaccess +0 -24
- data/examples/address_book/index.rhtml +0 -33
- data/examples/address_book/layout.rhtml +0 -8
- data/examples/address_book_controller.cgi +0 -9
- data/examples/address_book_controller.fcgi +0 -6
- data/examples/address_book_controller.rb +0 -52
- data/examples/address_book_controller.rbx +0 -4
- data/examples/benchmark.rb +0 -52
- data/examples/benchmark_with_ar.fcgi +0 -89
- data/examples/blog_controller.cgi +0 -53
- data/examples/debate/index.rhtml +0 -14
- data/examples/debate/new_topic.rhtml +0 -22
- data/examples/debate/topic.rhtml +0 -32
- data/examples/debate_controller.cgi +0 -57
- data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
- data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
- data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
- data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
- data/lib/action_controller/deprecated_dependencies.rb +0 -65
- data/lib/action_controller/deprecated_redirects.rb +0 -17
- data/lib/action_controller/deprecated_request_methods.rb +0 -34
- data/lib/action_controller/macros/auto_complete.rb +0 -53
- data/lib/action_controller/macros/in_place_editing.rb +0 -33
- data/lib/action_controller/pagination.rb +0 -408
- data/lib/action_controller/scaffolding.rb +0 -189
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
- data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
- data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
- data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
- data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
- data/lib/action_controller/vendor/xml_node.rb +0 -97
- data/lib/action_view/helpers/deprecated_helper.rb +0 -37
- data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
- data/lib/action_view/helpers/pagination_helper.rb +0 -86
- data/test/activerecord/active_record_assertions_test.rb +0 -92
- data/test/activerecord/pagination_test.rb +0 -165
- data/test/controller/deprecated_instance_variables_test.rb +0 -48
- data/test/controller/raw_post_test.rb +0 -68
- data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
- data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
- data/test/fixtures/test/_hash_object.rhtml +0 -1
- data/test/fixtures/test/list.rhtml +0 -1
- data/test/template/deprecated_helper_test.rb +0 -36
- data/test/template/deprecated_instance_variables_test.rb +0 -43
- data/test/template/java_script_macros_helper_test.rb +0 -109
@@ -1,8 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
-
|
3
|
-
unless defined?(Customer)
|
4
|
-
Customer = Struct.new("Customer", :name)
|
5
|
-
end
|
2
|
+
require File.dirname(__FILE__) + '/fake_models'
|
6
3
|
|
7
4
|
module Fun
|
8
5
|
class GamesController < ActionController::Base
|
@@ -19,32 +16,32 @@ class TestController < ActionController::Base
|
|
19
16
|
end
|
20
17
|
|
21
18
|
def render_hello_world
|
22
|
-
render "test/hello_world"
|
19
|
+
render :template => "test/hello_world"
|
23
20
|
end
|
24
21
|
|
25
22
|
def render_hello_world_from_variable
|
26
23
|
@person = "david"
|
27
|
-
|
24
|
+
render :text => "hello #{@person}"
|
28
25
|
end
|
29
26
|
|
30
27
|
def render_action_hello_world
|
31
|
-
|
28
|
+
render :action => "hello_world"
|
32
29
|
end
|
33
30
|
|
34
31
|
def render_action_hello_world_with_symbol
|
35
|
-
|
32
|
+
render :action => :hello_world
|
36
33
|
end
|
37
34
|
|
38
35
|
def render_text_hello_world
|
39
|
-
|
36
|
+
render :text => "hello world"
|
40
37
|
end
|
41
38
|
|
42
39
|
def render_json_hello_world
|
43
|
-
|
40
|
+
render :json => {:hello => 'world'}.to_json
|
44
41
|
end
|
45
42
|
|
46
43
|
def render_json_hello_world_with_callback
|
47
|
-
|
44
|
+
render :json => {:hello => 'world'}.to_json, :callback => 'alert'
|
48
45
|
end
|
49
46
|
|
50
47
|
def render_symbol_json
|
@@ -52,21 +49,24 @@ class TestController < ActionController::Base
|
|
52
49
|
end
|
53
50
|
|
54
51
|
def render_custom_code
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def render_text_appendix
|
59
|
-
render_text "hello world"
|
60
|
-
render_text ", goodbye!", "404 Not Found", true
|
52
|
+
render :text => "hello world", :status => 404
|
61
53
|
end
|
62
54
|
|
63
55
|
def render_nothing_with_appendix
|
64
|
-
|
56
|
+
render :text => "appended"
|
57
|
+
end
|
58
|
+
|
59
|
+
def render_invalid_args
|
60
|
+
render("test/hello")
|
65
61
|
end
|
66
62
|
|
67
63
|
def render_xml_hello
|
68
64
|
@name = "David"
|
69
|
-
render "test/hello"
|
65
|
+
render :template => "test/hello"
|
66
|
+
end
|
67
|
+
|
68
|
+
def heading
|
69
|
+
head :ok
|
70
70
|
end
|
71
71
|
|
72
72
|
def greeting
|
@@ -74,34 +74,34 @@ class TestController < ActionController::Base
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def layout_test
|
77
|
-
|
77
|
+
render :action => "hello_world"
|
78
78
|
end
|
79
79
|
|
80
80
|
def builder_layout_test
|
81
|
-
|
81
|
+
render :action => "hello"
|
82
82
|
end
|
83
83
|
|
84
84
|
def builder_partial_test
|
85
|
-
|
85
|
+
render :action => "hello_world_container"
|
86
86
|
end
|
87
87
|
|
88
88
|
def partials_list
|
89
89
|
@test_unchanged = 'hello'
|
90
90
|
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
91
|
-
|
91
|
+
render :action => "list"
|
92
92
|
end
|
93
93
|
|
94
94
|
def partial_only
|
95
|
-
|
95
|
+
render :partial => true
|
96
96
|
end
|
97
97
|
|
98
98
|
def hello_in_a_string
|
99
99
|
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
100
|
-
|
100
|
+
render :text => "How's there? " + render_to_string(:template => "test/list")
|
101
101
|
end
|
102
102
|
|
103
103
|
def accessing_params_in_template
|
104
|
-
|
104
|
+
render :inline => "Hello: <%= params[:name] %>"
|
105
105
|
end
|
106
106
|
|
107
107
|
def accessing_local_assigns_in_inline_template
|
@@ -118,24 +118,71 @@ class TestController < ActionController::Base
|
|
118
118
|
ActionView::Base.local_assigns_support_string_keys = false
|
119
119
|
end
|
120
120
|
|
121
|
+
def formatted_html_erb
|
122
|
+
end
|
123
|
+
|
124
|
+
def formatted_xml_erb
|
125
|
+
end
|
126
|
+
|
121
127
|
def render_to_string_test
|
122
128
|
@foo = render_to_string :inline => "this is a test"
|
123
129
|
end
|
124
130
|
|
131
|
+
def partial
|
132
|
+
render :partial => 'partial'
|
133
|
+
end
|
134
|
+
|
135
|
+
def partial_dot_html
|
136
|
+
render :partial => 'partial.html.erb'
|
137
|
+
end
|
138
|
+
|
139
|
+
def partial_as_rjs
|
140
|
+
render :update do |page|
|
141
|
+
page.replace :foo, :partial => 'partial'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def respond_to_partial_as_rjs
|
146
|
+
respond_to do |format|
|
147
|
+
format.js do
|
148
|
+
render :update do |page|
|
149
|
+
page.replace :foo, :partial => 'partial'
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def default_render
|
156
|
+
if @alternate_default_render
|
157
|
+
@alternate_default_render.call
|
158
|
+
else
|
159
|
+
render
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def render_alternate_default
|
164
|
+
# For this test, the method "default_render" is overridden:
|
165
|
+
@alternate_default_render = lambda {
|
166
|
+
render :update do |page|
|
167
|
+
page.replace :foo, :partial => 'partial'
|
168
|
+
end
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
125
172
|
def rescue_action(e) raise end
|
126
173
|
|
127
174
|
private
|
128
175
|
def determine_layout
|
129
176
|
case action_name
|
130
|
-
when "layout_test"
|
131
|
-
when "builder_layout_test"
|
132
|
-
when "render_symbol_json"
|
177
|
+
when "layout_test"; "layouts/standard"
|
178
|
+
when "builder_layout_test"; "layouts/builder"
|
179
|
+
when "render_symbol_json"; "layouts/standard" # to make sure layouts don't interfere
|
133
180
|
end
|
134
181
|
end
|
135
182
|
end
|
136
183
|
|
137
|
-
TestController.
|
138
|
-
Fun::GamesController.
|
184
|
+
TestController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
185
|
+
Fun::GamesController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
139
186
|
|
140
187
|
class RenderTest < Test::Unit::TestCase
|
141
188
|
def setup
|
@@ -153,7 +200,7 @@ class RenderTest < Test::Unit::TestCase
|
|
153
200
|
end
|
154
201
|
|
155
202
|
def test_do_with_render
|
156
|
-
|
203
|
+
get :render_hello_world
|
157
204
|
assert_template "test/hello_world"
|
158
205
|
end
|
159
206
|
|
@@ -179,31 +226,26 @@ class RenderTest < Test::Unit::TestCase
|
|
179
226
|
|
180
227
|
def test_do_with_render_json
|
181
228
|
get :render_json_hello_world
|
182
|
-
assert_equal '{hello: "world"}', @response.body
|
229
|
+
assert_equal '{"hello": "world"}', @response.body
|
183
230
|
assert_equal 'application/json', @response.content_type
|
184
231
|
end
|
185
232
|
|
186
233
|
def test_do_with_render_json_with_callback
|
187
234
|
get :render_json_hello_world_with_callback
|
188
|
-
assert_equal 'alert({hello: "world"})', @response.body
|
235
|
+
assert_equal 'alert({"hello": "world"})', @response.body
|
189
236
|
assert_equal 'application/json', @response.content_type
|
190
237
|
end
|
191
238
|
|
192
239
|
def test_do_with_render_symbol_json
|
193
240
|
get :render_symbol_json
|
194
|
-
assert_equal '{hello: "world"}', @response.body
|
241
|
+
assert_equal '{"hello": "world"}', @response.body
|
195
242
|
assert_equal 'application/json', @response.content_type
|
196
243
|
end
|
197
244
|
|
198
245
|
def test_do_with_render_custom_code
|
199
246
|
get :render_custom_code
|
200
247
|
assert_response 404
|
201
|
-
|
202
|
-
|
203
|
-
def test_do_with_render_text_appendix
|
204
|
-
get :render_text_appendix
|
205
|
-
assert_response 404
|
206
|
-
assert_equal 'hello world, goodbye!', @response.body
|
248
|
+
assert_equal 'hello world', @response.body
|
207
249
|
end
|
208
250
|
|
209
251
|
def test_do_with_render_nothing_with_appendix
|
@@ -211,7 +253,11 @@ class RenderTest < Test::Unit::TestCase
|
|
211
253
|
assert_response 200
|
212
254
|
assert_equal 'appended', @response.body
|
213
255
|
end
|
214
|
-
|
256
|
+
|
257
|
+
def test_attempt_to_render_with_invalid_arguments
|
258
|
+
assert_raises(ActionController::RenderError) { get :render_invalid_args }
|
259
|
+
end
|
260
|
+
|
215
261
|
def test_attempt_to_access_object_method
|
216
262
|
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
|
217
263
|
end
|
@@ -221,7 +267,7 @@ class RenderTest < Test::Unit::TestCase
|
|
221
267
|
end
|
222
268
|
|
223
269
|
def test_render_xml
|
224
|
-
|
270
|
+
get :render_xml_hello
|
225
271
|
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
|
226
272
|
end
|
227
273
|
|
@@ -286,8 +332,112 @@ class RenderTest < Test::Unit::TestCase
|
|
286
332
|
assert_equal "Goodbye, Local David", @response.body
|
287
333
|
end
|
288
334
|
|
335
|
+
def test_render_200_should_set_etag
|
336
|
+
get :render_hello_world_from_variable
|
337
|
+
assert_equal etag_for("hello david"), @response.headers['ETag']
|
338
|
+
assert_equal "private, max-age=0, must-revalidate", @response.headers['Cache-Control']
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_render_against_etag_request_should_304_when_match
|
342
|
+
@request.headers["HTTP_IF_NONE_MATCH"] = etag_for("hello david")
|
343
|
+
get :render_hello_world_from_variable
|
344
|
+
assert_equal "304 Not Modified", @response.headers['Status']
|
345
|
+
assert @response.body.empty?
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_render_against_etag_request_should_200_when_no_match
|
349
|
+
@request.headers["HTTP_IF_NONE_MATCH"] = etag_for("hello somewhere else")
|
350
|
+
get :render_hello_world_from_variable
|
351
|
+
assert_equal "200 OK", @response.headers['Status']
|
352
|
+
assert !@response.body.empty?
|
353
|
+
end
|
354
|
+
|
355
|
+
def test_render_with_etag
|
356
|
+
get :render_hello_world_from_variable
|
357
|
+
expected_etag = etag_for('hello david')
|
358
|
+
assert_equal expected_etag, @response.headers['ETag']
|
359
|
+
|
360
|
+
@request.headers["HTTP_IF_NONE_MATCH"] = expected_etag
|
361
|
+
get :render_hello_world_from_variable
|
362
|
+
assert_equal "304 Not Modified", @response.headers['Status']
|
363
|
+
|
364
|
+
@request.headers["HTTP_IF_NONE_MATCH"] = "\"diftag\""
|
365
|
+
get :render_hello_world_from_variable
|
366
|
+
assert_equal "200 OK", @response.headers['Status']
|
367
|
+
end
|
368
|
+
|
369
|
+
def render_with_404_shouldnt_have_etag
|
370
|
+
get :render_custom_code
|
371
|
+
assert_nil @response.headers['ETag']
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_etag_should_not_be_changed_when_already_set
|
375
|
+
expected_etag = etag_for("hello somewhere else")
|
376
|
+
@response.headers["ETag"] = expected_etag
|
377
|
+
get :render_hello_world_from_variable
|
378
|
+
assert_equal expected_etag, @response.headers['ETag']
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_etag_should_govern_renders_with_layouts_too
|
382
|
+
get :builder_layout_test
|
383
|
+
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
|
384
|
+
assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag']
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_should_render_formatted_template
|
388
|
+
get :formatted_html_erb
|
389
|
+
assert_equal 'formatted html erb', @response.body
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_should_render_formatted_xml_erb_template
|
393
|
+
get :formatted_xml_erb, :format => :xml
|
394
|
+
assert_equal '<test>passed formatted xml erb</test>', @response.body
|
395
|
+
end
|
396
|
+
|
397
|
+
def test_should_render_formatted_html_erb_template
|
398
|
+
get :formatted_xml_erb
|
399
|
+
assert_equal '<test>passed formatted html erb</test>', @response.body
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_should_render_formatted_html_erb_template_with_faulty_accepts_header
|
403
|
+
@request.env["HTTP_ACCEPT"] = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, appliction/x-shockwave-flash, */*"
|
404
|
+
get :formatted_xml_erb
|
405
|
+
assert_equal '<test>passed formatted html erb</test>', @response.body
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_should_render_html_formatted_partial
|
409
|
+
get :partial
|
410
|
+
assert_equal 'partial html', @response.body
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_should_render_html_partial_with_dot
|
414
|
+
get :partial_dot_html
|
415
|
+
assert_equal 'partial html', @response.body
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_should_render_html_formatted_partial_with_rjs
|
419
|
+
xhr :get, :partial_as_rjs
|
420
|
+
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
421
|
+
end
|
422
|
+
|
423
|
+
def test_should_render_html_formatted_partial_with_rjs_and_js_format
|
424
|
+
xhr :get, :respond_to_partial_as_rjs
|
425
|
+
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
426
|
+
end
|
427
|
+
|
428
|
+
def test_should_render_js_partial
|
429
|
+
xhr :get, :partial, :format => 'js'
|
430
|
+
assert_equal 'partial js', @response.body
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_should_render_with_alternate_default_render
|
434
|
+
xhr :get, :render_alternate_default
|
435
|
+
assert_equal %(Element.replace("foo", "partial html");), @response.body
|
436
|
+
end
|
437
|
+
|
289
438
|
protected
|
290
|
-
|
291
|
-
|
439
|
+
|
440
|
+
def etag_for(text)
|
441
|
+
%("#{Digest::MD5.hexdigest(text)}")
|
292
442
|
end
|
293
443
|
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
ActionController::Routing::Routes.draw do |map|
|
5
|
+
map.connect ':controller/:action/:id'
|
6
|
+
end
|
7
|
+
|
8
|
+
# simulates cookie session store
|
9
|
+
class FakeSessionDbMan
|
10
|
+
def self.generate_digest(data)
|
11
|
+
Digest::SHA1.hexdigest("secure")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# common controller actions
|
16
|
+
module RequestForgeryProtectionActions
|
17
|
+
def index
|
18
|
+
render :inline => "<%= form_tag('/') {} %>"
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_button
|
22
|
+
render :inline => "<%= button_to('New', '/') {} %>"
|
23
|
+
end
|
24
|
+
|
25
|
+
def unsafe
|
26
|
+
render :text => 'pwn'
|
27
|
+
end
|
28
|
+
|
29
|
+
def rescue_action(e) raise e end
|
30
|
+
end
|
31
|
+
|
32
|
+
# sample controllers
|
33
|
+
class RequestForgeryProtectionController < ActionController::Base
|
34
|
+
include RequestForgeryProtectionActions
|
35
|
+
protect_from_forgery :only => :index, :secret => 'abc'
|
36
|
+
end
|
37
|
+
|
38
|
+
class RequestForgeryProtectionWithoutSecretController < ActionController::Base
|
39
|
+
include RequestForgeryProtectionActions
|
40
|
+
protect_from_forgery
|
41
|
+
end
|
42
|
+
|
43
|
+
# no token is given, assume the cookie store is used
|
44
|
+
class CsrfCookieMonsterController < ActionController::Base
|
45
|
+
include RequestForgeryProtectionActions
|
46
|
+
protect_from_forgery :only => :index
|
47
|
+
end
|
48
|
+
|
49
|
+
class FreeCookieController < CsrfCookieMonsterController
|
50
|
+
self.allow_forgery_protection = false
|
51
|
+
|
52
|
+
def index
|
53
|
+
render :inline => "<%= form_tag('/') {} %>"
|
54
|
+
end
|
55
|
+
|
56
|
+
def show_button
|
57
|
+
render :inline => "<%= button_to('New', '/') {} %>"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# common test methods
|
62
|
+
|
63
|
+
module RequestForgeryProtectionTests
|
64
|
+
def teardown
|
65
|
+
ActionController::Base.request_forgery_protection_token = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_render_form_with_token_tag
|
69
|
+
get :index
|
70
|
+
assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_should_render_button_to_with_token_tag
|
74
|
+
get :show_button
|
75
|
+
assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_should_allow_get
|
79
|
+
get :index
|
80
|
+
assert_response :success
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_should_allow_post_without_token_on_unsafe_action
|
84
|
+
post :unsafe
|
85
|
+
assert_response :success
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_should_not_allow_post_without_token
|
89
|
+
assert_raises(ActionController::InvalidAuthenticityToken) { post :index }
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_should_not_allow_put_without_token
|
93
|
+
assert_raises(ActionController::InvalidAuthenticityToken) { put :index }
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_should_not_allow_delete_without_token
|
97
|
+
assert_raises(ActionController::InvalidAuthenticityToken) { delete :index }
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_should_not_allow_xhr_post_without_token
|
101
|
+
assert_raises(ActionController::InvalidAuthenticityToken) { xhr :post, :index }
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_should_not_allow_xhr_put_without_token
|
105
|
+
assert_raises(ActionController::InvalidAuthenticityToken) { xhr :put, :index }
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_should_not_allow_xhr_delete_without_token
|
109
|
+
assert_raises(ActionController::InvalidAuthenticityToken) { xhr :delete, :index }
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_should_allow_post_with_token
|
113
|
+
post :index, :authenticity_token => @token
|
114
|
+
assert_response :success
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_should_allow_put_with_token
|
118
|
+
put :index, :authenticity_token => @token
|
119
|
+
assert_response :success
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_should_allow_delete_with_token
|
123
|
+
delete :index, :authenticity_token => @token
|
124
|
+
assert_response :success
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_should_allow_post_with_xml
|
128
|
+
post :index, :format => 'xml'
|
129
|
+
assert_response :success
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_should_allow_put_with_xml
|
133
|
+
put :index, :format => 'xml'
|
134
|
+
assert_response :success
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_should_allow_delete_with_xml
|
138
|
+
delete :index, :format => 'xml'
|
139
|
+
assert_response :success
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# OK let's get our test on
|
144
|
+
|
145
|
+
class RequestForgeryProtectionControllerTest < Test::Unit::TestCase
|
146
|
+
include RequestForgeryProtectionTests
|
147
|
+
def setup
|
148
|
+
@controller = RequestForgeryProtectionController.new
|
149
|
+
@request = ActionController::TestRequest.new
|
150
|
+
@response = ActionController::TestResponse.new
|
151
|
+
class << @request.session
|
152
|
+
def session_id() '123' end
|
153
|
+
end
|
154
|
+
@token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
|
155
|
+
ActionController::Base.request_forgery_protection_token = :authenticity_token
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
class RequestForgeryProtectionWithoutSecretControllerTest < Test::Unit::TestCase
|
160
|
+
def setup
|
161
|
+
@controller = RequestForgeryProtectionWithoutSecretController.new
|
162
|
+
@request = ActionController::TestRequest.new
|
163
|
+
@response = ActionController::TestResponse.new
|
164
|
+
class << @request.session
|
165
|
+
def session_id() '123' end
|
166
|
+
end
|
167
|
+
@token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
|
168
|
+
ActionController::Base.request_forgery_protection_token = :authenticity_token
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_should_raise_error_without_secret
|
172
|
+
assert_raises ActionController::InvalidAuthenticityToken do
|
173
|
+
get :index
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class CsrfCookieMonsterControllerTest < Test::Unit::TestCase
|
179
|
+
include RequestForgeryProtectionTests
|
180
|
+
def setup
|
181
|
+
@controller = CsrfCookieMonsterController.new
|
182
|
+
@request = ActionController::TestRequest.new
|
183
|
+
@response = ActionController::TestResponse.new
|
184
|
+
class << @request.session
|
185
|
+
attr_accessor :dbman
|
186
|
+
end
|
187
|
+
# simulate a cookie session store
|
188
|
+
@request.session.dbman = FakeSessionDbMan
|
189
|
+
@token = Digest::SHA1.hexdigest("secure")
|
190
|
+
ActionController::Base.request_forgery_protection_token = :authenticity_token
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
class FreeCookieControllerTest < Test::Unit::TestCase
|
195
|
+
def setup
|
196
|
+
@controller = FreeCookieController.new
|
197
|
+
@request = ActionController::TestRequest.new
|
198
|
+
@response = ActionController::TestResponse.new
|
199
|
+
@token = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), 'abc', '123')
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_should_not_render_form_with_token_tag
|
203
|
+
get :index
|
204
|
+
assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token, false
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_should_not_render_button_to_with_token_tag
|
208
|
+
get :show_button
|
209
|
+
assert_select 'form>div>input[name=?][value=?]', 'authenticity_token', @token, false
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_should_allow_all_methods_without_token
|
213
|
+
[:post, :put, :delete].each do |method|
|
214
|
+
assert_nothing_raised { send(method, :index)}
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|