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,49 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
2
|
+
require "#{File.dirname(__FILE__)}/../testing_sandbox"
|
3
|
+
|
4
|
+
# The exhaustive tests are in test/controller/html/sanitizer_test.rb.
|
5
|
+
# This tests the that the helpers hook up correctly to the sanitizer classes.
|
6
|
+
class SanitizeHelperTest < Test::Unit::TestCase
|
7
|
+
include ActionView::Helpers::SanitizeHelper
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include TestingSandbox
|
10
|
+
|
11
|
+
def test_strip_links
|
12
|
+
assert_equal "Dont touch me", strip_links("Dont touch me")
|
13
|
+
assert_equal "<a<a", strip_links("<a<a")
|
14
|
+
assert_equal "on my mind\nall day long", strip_links("<a href='almost'>on my mind</a>\n<A href='almost'>all day long</A>")
|
15
|
+
assert_equal "0wn3d", strip_links("<a href='http://www.rubyonrails.com/'><a href='http://www.rubyonrails.com/' onlclick='steal()'>0wn3d</a></a>")
|
16
|
+
assert_equal "Magic", strip_links("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic")
|
17
|
+
assert_equal "FrrFox", strip_links("<href onlclick='steal()'>FrrFox</a></href>")
|
18
|
+
assert_equal "My mind\nall <b>day</b> long", strip_links("<a href='almost'>My mind</a>\n<A href='almost'>all <b>day</b> long</A>")
|
19
|
+
assert_equal "all <b>day</b> long", strip_links("<<a>a href='hello'>all <b>day</b> long<</A>/a>")
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_sanitize_form
|
23
|
+
assert_sanitized "<form action=\"/foo/bar\" method=\"post\"><input></form>", ''
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_sanitize_illegal_style_properties
|
27
|
+
raw = %(display:block; position:absolute; left:0; top:0; width:100%; height:100%; z-index:1; background-color:black; background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg); background-x:center; background-y:center; background-repeat:repeat;)
|
28
|
+
expected = %(display: block; width: 100%; height: 100%; background-color: black; background-image: ; background-x: center; background-y: center;)
|
29
|
+
assert_equal expected, sanitize_css(raw)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_strip_tags
|
33
|
+
assert_equal("<<<bad html", strip_tags("<<<bad html"))
|
34
|
+
assert_equal("<<", strip_tags("<<<bad html>"))
|
35
|
+
assert_equal("Dont touch me", strip_tags("Dont touch me"))
|
36
|
+
assert_equal("This is a test.", strip_tags("<p>This <u>is<u> a <a href='test.html'><strong>test</strong></a>.</p>"))
|
37
|
+
assert_equal("Weirdos", strip_tags("Wei<<a>a onclick='alert(document.cookie);'</a>/>rdos"))
|
38
|
+
assert_equal("This is a test.", strip_tags("This is a test."))
|
39
|
+
assert_equal(
|
40
|
+
%{This is a test.\n\n\nIt no longer contains any HTML.\n}, strip_tags(
|
41
|
+
%{<title>This is <b>a <a href="" target="_blank">test</a></b>.</title>\n\n<!-- it has a comment -->\n\n<p>It no <b>longer <strong>contains <em>any <strike>HTML</strike></em>.</strong></b></p>\n}))
|
42
|
+
assert_equal "This has a here.", strip_tags("This has a <!-- comment --> here.")
|
43
|
+
[nil, '', ' '].each { |blank| assert_equal blank, strip_tags(blank) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_sanitized(text, expected = nil)
|
47
|
+
assert_equal((expected || text), sanitize(text))
|
48
|
+
end
|
49
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
2
2
|
|
3
3
|
class ScriptaculousHelperTest < Test::Unit::TestCase
|
4
4
|
include ActionView::Helpers::JavaScriptHelper
|
@@ -13,7 +13,7 @@ class ScriptaculousHelperTest < Test::Unit::TestCase
|
|
13
13
|
|
14
14
|
def setup
|
15
15
|
@controller = Class.new do
|
16
|
-
def url_for(options
|
16
|
+
def url_for(options)
|
17
17
|
url = "http://www.example.com/"
|
18
18
|
url << options[:action].to_s if options and options[:action]
|
19
19
|
url
|
@@ -28,6 +28,8 @@ class ScriptaculousHelperTest < Test::Unit::TestCase
|
|
28
28
|
assert_equal "new Effect.Fade(\"fademe\",{duration:4.0});", visual_effect(:fade, "fademe", :duration => 4.0)
|
29
29
|
assert_equal "new Effect.Shake(element,{});", visual_effect(:shake)
|
30
30
|
assert_equal "new Effect.DropOut(\"dropme\",{queue:'end'});", visual_effect(:drop_out, 'dropme', :queue => :end)
|
31
|
+
assert_equal "new Effect.Highlight(\"status\",{endcolor:'#EEEEEE'});", visual_effect(:highlight, 'status', :endcolor => '#EEEEEE')
|
32
|
+
assert_equal "new Effect.Highlight(\"status\",{restorecolor:'#500000', startcolor:'#FEFEFE'});", visual_effect(:highlight, 'status', :restorecolor => '#500000', :startcolor => '#FEFEFE')
|
31
33
|
|
32
34
|
# chop the queue params into a comma separated list
|
33
35
|
beginning, ending = 'new Effect.DropOut("dropme",{queue:{', '}});'
|
@@ -87,4 +89,8 @@ class ScriptaculousHelperTest < Test::Unit::TestCase
|
|
87
89
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
88
90
|
drop_receiving_element("droptarget1", :accept => ['tshirts','mugs'], :update => 'infobox')
|
89
91
|
end
|
90
|
-
|
92
|
+
|
93
|
+
def protect_against_forgery?
|
94
|
+
false
|
95
|
+
end
|
96
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
2
2
|
|
3
3
|
class TagHelperTest < Test::Unit::TestCase
|
4
4
|
include ActionView::Helpers::TagHelper
|
@@ -13,7 +13,9 @@ class TagHelperTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_tag_options
|
16
|
-
|
16
|
+
str = tag("p", "class" => "show", :class => "elsewhere")
|
17
|
+
assert_match /class="show"/, str
|
18
|
+
assert_match /class="elsewhere"/, str
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_tag_options_rejects_nil_option
|
@@ -47,6 +49,11 @@ class TagHelperTest < Test::Unit::TestCase
|
|
47
49
|
assert_dom_equal %(<div class="green">Hello world!</div>), _erbout
|
48
50
|
end
|
49
51
|
|
52
|
+
def test_content_tag_with_block_and_options_outside_of_action_view
|
53
|
+
assert_equal content_tag("a", "Create", :href => "create"),
|
54
|
+
content_tag("a", "href" => "create") { "Create" }
|
55
|
+
end
|
56
|
+
|
50
57
|
def test_cdata_section
|
51
58
|
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
|
52
59
|
end
|
@@ -66,4 +73,8 @@ class TagHelperTest < Test::Unit::TestCase
|
|
66
73
|
assert_equal %(<a href="#{escaped.gsub /&/, '&'}" />), tag('a', :href => escaped)
|
67
74
|
end
|
68
75
|
end
|
76
|
+
|
77
|
+
def test_disable_escaping
|
78
|
+
assert_equal '<a href="&" />', tag('a', { :href => '&' }, false, false)
|
79
|
+
end
|
69
80
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
2
2
|
require "#{File.dirname(__FILE__)}/../testing_sandbox"
|
3
3
|
|
4
4
|
class TextHelperTest < Test::Unit::TestCase
|
5
5
|
include ActionView::Helpers::TextHelper
|
6
6
|
include ActionView::Helpers::TagHelper
|
7
7
|
include TestingSandbox
|
8
|
-
|
8
|
+
|
9
9
|
def setup
|
10
10
|
# This simulates the fact that instance variables are reset every time
|
11
11
|
# a view is rendered. The cycle helper depends on this behavior.
|
@@ -31,6 +31,11 @@ class TextHelperTest < Test::Unit::TestCase
|
|
31
31
|
assert_equal "Hello Wor...", truncate("Hello World!!", 12)
|
32
32
|
end
|
33
33
|
|
34
|
+
def test_truncate_should_use_default_length_of_30
|
35
|
+
str = "This is a string that will go longer then the default truncate length of 30"
|
36
|
+
assert_equal str[0...27] + "...", truncate(str)
|
37
|
+
end
|
38
|
+
|
34
39
|
def test_truncate_multibyte
|
35
40
|
with_kcode 'none' do
|
36
41
|
assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
|
@@ -41,10 +46,6 @@ class TextHelperTest < Test::Unit::TestCase
|
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
|
-
def test_strip_links
|
45
|
-
assert_equal "on my mind\nall day long", strip_links("<a href='almost'>on my mind</a>\n<A href='almost'>all day long</A>")
|
46
|
-
end
|
47
|
-
|
48
49
|
def test_highlighter
|
49
50
|
assert_equal(
|
50
51
|
"This is a <strong class=\"highlight\">beautiful</strong> morning",
|
@@ -65,6 +66,8 @@ class TextHelperTest < Test::Unit::TestCase
|
|
65
66
|
"This text is not changed because we supplied an empty phrase",
|
66
67
|
highlight("This text is not changed because we supplied an empty phrase", nil)
|
67
68
|
)
|
69
|
+
|
70
|
+
assert_equal ' ', highlight(' ', 'blank text is returned verbatim')
|
68
71
|
end
|
69
72
|
|
70
73
|
def test_highlighter_with_regexp
|
@@ -84,6 +87,10 @@ class TextHelperTest < Test::Unit::TestCase
|
|
84
87
|
)
|
85
88
|
end
|
86
89
|
|
90
|
+
def test_highlighting_multiple_phrases_in_one_pass
|
91
|
+
assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), '<em>\1</em>')
|
92
|
+
end
|
93
|
+
|
87
94
|
def test_excerpt
|
88
95
|
assert_equal("...is a beautiful morni...", excerpt("This is a beautiful morning", "beautiful", 5))
|
89
96
|
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
|
@@ -109,6 +116,10 @@ class TextHelperTest < Test::Unit::TestCase
|
|
109
116
|
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
|
110
117
|
end
|
111
118
|
|
119
|
+
def test_word_wrap_with_extra_newlines
|
120
|
+
assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", 15))
|
121
|
+
end
|
122
|
+
|
112
123
|
def test_pluralization
|
113
124
|
assert_equal("1 count", pluralize(1, "count"))
|
114
125
|
assert_equal("2 counts", pluralize(2, "count"))
|
@@ -117,6 +128,20 @@ class TextHelperTest < Test::Unit::TestCase
|
|
117
128
|
assert_equal("1,066 counts", pluralize('1,066', "count"))
|
118
129
|
assert_equal("1.25 counts", pluralize('1.25', "count"))
|
119
130
|
assert_equal("2 counters", pluralize(2, "count", "counters"))
|
131
|
+
assert_equal("0 counters", pluralize(nil, "count", "counters"))
|
132
|
+
assert_equal("2 people", pluralize(2, "person"))
|
133
|
+
assert_equal("10 buffaloes", pluralize(10, "buffalo"))
|
134
|
+
end
|
135
|
+
|
136
|
+
uses_mocha("should_just_add_s_for_pluralize_without_inflector_loaded") do
|
137
|
+
def test_should_just_add_s_for_pluralize_without_inflector_loaded
|
138
|
+
Object.expects(:const_defined?).with("Inflector").times(4).returns(false)
|
139
|
+
assert_equal("1 count", pluralize(1, "count"))
|
140
|
+
assert_equal("2 persons", pluralize(2, "person"))
|
141
|
+
assert_equal("2 personss", pluralize("2", "persons"))
|
142
|
+
assert_equal("2 counts", pluralize(2, "count"))
|
143
|
+
assert_equal("10 buffalos", pluralize(10, "buffalo"))
|
144
|
+
end
|
120
145
|
end
|
121
146
|
|
122
147
|
def test_auto_link_parsing
|
@@ -132,6 +157,7 @@ class TextHelperTest < Test::Unit::TestCase
|
|
132
157
|
http://www.rubyonrails.com/contact;new?with=query&string=params
|
133
158
|
http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
|
134
159
|
http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
|
160
|
+
http://www.mail-archive.com/rails@lists.rubyonrails.org/
|
135
161
|
)
|
136
162
|
|
137
163
|
urls.each do |url|
|
@@ -142,6 +168,8 @@ class TextHelperTest < Test::Unit::TestCase
|
|
142
168
|
def test_auto_linking
|
143
169
|
email_raw = 'david@loudthinking.com'
|
144
170
|
email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
|
171
|
+
email2_raw = '+david@loudthinking.com'
|
172
|
+
email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
|
145
173
|
link_raw = 'http://www.rubyonrails.com'
|
146
174
|
link_result = %{<a href="#{link_raw}">#{link_raw}</a>}
|
147
175
|
link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
|
@@ -161,6 +189,8 @@ class TextHelperTest < Test::Unit::TestCase
|
|
161
189
|
link8_result = %{<a href="#{link8_raw}">#{link8_raw}</a>}
|
162
190
|
link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
|
163
191
|
link9_result = %{<a href="#{link9_raw}">#{link9_raw}</a>}
|
192
|
+
link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
|
193
|
+
link10_result = %{<a href="#{link10_raw}">#{link10_raw}</a>}
|
164
194
|
|
165
195
|
assert_equal %(hello #{email_result}), auto_link("hello #{email_raw}", :email_addresses)
|
166
196
|
assert_equal %(Go to #{link_result}), auto_link("Go to #{link_raw}", :urls)
|
@@ -200,6 +230,8 @@ class TextHelperTest < Test::Unit::TestCase
|
|
200
230
|
assert_equal %(<p>#{link9_result} Link</p>), auto_link("<p>#{link9_raw} Link</p>")
|
201
231
|
assert_equal %(Go to #{link9_result}.), auto_link(%(Go to #{link9_raw}.))
|
202
232
|
assert_equal %(<p>Go to #{link9_result}. seriously, #{link9_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link9_raw}. seriously, #{link9_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
|
233
|
+
assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>")
|
234
|
+
assert_equal email2_result, auto_link(email2_raw)
|
203
235
|
assert_equal '', auto_link(nil)
|
204
236
|
assert_equal '', auto_link('')
|
205
237
|
end
|
@@ -218,42 +250,6 @@ class TextHelperTest < Test::Unit::TestCase
|
|
218
250
|
assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |url| truncate(url, 10) }
|
219
251
|
end
|
220
252
|
|
221
|
-
def test_sanitize_form
|
222
|
-
raw = "<form action=\"/foo/bar\" method=\"post\"><input></form>"
|
223
|
-
result = sanitize(raw)
|
224
|
-
assert_equal %(<form action="/foo/bar" method="post"><input></form>), result
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_sanitize_plaintext
|
228
|
-
raw = "<plaintext><span>foo</span></plaintext>"
|
229
|
-
result = sanitize(raw)
|
230
|
-
assert_equal "<plaintext><span>foo</span></plaintext>", result
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_sanitize_script
|
234
|
-
raw = "<script language=\"Javascript\">blah blah blah</script>"
|
235
|
-
result = sanitize(raw)
|
236
|
-
assert_equal %(<script language="Javascript">blah blah blah</script>), result
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_sanitize_js_handlers
|
240
|
-
raw = %{onthis="do that" <a href="#" onclick="hello" name="foo" onbogus="remove me">hello</a>}
|
241
|
-
result = sanitize(raw)
|
242
|
-
assert_equal %{onthis="do that" <a name="foo" href="#">hello</a>}, result
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_sanitize_javascript_href
|
246
|
-
raw = %{href="javascript:bang" <a href="javascript:bang" name="hello">foo</a>, <span href="javascript:bang">bar</span>}
|
247
|
-
result = sanitize(raw)
|
248
|
-
assert_equal %{href="javascript:bang" <a name="hello">foo</a>, <span>bar</span>}, result
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_sanitize_image_src
|
252
|
-
raw = %{src="javascript:bang" <img src="javascript:bang" width="5">foo</img>, <span src="javascript:bang">bar</span>}
|
253
|
-
result = sanitize(raw)
|
254
|
-
assert_equal %{src="javascript:bang" <img width="5">foo</img>, <span>bar</span>}, result
|
255
|
-
end
|
256
|
-
|
257
253
|
def test_cycle_class
|
258
254
|
value = Cycle.new("one", 2, "3")
|
259
255
|
assert_equal("one", value.to_s)
|
@@ -336,14 +332,4 @@ class TextHelperTest < Test::Unit::TestCase
|
|
336
332
|
assert_equal("red", cycle("red", "blue"))
|
337
333
|
assert_equal(%w{Specialized Fuji Giant}, @cycles)
|
338
334
|
end
|
339
|
-
|
340
|
-
def test_strip_tags
|
341
|
-
assert_equal("This is a test.", strip_tags("<p>This <u>is<u> a <a href='test.html'><strong>test</strong></a>.</p>"))
|
342
|
-
assert_equal("This is a test.", strip_tags("This is a test."))
|
343
|
-
assert_equal(
|
344
|
-
%{This is a test.\n\n\nIt no longer contains any HTML.\n}, strip_tags(
|
345
|
-
%{<title>This is <b>a <a href="" target="_blank">test</a></b>.</title>\n\n<!-- it has a comment -->\n\n<p>It no <b>longer <strong>contains <em>any <strike>HTML</strike></em>.</strong></b></p>\n}))
|
346
|
-
assert_equal "This has a here.", strip_tags("This has a <!-- comment --> here.")
|
347
|
-
[nil, '', ' '].each { |blank| assert_equal blank, strip_tags(blank) }
|
348
|
-
end
|
349
335
|
end
|
@@ -1,10 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
2
2
|
|
3
|
-
|
4
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/asset_tag_helper'
|
5
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
|
6
|
-
|
7
|
-
RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port)
|
3
|
+
RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env)
|
8
4
|
|
9
5
|
class UrlHelperTest < Test::Unit::TestCase
|
10
6
|
include ActionView::Helpers::AssetTagHelper
|
@@ -14,14 +10,14 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
14
10
|
def setup
|
15
11
|
@controller = Class.new do
|
16
12
|
attr_accessor :url, :request
|
17
|
-
def url_for(options
|
13
|
+
def url_for(options)
|
18
14
|
url
|
19
15
|
end
|
20
16
|
end
|
21
17
|
@controller = @controller.new
|
22
18
|
@controller.url = "http://www.example.com"
|
23
19
|
end
|
24
|
-
|
20
|
+
|
25
21
|
def test_url_for_escapes_urls
|
26
22
|
@controller.url = "http://www.example.com?a=b&c=d"
|
27
23
|
assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd')
|
@@ -29,6 +25,11 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
29
25
|
assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd', :escape => false)
|
30
26
|
end
|
31
27
|
|
28
|
+
def test_url_for_escapes_url_once
|
29
|
+
@controller.url = "http://www.example.com?a=b&c=d"
|
30
|
+
assert_equal "http://www.example.com?a=b&c=d", url_for("http://www.example.com?a=b&c=d")
|
31
|
+
end
|
32
|
+
|
32
33
|
# todo: missing test cases
|
33
34
|
def test_button_to_with_straight_url
|
34
35
|
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com")
|
@@ -63,14 +64,14 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
63
64
|
button_to("Hello", "http://www.example.com", :disabled => true)
|
64
65
|
)
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
def test_button_to_with_method_delete
|
68
69
|
assert_dom_equal(
|
69
70
|
"<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"hidden\" name=\"_method\" value=\"delete\" /><input type=\"submit\" value=\"Hello\" /></div></form>",
|
70
71
|
button_to("Hello", "http://www.example.com", :method => :delete)
|
71
72
|
)
|
72
73
|
end
|
73
|
-
|
74
|
+
|
74
75
|
def test_button_to_with_method_get
|
75
76
|
assert_dom_equal(
|
76
77
|
"<form method=\"get\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
|
@@ -81,6 +82,24 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
81
82
|
def test_link_tag_with_straight_url
|
82
83
|
assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", "http://www.example.com")
|
83
84
|
end
|
85
|
+
|
86
|
+
def test_link_tag_without_host_option
|
87
|
+
ActionController::Base.class_eval { attr_accessor :url }
|
88
|
+
url = {:controller => 'weblog', :action => 'show'}
|
89
|
+
@controller = ActionController::Base.new
|
90
|
+
@controller.request = ActionController::TestRequest.new
|
91
|
+
@controller.url = ActionController::UrlRewriter.new(@controller.request, url)
|
92
|
+
assert_dom_equal(%q{<a href="/weblog/show">Test Link</a>}, link_to('Test Link', url))
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_link_tag_with_host_option
|
96
|
+
ActionController::Base.class_eval { attr_accessor :url }
|
97
|
+
url = {:controller => 'weblog', :action => 'show', :host => 'www.example.com'}
|
98
|
+
@controller = ActionController::Base.new
|
99
|
+
@controller.request = ActionController::TestRequest.new
|
100
|
+
@controller.url = ActionController::UrlRewriter.new(@controller.request, url)
|
101
|
+
assert_dom_equal(%q{<a href="http://www.example.com/weblog/show">Test Link</a>}, link_to('Test Link', url))
|
102
|
+
end
|
84
103
|
|
85
104
|
def test_link_tag_with_query
|
86
105
|
assert_dom_equal "<a href=\"http://www.example.com?q1=v1&q2=v2\">Hello</a>", link_to("Hello", "http://www.example.com?q1=v1&q2=v2")
|
@@ -90,6 +109,26 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
90
109
|
assert_dom_equal "<a href=\"http://www.example.com?q1=v1&q2=v2\">http://www.example.com?q1=v1&q2=v2</a>", link_to(nil, "http://www.example.com?q1=v1&q2=v2")
|
91
110
|
end
|
92
111
|
|
112
|
+
def test_link_tag_with_back
|
113
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'})
|
114
|
+
assert_dom_equal "<a href=\"http://www.example.com/referer\">go back</a>", link_to('go back', :back)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_link_tag_with_back_and_no_referer
|
118
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {})
|
119
|
+
assert_dom_equal "<a href=\"javascript:history.back()\">go back</a>", link_to('go back', :back)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_link_tag_with_back
|
123
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'})
|
124
|
+
assert_dom_equal "<a href=\"http://www.example.com/referer\">go back</a>", link_to('go back', :back)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_link_tag_with_back_and_no_referer
|
128
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {})
|
129
|
+
assert_dom_equal "<a href=\"javascript:history.back()\">go back</a>", link_to('go back', :back)
|
130
|
+
end
|
131
|
+
|
93
132
|
def test_link_tag_with_img
|
94
133
|
assert_dom_equal "<a href=\"http://www.example.com\"><img src='/favicon.jpg' /></a>", link_to("<img src='/favicon.jpg' />", "http://www.example.com")
|
95
134
|
end
|
@@ -101,18 +140,18 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
101
140
|
def test_link_tag_with_custom_onclick
|
102
141
|
assert_dom_equal "<a href=\"http://www.example.com\" onclick=\"alert('yay!')\">Hello</a>", link_to("Hello", "http://www.example.com", :onclick => "alert('yay!')")
|
103
142
|
end
|
104
|
-
|
143
|
+
|
105
144
|
def test_link_tag_with_javascript_confirm
|
106
145
|
assert_dom_equal(
|
107
146
|
"<a href=\"http://www.example.com\" onclick=\"return confirm('Are you sure?');\">Hello</a>",
|
108
147
|
link_to("Hello", "http://www.example.com", :confirm => "Are you sure?")
|
109
148
|
)
|
110
149
|
assert_dom_equal(
|
111
|
-
"<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure, can you?');\">Hello</a>",
|
150
|
+
"<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure, can you?');\">Hello</a>",
|
112
151
|
link_to("Hello", "http://www.example.com", :confirm => "You can't possibly be sure, can you?")
|
113
152
|
)
|
114
153
|
assert_dom_equal(
|
115
|
-
"<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure,\\n can you?');\">Hello</a>",
|
154
|
+
"<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure,\\n can you?');\">Hello</a>",
|
116
155
|
link_to("Hello", "http://www.example.com", :confirm => "You can't possibly be sure,\n can you?")
|
117
156
|
)
|
118
157
|
end
|
@@ -123,15 +162,15 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
123
162
|
link_to("Hello", "http://www.example.com", :popup => true)
|
124
163
|
)
|
125
164
|
assert_dom_equal(
|
126
|
-
"<a href=\"http://www.example.com\" onclick=\"window.open(this.href);return false;\">Hello</a>",
|
165
|
+
"<a href=\"http://www.example.com\" onclick=\"window.open(this.href);return false;\">Hello</a>",
|
127
166
|
link_to("Hello", "http://www.example.com", :popup => 'true')
|
128
167
|
)
|
129
168
|
assert_dom_equal(
|
130
|
-
"<a href=\"http://www.example.com\" onclick=\"window.open(this.href,'window_name','width=300,height=300');return false;\">Hello</a>",
|
169
|
+
"<a href=\"http://www.example.com\" onclick=\"window.open(this.href,'window_name','width=300,height=300');return false;\">Hello</a>",
|
131
170
|
link_to("Hello", "http://www.example.com", :popup => ['window_name', 'width=300,height=300'])
|
132
171
|
)
|
133
172
|
end
|
134
|
-
|
173
|
+
|
135
174
|
def test_link_tag_with_popup_and_javascript_confirm
|
136
175
|
assert_dom_equal(
|
137
176
|
"<a href=\"http://www.example.com\" onclick=\"if (confirm('Fo\\' sho\\'?')) { window.open(this.href); };return false;\">Hello</a>",
|
@@ -142,16 +181,7 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
142
181
|
link_to("Hello", "http://www.example.com", { :popup => ['window_name', 'width=300,height=300'], :confirm => "Are you serious?" })
|
143
182
|
)
|
144
183
|
end
|
145
|
-
|
146
|
-
def test_link_tag_with_post_is_deprecated
|
147
|
-
assert_deprecated 'post' do
|
148
|
-
assert_dom_equal(
|
149
|
-
"<a href='http://www.example.com' onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();return false;\">Hello</a>",
|
150
|
-
link_to("Hello", "http://www.example.com", :post => true)
|
151
|
-
)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
184
|
+
|
155
185
|
def test_link_tag_using_post_javascript
|
156
186
|
assert_dom_equal(
|
157
187
|
"<a href='http://www.example.com' onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit();return false;\">Hello</a>",
|
@@ -165,14 +195,21 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
165
195
|
link_to("Destroy", "http://www.example.com", :method => :delete)
|
166
196
|
)
|
167
197
|
end
|
168
|
-
|
198
|
+
|
199
|
+
def test_link_tag_using_delete_javascript_and_href
|
200
|
+
assert_dom_equal(
|
201
|
+
"<a href='\#' onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = 'http://www.example.com';var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit();return false;\">Destroy</a>",
|
202
|
+
link_to("Destroy", "http://www.example.com", :method => :delete, :href => '#')
|
203
|
+
)
|
204
|
+
end
|
205
|
+
|
169
206
|
def test_link_tag_using_post_javascript_and_confirm
|
170
207
|
assert_dom_equal(
|
171
208
|
"<a href=\"http://www.example.com\" onclick=\"if (confirm('Are you serious?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.submit(); };return false;\">Hello</a>",
|
172
209
|
link_to("Hello", "http://www.example.com", :method => :post, :confirm => "Are you serious?")
|
173
|
-
)
|
210
|
+
)
|
174
211
|
end
|
175
|
-
|
212
|
+
|
176
213
|
def test_link_tag_using_post_javascript_and_popup
|
177
214
|
assert_raises(ActionView::ActionViewError) { link_to("Hello", "http://www.example.com", :popup => true, :method => :post, :confirm => "Are you serious?") }
|
178
215
|
end
|
@@ -181,17 +218,17 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
181
218
|
assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog")
|
182
219
|
assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_unless(false, "Listing", :action => "list", :controller => "weblog")
|
183
220
|
assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1)
|
184
|
-
assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name, options, html_options
|
221
|
+
assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name, options, html_options|
|
185
222
|
"<strong>#{name}</strong>"
|
186
223
|
}
|
187
224
|
assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name|
|
188
225
|
"<strong>#{name}</strong>"
|
189
|
-
}
|
226
|
+
}
|
190
227
|
assert_equal "test", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) {
|
191
228
|
"test"
|
192
|
-
}
|
229
|
+
}
|
193
230
|
end
|
194
|
-
|
231
|
+
|
195
232
|
def test_link_to_if
|
196
233
|
assert_equal "Showing", link_to_if(false, "Showing", :action => "show", :controller => "weblog")
|
197
234
|
assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_if(true, "Listing", :action => "list", :controller => "weblog")
|
@@ -226,41 +263,46 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
226
263
|
def test_mail_to_with_javascript
|
227
264
|
assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript")
|
228
265
|
end
|
229
|
-
|
266
|
+
|
230
267
|
def test_mail_with_options
|
231
268
|
assert_dom_equal(
|
232
269
|
%(<a href="mailto:me@example.com?cc=ccaddress%40example.com&bcc=bccaddress%40example.com&body=This%20is%20the%20body%20of%20the%20message.&subject=This%20is%20an%20example%20email">My email</a>),
|
233
270
|
mail_to("me@example.com", "My email", :cc => "ccaddress@example.com", :bcc => "bccaddress@example.com", :subject => "This is an example email", :body => "This is the body of the message.")
|
234
271
|
)
|
235
272
|
end
|
236
|
-
|
273
|
+
|
237
274
|
def test_mail_to_with_img
|
238
275
|
assert_dom_equal %(<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>), mail_to('feedback@example.com', '<img src="/feedback.png" />')
|
239
276
|
end
|
240
277
|
|
241
278
|
def test_mail_to_with_hex
|
242
|
-
assert_dom_equal "<a href=\"
|
279
|
+
assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex")
|
280
|
+
assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me@domain.com</a>", mail_to("me@domain.com", nil, :encode => "hex")
|
243
281
|
end
|
244
282
|
|
245
283
|
def test_mail_to_with_replace_options
|
246
284
|
assert_dom_equal "<a href=\"mailto:wolfgang@stufenlos.net\">wolfgang(at)stufenlos(dot)net</a>", mail_to("wolfgang@stufenlos.net", nil, :replace_at => "(at)", :replace_dot => "(dot)")
|
247
|
-
assert_dom_equal "<a href=\"
|
248
|
-
assert_dom_equal "<a href=\"
|
249
|
-
assert_dom_equal "<a href=\"
|
285
|
+
assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain.com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)")
|
286
|
+
assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex", :replace_at => "(at)")
|
287
|
+
assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain(dot)com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)")
|
250
288
|
assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
|
251
289
|
end
|
290
|
+
|
291
|
+
def protect_against_forgery?
|
292
|
+
false
|
293
|
+
end
|
252
294
|
end
|
253
295
|
|
254
296
|
class UrlHelperWithControllerTest < Test::Unit::TestCase
|
255
297
|
class UrlHelperController < ActionController::Base
|
256
|
-
self.
|
298
|
+
self.view_paths = [ "#{File.dirname(__FILE__)}/../fixtures/" ]
|
257
299
|
|
258
300
|
def self.controller_path; 'url_helper_with_controller' end
|
259
301
|
|
260
302
|
def show_url_for
|
261
303
|
render :inline => "<%= url_for :controller => 'url_helper_with_controller', :action => 'show_url_for' %>"
|
262
304
|
end
|
263
|
-
|
305
|
+
|
264
306
|
def show_named_route
|
265
307
|
render :inline => "<%= show_named_route_#{params[:kind]} %>"
|
266
308
|
end
|
@@ -275,26 +317,26 @@ class UrlHelperWithControllerTest < Test::Unit::TestCase
|
|
275
317
|
@response = ActionController::TestResponse.new
|
276
318
|
@controller = UrlHelperController.new
|
277
319
|
end
|
278
|
-
|
320
|
+
|
279
321
|
def test_url_for_shows_only_path
|
280
322
|
get :show_url_for
|
281
323
|
assert_equal '/url_helper_with_controller/show_url_for', @response.body
|
282
324
|
end
|
283
|
-
|
325
|
+
|
284
326
|
def test_named_route_shows_host_and_path
|
285
327
|
with_url_helper_routing do
|
286
328
|
get :show_named_route, :kind => 'url'
|
287
329
|
assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body
|
288
330
|
end
|
289
331
|
end
|
290
|
-
|
332
|
+
|
291
333
|
def test_named_route_path_shows_only_path
|
292
334
|
with_url_helper_routing do
|
293
335
|
get :show_named_route, :kind => 'path'
|
294
336
|
assert_equal '/url_helper_with_controller/show_named_route', @response.body
|
295
337
|
end
|
296
338
|
end
|
297
|
-
|
339
|
+
|
298
340
|
protected
|
299
341
|
def with_url_helper_routing
|
300
342
|
with_routing do |set|
|
@@ -308,7 +350,7 @@ end
|
|
308
350
|
|
309
351
|
class LinkToUnlessCurrentWithControllerTest < Test::Unit::TestCase
|
310
352
|
class TasksController < ActionController::Base
|
311
|
-
self.
|
353
|
+
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
|
312
354
|
|
313
355
|
def self.controller_path; 'tasks' end
|
314
356
|
|
@@ -364,3 +406,131 @@ class LinkToUnlessCurrentWithControllerTest < Test::Unit::TestCase
|
|
364
406
|
end
|
365
407
|
end
|
366
408
|
end
|
409
|
+
|
410
|
+
|
411
|
+
class Workshop
|
412
|
+
attr_accessor :id, :new_record
|
413
|
+
|
414
|
+
def initialize(id, new_record)
|
415
|
+
@id, @new_record = id, new_record
|
416
|
+
end
|
417
|
+
|
418
|
+
def new_record?
|
419
|
+
@new_record
|
420
|
+
end
|
421
|
+
|
422
|
+
def to_s
|
423
|
+
id.to_s
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
class Session
|
428
|
+
attr_accessor :id, :workshop_id, :new_record
|
429
|
+
|
430
|
+
def initialize(id, new_record)
|
431
|
+
@id, @new_record = id, new_record
|
432
|
+
end
|
433
|
+
|
434
|
+
def new_record?
|
435
|
+
@new_record
|
436
|
+
end
|
437
|
+
|
438
|
+
def to_s
|
439
|
+
id.to_s
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
class PolymorphicControllerTest < Test::Unit::TestCase
|
444
|
+
class WorkshopsController < ActionController::Base
|
445
|
+
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
|
446
|
+
|
447
|
+
def self.controller_path; 'workshops' end
|
448
|
+
|
449
|
+
def index
|
450
|
+
@workshop = Workshop.new(1, true)
|
451
|
+
render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>"
|
452
|
+
end
|
453
|
+
|
454
|
+
def show
|
455
|
+
@workshop = Workshop.new(params[:id], false)
|
456
|
+
render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>"
|
457
|
+
end
|
458
|
+
|
459
|
+
def rescue_action(e) raise e end
|
460
|
+
end
|
461
|
+
|
462
|
+
class SessionsController < ActionController::Base
|
463
|
+
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
|
464
|
+
|
465
|
+
def self.controller_path; 'sessions' end
|
466
|
+
|
467
|
+
def index
|
468
|
+
@workshop = Workshop.new(params[:workshop_id], false)
|
469
|
+
@session = Session.new(1, true)
|
470
|
+
render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>"
|
471
|
+
end
|
472
|
+
|
473
|
+
def show
|
474
|
+
@workshop = Workshop.new(params[:workshop_id], false)
|
475
|
+
@session = Session.new(params[:id], false)
|
476
|
+
render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>"
|
477
|
+
end
|
478
|
+
|
479
|
+
def rescue_action(e) raise e end
|
480
|
+
end
|
481
|
+
|
482
|
+
include ActionView::Helpers::UrlHelper
|
483
|
+
|
484
|
+
def setup
|
485
|
+
@request = ActionController::TestRequest.new
|
486
|
+
@response = ActionController::TestResponse.new
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_new_resource
|
490
|
+
@controller = WorkshopsController.new
|
491
|
+
|
492
|
+
with_restful_routing do
|
493
|
+
get :index
|
494
|
+
assert_equal "/workshops\n<a href=\"/workshops\">Workshop</a>", @response.body
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_existing_resource
|
499
|
+
@controller = WorkshopsController.new
|
500
|
+
|
501
|
+
with_restful_routing do
|
502
|
+
get :show, :id => 1
|
503
|
+
assert_equal "/workshops/1\n<a href=\"/workshops/1\">Workshop</a>", @response.body
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
def test_new_nested_resource
|
508
|
+
@controller = SessionsController.new
|
509
|
+
|
510
|
+
with_restful_routing do
|
511
|
+
get :index, :workshop_id => 1
|
512
|
+
assert_equal "/workshops/1/sessions\n<a href=\"/workshops/1/sessions\">Session</a>", @response.body
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
def test_existing_nested_resource
|
517
|
+
@controller = SessionsController.new
|
518
|
+
|
519
|
+
with_restful_routing do
|
520
|
+
get :show, :workshop_id => 1, :id => 1
|
521
|
+
assert_equal "/workshops/1/sessions/1\n<a href=\"/workshops/1/sessions/1\">Session</a>", @response.body
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
protected
|
526
|
+
def with_restful_routing
|
527
|
+
with_routing do |set|
|
528
|
+
set.draw do |map|
|
529
|
+
map.resources :workshops do |w|
|
530
|
+
w.resources :sessions
|
531
|
+
end
|
532
|
+
end
|
533
|
+
yield
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|