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
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../abstract_unit'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TextNodeTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@node = HTML::Text.new(nil, 0, 0, "hello, howdy, aloha, annyeong")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_to_s
|
10
|
+
assert_equal "hello, howdy, aloha, annyeong", @node.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_find_string
|
14
|
+
assert_equal @node, @node.find("hello, howdy, aloha, annyeong")
|
15
|
+
assert_equal false, @node.find("bogus")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_find_regexp
|
19
|
+
assert_equal @node, @node.find(/an+y/)
|
20
|
+
assert_nil @node.find(/b/)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_find_hash
|
24
|
+
assert_equal @node, @node.find(:content => /howdy/)
|
25
|
+
assert_nil @node.find(:content => /^howdy$/)
|
26
|
+
assert_equal false, @node.find(:content => "howdy")
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_find_other
|
30
|
+
assert_nil @node.find(:hello)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_match_string
|
34
|
+
assert @node.match("hello, howdy, aloha, annyeong")
|
35
|
+
assert_equal false, @node.match("bogus")
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_match_regexp
|
39
|
+
assert_not_nil @node, @node.match(/an+y/)
|
40
|
+
assert_nil @node.match(/b/)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_match_hash
|
44
|
+
assert_not_nil @node, @node.match(:content => "howdy")
|
45
|
+
assert_nil @node.match(:content => /^howdy$/)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_match_other
|
49
|
+
assert_nil @node.match(:hello)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../abstract_unit'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TokenizerTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_blank
|
7
|
+
tokenize ""
|
8
|
+
assert_end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_space
|
12
|
+
tokenize " "
|
13
|
+
assert_next " "
|
14
|
+
assert_end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_tag_simple_open
|
18
|
+
tokenize "<tag>"
|
19
|
+
assert_next "<tag>"
|
20
|
+
assert_end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_tag_simple_self_closing
|
24
|
+
tokenize "<tag />"
|
25
|
+
assert_next "<tag />"
|
26
|
+
assert_end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_tag_simple_closing
|
30
|
+
tokenize "</tag>"
|
31
|
+
assert_next "</tag>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_tag_with_single_quoted_attribute
|
35
|
+
tokenize %{<tag a='hello'>x}
|
36
|
+
assert_next %{<tag a='hello'>}
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_tag_with_single_quoted_attribute_with_escape
|
40
|
+
tokenize %{<tag a='hello\\''>x}
|
41
|
+
assert_next %{<tag a='hello\\''>}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_tag_with_double_quoted_attribute
|
45
|
+
tokenize %{<tag a="hello">x}
|
46
|
+
assert_next %{<tag a="hello">}
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_tag_with_double_quoted_attribute_with_escape
|
50
|
+
tokenize %{<tag a="hello\\"">x}
|
51
|
+
assert_next %{<tag a="hello\\"">}
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_tag_with_unquoted_attribute
|
55
|
+
tokenize %{<tag a=hello>x}
|
56
|
+
assert_next %{<tag a=hello>}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_tag_with_lt_char_in_attribute
|
60
|
+
tokenize %{<tag a="x < y">x}
|
61
|
+
assert_next %{<tag a="x < y">}
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_tag_with_gt_char_in_attribute
|
65
|
+
tokenize %{<tag a="x > y">x}
|
66
|
+
assert_next %{<tag a="x > y">}
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_doctype_tag
|
70
|
+
tokenize %{<!DOCTYPE "blah" "blah" "blah">\n <html>}
|
71
|
+
assert_next %{<!DOCTYPE "blah" "blah" "blah">}
|
72
|
+
assert_next %{\n }
|
73
|
+
assert_next %{<html>}
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_cdata_tag
|
77
|
+
tokenize %{<![CDATA[<br>]]>}
|
78
|
+
assert_next %{<![CDATA[<br>]]>}
|
79
|
+
assert_end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_less_than_with_space
|
83
|
+
tokenize %{original < hello > world}
|
84
|
+
assert_next %{original }
|
85
|
+
assert_next %{< hello > world}
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_less_than_without_matching_greater_than
|
89
|
+
tokenize %{hello <span onmouseover="gotcha"\n<b>foo</b>\nbar</span>}
|
90
|
+
assert_next %{hello }
|
91
|
+
assert_next %{<span onmouseover="gotcha"\n}
|
92
|
+
assert_next %{<b>}
|
93
|
+
assert_next %{foo}
|
94
|
+
assert_next %{</b>}
|
95
|
+
assert_next %{\nbar}
|
96
|
+
assert_next %{</span>}
|
97
|
+
assert_end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_unterminated_comment
|
101
|
+
tokenize %{hello <!-- neverending...}
|
102
|
+
assert_next %{hello }
|
103
|
+
assert_next %{<!-- neverending...}
|
104
|
+
assert_end
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def tokenize(text)
|
110
|
+
@tokenizer = HTML::Tokenizer.new(text)
|
111
|
+
end
|
112
|
+
|
113
|
+
def assert_next(expected, message=nil)
|
114
|
+
token = @tokenizer.next
|
115
|
+
assert_equal expected, token, message
|
116
|
+
end
|
117
|
+
|
118
|
+
def assert_sequence(*expected)
|
119
|
+
assert_next expected.shift until expected.empty?
|
120
|
+
end
|
121
|
+
|
122
|
+
def assert_end(message=nil)
|
123
|
+
assert_nil @tokenizer.next, message
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
|
3
|
+
class HttpBasicAuthenticationTest < Test::Unit::TestCase
|
4
|
+
include ActionController::HttpAuthentication::Basic
|
5
|
+
|
6
|
+
class DummyController
|
7
|
+
attr_accessor :headers, :renders, :request
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@headers, @renders = {}, []
|
11
|
+
@request = ActionController::TestRequest.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(options)
|
15
|
+
self.renders << options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@controller = DummyController.new
|
21
|
+
@credentials = ActionController::HttpAuthentication::Basic.encode_credentials("dhh", "secret")
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_successful_authentication
|
25
|
+
login = Proc.new { |user_name, password| user_name == "dhh" && password == "secret" }
|
26
|
+
set_headers
|
27
|
+
assert authenticate(@controller, &login)
|
28
|
+
|
29
|
+
set_headers ''
|
30
|
+
assert_nothing_raised do
|
31
|
+
assert !authenticate(@controller, &login)
|
32
|
+
end
|
33
|
+
|
34
|
+
set_headers nil
|
35
|
+
set_headers @credentials, 'REDIRECT_X_HTTP_AUTHORIZATION'
|
36
|
+
assert authenticate(@controller, &login)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_failing_authentication
|
40
|
+
set_headers
|
41
|
+
assert !authenticate(@controller) { |user_name, password| user_name == "dhh" && password == "incorrect" }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_authentication_request
|
45
|
+
authentication_request(@controller, "Megaglobalapp")
|
46
|
+
assert_equal 'Basic realm="Megaglobalapp"', @controller.headers["WWW-Authenticate"]
|
47
|
+
assert_equal :unauthorized, @controller.renders.first[:status]
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def set_headers(value = @credentials, name = 'HTTP_AUTHORIZATION')
|
52
|
+
@controller.request.env[name] = value
|
53
|
+
end
|
54
|
+
end
|
@@ -3,9 +3,7 @@ require File.dirname(__FILE__) + '/../abstract_unit'
|
|
3
3
|
$:.unshift File.dirname(__FILE__) + '/../../../railties/lib'
|
4
4
|
require 'action_controller/integration'
|
5
5
|
|
6
|
-
|
7
|
-
require 'mocha'
|
8
|
-
require 'stubba'
|
6
|
+
uses_mocha 'integration' do
|
9
7
|
|
10
8
|
# Stub process for testing.
|
11
9
|
module ActionController
|
@@ -52,27 +50,27 @@ class SessionTest < Test::Unit::TestCase
|
|
52
50
|
end
|
53
51
|
|
54
52
|
def test_get_via_redirect
|
55
|
-
path = "/somepath"; args = {:id => '1'}
|
53
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
56
54
|
|
57
|
-
@session.expects(:get).with(path,args)
|
55
|
+
@session.expects(:get).with(path,args,headers)
|
58
56
|
|
59
|
-
@session.stubs(:redirect?).returns(true
|
57
|
+
@session.stubs(:redirect?).returns(true, true, false)
|
60
58
|
@session.expects(:follow_redirect!).times(2)
|
61
59
|
|
62
60
|
@session.stubs(:status).returns(200)
|
63
|
-
assert_equal 200, @session.get_via_redirect(path, args)
|
61
|
+
assert_equal 200, @session.get_via_redirect(path, args, headers)
|
64
62
|
end
|
65
63
|
|
66
64
|
def test_post_via_redirect
|
67
|
-
path = "/somepath"; args = {:id => '1'}
|
65
|
+
path = "/somepath"; args = {:id => '1'}; headers = {"X-Test-Header" => "testvalue" }
|
68
66
|
|
69
|
-
@session.expects(:post).with(path,args)
|
67
|
+
@session.expects(:post).with(path,args,headers)
|
70
68
|
|
71
|
-
@session.stubs(:redirect?).returns(true
|
69
|
+
@session.stubs(:redirect?).returns(true, true, false)
|
72
70
|
@session.expects(:follow_redirect!).times(2)
|
73
71
|
|
74
72
|
@session.stubs(:status).returns(200)
|
75
|
-
assert_equal 200, @session.post_via_redirect(path, args)
|
73
|
+
assert_equal 200, @session.post_via_redirect(path, args, headers)
|
76
74
|
end
|
77
75
|
|
78
76
|
def test_url_for_with_controller
|
@@ -132,16 +130,6 @@ class SessionTest < Test::Unit::TestCase
|
|
132
130
|
@session.head(path,params,headers)
|
133
131
|
end
|
134
132
|
|
135
|
-
def test_xml_http_request_deprecated_call
|
136
|
-
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
137
|
-
headers_after_xhr = headers.merge(
|
138
|
-
"X-Requested-With" => "XMLHttpRequest",
|
139
|
-
"Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
|
140
|
-
)
|
141
|
-
@session.expects(:process).with(:post,path,params,headers_after_xhr)
|
142
|
-
assert_deprecated { @session.xml_http_request(path,params,headers) }
|
143
|
-
end
|
144
|
-
|
145
133
|
def test_xml_http_request_get
|
146
134
|
path = "/index"; params = "blah"; headers = {:location => 'blah'}
|
147
135
|
headers_after_xhr = headers.merge(
|
@@ -200,7 +188,7 @@ class IntegrationTestTest < Test::Unit::TestCase
|
|
200
188
|
@test.class.stubs(:fixture_table_names).returns([])
|
201
189
|
@session = @test.open_session
|
202
190
|
end
|
203
|
-
|
191
|
+
|
204
192
|
def test_opens_new_session
|
205
193
|
@test.class.expects(:fixture_table_names).times(2).returns(['foo'])
|
206
194
|
|
@@ -224,7 +212,7 @@ class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
|
|
224
212
|
|
225
213
|
def test_integration_methods_called
|
226
214
|
%w( get post head put delete ).each do |verb|
|
227
|
-
assert_nothing_raised("'#{verb}' should use integration test methods") { send(verb, '/') }
|
215
|
+
assert_nothing_raised("'#{verb}' should use integration test methods") { send!(verb, '/') }
|
228
216
|
end
|
229
217
|
end
|
230
218
|
|
@@ -234,6 +222,4 @@ end
|
|
234
222
|
# class MockCGITest < Test::Unit::TestCase
|
235
223
|
# end
|
236
224
|
|
237
|
-
|
238
|
-
$stderr.puts "Skipping integration tests. `gem install mocha` and try again."
|
239
|
-
end
|
225
|
+
end # uses_mocha
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
2
|
|
3
|
-
# The
|
4
|
-
# the
|
5
|
-
ActionController::Base.
|
3
|
+
# The view_paths array must be set on Base and not LayoutTest so that LayoutTest's inherited
|
4
|
+
# method has access to the view_paths array when looking for a layout to automatically assign.
|
5
|
+
old_load_paths = ActionController::Base.view_paths
|
6
|
+
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ]
|
6
7
|
|
7
8
|
class LayoutTest < ActionController::Base
|
8
9
|
def self.controller_path; 'views' end
|
10
|
+
self.view_paths = ActionController::Base.view_paths.dup
|
9
11
|
end
|
10
12
|
|
11
|
-
# Restore
|
12
|
-
ActionController::Base.
|
13
|
+
# Restore view_paths to previous value
|
14
|
+
ActionController::Base.view_paths = old_load_paths
|
13
15
|
|
14
16
|
class ProductController < LayoutTest
|
15
17
|
end
|
@@ -26,6 +28,9 @@ end
|
|
26
28
|
class ControllerNameSpace::NestedController < LayoutTest
|
27
29
|
end
|
28
30
|
|
31
|
+
class MultipleExtensions < LayoutTest
|
32
|
+
end
|
33
|
+
|
29
34
|
class MabView
|
30
35
|
def initialize(view)
|
31
36
|
end
|
@@ -61,6 +66,7 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
|
|
61
66
|
@controller = ThirdPartyTemplateLibraryController.new
|
62
67
|
get :hello
|
63
68
|
assert_equal 'layouts/third_party_template_library', @controller.active_layout
|
69
|
+
assert_equal 'layouts/third_party_template_library', @response.layout
|
64
70
|
assert_equal 'Mab', @response.body
|
65
71
|
end
|
66
72
|
|
@@ -70,6 +76,13 @@ class LayoutAutoDiscoveryTest < Test::Unit::TestCase
|
|
70
76
|
assert_equal 'layouts/controller_name_space/nested', @controller.active_layout
|
71
77
|
assert_equal 'controller_name_space/nested.rhtml hello.rhtml', @response.body
|
72
78
|
end
|
79
|
+
|
80
|
+
def test_namespaced_controllers_auto_detect_layouts
|
81
|
+
@controller = MultipleExtensions.new
|
82
|
+
get :hello
|
83
|
+
assert_equal 'layouts/multiple_extensions', @controller.active_layout
|
84
|
+
assert_equal 'multiple_extensions.html.erb hello.rhtml', @response.body.strip
|
85
|
+
end
|
73
86
|
end
|
74
87
|
|
75
88
|
class ExemptFromLayoutTest < Test::Unit::TestCase
|
@@ -80,16 +93,16 @@ class ExemptFromLayoutTest < Test::Unit::TestCase
|
|
80
93
|
end
|
81
94
|
|
82
95
|
def test_rjs_exempt_from_layout
|
83
|
-
assert @controller.send(:template_exempt_from_layout?, 'test.rjs')
|
96
|
+
assert @controller.send!(:template_exempt_from_layout?, 'test.rjs')
|
84
97
|
end
|
85
98
|
|
86
99
|
def test_rhtml_and_rxml_not_exempt_from_layout
|
87
|
-
assert !@controller.send(:template_exempt_from_layout?, 'test.rhtml')
|
88
|
-
assert !@controller.send(:template_exempt_from_layout?, 'test.rxml')
|
100
|
+
assert !@controller.send!(:template_exempt_from_layout?, 'test.rhtml')
|
101
|
+
assert !@controller.send!(:template_exempt_from_layout?, 'test.rxml')
|
89
102
|
end
|
90
103
|
|
91
104
|
def test_other_extension_not_exempt_from_layout
|
92
|
-
assert !@controller.send(:template_exempt_from_layout?, 'test.random')
|
105
|
+
assert !@controller.send!(:template_exempt_from_layout?, 'test.random')
|
93
106
|
end
|
94
107
|
|
95
108
|
def test_add_extension_to_exempt_from_layout
|
@@ -97,18 +110,20 @@ class ExemptFromLayoutTest < Test::Unit::TestCase
|
|
97
110
|
assert_nothing_raised do
|
98
111
|
ActionController::Base.exempt_from_layout ext
|
99
112
|
end
|
100
|
-
assert @controller.send(:template_exempt_from_layout?, "test.#{ext}")
|
113
|
+
assert @controller.send!(:template_exempt_from_layout?, "test.#{ext}")
|
101
114
|
end
|
102
115
|
end
|
103
116
|
|
104
117
|
def test_add_regexp_to_exempt_from_layout
|
105
118
|
ActionController::Base.exempt_from_layout /\.rdoc/
|
106
|
-
assert @controller.send(:template_exempt_from_layout?, 'test.rdoc')
|
119
|
+
assert @controller.send!(:template_exempt_from_layout?, 'test.rdoc')
|
107
120
|
end
|
108
121
|
|
109
122
|
def test_rhtml_exempt_from_layout_status_should_prevent_layout_render
|
110
123
|
ActionController::Base.exempt_from_layout :rhtml
|
111
|
-
|
124
|
+
|
125
|
+
assert @controller.send!(:template_exempt_from_layout?, 'test.rhtml')
|
126
|
+
assert @controller.send!(:template_exempt_from_layout?, 'hello.rhtml')
|
112
127
|
|
113
128
|
get :hello
|
114
129
|
assert_equal 'hello.rhtml', @response.body
|
@@ -165,8 +180,26 @@ class LayoutSetInResponseTest < Test::Unit::TestCase
|
|
165
180
|
get :hello
|
166
181
|
assert_nil @response.layout
|
167
182
|
end
|
183
|
+
|
184
|
+
def test_exempt_from_layout_honored_by_render_template
|
185
|
+
ActionController::Base.exempt_from_layout :rhtml
|
186
|
+
@controller = RenderWithTemplateOptionController.new
|
187
|
+
|
188
|
+
assert @controller.send(:template_exempt_from_layout?, 'alt/hello.rhtml')
|
189
|
+
|
190
|
+
get :hello
|
191
|
+
assert_equal "alt/hello.rhtml", @response.body.strip
|
192
|
+
|
193
|
+
ensure
|
194
|
+
ActionController::Base.exempt_from_layout.delete(/\.rhtml$/)
|
195
|
+
end
|
168
196
|
end
|
169
197
|
|
198
|
+
class RenderWithTemplateOptionController < LayoutTest
|
199
|
+
def hello
|
200
|
+
render :template => 'alt/hello'
|
201
|
+
end
|
202
|
+
end
|
170
203
|
|
171
204
|
class SetsNonExistentLayoutFile < LayoutTest
|
172
205
|
layout "nofile.rhtml"
|
@@ -185,3 +218,22 @@ class LayoutExceptionRaised < Test::Unit::TestCase
|
|
185
218
|
assert_equal ActionController::MissingTemplate, @response.template.exception.class
|
186
219
|
end
|
187
220
|
end
|
221
|
+
|
222
|
+
class LayoutStatusIsRendered < LayoutTest
|
223
|
+
def hello
|
224
|
+
render :status => 401
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
class LayoutStatusIsRenderedTest < Test::Unit::TestCase
|
229
|
+
def setup
|
230
|
+
@request = ActionController::TestRequest.new
|
231
|
+
@response = ActionController::TestResponse.new
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_layout_status_is_rendered
|
235
|
+
@controller = LayoutStatusIsRendered.new
|
236
|
+
get :hello
|
237
|
+
assert_response 401
|
238
|
+
end
|
239
|
+
end
|