actionpack 1.13.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +1400 -20
- data/MIT-LICENSE +1 -1
- data/README +5 -5
- data/RUNNING_UNIT_TESTS +4 -5
- data/Rakefile +5 -6
- data/install.rb +2 -2
- data/lib/action_controller.rb +11 -15
- data/lib/action_controller/assertions.rb +12 -25
- data/lib/action_controller/assertions/dom_assertions.rb +18 -4
- data/lib/action_controller/assertions/model_assertions.rb +8 -1
- data/lib/action_controller/assertions/response_assertions.rb +35 -12
- data/lib/action_controller/assertions/routing_assertions.rb +56 -12
- data/lib/action_controller/assertions/selector_assertions.rb +105 -38
- data/lib/action_controller/assertions/tag_assertions.rb +28 -15
- data/lib/action_controller/base.rb +318 -250
- data/lib/action_controller/benchmarking.rb +33 -29
- data/lib/action_controller/caching.rb +130 -64
- data/lib/action_controller/cgi_ext.rb +16 -0
- data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
- data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
- data/lib/action_controller/cgi_ext/session.rb +73 -0
- data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
- data/lib/action_controller/cgi_process.rb +34 -57
- data/lib/action_controller/components.rb +19 -36
- data/lib/action_controller/cookies.rb +10 -9
- data/lib/action_controller/dispatcher.rb +195 -0
- data/lib/action_controller/filters.rb +35 -34
- data/lib/action_controller/flash.rb +30 -35
- data/lib/action_controller/helpers.rb +121 -47
- data/lib/action_controller/http_authentication.rb +126 -0
- data/lib/action_controller/integration.rb +105 -101
- data/lib/action_controller/layout.rb +59 -47
- data/lib/action_controller/mime_responds.rb +57 -68
- data/lib/action_controller/mime_type.rb +43 -80
- data/lib/action_controller/mime_types.rb +20 -0
- data/lib/action_controller/polymorphic_routes.rb +88 -0
- data/lib/action_controller/record_identifier.rb +91 -0
- data/lib/action_controller/request.rb +553 -88
- data/lib/action_controller/request_forgery_protection.rb +126 -0
- data/lib/action_controller/request_profiler.rb +138 -0
- data/lib/action_controller/rescue.rb +185 -69
- data/lib/action_controller/resources.rb +211 -172
- data/lib/action_controller/response.rb +49 -8
- data/lib/action_controller/routing.rb +359 -236
- data/lib/action_controller/routing_optimisation.rb +119 -0
- data/lib/action_controller/session/active_record_store.rb +3 -2
- data/lib/action_controller/session/cookie_store.rb +161 -0
- data/lib/action_controller/session/mem_cache_store.rb +9 -16
- data/lib/action_controller/session_management.rb +17 -8
- data/lib/action_controller/streaming.rb +6 -3
- data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
- data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
- data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
- data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
- data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
- data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
- data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
- data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
- data/lib/action_controller/test_case.rb +53 -0
- data/lib/action_controller/test_process.rb +59 -46
- data/lib/action_controller/url_rewriter.rb +48 -24
- data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
- data/lib/action_controller/verification.rb +27 -21
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +4 -4
- data/lib/action_view.rb +2 -3
- data/lib/action_view/base.rb +218 -63
- data/lib/action_view/compiled_templates.rb +1 -2
- data/lib/action_view/helpers/active_record_helper.rb +35 -17
- data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
- data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
- data/lib/action_view/helpers/benchmark_helper.rb +12 -5
- data/lib/action_view/helpers/cache_helper.rb +29 -0
- data/lib/action_view/helpers/capture_helper.rb +97 -63
- data/lib/action_view/helpers/date_helper.rb +295 -35
- data/lib/action_view/helpers/debug_helper.rb +6 -2
- data/lib/action_view/helpers/form_helper.rb +354 -111
- data/lib/action_view/helpers/form_options_helper.rb +171 -109
- data/lib/action_view/helpers/form_tag_helper.rb +332 -76
- data/lib/action_view/helpers/javascript_helper.rb +35 -11
- data/lib/action_view/helpers/javascripts/controls.js +484 -354
- data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
- data/lib/action_view/helpers/javascripts/effects.js +396 -364
- data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
- data/lib/action_view/helpers/number_helper.rb +84 -60
- data/lib/action_view/helpers/prototype_helper.rb +419 -43
- data/lib/action_view/helpers/record_identification_helper.rb +20 -0
- data/lib/action_view/helpers/record_tag_helper.rb +59 -0
- data/lib/action_view/helpers/sanitize_helper.rb +223 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
- data/lib/action_view/helpers/tag_helper.rb +69 -39
- data/lib/action_view/helpers/text_helper.rb +221 -148
- data/lib/action_view/helpers/url_helper.rb +283 -165
- data/lib/action_view/partials.rb +134 -62
- data/lib/action_view/template_error.rb +4 -12
- data/lib/actionpack.rb +1 -0
- data/test/abstract_unit.rb +21 -1
- data/test/action_view_test.rb +26 -0
- data/test/active_record_unit.rb +12 -20
- data/test/activerecord/active_record_store_test.rb +2 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
- data/test/controller/action_pack_assertions_test.rb +21 -152
- data/test/controller/addresses_render_test.rb +2 -7
- data/test/controller/assert_select_test.rb +120 -14
- data/test/controller/base_test.rb +11 -13
- data/test/controller/caching_test.rb +125 -5
- data/test/controller/capture_test.rb +23 -16
- data/test/controller/cgi_test.rb +66 -391
- data/test/controller/components_test.rb +31 -42
- data/test/controller/content_type_test.rb +1 -1
- data/test/controller/cookie_test.rb +42 -14
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
- data/test/controller/dispatcher_test.rb +123 -0
- data/test/controller/fake_models.rb +5 -0
- data/test/controller/filters_test.rb +44 -7
- data/test/controller/flash_test.rb +46 -2
- data/test/controller/fragment_store_setting_test.rb +10 -8
- data/test/controller/helper_test.rb +19 -2
- data/test/controller/html-scanner/document_test.rb +124 -0
- data/test/controller/html-scanner/node_test.rb +69 -0
- data/test/controller/html-scanner/sanitizer_test.rb +250 -0
- data/test/controller/html-scanner/tag_node_test.rb +239 -0
- data/test/controller/html-scanner/text_node_test.rb +51 -0
- data/test/controller/html-scanner/tokenizer_test.rb +125 -0
- data/test/controller/http_authentication_test.rb +54 -0
- data/test/controller/integration_test.rb +12 -26
- data/test/controller/layout_test.rb +64 -12
- data/test/controller/mime_responds_test.rb +193 -38
- data/test/controller/mime_type_test.rb +30 -8
- data/test/controller/new_render_test.rb +104 -22
- data/test/controller/polymorphic_routes_test.rb +98 -0
- data/test/controller/record_identifier_test.rb +103 -0
- data/test/controller/redirect_test.rb +120 -18
- data/test/controller/render_test.rb +195 -45
- data/test/controller/request_forgery_protection_test.rb +217 -0
- data/test/controller/request_test.rb +545 -27
- data/test/controller/rescue_test.rb +501 -0
- data/test/controller/resources_test.rb +258 -132
- data/test/controller/routing_test.rb +502 -106
- data/test/controller/selector_test.rb +5 -5
- data/test/controller/send_file_test.rb +17 -7
- data/test/controller/session/cookie_store_test.rb +246 -0
- data/test/controller/session/mem_cache_store_test.rb +182 -0
- data/test/controller/session_fixation_test.rb +8 -11
- data/test/controller/session_management_test.rb +7 -7
- data/test/controller/test_test.rb +150 -38
- data/test/controller/url_rewriter_test.rb +87 -12
- data/test/controller/verification_test.rb +11 -0
- data/test/controller/view_paths_test.rb +137 -0
- data/test/controller/webservice_test.rb +11 -75
- data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
- data/test/fixtures/db_definitions/sqlite.sql +2 -1
- data/test/fixtures/developer.rb +2 -0
- data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
- data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
- data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
- data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
- data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
- data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/bracketed_param +5 -0
- data/test/fixtures/override/test/hello_world.erb +1 -0
- data/test/fixtures/override2/layouts/test/sub.erb +1 -0
- data/test/fixtures/post_test/layouts/post.html.erb +1 -0
- data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
- data/test/fixtures/post_test/post/index.html.erb +1 -0
- data/test/fixtures/post_test/post/index.iphone.erb +1 -0
- data/test/fixtures/post_test/super_post/index.html.erb +1 -0
- data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
- data/test/fixtures/public/404.html +1 -0
- data/test/fixtures/public/500.html +1 -0
- data/test/fixtures/public/javascripts/application.js +0 -1
- data/test/fixtures/public/javascripts/bank.js +1 -0
- data/test/fixtures/public/javascripts/robber.js +1 -0
- data/test/fixtures/public/stylesheets/bank.css +1 -0
- data/test/fixtures/public/stylesheets/robber.css +1 -0
- data/test/fixtures/replies.yml +2 -0
- data/test/fixtures/reply.rb +2 -1
- data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
- data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
- data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
- data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
- data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
- data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
- data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
- data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
- data/test/fixtures/test/_hash_greeting.erb +1 -0
- data/test/fixtures/test/_hash_object.erb +2 -0
- data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
- data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
- data/test/fixtures/test/_partial.erb +1 -0
- data/test/fixtures/test/_partial.html.erb +1 -0
- data/test/fixtures/test/_partial.js.erb +1 -0
- data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
- data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
- data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
- data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
- data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
- data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
- data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
- data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
- data/test/fixtures/test/content_for_concatenated.erb +3 -0
- data/test/fixtures/test/content_for_with_parameter.erb +2 -0
- data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
- data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.builder +1 -0
- data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
- data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
- data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
- data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
- data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
- data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
- data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
- data/test/fixtures/test/list.erb +1 -0
- data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
- data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
- data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
- data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
- data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
- data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
- data/test/fixtures/topic.rb +1 -1
- data/test/template/active_record_helper_test.rb +67 -20
- data/test/template/asset_tag_helper_test.rb +222 -54
- data/test/template/atom_feed_helper_test.rb +101 -0
- data/test/template/benchmark_helper_test.rb +2 -2
- data/test/template/compiled_templates_test.rb +76 -32
- data/test/template/date_helper_test.rb +125 -9
- data/test/template/form_helper_test.rb +326 -33
- data/test/template/form_options_helper_test.rb +822 -15
- data/test/template/form_tag_helper_test.rb +96 -30
- data/test/template/javascript_helper_test.rb +61 -13
- data/test/template/number_helper_test.rb +12 -11
- data/test/template/prototype_helper_test.rb +185 -24
- data/test/template/sanitize_helper_test.rb +49 -0
- data/test/template/scriptaculous_helper_test.rb +9 -3
- data/test/template/tag_helper_test.rb +13 -2
- data/test/template/text_helper_test.rb +38 -52
- data/test/template/url_helper_test.rb +216 -46
- metadata +144 -116
- data/examples/.htaccess +0 -24
- data/examples/address_book/index.rhtml +0 -33
- data/examples/address_book/layout.rhtml +0 -8
- data/examples/address_book_controller.cgi +0 -9
- data/examples/address_book_controller.fcgi +0 -6
- data/examples/address_book_controller.rb +0 -52
- data/examples/address_book_controller.rbx +0 -4
- data/examples/benchmark.rb +0 -52
- data/examples/benchmark_with_ar.fcgi +0 -89
- data/examples/blog_controller.cgi +0 -53
- data/examples/debate/index.rhtml +0 -14
- data/examples/debate/new_topic.rhtml +0 -22
- data/examples/debate/topic.rhtml +0 -32
- data/examples/debate_controller.cgi +0 -57
- data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
- data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
- data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
- data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
- data/lib/action_controller/deprecated_dependencies.rb +0 -65
- data/lib/action_controller/deprecated_redirects.rb +0 -17
- data/lib/action_controller/deprecated_request_methods.rb +0 -34
- data/lib/action_controller/macros/auto_complete.rb +0 -53
- data/lib/action_controller/macros/in_place_editing.rb +0 -33
- data/lib/action_controller/pagination.rb +0 -408
- data/lib/action_controller/scaffolding.rb +0 -189
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
- data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
- data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
- data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
- data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
- data/lib/action_controller/vendor/xml_node.rb +0 -97
- data/lib/action_view/helpers/deprecated_helper.rb +0 -37
- data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
- data/lib/action_view/helpers/pagination_helper.rb +0 -86
- data/test/activerecord/active_record_assertions_test.rb +0 -92
- data/test/activerecord/pagination_test.rb +0 -165
- data/test/controller/deprecated_instance_variables_test.rb +0 -48
- data/test/controller/raw_post_test.rb +0 -68
- data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
- data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
- data/test/fixtures/test/_hash_object.rhtml +0 -1
- data/test/fixtures/test/list.rhtml +0 -1
- data/test/template/deprecated_helper_test.rb +0 -36
- data/test/template/deprecated_instance_variables_test.rb +0 -43
- data/test/template/java_script_macros_helper_test.rb +0 -109
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= greeting %>: <%= hash_greeting[:first_name] %>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
invalid
|
@@ -0,0 +1 @@
|
|
1
|
+
partial html
|
@@ -0,0 +1 @@
|
|
1
|
+
partial js
|
@@ -0,0 +1 @@
|
|
1
|
+
Inside from partial (<%= name %>)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render(:layout => "layout_for_partial", :partial => "partial_for_use_in_layout", :locals => { :name => "David" }) %>
|
File without changes
|
File without changes
|
data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb}
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
formatted html erb
|
@@ -0,0 +1 @@
|
|
1
|
+
xml.test 'failed'
|
@@ -0,0 +1 @@
|
|
1
|
+
<test>passed formatted html erb</test>
|
@@ -0,0 +1 @@
|
|
1
|
+
<test>passed formatted xml erb</test>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb}
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @test_unchanged = 'goodbye' %><%= render :partial => 'customer', :collection => @customers %><%= @test_unchanged %>
|
data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb}
RENAMED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<% render(:layout => "layout_for_partial", :locals => { :name => "David" }) do %>Inside from block<% end %>
|
data/test/fixtures/topic.rb
CHANGED
@@ -1,11 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
|
3
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_helper'
|
4
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
|
5
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
|
6
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/url_helper'
|
7
|
-
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_tag_helper'
|
8
|
-
# require File.dirname(__FILE__) + '/../../lib/action_view/helpers/active_record_helper'
|
1
|
+
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
9
2
|
|
10
3
|
class ActiveRecordHelperTest < Test::Unit::TestCase
|
11
4
|
include ActionView::Helpers::FormHelper
|
@@ -35,7 +28,16 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
35
28
|
@post = Post.new
|
36
29
|
def @post.errors
|
37
30
|
Class.new {
|
38
|
-
def on(field)
|
31
|
+
def on(field)
|
32
|
+
case field.to_s
|
33
|
+
when "author_name"
|
34
|
+
"can't be empty"
|
35
|
+
when "body"
|
36
|
+
true
|
37
|
+
else
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
39
41
|
def empty?() false end
|
40
42
|
def count() 1 end
|
41
43
|
def full_messages() [ "Author name can't be empty" ] end
|
@@ -59,7 +61,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
59
61
|
@post.secret = 1
|
60
62
|
@post.written_on = Date.new(2004, 6, 15)
|
61
63
|
end
|
62
|
-
|
64
|
+
|
63
65
|
def setup_user
|
64
66
|
@user = User.new
|
65
67
|
def @user.errors
|
@@ -89,8 +91,10 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
89
91
|
setup_post
|
90
92
|
setup_user
|
91
93
|
|
94
|
+
@response = ActionController::TestResponse.new
|
95
|
+
|
92
96
|
@controller = Object.new
|
93
|
-
def @controller.url_for(options
|
97
|
+
def @controller.url_for(options)
|
94
98
|
options = options.symbolize_keys
|
95
99
|
|
96
100
|
[options[:action], options[:id].to_param].compact.join('/')
|
@@ -102,7 +106,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
102
106
|
%(<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />), input("post", "title")
|
103
107
|
)
|
104
108
|
end
|
105
|
-
|
109
|
+
|
106
110
|
def test_text_area_with_errors
|
107
111
|
assert_dom_equal(
|
108
112
|
%(<div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div>),
|
@@ -116,7 +120,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
116
120
|
text_field("post", "author_name")
|
117
121
|
)
|
118
122
|
end
|
119
|
-
|
123
|
+
|
120
124
|
def test_form_with_string
|
121
125
|
assert_dom_equal(
|
122
126
|
%(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
|
@@ -136,7 +140,14 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
136
140
|
form("post")
|
137
141
|
)
|
138
142
|
end
|
139
|
-
|
143
|
+
|
144
|
+
def test_form_with_action_option
|
145
|
+
@response.body = form("post", :action => "sign")
|
146
|
+
assert_select "form[action=sign]" do |form|
|
147
|
+
assert_select "input[type=submit][value=Sign]"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
140
151
|
def test_form_with_date
|
141
152
|
silence_warnings do
|
142
153
|
def Post.content_columns() [ Column.new(:date, "written_on", "Written on") ] end
|
@@ -159,26 +170,35 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
159
170
|
form("post")
|
160
171
|
)
|
161
172
|
end
|
162
|
-
|
173
|
+
|
163
174
|
def test_error_for_block
|
164
175
|
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post")
|
165
176
|
assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
|
166
177
|
assert_equal %(<div id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => nil, :id => "errorDeathById", :header_tag => "h1")
|
167
178
|
assert_equal %(<div class="errorDeathByClass"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => nil, :header_tag => "h1")
|
168
179
|
end
|
169
|
-
|
180
|
+
|
170
181
|
def test_error_messages_for_handles_nil
|
171
182
|
assert_equal "", error_messages_for("notthere")
|
172
183
|
end
|
173
|
-
|
184
|
+
|
174
185
|
def test_error_message_on_handles_nil
|
175
186
|
assert_equal "", error_message_on("notthere", "notthere")
|
176
187
|
end
|
177
|
-
|
188
|
+
|
178
189
|
def test_error_message_on
|
179
|
-
|
190
|
+
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(:post, :author_name)
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_error_message_on_no_instance_variable
|
194
|
+
other_post = @post
|
195
|
+
assert_dom_equal "<div class=\"formError\">can't be empty</div>", error_message_on(other_post, :author_name)
|
180
196
|
end
|
181
197
|
|
198
|
+
def test_error_message_on_should_use_options
|
199
|
+
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, "before", "after", "differentError")
|
200
|
+
end
|
201
|
+
|
182
202
|
def test_error_messages_for_many_objects
|
183
203
|
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")
|
184
204
|
|
@@ -193,8 +213,35 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
|
193
213
|
|
194
214
|
# any default works too
|
195
215
|
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this monkey from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "monkey")
|
196
|
-
end
|
197
216
|
|
217
|
+
# should space object name
|
218
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this chunky bacon from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :object_name => "chunky_bacon")
|
219
|
+
|
220
|
+
# hide header and explanation messages with nil or empty string
|
221
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => nil, :message => "")
|
222
|
+
|
223
|
+
# override header and explanation messages
|
224
|
+
header_message = "Yikes! Some errors"
|
225
|
+
message = "Please fix the following fields and resubmit:"
|
226
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>#{header_message}</h2><p>#{message}</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for(:user, :post, :header_message => header_message, :message => message)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_error_messages_for_non_instance_variable
|
230
|
+
actual_user = @user
|
231
|
+
actual_post = @post
|
232
|
+
@user = nil
|
233
|
+
@post = nil
|
234
|
+
|
235
|
+
#explicitly set object
|
236
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :object => actual_post)
|
237
|
+
|
238
|
+
#multiple objects
|
239
|
+
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors prohibited this user from being saved</h2><p>There were problems with the following fields:</p><ul><li>User email can't be empty</li><li>Author name can't be empty</li></ul></div>), error_messages_for("user", "post", :object => [actual_user, actual_post])
|
240
|
+
|
241
|
+
#nil object
|
242
|
+
assert_equal '', error_messages_for('user', :object => nil)
|
243
|
+
end
|
244
|
+
|
198
245
|
def test_form_with_string_multipart
|
199
246
|
assert_dom_equal(
|
200
247
|
%(<form action="create" enctype="multipart/form-data" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
2
2
|
|
3
3
|
class AssetTagHelperTest < Test::Unit::TestCase
|
4
4
|
include ActionView::Helpers::TagHelper
|
@@ -6,29 +6,46 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
6
6
|
include ActionView::Helpers::AssetTagHelper
|
7
7
|
|
8
8
|
def setup
|
9
|
-
|
9
|
+
silence_warnings do
|
10
|
+
ActionView::Helpers::AssetTagHelper.send(
|
11
|
+
:const_set,
|
12
|
+
:JAVASCRIPTS_DIR,
|
13
|
+
File.dirname(__FILE__) + "/../fixtures/public/javascripts"
|
14
|
+
)
|
15
|
+
|
16
|
+
ActionView::Helpers::AssetTagHelper.send(
|
17
|
+
:const_set,
|
18
|
+
:STYLESHEETS_DIR,
|
19
|
+
File.dirname(__FILE__) + "/../fixtures/public/stylesheets"
|
20
|
+
)
|
21
|
+
|
22
|
+
ActionView::Helpers::AssetTagHelper.send(
|
23
|
+
:const_set,
|
24
|
+
:ASSETS_DIR,
|
25
|
+
File.dirname(__FILE__) + "/../fixtures/public"
|
26
|
+
)
|
27
|
+
end
|
10
28
|
|
29
|
+
@controller = Class.new do
|
11
30
|
attr_accessor :request
|
12
|
-
|
13
|
-
def url_for(options, *parameters_for_method_reference)
|
14
|
-
"http://www.example.com"
|
15
|
-
end
|
16
|
-
|
31
|
+
def url_for(*args) "http://www.example.com" end
|
17
32
|
end.new
|
18
|
-
|
19
|
-
@request = Class.new do
|
20
|
-
def relative_url_root
|
21
|
-
|
22
|
-
end
|
33
|
+
|
34
|
+
@request = Class.new do
|
35
|
+
def relative_url_root() "" end
|
36
|
+
def protocol() 'http://' end
|
23
37
|
end.new
|
24
38
|
|
25
39
|
@controller.request = @request
|
26
|
-
|
40
|
+
|
27
41
|
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
|
42
|
+
|
43
|
+
ActionView::Base.computed_public_paths.clear
|
28
44
|
end
|
29
45
|
|
30
46
|
def teardown
|
31
|
-
|
47
|
+
ActionController::Base.perform_caching = false
|
48
|
+
ActionController::Base.asset_host = nil
|
32
49
|
ENV["RAILS_ASSET_ID"] = nil
|
33
50
|
end
|
34
51
|
|
@@ -36,6 +53,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
36
53
|
%(auto_discovery_link_tag) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
37
54
|
%(auto_discovery_link_tag(:rss)) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
38
55
|
%(auto_discovery_link_tag(:atom)) => %(<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />),
|
56
|
+
%(auto_discovery_link_tag(:xml)) => %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />),
|
39
57
|
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
|
40
58
|
%(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
|
41
59
|
%(auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
|
@@ -52,14 +70,21 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
52
70
|
%(javascript_path("/super/xmlhr.js")) => %(/super/xmlhr.js)
|
53
71
|
}
|
54
72
|
|
73
|
+
PathToJavascriptToTag = {
|
74
|
+
%(path_to_javascript("xmlhr")) => %(/javascripts/xmlhr.js),
|
75
|
+
%(path_to_javascript("super/xmlhr")) => %(/javascripts/super/xmlhr.js),
|
76
|
+
%(path_to_javascript("/super/xmlhr.js")) => %(/super/xmlhr.js)
|
77
|
+
}
|
78
|
+
|
55
79
|
JavascriptIncludeToTag = {
|
56
80
|
%(javascript_include_tag("xmlhr")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
57
81
|
%(javascript_include_tag("xmlhr.js")) => %(<script src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
58
82
|
%(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>),
|
59
83
|
%(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>),
|
60
|
-
%(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>),
|
61
|
-
%(javascript_include_tag(:
|
62
|
-
%(javascript_include_tag("test"
|
84
|
+
%(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
|
85
|
+
%(javascript_include_tag(:all)) => %(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
|
86
|
+
%(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
|
87
|
+
%(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
|
63
88
|
}
|
64
89
|
|
65
90
|
StylePathToTag = {
|
@@ -69,22 +94,39 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
69
94
|
%(stylesheet_path('/dir/file.rcss')) => %(/dir/file.rcss)
|
70
95
|
}
|
71
96
|
|
97
|
+
PathToStyleToTag = {
|
98
|
+
%(path_to_stylesheet("style")) => %(/stylesheets/style.css),
|
99
|
+
%(path_to_stylesheet("style.css")) => %(/stylesheets/style.css),
|
100
|
+
%(path_to_stylesheet('dir/file')) => %(/stylesheets/dir/file.css),
|
101
|
+
%(path_to_stylesheet('/dir/file.rcss')) => %(/dir/file.rcss)
|
102
|
+
}
|
103
|
+
|
72
104
|
StyleLinkToTag = {
|
73
|
-
%(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="
|
74
|
-
%(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="
|
75
|
-
%(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="
|
76
|
-
%(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="
|
77
|
-
%(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="
|
78
|
-
%(stylesheet_link_tag(
|
79
|
-
%(stylesheet_link_tag("
|
105
|
+
%(stylesheet_link_tag("style")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
|
106
|
+
%(stylesheet_link_tag("style.css")) => %(<link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />),
|
107
|
+
%(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
|
108
|
+
%(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
|
109
|
+
%(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />),
|
110
|
+
%(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
|
111
|
+
%(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />),
|
112
|
+
%(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />),
|
113
|
+
%(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />)
|
80
114
|
}
|
81
115
|
|
82
116
|
ImagePathToTag = {
|
83
|
-
%(image_path("xml
|
84
|
-
%(image_path("
|
117
|
+
%(image_path("xml")) => %(/images/xml),
|
118
|
+
%(image_path("xml.png")) => %(/images/xml.png),
|
119
|
+
%(image_path("dir/xml.png")) => %(/images/dir/xml.png),
|
85
120
|
%(image_path("/dir/xml.png")) => %(/dir/xml.png)
|
86
121
|
}
|
87
122
|
|
123
|
+
PathToImageToTag = {
|
124
|
+
%(path_to_image("xml")) => %(/images/xml),
|
125
|
+
%(path_to_image("xml.png")) => %(/images/xml.png),
|
126
|
+
%(path_to_image("dir/xml.png")) => %(/images/dir/xml.png),
|
127
|
+
%(path_to_image("/dir/xml.png")) => %(/dir/xml.png)
|
128
|
+
}
|
129
|
+
|
88
130
|
ImageLinkToTag = {
|
89
131
|
%(image_tag("xml.png")) => %(<img alt="Xml" src="/images/xml.png" />),
|
90
132
|
%(image_tag("rss.gif", :alt => "rss syndication")) => %(<img alt="rss syndication" src="/images/rss.gif" />),
|
@@ -93,11 +135,10 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
93
135
|
%(image_tag("error.png", "size" => "45")) => %(<img alt="Error" src="/images/error.png" />),
|
94
136
|
%(image_tag("error.png", "size" => "45 x 70")) => %(<img alt="Error" src="/images/error.png" />),
|
95
137
|
%(image_tag("error.png", "size" => "x")) => %(<img alt="Error" src="/images/error.png" />),
|
96
|
-
%(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
%(image_path("xml")) => %(/images/xml.png)
|
138
|
+
%(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
|
139
|
+
%(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
|
140
|
+
%(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
|
141
|
+
%(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />)
|
101
142
|
}
|
102
143
|
|
103
144
|
|
@@ -109,26 +150,38 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
109
150
|
JavascriptPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
110
151
|
end
|
111
152
|
|
153
|
+
def test_path_to_javascript_alias_for_javascript_path
|
154
|
+
PathToJavascriptToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
155
|
+
end
|
156
|
+
|
112
157
|
def test_javascript_include_tag
|
158
|
+
ENV["RAILS_ASSET_ID"] = ""
|
113
159
|
JavascriptIncludeToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
114
|
-
|
115
|
-
|
116
|
-
|
160
|
+
|
161
|
+
ActionView::Base.computed_public_paths.clear
|
162
|
+
|
163
|
+
ENV["RAILS_ASSET_ID"] = "1"
|
117
164
|
assert_dom_equal(%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>), javascript_include_tag(:defaults))
|
118
165
|
end
|
119
|
-
|
166
|
+
|
120
167
|
def test_register_javascript_include_default
|
168
|
+
ENV["RAILS_ASSET_ID"] = ""
|
121
169
|
ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'slider'
|
122
|
-
assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
|
170
|
+
assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
|
123
171
|
ActionView::Helpers::AssetTagHelper::register_javascript_include_default 'lib1', '/elsewhere/blub/lib2'
|
124
|
-
assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
|
172
|
+
assert_dom_equal %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/slider.js" type="text/javascript"></script>\n<script src="/javascripts/lib1.js" type="text/javascript"></script>\n<script src="/elsewhere/blub/lib2.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>), javascript_include_tag(:defaults)
|
125
173
|
end
|
126
174
|
|
127
175
|
def test_stylesheet_path
|
128
176
|
StylePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
129
177
|
end
|
130
178
|
|
179
|
+
def test_path_to_stylesheet_alias_for_stylesheet_path
|
180
|
+
PathToStyleToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
181
|
+
end
|
182
|
+
|
131
183
|
def test_stylesheet_link_tag
|
184
|
+
ENV["RAILS_ASSET_ID"] = ""
|
132
185
|
StyleLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
133
186
|
end
|
134
187
|
|
@@ -136,41 +189,30 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
136
189
|
ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
137
190
|
end
|
138
191
|
|
192
|
+
def test_path_to_image_alias_for_image_path
|
193
|
+
PathToImageToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
194
|
+
end
|
195
|
+
|
139
196
|
def test_image_tag
|
140
197
|
ImageLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) }
|
141
198
|
end
|
142
199
|
|
143
|
-
def test_should_deprecate_image_filename_with_no_extension
|
144
|
-
DeprecatedImagePathToTag.each do |method, tag|
|
145
|
-
assert_deprecated("image_path") { assert_dom_equal(tag, eval(method)) }
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
200
|
def test_timebased_asset_id
|
150
|
-
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
151
201
|
expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s
|
152
202
|
assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png")
|
153
203
|
end
|
154
204
|
|
155
205
|
def test_should_skip_asset_id_on_complete_url
|
156
|
-
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
157
206
|
assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png")
|
158
207
|
end
|
159
208
|
|
160
209
|
def test_should_use_preset_asset_id
|
161
|
-
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
162
210
|
ENV["RAILS_ASSET_ID"] = "4500"
|
163
211
|
assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
|
164
212
|
end
|
165
213
|
|
166
214
|
def test_preset_empty_asset_id
|
167
|
-
Object.send(:const_set, :RAILS_ROOT, File.dirname(__FILE__) + "/../fixtures/")
|
168
|
-
# on windows, setting ENV["XXX"] to "" makes ENV["XXX"] return nil
|
169
|
-
if RUBY_PLATFORM =~ /win32/
|
170
|
-
ENV["RAILS_ASSET_ID"] = " "
|
171
|
-
else
|
172
215
|
ENV["RAILS_ASSET_ID"] = ""
|
173
|
-
end
|
174
216
|
assert_equal %(<img alt="Rails" src="/images/rails.png" />), image_tag("rails.png")
|
175
217
|
end
|
176
218
|
|
@@ -180,6 +222,107 @@ class AssetTagHelperTest < Test::Unit::TestCase
|
|
180
222
|
image_tag(source)
|
181
223
|
assert_equal copy, source
|
182
224
|
end
|
225
|
+
|
226
|
+
|
227
|
+
def test_caching_javascript_include_tag_when_caching_on
|
228
|
+
ENV["RAILS_ASSET_ID"] = ""
|
229
|
+
ActionController::Base.asset_host = 'http://a%d.example.com'
|
230
|
+
ActionController::Base.perform_caching = true
|
231
|
+
|
232
|
+
assert_dom_equal(
|
233
|
+
%(<script src="http://a0.example.com/javascripts/all.js" type="text/javascript"></script>),
|
234
|
+
javascript_include_tag(:all, :cache => true)
|
235
|
+
)
|
236
|
+
|
237
|
+
assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
|
238
|
+
|
239
|
+
assert_dom_equal(
|
240
|
+
%(<script src="http://a2.example.com/javascripts/money.js" type="text/javascript"></script>),
|
241
|
+
javascript_include_tag(:all, :cache => "money")
|
242
|
+
)
|
243
|
+
|
244
|
+
assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
|
245
|
+
|
246
|
+
ensure
|
247
|
+
File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
|
248
|
+
File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
|
252
|
+
ENV["RAILS_ASSET_ID"] = ""
|
253
|
+
ActionController::Base.asset_host = 'http://a%d.example.com'
|
254
|
+
ActionController::Base.perform_caching = true
|
255
|
+
|
256
|
+
assert_dom_equal(
|
257
|
+
%(<script src="http://a3.example.com/javascripts/cache/money.js" type="text/javascript"></script>),
|
258
|
+
javascript_include_tag(:all, :cache => "cache/money")
|
259
|
+
)
|
260
|
+
|
261
|
+
assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
|
262
|
+
ensure
|
263
|
+
File.delete(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'cache', 'money.js'))
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_caching_javascript_include_tag_when_caching_off
|
267
|
+
ENV["RAILS_ASSET_ID"] = ""
|
268
|
+
ActionController::Base.perform_caching = false
|
269
|
+
|
270
|
+
assert_dom_equal(
|
271
|
+
%(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
|
272
|
+
javascript_include_tag(:all, :cache => true)
|
273
|
+
)
|
274
|
+
|
275
|
+
assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
|
276
|
+
|
277
|
+
assert_dom_equal(
|
278
|
+
%(<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
|
279
|
+
javascript_include_tag(:all, :cache => "money")
|
280
|
+
)
|
281
|
+
|
282
|
+
assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'money.js'))
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_caching_stylesheet_link_tag_when_caching_on
|
286
|
+
ENV["RAILS_ASSET_ID"] = ""
|
287
|
+
ActionController::Base.asset_host = 'http://a%d.example.com'
|
288
|
+
ActionController::Base.perform_caching = true
|
289
|
+
|
290
|
+
assert_dom_equal(
|
291
|
+
%(<link href="http://a3.example.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />),
|
292
|
+
stylesheet_link_tag(:all, :cache => true)
|
293
|
+
)
|
294
|
+
|
295
|
+
assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
|
296
|
+
|
297
|
+
assert_dom_equal(
|
298
|
+
%(<link href="http://a3.example.com/stylesheets/money.css" media="screen" rel="stylesheet" type="text/css" />),
|
299
|
+
stylesheet_link_tag(:all, :cache => "money")
|
300
|
+
)
|
301
|
+
|
302
|
+
assert File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
|
303
|
+
ensure
|
304
|
+
File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
|
305
|
+
File.delete(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_caching_stylesheet_include_tag_when_caching_off
|
309
|
+
ENV["RAILS_ASSET_ID"] = ""
|
310
|
+
ActionController::Base.perform_caching = false
|
311
|
+
|
312
|
+
assert_dom_equal(
|
313
|
+
%(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
|
314
|
+
stylesheet_link_tag(:all, :cache => true)
|
315
|
+
)
|
316
|
+
|
317
|
+
assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
|
318
|
+
|
319
|
+
assert_dom_equal(
|
320
|
+
%(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
|
321
|
+
stylesheet_link_tag(:all, :cache => "money")
|
322
|
+
)
|
323
|
+
|
324
|
+
assert !File.exists?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'money.css'))
|
325
|
+
end
|
183
326
|
end
|
184
327
|
|
185
328
|
class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
@@ -191,7 +334,7 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
|
191
334
|
@controller = Class.new do
|
192
335
|
attr_accessor :request
|
193
336
|
|
194
|
-
def url_for(options
|
337
|
+
def url_for(options)
|
195
338
|
"http://www.example.com/collaboration/hieraki"
|
196
339
|
end
|
197
340
|
end.new
|
@@ -200,6 +343,10 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
|
200
343
|
def relative_url_root
|
201
344
|
"/collaboration/hieraki"
|
202
345
|
end
|
346
|
+
|
347
|
+
def protocol
|
348
|
+
'gopher://'
|
349
|
+
end
|
203
350
|
end.new
|
204
351
|
|
205
352
|
@controller.request = @request
|
@@ -230,8 +377,29 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase
|
|
230
377
|
|
231
378
|
def test_should_ignore_asset_host_on_complete_url
|
232
379
|
ActionController::Base.asset_host = "http://assets.example.com"
|
233
|
-
assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="
|
380
|
+
assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
|
234
381
|
ensure
|
235
382
|
ActionController::Base.asset_host = ""
|
236
383
|
end
|
384
|
+
|
385
|
+
def test_should_wildcard_asset_host_between_zero_and_four
|
386
|
+
ActionController::Base.asset_host = 'http://a%d.example.com'
|
387
|
+
assert_match %r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png')
|
388
|
+
ensure
|
389
|
+
ActionController::Base.asset_host = nil
|
390
|
+
end
|
391
|
+
|
392
|
+
def test_asset_host_without_protocol_should_use_request_protocol
|
393
|
+
ActionController::Base.asset_host = 'a.example.com'
|
394
|
+
assert_equal 'gopher://a.example.com/collaboration/hieraki/images/xml.png', image_path('xml.png')
|
395
|
+
ensure
|
396
|
+
ActionController::Base.asset_host = nil
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_asset_host_without_protocol_should_use_request_protocol_even_if_path_present
|
400
|
+
ActionController::Base.asset_host = 'a.example.com/files/go/here'
|
401
|
+
assert_equal 'gopher://a.example.com/files/go/here/collaboration/hieraki/images/xml.png', image_path('xml.png')
|
402
|
+
ensure
|
403
|
+
ActionController::Base.asset_host = nil
|
404
|
+
end
|
237
405
|
end
|