eactionpack 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,544 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env)
|
|
4
|
+
|
|
5
|
+
class UrlHelperTest < ActionView::TestCase
|
|
6
|
+
tests ActionView::Helpers::UrlHelper
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@controller = Class.new do
|
|
10
|
+
attr_accessor :url, :request
|
|
11
|
+
def url_for(options)
|
|
12
|
+
url
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
@controller = @controller.new
|
|
16
|
+
@controller.url = "http://www.example.com"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_url_for_escapes_urls
|
|
20
|
+
@controller.url = "http://www.example.com?a=b&c=d"
|
|
21
|
+
assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd')
|
|
22
|
+
assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd', :escape => true)
|
|
23
|
+
assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd', :escape => false)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_url_for_escapes_url_once
|
|
27
|
+
@controller.url = "http://www.example.com?a=b&c=d"
|
|
28
|
+
assert_equal "http://www.example.com?a=b&c=d", url_for("http://www.example.com?a=b&c=d")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# todo: missing test cases
|
|
32
|
+
def test_button_to_with_straight_url
|
|
33
|
+
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")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_button_to_with_query
|
|
37
|
+
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&q2=v2\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&q2=v2")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_button_to_with_escaped_query
|
|
41
|
+
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&q2=v2\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&q2=v2")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_button_to_with_query_and_no_name
|
|
45
|
+
assert_dom_equal "<form method=\"post\" action=\"http://www.example.com?q1=v1&q2=v2\" class=\"button-to\"><div><input type=\"submit\" value=\"http://www.example.com?q1=v1&q2=v2\" /></div></form>", button_to(nil, "http://www.example.com?q1=v1&q2=v2")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_button_to_with_javascript_confirm
|
|
49
|
+
assert_dom_equal(
|
|
50
|
+
"<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input onclick=\"return confirm('Are you sure?');\" type=\"submit\" value=\"Hello\" /></div></form>",
|
|
51
|
+
button_to("Hello", "http://www.example.com", :confirm => "Are you sure?")
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_button_to_enabled_disabled
|
|
56
|
+
assert_dom_equal(
|
|
57
|
+
"<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
|
|
58
|
+
button_to("Hello", "http://www.example.com", :disabled => false)
|
|
59
|
+
)
|
|
60
|
+
assert_dom_equal(
|
|
61
|
+
"<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input disabled=\"disabled\" type=\"submit\" value=\"Hello\" /></div></form>",
|
|
62
|
+
button_to("Hello", "http://www.example.com", :disabled => true)
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_button_to_with_method_delete
|
|
67
|
+
assert_dom_equal(
|
|
68
|
+
"<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>",
|
|
69
|
+
button_to("Hello", "http://www.example.com", :method => :delete)
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_button_to_with_method_get
|
|
74
|
+
assert_dom_equal(
|
|
75
|
+
"<form method=\"get\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
|
|
76
|
+
button_to("Hello", "http://www.example.com", :method => :get)
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_link_tag_with_straight_url
|
|
81
|
+
assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", "http://www.example.com")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_link_tag_without_host_option
|
|
85
|
+
ActionController::Base.class_eval { attr_accessor :url }
|
|
86
|
+
url = {:controller => 'weblog', :action => 'show'}
|
|
87
|
+
@controller = ActionController::Base.new
|
|
88
|
+
@controller.request = ActionController::TestRequest.new
|
|
89
|
+
@controller.url = ActionController::UrlRewriter.new(@controller.request, url)
|
|
90
|
+
assert_dom_equal(%q{<a href="/weblog/show">Test Link</a>}, link_to('Test Link', url))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_link_tag_with_host_option
|
|
94
|
+
ActionController::Base.class_eval { attr_accessor :url }
|
|
95
|
+
url = {:controller => 'weblog', :action => 'show', :host => 'www.example.com'}
|
|
96
|
+
@controller = ActionController::Base.new
|
|
97
|
+
@controller.request = ActionController::TestRequest.new
|
|
98
|
+
@controller.url = ActionController::UrlRewriter.new(@controller.request, url)
|
|
99
|
+
assert_dom_equal(%q{<a href="http://www.example.com/weblog/show">Test Link</a>}, link_to('Test Link', url))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_link_tag_with_query
|
|
103
|
+
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")
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_link_tag_with_query_and_no_name
|
|
107
|
+
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")
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_link_tag_with_back
|
|
111
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'})
|
|
112
|
+
assert_dom_equal "<a href=\"http://www.example.com/referer\">go back</a>", link_to('go back', :back)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_link_tag_with_back_and_no_referer
|
|
116
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {})
|
|
117
|
+
assert_dom_equal "<a href=\"javascript:history.back()\">go back</a>", link_to('go back', :back)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_link_tag_with_back
|
|
121
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'})
|
|
122
|
+
assert_dom_equal "<a href=\"http://www.example.com/referer\">go back</a>", link_to('go back', :back)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_link_tag_with_back_and_no_referer
|
|
126
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {})
|
|
127
|
+
assert_dom_equal "<a href=\"javascript:history.back()\">go back</a>", link_to('go back', :back)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_link_tag_with_img
|
|
131
|
+
assert_dom_equal "<a href=\"http://www.example.com\"><img src='/favicon.jpg' /></a>", link_to("<img src='/favicon.jpg' />", "http://www.example.com")
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_link_with_nil_html_options
|
|
135
|
+
assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_link_tag_with_custom_onclick
|
|
139
|
+
assert_dom_equal "<a href=\"http://www.example.com\" onclick=\"alert('yay!')\">Hello</a>", link_to("Hello", "http://www.example.com", :onclick => "alert('yay!')")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def test_link_tag_with_javascript_confirm
|
|
143
|
+
assert_dom_equal(
|
|
144
|
+
"<a href=\"http://www.example.com\" onclick=\"return confirm('Are you sure?');\">Hello</a>",
|
|
145
|
+
link_to("Hello", "http://www.example.com", :confirm => "Are you sure?")
|
|
146
|
+
)
|
|
147
|
+
assert_dom_equal(
|
|
148
|
+
"<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure, can you?');\">Hello</a>",
|
|
149
|
+
link_to("Hello", "http://www.example.com", :confirm => "You can't possibly be sure, can you?")
|
|
150
|
+
)
|
|
151
|
+
assert_dom_equal(
|
|
152
|
+
"<a href=\"http://www.example.com\" onclick=\"return confirm('You can\\'t possibly be sure,\\n can you?');\">Hello</a>",
|
|
153
|
+
link_to("Hello", "http://www.example.com", :confirm => "You can't possibly be sure,\n can you?")
|
|
154
|
+
)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_link_tag_with_popup
|
|
158
|
+
assert_dom_equal(
|
|
159
|
+
"<a href=\"http://www.example.com\" onclick=\"window.open(this.href);return false;\">Hello</a>",
|
|
160
|
+
link_to("Hello", "http://www.example.com", :popup => true)
|
|
161
|
+
)
|
|
162
|
+
assert_dom_equal(
|
|
163
|
+
"<a href=\"http://www.example.com\" onclick=\"window.open(this.href);return false;\">Hello</a>",
|
|
164
|
+
link_to("Hello", "http://www.example.com", :popup => 'true')
|
|
165
|
+
)
|
|
166
|
+
assert_dom_equal(
|
|
167
|
+
"<a href=\"http://www.example.com\" onclick=\"window.open(this.href,'window_name','width=300,height=300');return false;\">Hello</a>",
|
|
168
|
+
link_to("Hello", "http://www.example.com", :popup => ['window_name', 'width=300,height=300'])
|
|
169
|
+
)
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def test_link_tag_with_popup_and_javascript_confirm
|
|
173
|
+
assert_dom_equal(
|
|
174
|
+
"<a href=\"http://www.example.com\" onclick=\"if (confirm('Fo\\' sho\\'?')) { window.open(this.href); };return false;\">Hello</a>",
|
|
175
|
+
link_to("Hello", "http://www.example.com", { :popup => true, :confirm => "Fo' sho'?" })
|
|
176
|
+
)
|
|
177
|
+
assert_dom_equal(
|
|
178
|
+
"<a href=\"http://www.example.com\" onclick=\"if (confirm('Are you serious?')) { window.open(this.href,'window_name','width=300,height=300'); };return false;\">Hello</a>",
|
|
179
|
+
link_to("Hello", "http://www.example.com", { :popup => ['window_name', 'width=300,height=300'], :confirm => "Are you serious?" })
|
|
180
|
+
)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_link_tag_using_post_javascript
|
|
184
|
+
assert_dom_equal(
|
|
185
|
+
"<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>",
|
|
186
|
+
link_to("Hello", "http://www.example.com", :method => :post)
|
|
187
|
+
)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def test_link_tag_using_delete_javascript
|
|
191
|
+
assert_dom_equal(
|
|
192
|
+
"<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;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>",
|
|
193
|
+
link_to("Destroy", "http://www.example.com", :method => :delete)
|
|
194
|
+
)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_link_tag_using_delete_javascript_and_href
|
|
198
|
+
assert_dom_equal(
|
|
199
|
+
"<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>",
|
|
200
|
+
link_to("Destroy", "http://www.example.com", :method => :delete, :href => '#')
|
|
201
|
+
)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def test_link_tag_using_post_javascript_and_confirm
|
|
205
|
+
assert_dom_equal(
|
|
206
|
+
"<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>",
|
|
207
|
+
link_to("Hello", "http://www.example.com", :method => :post, :confirm => "Are you serious?")
|
|
208
|
+
)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_link_tag_using_post_javascript_and_popup
|
|
212
|
+
assert_raises(ActionView::ActionViewError) { link_to("Hello", "http://www.example.com", :popup => true, :method => :post, :confirm => "Are you serious?") }
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def test_link_to_unless
|
|
216
|
+
assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog")
|
|
217
|
+
assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_unless(false, "Listing", :action => "list", :controller => "weblog")
|
|
218
|
+
assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1)
|
|
219
|
+
assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name, options, html_options|
|
|
220
|
+
"<strong>#{name}</strong>"
|
|
221
|
+
}
|
|
222
|
+
assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name|
|
|
223
|
+
"<strong>#{name}</strong>"
|
|
224
|
+
}
|
|
225
|
+
assert_equal "test", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) {
|
|
226
|
+
"test"
|
|
227
|
+
}
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def test_link_to_if
|
|
231
|
+
assert_equal "Showing", link_to_if(false, "Showing", :action => "show", :controller => "weblog")
|
|
232
|
+
assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_if(true, "Listing", :action => "list", :controller => "weblog")
|
|
233
|
+
assert_equal "Showing", link_to_if(false, "Showing", :action => "show", :controller => "weblog", :id => 1)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def test_link_unless_current
|
|
237
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show")
|
|
238
|
+
@controller.url = "http://www.example.com/weblog/show"
|
|
239
|
+
assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
|
|
240
|
+
assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show")
|
|
241
|
+
|
|
242
|
+
@controller.request = RequestMock.new("http://www.example.com/weblog/show")
|
|
243
|
+
@controller.url = "http://www.example.com/weblog/list"
|
|
244
|
+
assert_equal "<a href=\"http://www.example.com/weblog/list\">Listing</a>",
|
|
245
|
+
link_to_unless_current("Listing", :action => "list", :controller => "weblog")
|
|
246
|
+
assert_equal "<a href=\"http://www.example.com/weblog/list\">Listing</a>",
|
|
247
|
+
link_to_unless_current("Listing", "http://www.example.com/weblog/list")
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def test_mail_to
|
|
251
|
+
assert_dom_equal "<a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>", mail_to("david@loudthinking.com")
|
|
252
|
+
assert_dom_equal "<a href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>", mail_to("david@loudthinking.com", "David Heinemeier Hansson")
|
|
253
|
+
assert_dom_equal(
|
|
254
|
+
"<a class=\"admin\" href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>",
|
|
255
|
+
mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin")
|
|
256
|
+
)
|
|
257
|
+
assert_equal mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin"),
|
|
258
|
+
mail_to("david@loudthinking.com", "David Heinemeier Hansson", :class => "admin")
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def test_mail_to_with_javascript
|
|
262
|
+
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")
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def test_mail_with_options
|
|
266
|
+
assert_dom_equal(
|
|
267
|
+
%(<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>),
|
|
268
|
+
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.")
|
|
269
|
+
)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def test_mail_to_with_img
|
|
273
|
+
assert_dom_equal %(<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>), mail_to('feedback@example.com', '<img src="/feedback.png" />')
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
def test_mail_to_with_hex
|
|
277
|
+
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")
|
|
278
|
+
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")
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def test_mail_to_with_replace_options
|
|
282
|
+
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)")
|
|
283
|
+
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)")
|
|
284
|
+
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)")
|
|
285
|
+
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)")
|
|
286
|
+
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)")
|
|
287
|
+
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%6d%65%28%61%74%29%64%6f%6d%61%69%6e%28%64%6f%74%29%63%6f%6d%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", nil, :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def protect_against_forgery?
|
|
291
|
+
false
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
class UrlHelperWithControllerTest < ActionView::TestCase
|
|
296
|
+
class UrlHelperController < ActionController::Base
|
|
297
|
+
self.view_paths = [ "#{File.dirname(__FILE__)}/../fixtures/" ]
|
|
298
|
+
|
|
299
|
+
def self.controller_path; 'url_helper_with_controller' end
|
|
300
|
+
|
|
301
|
+
def show_url_for
|
|
302
|
+
render :inline => "<%= url_for :controller => 'url_helper_with_controller', :action => 'show_url_for' %>"
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def show_named_route
|
|
306
|
+
render :inline => "<%= show_named_route_#{params[:kind]} %>"
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def nil_url_for
|
|
310
|
+
render :inline => '<%= url_for(nil) %>'
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def rescue_action(e) raise e end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
tests ActionView::Helpers::UrlHelper
|
|
317
|
+
|
|
318
|
+
def setup
|
|
319
|
+
@request = ActionController::TestRequest.new
|
|
320
|
+
@response = ActionController::TestResponse.new
|
|
321
|
+
@controller = UrlHelperController.new
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def test_url_for_shows_only_path
|
|
325
|
+
get :show_url_for
|
|
326
|
+
assert_equal '/url_helper_with_controller/show_url_for', @response.body
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def test_named_route_url_shows_host_and_path
|
|
330
|
+
with_url_helper_routing do
|
|
331
|
+
get :show_named_route, :kind => 'url'
|
|
332
|
+
assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
def test_named_route_path_shows_only_path
|
|
337
|
+
with_url_helper_routing do
|
|
338
|
+
get :show_named_route, :kind => 'path'
|
|
339
|
+
assert_equal '/url_helper_with_controller/show_named_route', @response.body
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def test_url_for_nil_returns_current_path
|
|
344
|
+
get :nil_url_for
|
|
345
|
+
assert_equal '/url_helper_with_controller/nil_url_for', @response.body
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
protected
|
|
349
|
+
def with_url_helper_routing
|
|
350
|
+
with_routing do |set|
|
|
351
|
+
set.draw do |map|
|
|
352
|
+
map.show_named_route 'url_helper_with_controller/show_named_route', :controller => 'url_helper_with_controller', :action => 'show_named_route'
|
|
353
|
+
end
|
|
354
|
+
yield
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase
|
|
360
|
+
class TasksController < ActionController::Base
|
|
361
|
+
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
|
|
362
|
+
|
|
363
|
+
def self.controller_path; 'tasks' end
|
|
364
|
+
|
|
365
|
+
def index
|
|
366
|
+
render_default
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
def show
|
|
370
|
+
render_default
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def rescue_action(e) raise e end
|
|
374
|
+
|
|
375
|
+
protected
|
|
376
|
+
def render_default
|
|
377
|
+
render :inline =>
|
|
378
|
+
"<%= link_to_unless_current(\"tasks\", tasks_path) %>\n" +
|
|
379
|
+
"<%= link_to_unless_current(\"tasks\", tasks_url) %>"
|
|
380
|
+
end
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
tests ActionView::Helpers::UrlHelper
|
|
384
|
+
|
|
385
|
+
def setup
|
|
386
|
+
@request = ActionController::TestRequest.new
|
|
387
|
+
@response = ActionController::TestResponse.new
|
|
388
|
+
@controller = TasksController.new
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
def test_link_to_unless_current_to_current
|
|
392
|
+
with_restful_routing do
|
|
393
|
+
get :index
|
|
394
|
+
assert_equal "tasks\ntasks", @response.body
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def test_link_to_unless_current_shows_link
|
|
399
|
+
with_restful_routing do
|
|
400
|
+
get :show, :id => 1
|
|
401
|
+
assert_equal "<a href=\"/tasks\">tasks</a>\n" +
|
|
402
|
+
"<a href=\"#{@request.protocol}#{@request.host_with_port}/tasks\">tasks</a>",
|
|
403
|
+
@response.body
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
protected
|
|
408
|
+
def with_restful_routing
|
|
409
|
+
with_routing do |set|
|
|
410
|
+
set.draw do |map|
|
|
411
|
+
map.resources :tasks
|
|
412
|
+
end
|
|
413
|
+
yield
|
|
414
|
+
end
|
|
415
|
+
end
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class Workshop
|
|
420
|
+
attr_accessor :id, :new_record
|
|
421
|
+
|
|
422
|
+
def initialize(id, new_record)
|
|
423
|
+
@id, @new_record = id, new_record
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
def new_record?
|
|
427
|
+
@new_record
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def to_s
|
|
431
|
+
id.to_s
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
class Session
|
|
436
|
+
attr_accessor :id, :workshop_id, :new_record
|
|
437
|
+
|
|
438
|
+
def initialize(id, new_record)
|
|
439
|
+
@id, @new_record = id, new_record
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
def new_record?
|
|
443
|
+
@new_record
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
def to_s
|
|
447
|
+
id.to_s
|
|
448
|
+
end
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
class PolymorphicControllerTest < ActionView::TestCase
|
|
452
|
+
class WorkshopsController < ActionController::Base
|
|
453
|
+
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
|
|
454
|
+
|
|
455
|
+
def self.controller_path; 'workshops' end
|
|
456
|
+
|
|
457
|
+
def index
|
|
458
|
+
@workshop = Workshop.new(1, true)
|
|
459
|
+
render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>"
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
def show
|
|
463
|
+
@workshop = Workshop.new(params[:id], false)
|
|
464
|
+
render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>"
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
def rescue_action(e) raise e end
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
class SessionsController < ActionController::Base
|
|
471
|
+
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
|
|
472
|
+
|
|
473
|
+
def self.controller_path; 'sessions' end
|
|
474
|
+
|
|
475
|
+
def index
|
|
476
|
+
@workshop = Workshop.new(params[:workshop_id], false)
|
|
477
|
+
@session = Session.new(1, true)
|
|
478
|
+
render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>"
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
def show
|
|
482
|
+
@workshop = Workshop.new(params[:workshop_id], false)
|
|
483
|
+
@session = Session.new(params[:id], false)
|
|
484
|
+
render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>"
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
def rescue_action(e) raise e end
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
tests ActionView::Helpers::UrlHelper
|
|
491
|
+
|
|
492
|
+
def setup
|
|
493
|
+
@request = ActionController::TestRequest.new
|
|
494
|
+
@response = ActionController::TestResponse.new
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
def test_new_resource
|
|
498
|
+
@controller = WorkshopsController.new
|
|
499
|
+
|
|
500
|
+
with_restful_routing do
|
|
501
|
+
get :index
|
|
502
|
+
assert_equal "/workshops\n<a href=\"/workshops\">Workshop</a>", @response.body
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
def test_existing_resource
|
|
507
|
+
@controller = WorkshopsController.new
|
|
508
|
+
|
|
509
|
+
with_restful_routing do
|
|
510
|
+
get :show, :id => 1
|
|
511
|
+
assert_equal "/workshops/1\n<a href=\"/workshops/1\">Workshop</a>", @response.body
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
def test_new_nested_resource
|
|
516
|
+
@controller = SessionsController.new
|
|
517
|
+
|
|
518
|
+
with_restful_routing do
|
|
519
|
+
get :index, :workshop_id => 1
|
|
520
|
+
assert_equal "/workshops/1/sessions\n<a href=\"/workshops/1/sessions\">Session</a>", @response.body
|
|
521
|
+
end
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
def test_existing_nested_resource
|
|
525
|
+
@controller = SessionsController.new
|
|
526
|
+
|
|
527
|
+
with_restful_routing do
|
|
528
|
+
get :show, :workshop_id => 1, :id => 1
|
|
529
|
+
assert_equal "/workshops/1/sessions/1\n<a href=\"/workshops/1/sessions/1\">Session</a>", @response.body
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
protected
|
|
534
|
+
def with_restful_routing
|
|
535
|
+
with_routing do |set|
|
|
536
|
+
set.draw do |map|
|
|
537
|
+
map.resources :workshops do |w|
|
|
538
|
+
w.resources :sessions
|
|
539
|
+
end
|
|
540
|
+
end
|
|
541
|
+
yield
|
|
542
|
+
end
|
|
543
|
+
end
|
|
544
|
+
end
|