eactionpack 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/MIT-LICENSE +21 -0
- data/README +469 -0
- data/RUNNING_UNIT_TESTS +24 -0
- data/Rakefile +146 -0
- data/install.rb +30 -0
- data/lib/action_controller.rb +79 -0
- data/lib/action_controller/assertions.rb +69 -0
- data/lib/action_controller/assertions/dom_assertions.rb +39 -0
- data/lib/action_controller/assertions/model_assertions.rb +20 -0
- data/lib/action_controller/assertions/response_assertions.rb +172 -0
- data/lib/action_controller/assertions/routing_assertions.rb +146 -0
- data/lib/action_controller/assertions/selector_assertions.rb +491 -0
- data/lib/action_controller/assertions/tag_assertions.rb +130 -0
- data/lib/action_controller/base.rb +1288 -0
- data/lib/action_controller/benchmarking.rb +94 -0
- data/lib/action_controller/caching.rb +72 -0
- data/lib/action_controller/caching/actions.rb +144 -0
- data/lib/action_controller/caching/fragments.rb +138 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sql_cache.rb +18 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/cgi_ext.rb +16 -0
- data/lib/action_controller/cgi_ext/cookie.rb +110 -0
- 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 +24 -0
- data/lib/action_controller/cgi_process.rb +223 -0
- data/lib/action_controller/components.rb +166 -0
- data/lib/action_controller/cookies.rb +96 -0
- data/lib/action_controller/dispatcher.rb +162 -0
- data/lib/action_controller/filters.rb +642 -0
- data/lib/action_controller/flash.rb +172 -0
- data/lib/action_controller/headers.rb +31 -0
- data/lib/action_controller/helpers.rb +221 -0
- data/lib/action_controller/http_authentication.rb +124 -0
- data/lib/action_controller/integration.rb +634 -0
- data/lib/action_controller/layout.rb +309 -0
- data/lib/action_controller/mime_responds.rb +173 -0
- data/lib/action_controller/mime_type.rb +186 -0
- data/lib/action_controller/mime_types.rb +20 -0
- data/lib/action_controller/polymorphic_routes.rb +191 -0
- data/lib/action_controller/record_identifier.rb +102 -0
- data/lib/action_controller/request.rb +764 -0
- data/lib/action_controller/request_forgery_protection.rb +140 -0
- data/lib/action_controller/request_profiler.rb +169 -0
- data/lib/action_controller/rescue.rb +258 -0
- data/lib/action_controller/resources.rb +572 -0
- data/lib/action_controller/response.rb +76 -0
- data/lib/action_controller/routing.rb +387 -0
- data/lib/action_controller/routing/builder.rb +203 -0
- data/lib/action_controller/routing/optimisations.rb +120 -0
- data/lib/action_controller/routing/recognition_optimisation.rb +162 -0
- data/lib/action_controller/routing/route.rb +240 -0
- data/lib/action_controller/routing/route_set.rb +436 -0
- data/lib/action_controller/routing/routing_ext.rb +46 -0
- data/lib/action_controller/routing/segments.rb +283 -0
- data/lib/action_controller/session/active_record_store.rb +340 -0
- data/lib/action_controller/session/cookie_store.rb +166 -0
- data/lib/action_controller/session/drb_server.rb +32 -0
- data/lib/action_controller/session/drb_store.rb +35 -0
- data/lib/action_controller/session/mem_cache_store.rb +98 -0
- data/lib/action_controller/session_management.rb +158 -0
- data/lib/action_controller/status_codes.rb +88 -0
- data/lib/action_controller/streaming.rb +155 -0
- data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
- data/lib/action_controller/templates/rescues/_trace.erb +26 -0
- data/lib/action_controller/templates/rescues/diagnostics.erb +11 -0
- data/lib/action_controller/templates/rescues/layout.erb +29 -0
- data/lib/action_controller/templates/rescues/missing_template.erb +2 -0
- data/lib/action_controller/templates/rescues/routing_error.erb +10 -0
- data/lib/action_controller/templates/rescues/template_error.erb +21 -0
- data/lib/action_controller/templates/rescues/unknown_action.erb +2 -0
- data/lib/action_controller/test_case.rb +83 -0
- data/lib/action_controller/test_process.rb +526 -0
- data/lib/action_controller/url_rewriter.rb +142 -0
- data/lib/action_controller/vendor/html-scanner/html/document.rb +68 -0
- data/lib/action_controller/vendor/html-scanner/html/node.rb +537 -0
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +828 -0
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +105 -0
- data/lib/action_controller/vendor/html-scanner/html/version.rb +11 -0
- data/lib/action_controller/verification.rb +130 -0
- data/lib/action_pack.rb +24 -0
- data/lib/action_pack/version.rb +9 -0
- data/lib/action_view.rb +44 -0
- data/lib/action_view/base.rb +335 -0
- data/lib/action_view/helpers/active_record_helper.rb +276 -0
- data/lib/action_view/helpers/asset_tag_helper.rb +599 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +143 -0
- data/lib/action_view/helpers/benchmark_helper.rb +33 -0
- data/lib/action_view/helpers/cache_helper.rb +40 -0
- data/lib/action_view/helpers/capture_helper.rb +161 -0
- data/lib/action_view/helpers/date_helper.rb +711 -0
- data/lib/action_view/helpers/debug_helper.rb +31 -0
- data/lib/action_view/helpers/form_helper.rb +767 -0
- data/lib/action_view/helpers/form_options_helper.rb +458 -0
- data/lib/action_view/helpers/form_tag_helper.rb +458 -0
- data/lib/action_view/helpers/javascript_helper.rb +148 -0
- data/lib/action_view/helpers/number_helper.rb +186 -0
- 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 +229 -0
- data/lib/action_view/helpers/tag_helper.rb +134 -0
- data/lib/action_view/helpers/text_helper.rb +507 -0
- data/lib/action_view/helpers/url_helper.rb +573 -0
- data/lib/action_view/inline_template.rb +20 -0
- data/lib/action_view/partial_template.rb +70 -0
- data/lib/action_view/partials.rb +158 -0
- data/lib/action_view/template.rb +125 -0
- data/lib/action_view/template_error.rb +110 -0
- data/lib/action_view/template_finder.rb +176 -0
- data/lib/action_view/template_handler.rb +34 -0
- data/lib/action_view/template_handlers/builder.rb +27 -0
- data/lib/action_view/template_handlers/compilable.rb +128 -0
- data/lib/action_view/template_handlers/erb.rb +56 -0
- data/lib/action_view/test_case.rb +58 -0
- data/lib/actionpack.rb +1 -0
- data/test/abstract_unit.rb +36 -0
- data/test/active_record_unit.rb +105 -0
- data/test/activerecord/active_record_store_test.rb +141 -0
- data/test/activerecord/render_partial_with_record_identification_test.rb +191 -0
- data/test/adv_attr_test.rb +20 -0
- data/test/controller/action_pack_assertions_test.rb +543 -0
- data/test/controller/addresses_render_test.rb +43 -0
- data/test/controller/assert_select_test.rb +331 -0
- data/test/controller/base_test.rb +219 -0
- data/test/controller/benchmark_test.rb +32 -0
- data/test/controller/caching_test.rb +581 -0
- data/test/controller/capture_test.rb +89 -0
- data/test/controller/cgi_test.rb +116 -0
- data/test/controller/components_test.rb +140 -0
- data/test/controller/content_type_test.rb +139 -0
- data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
- data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
- data/test/controller/cookie_test.rb +146 -0
- data/test/controller/custom_handler_test.rb +45 -0
- data/test/controller/deprecation/deprecated_base_methods_test.rb +37 -0
- data/test/controller/dispatcher_test.rb +105 -0
- data/test/controller/fake_controllers.rb +33 -0
- data/test/controller/fake_models.rb +11 -0
- data/test/controller/filter_params_test.rb +49 -0
- data/test/controller/filters_test.rb +881 -0
- data/test/controller/flash_test.rb +146 -0
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +210 -0
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/document_test.rb +148 -0
- data/test/controller/html-scanner/node_test.rb +89 -0
- data/test/controller/html-scanner/sanitizer_test.rb +269 -0
- data/test/controller/html-scanner/tag_node_test.rb +238 -0
- data/test/controller/html-scanner/text_node_test.rb +50 -0
- data/test/controller/html-scanner/tokenizer_test.rb +131 -0
- data/test/controller/http_authentication_test.rb +54 -0
- data/test/controller/integration_test.rb +252 -0
- data/test/controller/integration_upload_test.rb +43 -0
- data/test/controller/layout_test.rb +255 -0
- data/test/controller/mime_responds_test.rb +514 -0
- data/test/controller/mime_type_test.rb +84 -0
- data/test/controller/new_render_test.rb +843 -0
- data/test/controller/polymorphic_routes_test.rb +174 -0
- data/test/controller/record_identifier_test.rb +139 -0
- data/test/controller/redirect_test.rb +289 -0
- data/test/controller/render_test.rb +484 -0
- data/test/controller/request_forgery_protection_test.rb +305 -0
- data/test/controller/request_test.rb +928 -0
- data/test/controller/rescue_test.rb +517 -0
- data/test/controller/resources_test.rb +873 -0
- data/test/controller/routing_test.rb +2464 -0
- data/test/controller/selector_test.rb +628 -0
- data/test/controller/send_file_test.rb +138 -0
- data/test/controller/session/cookie_store_test.rb +258 -0
- data/test/controller/session/mem_cache_store_test.rb +181 -0
- data/test/controller/session_fixation_test.rb +89 -0
- data/test/controller/session_management_test.rb +178 -0
- data/test/controller/test_test.rb +695 -0
- data/test/controller/url_rewriter_test.rb +310 -0
- data/test/controller/verification_test.rb +270 -0
- data/test/controller/view_paths_test.rb +140 -0
- data/test/controller/webservice_test.rb +229 -0
- data/test/fixtures/addresses/list.erb +1 -0
- data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/test/fixtures/companies.yml +24 -0
- data/test/fixtures/company.rb +10 -0
- data/test/fixtures/content_type/render_default_content_types_for_respond_to.rhtml +1 -0
- data/test/fixtures/content_type/render_default_for_js.js.erb +1 -0
- data/test/fixtures/content_type/render_default_for_rhtml.rhtml +1 -0
- data/test/fixtures/content_type/render_default_for_rxml.rxml +1 -0
- data/test/fixtures/customers/_customer.html.erb +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +49 -0
- data/test/fixtures/developer.rb +9 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +13 -0
- data/test/fixtures/fun/games/hello_world.erb +1 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
- data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/test/fixtures/helpers/abc_helper.rb +5 -0
- data/test/fixtures/helpers/fun/games_helper.rb +3 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
- data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
- data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
- data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
- data/test/fixtures/layouts/block_with_layout.erb +3 -0
- data/test/fixtures/layouts/builder.builder +3 -0
- data/test/fixtures/layouts/partial_with_layout.erb +3 -0
- data/test/fixtures/layouts/standard.erb +1 -0
- data/test/fixtures/layouts/talk_from_action.erb +2 -0
- data/test/fixtures/layouts/yield.erb +2 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/mascots.yml +4 -0
- data/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/boundary_problem_file +10 -0
- data/test/fixtures/multipart/bracketed_param +5 -0
- data/test/fixtures/multipart/large_text_file +10 -0
- data/test/fixtures/multipart/mixed_files +0 -0
- data/test/fixtures/multipart/mona_lisa.jpg +0 -0
- data/test/fixtures/multipart/single_parameter +5 -0
- data/test/fixtures/multipart/text_file +10 -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/project.rb +3 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/public/404.html +1 -0
- data/test/fixtures/public/500.html +1 -0
- data/test/fixtures/public/images/rails.png +0 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/public/javascripts/bank.js +1 -0
- data/test/fixtures/public/javascripts/robber.js +1 -0
- data/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/test/fixtures/public/stylesheets/bank.css +1 -0
- data/test/fixtures/public/stylesheets/robber.css +1 -0
- data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/test/fixtures/replies.yml +15 -0
- data/test/fixtures/reply.rb +7 -0
- data/test/fixtures/respond_to/all_types_with_layout.html.erb +1 -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.html.erb +1 -0
- data/test/fixtures/respond_to/using_defaults.js.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults.xml.builder +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.html.erb +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder +1 -0
- data/test/fixtures/scope/test/modgreet.erb +1 -0
- data/test/fixtures/shared.html.erb +1 -0
- data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
- data/test/fixtures/test/_customer.erb +1 -0
- data/test/fixtures/test/_customer_counter.erb +1 -0
- data/test/fixtures/test/_customer_greeting.erb +1 -0
- data/test/fixtures/test/_form.erb +1 -0
- data/test/fixtures/test/_hash_greeting.erb +1 -0
- data/test/fixtures/test/_hash_object.erb +2 -0
- data/test/fixtures/test/_hello.builder +1 -0
- data/test/fixtures/test/_labelling_form.erb +1 -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.erb +1 -0
- data/test/fixtures/test/_person.erb +2 -0
- data/test/fixtures/test/_raise.html.erb +1 -0
- data/test/fixtures/test/action_talk_to_layout.erb +2 -0
- data/test/fixtures/test/block_content_for.erb +2 -0
- data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
- data/test/fixtures/test/capturing.erb +4 -0
- data/test/fixtures/test/content_for.erb +2 -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/delete_with_js.rjs +2 -0
- data/test/fixtures/test/dot.directory/render_file_with_ivar.erb +1 -0
- data/test/fixtures/test/enum_rjs_test.rjs +6 -0
- data/test/fixtures/test/erb_content_for.erb +2 -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.erb +1 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/test/hello.builder +4 -0
- data/test/fixtures/test/hello_world.erb +1 -0
- data/test/fixtures/test/hello_world_container.builder +3 -0
- data/test/fixtures/test/hello_world_from_rxml.builder +4 -0
- data/test/fixtures/test/hello_world_with_layout_false.erb +1 -0
- data/test/fixtures/test/hello_xml_world.builder +11 -0
- data/test/fixtures/test/list.erb +1 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +4 -0
- data/test/fixtures/test/potential_conflicts.erb +4 -0
- data/test/fixtures/test/render_file_from_template.html.erb +1 -0
- data/test/fixtures/test/render_file_with_ivar.erb +1 -0
- data/test/fixtures/test/render_file_with_locals.erb +1 -0
- data/test/fixtures/test/render_to_string_test.erb +1 -0
- data/test/fixtures/test/update_element_with_capture.erb +9 -0
- data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/fixtures/topics/_topic.html.erb +1 -0
- data/test/template/active_record_helper_test.rb +268 -0
- data/test/template/asset_tag_helper_test.rb +514 -0
- data/test/template/atom_feed_helper_test.rb +179 -0
- data/test/template/benchmark_helper_test.rb +60 -0
- data/test/template/date_helper_test.rb +1791 -0
- data/test/template/deprecated_erb_variable_test.rb +9 -0
- data/test/template/erb_util_test.rb +24 -0
- data/test/template/form_helper_test.rb +885 -0
- data/test/template/form_options_helper_test.rb +1333 -0
- data/test/template/form_tag_helper_test.rb +272 -0
- data/test/template/javascript_helper_test.rb +73 -0
- data/test/template/number_helper_test.rb +97 -0
- data/test/template/record_tag_helper_test.rb +54 -0
- data/test/template/sanitize_helper_test.rb +48 -0
- data/test/template/tag_helper_test.rb +77 -0
- data/test/template/template_finder_test.rb +73 -0
- data/test/template/template_object_test.rb +95 -0
- data/test/template/test_test.rb +56 -0
- data/test/template/text_helper_test.rb +367 -0
- data/test/template/url_helper_test.rb +544 -0
- data/test/testing_sandbox.rb +15 -0
- metadata +469 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require '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 < ActionView::TestCase
|
7
|
+
tests ActionView::Helpers::SanitizeHelper
|
8
|
+
include TestingSandbox
|
9
|
+
|
10
|
+
def test_strip_links
|
11
|
+
assert_equal "Dont touch me", strip_links("Dont touch me")
|
12
|
+
assert_equal "<a<a", strip_links("<a<a")
|
13
|
+
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>")
|
14
|
+
assert_equal "0wn3d", strip_links("<a href='http://www.rubyonrails.com/'><a href='http://www.rubyonrails.com/' onlclick='steal()'>0wn3d</a></a>")
|
15
|
+
assert_equal "Magic", strip_links("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic")
|
16
|
+
assert_equal "FrrFox", strip_links("<href onlclick='steal()'>FrrFox</a></href>")
|
17
|
+
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>")
|
18
|
+
assert_equal "all <b>day</b> long", strip_links("<<a>a href='hello'>all <b>day</b> long<</A>/a>")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_sanitize_form
|
22
|
+
assert_sanitized "<form action=\"/foo/bar\" method=\"post\"><input></form>", ''
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_sanitize_illegal_style_properties
|
26
|
+
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;)
|
27
|
+
expected = %(display: block; width: 100%; height: 100%; background-color: black; background-image: ; background-x: center; background-y: center;)
|
28
|
+
assert_equal expected, sanitize_css(raw)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_strip_tags
|
32
|
+
assert_equal("<<<bad html", strip_tags("<<<bad html"))
|
33
|
+
assert_equal("<<", strip_tags("<<<bad html>"))
|
34
|
+
assert_equal("Dont touch me", strip_tags("Dont touch me"))
|
35
|
+
assert_equal("This is a test.", strip_tags("<p>This <u>is<u> a <a href='test.html'><strong>test</strong></a>.</p>"))
|
36
|
+
assert_equal("Weirdos", strip_tags("Wei<<a>a onclick='alert(document.cookie);'</a>/>rdos"))
|
37
|
+
assert_equal("This is a test.", strip_tags("This is a test."))
|
38
|
+
assert_equal(
|
39
|
+
%{This is a test.\n\n\nIt no longer contains any HTML.\n}, strip_tags(
|
40
|
+
%{<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}))
|
41
|
+
assert_equal "This has a here.", strip_tags("This has a <!-- comment --> here.")
|
42
|
+
[nil, '', ' '].each { |blank| assert_equal blank, strip_tags(blank) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def assert_sanitized(text, expected = nil)
|
46
|
+
assert_equal((expected || text), sanitize(text))
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class TagHelperTest < ActionView::TestCase
|
4
|
+
tests ActionView::Helpers::TagHelper
|
5
|
+
|
6
|
+
def test_tag
|
7
|
+
assert_equal "<br />", tag("br")
|
8
|
+
assert_equal "<br clear=\"left\" />", tag(:br, :clear => "left")
|
9
|
+
assert_equal "<br>", tag("br", nil, true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_tag_options
|
13
|
+
str = tag("p", "class" => "show", :class => "elsewhere")
|
14
|
+
assert_match /class="show"/, str
|
15
|
+
assert_match /class="elsewhere"/, str
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_tag_options_rejects_nil_option
|
19
|
+
assert_equal "<p />", tag("p", :ignored => nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_tag_options_accepts_blank_option
|
23
|
+
assert_equal "<p included=\"\" />", tag("p", :included => '')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_tag_options_converts_boolean_option
|
27
|
+
assert_equal '<p disabled="disabled" multiple="multiple" readonly="readonly" />',
|
28
|
+
tag("p", :disabled => true, :multiple => true, :readonly => true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_content_tag
|
32
|
+
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
|
33
|
+
assert_equal content_tag("a", "Create", "href" => "create"),
|
34
|
+
content_tag("a", "Create", :href => "create")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_content_tag_with_block
|
38
|
+
_erbout = ''
|
39
|
+
content_tag(:div) { _erbout.concat "Hello world!" }
|
40
|
+
assert_dom_equal "<div>Hello world!</div>", _erbout
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_content_tag_with_block_and_options
|
44
|
+
_erbout = ''
|
45
|
+
content_tag(:div, :class => "green") { _erbout.concat "Hello world!" }
|
46
|
+
assert_dom_equal %(<div class="green">Hello world!</div>), _erbout
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_content_tag_with_block_and_options_outside_of_action_view
|
50
|
+
assert_equal content_tag("a", "Create", :href => "create"),
|
51
|
+
content_tag("a", "href" => "create") { "Create" }
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_cdata_section
|
55
|
+
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_escape_once
|
59
|
+
assert_equal '1 < 2 & 3', escape_once('1 < 2 & 3')
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_double_escaping_attributes
|
63
|
+
['1&2', '1 < 2', '“test“'].each do |escaped|
|
64
|
+
assert_equal %(<a href="#{escaped}" />), tag('a', :href => escaped)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_skip_invalid_escaped_attributes
|
69
|
+
['&1;', 'dfa3;', '& #123;'].each do |escaped|
|
70
|
+
assert_equal %(<a href="#{escaped.gsub /&/, '&'}" />), tag('a', :href => escaped)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_disable_escaping
|
75
|
+
assert_equal '<a href="&" />', tag('a', { :href => '&' }, false, false)
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class TemplateFinderTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
6
|
+
|
7
|
+
def setup
|
8
|
+
ActionView::TemplateFinder.process_view_paths(LOAD_PATH_ROOT)
|
9
|
+
ActionView::Template::register_template_handler :mab, Class.new(ActionView::TemplateHandler)
|
10
|
+
@template = ActionView::Base.new
|
11
|
+
@finder = ActionView::TemplateFinder.new(@template, LOAD_PATH_ROOT)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_raise_exception_for_unprocessed_view_path
|
15
|
+
assert_raises ActionView::TemplateFinder::InvalidViewPath do
|
16
|
+
ActionView::TemplateFinder.new(@template, File.dirname(__FILE__))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_cache_file_extension_properly
|
21
|
+
assert_equal ["builder", "erb", "rhtml", "rxml", "mab"].sort,
|
22
|
+
ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].values.flatten.uniq.sort
|
23
|
+
|
24
|
+
assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rhtml,builder,rxml,mab}") |
|
25
|
+
Dir.glob("#{LOAD_PATH_ROOT}/**.{erb,rhtml,builder,rxml,mab}")).size,
|
26
|
+
ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].keys.size
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_cache_dir_content_properly
|
30
|
+
assert ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT]
|
31
|
+
assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/**") | Dir.glob("#{LOAD_PATH_ROOT}/**")).find_all {|f| !File.directory?(f) }.size,
|
32
|
+
ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT].size
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_find_template_extension_from_first_render
|
36
|
+
assert_nil @finder.send(:find_template_extension_from_first_render)
|
37
|
+
|
38
|
+
{
|
39
|
+
nil => nil,
|
40
|
+
'' => nil,
|
41
|
+
'foo' => nil,
|
42
|
+
'/foo' => nil,
|
43
|
+
'foo.rb' => 'rb',
|
44
|
+
'foo.bar.rb' => 'bar.rb',
|
45
|
+
'baz/foo.rb' => 'rb',
|
46
|
+
'baz/foo.bar.rb' => 'bar.rb',
|
47
|
+
'baz/foo.o/foo.rb' => 'rb',
|
48
|
+
'baz/foo.o/foo.bar.rb' => 'bar.rb',
|
49
|
+
}.each do |input,expectation|
|
50
|
+
@template.instance_variable_set('@first_render', input)
|
51
|
+
assert_equal expectation, @finder.send(:find_template_extension_from_first_render)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_report_file_exists_correctly
|
56
|
+
assert_nil @finder.send(:find_template_extension_from_first_render)
|
57
|
+
assert_equal false, @finder.send(:file_exists?, 'test.rhtml')
|
58
|
+
assert_equal false, @finder.send(:file_exists?, 'test.rb')
|
59
|
+
|
60
|
+
@template.instance_variable_set('@first_render', 'foo.rb')
|
61
|
+
|
62
|
+
assert_equal 'rb', @finder.send(:find_template_extension_from_first_render)
|
63
|
+
assert_equal false, @finder.send(:file_exists?, 'baz')
|
64
|
+
assert_equal false, @finder.send(:file_exists?, 'baz.rb')
|
65
|
+
end
|
66
|
+
|
67
|
+
uses_mocha 'Template finder tests' do
|
68
|
+
def test_should_update_extension_cache_when_template_handler_is_registered
|
69
|
+
ActionView::TemplateFinder.expects(:update_extension_cache_for).with("funky")
|
70
|
+
ActionView::Template::register_template_handler :funky, Class.new(ActionView::TemplateHandler)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class TemplateObjectTest < Test::Unit::TestCase
|
4
|
+
LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
5
|
+
ActionView::TemplateFinder.process_view_paths(LOAD_PATH_ROOT)
|
6
|
+
|
7
|
+
class TemplateTest < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
@view = ActionView::Base.new(LOAD_PATH_ROOT)
|
10
|
+
@path = "test/hello_world.erb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_create_valid_template
|
14
|
+
template = ActionView::Template.new(@view, @path, true)
|
15
|
+
|
16
|
+
assert_kind_of ActionView::TemplateHandlers::ERB, template.handler
|
17
|
+
assert_equal "test/hello_world.erb", template.path
|
18
|
+
assert_nil template.instance_variable_get(:"@source")
|
19
|
+
assert_equal "erb", template.extension
|
20
|
+
end
|
21
|
+
|
22
|
+
uses_mocha 'Template preparation tests' do
|
23
|
+
|
24
|
+
def test_should_prepare_template_properly
|
25
|
+
template = ActionView::Template.new(@view, @path, true)
|
26
|
+
view = template.instance_variable_get(:"@view")
|
27
|
+
|
28
|
+
view.expects(:evaluate_assigns)
|
29
|
+
template.handler.expects(:compile_template).with(template)
|
30
|
+
view.expects(:method_names).returns({})
|
31
|
+
|
32
|
+
template.prepare!
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class PartialTemplateTest < Test::Unit::TestCase
|
39
|
+
def setup
|
40
|
+
@view = ActionView::Base.new(LOAD_PATH_ROOT)
|
41
|
+
@path = "test/partial_only"
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_create_valid_partial_template
|
45
|
+
template = ActionView::PartialTemplate.new(@view, @path, nil)
|
46
|
+
|
47
|
+
assert_equal "test/_partial_only", template.path
|
48
|
+
assert_equal :partial_only, template.variable_name
|
49
|
+
|
50
|
+
assert template.locals.has_key?(:object)
|
51
|
+
assert template.locals.has_key?(:partial_only)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_partial_with_errors
|
55
|
+
template = ActionView::PartialTemplate.new(@view, 'test/raise', nil)
|
56
|
+
assert_raise(ActionView::TemplateError) { template.render_template }
|
57
|
+
end
|
58
|
+
|
59
|
+
uses_mocha 'Partial template preparation tests' do
|
60
|
+
def test_should_prepare_on_initialization
|
61
|
+
ActionView::PartialTemplate.any_instance.expects(:prepare!)
|
62
|
+
template = ActionView::PartialTemplate.new(@view, @path, 1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class PartialTemplateFallbackTest < Test::Unit::TestCase
|
68
|
+
def setup
|
69
|
+
@view = ActionView::Base.new(LOAD_PATH_ROOT)
|
70
|
+
@path = 'test/layout_for_partial'
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_default
|
74
|
+
template = ActionView::PartialTemplate.new(@view, @path, nil)
|
75
|
+
assert_equal 'test/_layout_for_partial', template.path
|
76
|
+
assert_equal 'erb', template.extension
|
77
|
+
assert_equal :html, @view.template_format
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_js
|
81
|
+
@view.template_format = :js
|
82
|
+
template = ActionView::PartialTemplate.new(@view, @path, nil)
|
83
|
+
assert_equal 'test/_layout_for_partial', template.path
|
84
|
+
assert_equal 'erb', template.extension
|
85
|
+
assert_equal :html, @view.template_format
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_xml
|
89
|
+
@view.template_format = :xml
|
90
|
+
assert_raise ActionView::MissingTemplate do
|
91
|
+
ActionView::PartialTemplate.new(@view, @path, nil)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
module PeopleHelper
|
4
|
+
def title(text)
|
5
|
+
content_tag(:h1, text)
|
6
|
+
end
|
7
|
+
|
8
|
+
def homepage_path
|
9
|
+
people_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def homepage_url
|
13
|
+
people_url
|
14
|
+
end
|
15
|
+
|
16
|
+
def link_to_person(person)
|
17
|
+
link_to person.name, person
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class PeopleHelperTest < ActionView::TestCase
|
22
|
+
def setup
|
23
|
+
ActionController::Routing::Routes.draw do |map|
|
24
|
+
map.people 'people', :controller => 'people', :action => 'index'
|
25
|
+
map.connect ':controller/:action/:id'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_title
|
30
|
+
assert_equal "<h1>Ruby on Rails</h1>", title("Ruby on Rails")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_homepage_path
|
34
|
+
assert_equal "/people", homepage_path
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_homepage_url
|
38
|
+
assert_equal "http://test.host/people", homepage_url
|
39
|
+
end
|
40
|
+
|
41
|
+
uses_mocha "link_to_person" do
|
42
|
+
def test_link_to_person
|
43
|
+
person = mock(:name => "David")
|
44
|
+
expects(:mocha_mock_path).with(person).returns("/people/1")
|
45
|
+
assert_equal '<a href="/people/1">David</a>', link_to_person(person)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class CrazyHelperTest < ActionView::TestCase
|
51
|
+
tests PeopleHelper
|
52
|
+
|
53
|
+
def test_helper_class_can_be_set_manually_not_just_inferred
|
54
|
+
assert_equal PeopleHelper, self.class.helper_class
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,367 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'testing_sandbox'
|
3
|
+
|
4
|
+
class TextHelperTest < ActionView::TestCase
|
5
|
+
tests ActionView::Helpers::TextHelper
|
6
|
+
include TestingSandbox
|
7
|
+
|
8
|
+
def setup
|
9
|
+
# This simulates the fact that instance variables are reset every time
|
10
|
+
# a view is rendered. The cycle helper depends on this behavior.
|
11
|
+
@_cycles = nil if (defined? @_cycles)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_simple_format
|
15
|
+
assert_equal "<p></p>", simple_format(nil)
|
16
|
+
|
17
|
+
assert_equal "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>", simple_format("crazy\r\n cross\r platform linebreaks")
|
18
|
+
assert_equal "<p>A paragraph</p>\n\n<p>and another one!</p>", simple_format("A paragraph\n\nand another one!")
|
19
|
+
assert_equal "<p>A paragraph\n<br /> With a newline</p>", simple_format("A paragraph\n With a newline")
|
20
|
+
|
21
|
+
text = "A\nB\nC\nD".freeze
|
22
|
+
assert_equal "<p>A\n<br />B\n<br />C\n<br />D</p>", simple_format(text)
|
23
|
+
|
24
|
+
text = "A\r\n \nB\n\n\r\n\t\nC\nD".freeze
|
25
|
+
assert_equal "<p>A\n<br /> \n<br />B</p>\n\n<p>\t\n<br />C\n<br />D</p>", simple_format(text)
|
26
|
+
|
27
|
+
assert_equal %q(<p class="test">This is a classy test</p>), simple_format("This is a classy test", :class => 'test')
|
28
|
+
assert_equal %Q(<p class="test">para 1</p>\n\n<p class="test">para 2</p>), simple_format("para 1\n\npara 2", :class => 'test')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_truncate
|
32
|
+
assert_equal "Hello World!", truncate("Hello World!", 12)
|
33
|
+
assert_equal "Hello Wor...", truncate("Hello World!!", 12)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_truncate_should_use_default_length_of_30
|
37
|
+
str = "This is a string that will go longer then the default truncate length of 30"
|
38
|
+
assert_equal str[0...27] + "...", truncate(str)
|
39
|
+
end
|
40
|
+
|
41
|
+
if RUBY_VERSION < '1.9.0'
|
42
|
+
def test_truncate_multibyte
|
43
|
+
with_kcode 'none' do
|
44
|
+
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)
|
45
|
+
end
|
46
|
+
with_kcode 'u' do
|
47
|
+
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
|
48
|
+
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", 10)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
def test_truncate_multibyte
|
53
|
+
assert_equal "\354\225\210\353\205\225\355...",
|
54
|
+
truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
|
55
|
+
|
56
|
+
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'),
|
57
|
+
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), 10)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_highlighter
|
62
|
+
assert_equal(
|
63
|
+
"This is a <strong class=\"highlight\">beautiful</strong> morning",
|
64
|
+
highlight("This is a beautiful morning", "beautiful")
|
65
|
+
)
|
66
|
+
|
67
|
+
assert_equal(
|
68
|
+
"This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day",
|
69
|
+
highlight("This is a beautiful morning, but also a beautiful day", "beautiful")
|
70
|
+
)
|
71
|
+
|
72
|
+
assert_equal(
|
73
|
+
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
|
74
|
+
highlight("This is a beautiful morning, but also a beautiful day", "beautiful", '<b>\1</b>')
|
75
|
+
)
|
76
|
+
|
77
|
+
assert_equal(
|
78
|
+
"This text is not changed because we supplied an empty phrase",
|
79
|
+
highlight("This text is not changed because we supplied an empty phrase", nil)
|
80
|
+
)
|
81
|
+
|
82
|
+
assert_equal ' ', highlight(' ', 'blank text is returned verbatim')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_highlighter_with_regexp
|
86
|
+
assert_equal(
|
87
|
+
"This is a <strong class=\"highlight\">beautiful!</strong> morning",
|
88
|
+
highlight("This is a beautiful! morning", "beautiful!")
|
89
|
+
)
|
90
|
+
|
91
|
+
assert_equal(
|
92
|
+
"This is a <strong class=\"highlight\">beautiful! morning</strong>",
|
93
|
+
highlight("This is a beautiful! morning", "beautiful! morning")
|
94
|
+
)
|
95
|
+
|
96
|
+
assert_equal(
|
97
|
+
"This is a <strong class=\"highlight\">beautiful? morning</strong>",
|
98
|
+
highlight("This is a beautiful? morning", "beautiful? morning")
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_highlighting_multiple_phrases_in_one_pass
|
103
|
+
assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), '<em>\1</em>')
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_excerpt
|
107
|
+
assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5))
|
108
|
+
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
|
109
|
+
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
|
110
|
+
assert_nil excerpt("This is a beautiful morning", "day")
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_excerpt_in_borderline_cases
|
114
|
+
assert_equal("", excerpt("", "", 0))
|
115
|
+
assert_equal("a", excerpt("a", "a", 0))
|
116
|
+
assert_equal("...b...", excerpt("abc", "b", 0))
|
117
|
+
assert_equal("abc", excerpt("abc", "b", 1))
|
118
|
+
assert_equal("abc...", excerpt("abcd", "b", 1))
|
119
|
+
assert_equal("...abc", excerpt("zabc", "b", 1))
|
120
|
+
assert_equal("...abc...", excerpt("zabcd", "b", 1))
|
121
|
+
assert_equal("zabcd", excerpt("zabcd", "b", 2))
|
122
|
+
|
123
|
+
# excerpt strips the resulting string before ap-/prepending excerpt_string.
|
124
|
+
# whether this behavior is meaningful when excerpt_string is not to be
|
125
|
+
# appended is questionable.
|
126
|
+
assert_equal("zabcd", excerpt(" zabcd ", "b", 4))
|
127
|
+
assert_equal("...abc...", excerpt("z abc d", "b", 1))
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_excerpt_with_regex
|
131
|
+
assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', 5))
|
132
|
+
assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', 5))
|
133
|
+
end
|
134
|
+
|
135
|
+
if RUBY_VERSION < '1.9'
|
136
|
+
def test_excerpt_with_utf8
|
137
|
+
with_kcode('u') do
|
138
|
+
assert_equal("...\357\254\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
|
139
|
+
end
|
140
|
+
with_kcode('none') do
|
141
|
+
assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
|
142
|
+
end
|
143
|
+
end
|
144
|
+
else
|
145
|
+
def test_excerpt_with_utf8
|
146
|
+
assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', 8))
|
147
|
+
assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_word_wrap
|
152
|
+
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_word_wrap_with_extra_newlines
|
156
|
+
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))
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_pluralization
|
160
|
+
assert_equal("1 count", pluralize(1, "count"))
|
161
|
+
assert_equal("2 counts", pluralize(2, "count"))
|
162
|
+
assert_equal("1 count", pluralize('1', "count"))
|
163
|
+
assert_equal("2 counts", pluralize('2', "count"))
|
164
|
+
assert_equal("1,066 counts", pluralize('1,066', "count"))
|
165
|
+
assert_equal("1.25 counts", pluralize('1.25', "count"))
|
166
|
+
assert_equal("2 counters", pluralize(2, "count", "counters"))
|
167
|
+
assert_equal("0 counters", pluralize(nil, "count", "counters"))
|
168
|
+
assert_equal("2 people", pluralize(2, "person"))
|
169
|
+
assert_equal("10 buffaloes", pluralize(10, "buffalo"))
|
170
|
+
assert_equal("1 berry", pluralize(1, "berry"))
|
171
|
+
assert_equal("12 berries", pluralize(12, "berry"))
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_auto_link_parsing
|
175
|
+
urls = %w(http://www.rubyonrails.com
|
176
|
+
http://www.rubyonrails.com:80
|
177
|
+
http://www.rubyonrails.com/~minam
|
178
|
+
https://www.rubyonrails.com/~minam
|
179
|
+
http://www.rubyonrails.com/~minam/url%20with%20spaces
|
180
|
+
http://www.rubyonrails.com/foo.cgi?something=here
|
181
|
+
http://www.rubyonrails.com/foo.cgi?something=here&and=here
|
182
|
+
http://www.rubyonrails.com/contact;new
|
183
|
+
http://www.rubyonrails.com/contact;new%20with%20spaces
|
184
|
+
http://www.rubyonrails.com/contact;new?with=query&string=params
|
185
|
+
http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
|
186
|
+
http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
|
187
|
+
http://www.mail-archive.com/rails@lists.rubyonrails.org/
|
188
|
+
http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
|
189
|
+
http://en.wikipedia.org/wiki/Sprite_(computer_graphics)
|
190
|
+
http://en.wikipedia.org/wiki/Texas_hold'em
|
191
|
+
)
|
192
|
+
|
193
|
+
urls.each do |url|
|
194
|
+
assert_equal %(<a href="#{url}">#{url}</a>), auto_link(url)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_auto_linking
|
199
|
+
email_raw = 'david@loudthinking.com'
|
200
|
+
email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
|
201
|
+
email2_raw = '+david@loudthinking.com'
|
202
|
+
email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
|
203
|
+
link_raw = 'http://www.rubyonrails.com'
|
204
|
+
link_result = %{<a href="#{link_raw}">#{link_raw}</a>}
|
205
|
+
link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
|
206
|
+
link2_raw = 'www.rubyonrails.com'
|
207
|
+
link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
|
208
|
+
link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
|
209
|
+
link3_result = %{<a href="#{link3_raw}">#{link3_raw}</a>}
|
210
|
+
link4_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
|
211
|
+
link4_result = %{<a href="#{link4_raw}">#{link4_raw}</a>}
|
212
|
+
link5_raw = 'http://foo.example.com:3000/controller/action'
|
213
|
+
link5_result = %{<a href="#{link5_raw}">#{link5_raw}</a>}
|
214
|
+
link6_raw = 'http://foo.example.com:3000/controller/action+pack'
|
215
|
+
link6_result = %{<a href="#{link6_raw}">#{link6_raw}</a>}
|
216
|
+
link7_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
|
217
|
+
link7_result = %{<a href="#{link7_raw}">#{link7_raw}</a>}
|
218
|
+
link8_raw = 'http://foo.example.com:3000/controller/action.html'
|
219
|
+
link8_result = %{<a href="#{link8_raw}">#{link8_raw}</a>}
|
220
|
+
link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
|
221
|
+
link9_result = %{<a href="#{link9_raw}">#{link9_raw}</a>}
|
222
|
+
link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
|
223
|
+
link10_result = %{<a href="#{link10_raw}">#{link10_raw}</a>}
|
224
|
+
|
225
|
+
assert_equal %(hello #{email_result}), auto_link("hello #{email_raw}", :email_addresses)
|
226
|
+
assert_equal %(Go to #{link_result}), auto_link("Go to #{link_raw}", :urls)
|
227
|
+
assert_equal %(Go to #{link_raw}), auto_link("Go to #{link_raw}", :email_addresses)
|
228
|
+
assert_equal %(Go to #{link_result} and say hello to #{email_result}), auto_link("Go to #{link_raw} and say hello to #{email_raw}")
|
229
|
+
assert_equal %(<p>Link #{link_result}</p>), auto_link("<p>Link #{link_raw}</p>")
|
230
|
+
assert_equal %(<p>#{link_result} Link</p>), auto_link("<p>#{link_raw} Link</p>")
|
231
|
+
assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
|
232
|
+
assert_equal %(Go to #{link_result}.), auto_link(%(Go to #{link_raw}.))
|
233
|
+
assert_equal %(<p>Go to #{link_result}, then say hello to #{email_result}.</p>), auto_link(%(<p>Go to #{link_raw}, then say hello to #{email_raw}.</p>))
|
234
|
+
assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls)
|
235
|
+
assert_equal %(Go to #{link2_raw}), auto_link("Go to #{link2_raw}", :email_addresses)
|
236
|
+
assert_equal %(<p>Link #{link2_result}</p>), auto_link("<p>Link #{link2_raw}</p>")
|
237
|
+
assert_equal %(<p>#{link2_result} Link</p>), auto_link("<p>#{link2_raw} Link</p>")
|
238
|
+
assert_equal %(Go to #{link2_result}.), auto_link(%(Go to #{link2_raw}.))
|
239
|
+
assert_equal %(<p>Say hello to #{email_result}, then go to #{link2_result}.</p>), auto_link(%(<p>Say hello to #{email_raw}, then go to #{link2_raw}.</p>))
|
240
|
+
assert_equal %(Go to #{link3_result}), auto_link("Go to #{link3_raw}", :urls)
|
241
|
+
assert_equal %(Go to #{link3_raw}), auto_link("Go to #{link3_raw}", :email_addresses)
|
242
|
+
assert_equal %(<p>Link #{link3_result}</p>), auto_link("<p>Link #{link3_raw}</p>")
|
243
|
+
assert_equal %(<p>#{link3_result} Link</p>), auto_link("<p>#{link3_raw} Link</p>")
|
244
|
+
assert_equal %(Go to #{link3_result}.), auto_link(%(Go to #{link3_raw}.))
|
245
|
+
assert_equal %(<p>Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
|
246
|
+
assert_equal %(<p>Link #{link4_result}</p>), auto_link("<p>Link #{link4_raw}</p>")
|
247
|
+
assert_equal %(<p>#{link4_result} Link</p>), auto_link("<p>#{link4_raw} Link</p>")
|
248
|
+
assert_equal %(<p>#{link5_result} Link</p>), auto_link("<p>#{link5_raw} Link</p>")
|
249
|
+
assert_equal %(<p>#{link6_result} Link</p>), auto_link("<p>#{link6_raw} Link</p>")
|
250
|
+
assert_equal %(<p>#{link7_result} Link</p>), auto_link("<p>#{link7_raw} Link</p>")
|
251
|
+
assert_equal %(Go to #{link8_result}), auto_link("Go to #{link8_raw}", :urls)
|
252
|
+
assert_equal %(Go to #{link8_raw}), auto_link("Go to #{link8_raw}", :email_addresses)
|
253
|
+
assert_equal %(<p>Link #{link8_result}</p>), auto_link("<p>Link #{link8_raw}</p>")
|
254
|
+
assert_equal %(<p>#{link8_result} Link</p>), auto_link("<p>#{link8_raw} Link</p>")
|
255
|
+
assert_equal %(Go to #{link8_result}.), auto_link(%(Go to #{link8_raw}.))
|
256
|
+
assert_equal %(<p>Go to #{link8_result}. seriously, #{link8_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link8_raw}. seriously, #{link8_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
|
257
|
+
assert_equal %(Go to #{link9_result}), auto_link("Go to #{link9_raw}", :urls)
|
258
|
+
assert_equal %(Go to #{link9_raw}), auto_link("Go to #{link9_raw}", :email_addresses)
|
259
|
+
assert_equal %(<p>Link #{link9_result}</p>), auto_link("<p>Link #{link9_raw}</p>")
|
260
|
+
assert_equal %(<p>#{link9_result} Link</p>), auto_link("<p>#{link9_raw} Link</p>")
|
261
|
+
assert_equal %(Go to #{link9_result}.), auto_link(%(Go to #{link9_raw}.))
|
262
|
+
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>))
|
263
|
+
assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>")
|
264
|
+
assert_equal email2_result, auto_link(email2_raw)
|
265
|
+
assert_equal '', auto_link(nil)
|
266
|
+
assert_equal '', auto_link('')
|
267
|
+
assert_equal "#{link_result} #{link_result} #{link_result}", auto_link("#{link_raw} #{link_raw} #{link_raw}")
|
268
|
+
assert_equal '<a href="http://www.rubyonrails.com">Ruby On Rails</a>', auto_link('<a href="http://www.rubyonrails.com">Ruby On Rails</a>')
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_auto_link_at_eol
|
272
|
+
url1 = "http://api.rubyonrails.com/Foo.html"
|
273
|
+
url2 = "http://www.ruby-doc.org/core/Bar.html"
|
274
|
+
|
275
|
+
assert_equal %(<p><a href="#{url1}">#{url1}</a><br /><a href="#{url2}">#{url2}</a><br /></p>), auto_link("<p>#{url1}<br />#{url2}<br /></p>")
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_auto_link_with_block
|
279
|
+
url = "http://api.rubyonrails.com/Foo.html"
|
280
|
+
email = "fantabulous@shiznadel.ic"
|
281
|
+
|
282
|
+
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) }
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_cycle_class
|
286
|
+
value = Cycle.new("one", 2, "3")
|
287
|
+
assert_equal("one", value.to_s)
|
288
|
+
assert_equal("2", value.to_s)
|
289
|
+
assert_equal("3", value.to_s)
|
290
|
+
assert_equal("one", value.to_s)
|
291
|
+
value.reset
|
292
|
+
assert_equal("one", value.to_s)
|
293
|
+
assert_equal("2", value.to_s)
|
294
|
+
assert_equal("3", value.to_s)
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_cycle_class_with_no_arguments
|
298
|
+
assert_raise(ArgumentError) { value = Cycle.new() }
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_cycle
|
302
|
+
assert_equal("one", cycle("one", 2, "3"))
|
303
|
+
assert_equal("2", cycle("one", 2, "3"))
|
304
|
+
assert_equal("3", cycle("one", 2, "3"))
|
305
|
+
assert_equal("one", cycle("one", 2, "3"))
|
306
|
+
assert_equal("2", cycle("one", 2, "3"))
|
307
|
+
assert_equal("3", cycle("one", 2, "3"))
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_cycle_with_no_arguments
|
311
|
+
assert_raise(ArgumentError) { value = cycle() }
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_cycle_resets_with_new_values
|
315
|
+
assert_equal("even", cycle("even", "odd"))
|
316
|
+
assert_equal("odd", cycle("even", "odd"))
|
317
|
+
assert_equal("even", cycle("even", "odd"))
|
318
|
+
assert_equal("1", cycle(1, 2, 3))
|
319
|
+
assert_equal("2", cycle(1, 2, 3))
|
320
|
+
assert_equal("3", cycle(1, 2, 3))
|
321
|
+
assert_equal("1", cycle(1, 2, 3))
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_named_cycles
|
325
|
+
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
326
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
327
|
+
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
|
328
|
+
assert_equal("blue", cycle("red", "blue", :name => "colors"))
|
329
|
+
assert_equal("3", cycle(1, 2, 3, :name => "numbers"))
|
330
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_default_named_cycle
|
334
|
+
assert_equal("1", cycle(1, 2, 3))
|
335
|
+
assert_equal("2", cycle(1, 2, 3, :name => "default"))
|
336
|
+
assert_equal("3", cycle(1, 2, 3))
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_reset_cycle
|
340
|
+
assert_equal("1", cycle(1, 2, 3))
|
341
|
+
assert_equal("2", cycle(1, 2, 3))
|
342
|
+
reset_cycle
|
343
|
+
assert_equal("1", cycle(1, 2, 3))
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_reset_unknown_cycle
|
347
|
+
reset_cycle("colors")
|
348
|
+
end
|
349
|
+
|
350
|
+
def test_recet_named_cycle
|
351
|
+
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
352
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
353
|
+
reset_cycle("numbers")
|
354
|
+
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
355
|
+
assert_equal("blue", cycle("red", "blue", :name => "colors"))
|
356
|
+
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
|
357
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_cycle_no_instance_variable_clashes
|
361
|
+
@cycles = %w{Specialized Fuji Giant}
|
362
|
+
assert_equal("red", cycle("red", "blue"))
|
363
|
+
assert_equal("blue", cycle("red", "blue"))
|
364
|
+
assert_equal("red", cycle("red", "blue"))
|
365
|
+
assert_equal(%w{Specialized Fuji Giant}, @cycles)
|
366
|
+
end
|
367
|
+
end
|