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,272 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class FormTagHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::FormTagHelper
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@controller = Class.new do
|
|
8
|
+
def url_for(options)
|
|
9
|
+
"http://www.example.com"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
@controller = @controller.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_check_box_tag
|
|
16
|
+
actual = check_box_tag "admin"
|
|
17
|
+
expected = %(<input id="admin" name="admin" type="checkbox" value="1" />)
|
|
18
|
+
assert_dom_equal expected, actual
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_form_tag
|
|
22
|
+
actual = form_tag
|
|
23
|
+
expected = %(<form action="http://www.example.com" method="post">)
|
|
24
|
+
assert_dom_equal expected, actual
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_form_tag_multipart
|
|
28
|
+
actual = form_tag({}, { 'multipart' => true })
|
|
29
|
+
expected = %(<form action="http://www.example.com" enctype="multipart/form-data" method="post">)
|
|
30
|
+
assert_dom_equal expected, actual
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_form_tag_with_method_put
|
|
34
|
+
actual = form_tag({}, { :method => :put })
|
|
35
|
+
expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>)
|
|
36
|
+
assert_dom_equal expected, actual
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_form_tag_with_method_delete
|
|
40
|
+
actual = form_tag({}, { :method => :delete })
|
|
41
|
+
expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="delete" /></div>)
|
|
42
|
+
assert_dom_equal expected, actual
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_form_tag_with_block
|
|
46
|
+
_erbout = ''
|
|
47
|
+
form_tag("http://example.com") { _erbout.concat "Hello world!" }
|
|
48
|
+
|
|
49
|
+
expected = %(<form action="http://example.com" method="post">Hello world!</form>)
|
|
50
|
+
assert_dom_equal expected, _erbout
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_form_tag_with_block_and_method
|
|
54
|
+
_erbout = ''
|
|
55
|
+
form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" }
|
|
56
|
+
|
|
57
|
+
expected = %(<form action="http://example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
|
|
58
|
+
assert_dom_equal expected, _erbout
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_hidden_field_tag
|
|
62
|
+
actual = hidden_field_tag "id", 3
|
|
63
|
+
expected = %(<input id="id" name="id" type="hidden" value="3" />)
|
|
64
|
+
assert_dom_equal expected, actual
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_file_field_tag
|
|
68
|
+
assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" />", file_field_tag("picsplz")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_file_field_tag_with_options
|
|
72
|
+
assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" class=\"pix\"/>", file_field_tag("picsplz", :class => "pix")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_password_field_tag
|
|
76
|
+
actual = password_field_tag
|
|
77
|
+
expected = %(<input id="password" name="password" type="password" />)
|
|
78
|
+
assert_dom_equal expected, actual
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_radio_button_tag
|
|
82
|
+
actual = radio_button_tag "people", "david"
|
|
83
|
+
expected = %(<input id="people_david" name="people" type="radio" value="david" />)
|
|
84
|
+
assert_dom_equal expected, actual
|
|
85
|
+
|
|
86
|
+
actual = radio_button_tag("num_people", 5)
|
|
87
|
+
expected = %(<input id="num_people_5" name="num_people" type="radio" value="5" />)
|
|
88
|
+
assert_dom_equal expected, actual
|
|
89
|
+
|
|
90
|
+
actual = radio_button_tag("gender", "m") + radio_button_tag("gender", "f")
|
|
91
|
+
expected = %(<input id="gender_m" name="gender" type="radio" value="m" /><input id="gender_f" name="gender" type="radio" value="f" />)
|
|
92
|
+
assert_dom_equal expected, actual
|
|
93
|
+
|
|
94
|
+
actual = radio_button_tag("opinion", "-1") + radio_button_tag("opinion", "1")
|
|
95
|
+
expected = %(<input id="opinion_-1" name="opinion" type="radio" value="-1" /><input id="opinion_1" name="opinion" type="radio" value="1" />)
|
|
96
|
+
assert_dom_equal expected, actual
|
|
97
|
+
|
|
98
|
+
actual = radio_button_tag("person[gender]", "m")
|
|
99
|
+
expected = %(<input id="person_gender_m" name="person[gender]" type="radio" value="m" />)
|
|
100
|
+
assert_dom_equal expected, actual
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_select_tag
|
|
104
|
+
actual = select_tag "people", "<option>david</option>"
|
|
105
|
+
expected = %(<select id="people" name="people"><option>david</option></select>)
|
|
106
|
+
assert_dom_equal expected, actual
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_select_tag_with_multiple
|
|
110
|
+
actual = select_tag "colors", "<option>Red</option><option>Blue</option><option>Green</option>", :multiple => :true
|
|
111
|
+
expected = %(<select id="colors" multiple="multiple" name="colors"><option>Red</option><option>Blue</option><option>Green</option></select>)
|
|
112
|
+
assert_dom_equal expected, actual
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_select_tag_disabled
|
|
116
|
+
actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>", :disabled => :true
|
|
117
|
+
expected = %(<select id="places" disabled="disabled" name="places"><option>Home</option><option>Work</option><option>Pub</option></select>)
|
|
118
|
+
assert_dom_equal expected, actual
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_text_area_tag_size_string
|
|
122
|
+
actual = text_area_tag "body", "hello world", "size" => "20x40"
|
|
123
|
+
expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
|
|
124
|
+
assert_dom_equal expected, actual
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_text_area_tag_size_symbol
|
|
128
|
+
actual = text_area_tag "body", "hello world", :size => "20x40"
|
|
129
|
+
expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
|
|
130
|
+
assert_dom_equal expected, actual
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_text_area_tag_should_disregard_size_if_its_given_as_an_integer
|
|
134
|
+
actual = text_area_tag "body", "hello world", :size => 20
|
|
135
|
+
expected = %(<textarea id="body" name="body">hello world</textarea>)
|
|
136
|
+
assert_dom_equal expected, actual
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_text_field_tag
|
|
140
|
+
actual = text_field_tag "title", "Hello!"
|
|
141
|
+
expected = %(<input id="title" name="title" type="text" value="Hello!" />)
|
|
142
|
+
assert_dom_equal expected, actual
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_text_field_tag_class_string
|
|
146
|
+
actual = text_field_tag "title", "Hello!", "class" => "admin"
|
|
147
|
+
expected = %(<input class="admin" id="title" name="title" type="text" value="Hello!" />)
|
|
148
|
+
assert_dom_equal expected, actual
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_text_field_tag_size_symbol
|
|
152
|
+
actual = text_field_tag "title", "Hello!", :size => 75
|
|
153
|
+
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
|
|
154
|
+
assert_dom_equal expected, actual
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_text_field_tag_size_string
|
|
158
|
+
actual = text_field_tag "title", "Hello!", "size" => "75"
|
|
159
|
+
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
|
|
160
|
+
assert_dom_equal expected, actual
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_text_field_tag_maxlength_symbol
|
|
164
|
+
actual = text_field_tag "title", "Hello!", :maxlength => 75
|
|
165
|
+
expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
|
|
166
|
+
assert_dom_equal expected, actual
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_text_field_tag_maxlength_string
|
|
170
|
+
actual = text_field_tag "title", "Hello!", "maxlength" => "75"
|
|
171
|
+
expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
|
|
172
|
+
assert_dom_equal expected, actual
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def test_text_field_disabled
|
|
176
|
+
actual = text_field_tag "title", "Hello!", :disabled => :true
|
|
177
|
+
expected = %(<input id="title" name="title" disabled="disabled" type="text" value="Hello!" />)
|
|
178
|
+
assert_dom_equal expected, actual
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def test_text_field_tag_with_multiple_options
|
|
182
|
+
actual = text_field_tag "title", "Hello!", :size => 70, :maxlength => 80
|
|
183
|
+
expected = %(<input id="title" name="title" size="70" maxlength="80" type="text" value="Hello!" />)
|
|
184
|
+
assert_dom_equal expected, actual
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def test_label_tag_without_text
|
|
188
|
+
actual = label_tag "title"
|
|
189
|
+
expected = %(<label for="title">Title</label>)
|
|
190
|
+
assert_dom_equal expected, actual
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def test_label_tag_with_symbol
|
|
194
|
+
actual = label_tag :title
|
|
195
|
+
expected = %(<label for="title">Title</label>)
|
|
196
|
+
assert_dom_equal expected, actual
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_label_tag_with_text
|
|
200
|
+
actual = label_tag "title", "My Title"
|
|
201
|
+
expected = %(<label for="title">My Title</label>)
|
|
202
|
+
assert_dom_equal expected, actual
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def test_label_tag_class_string
|
|
206
|
+
actual = label_tag "title", "My Title", "class" => "small_label"
|
|
207
|
+
expected = %(<label for="title" class="small_label">My Title</label>)
|
|
208
|
+
assert_dom_equal expected, actual
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_boolean_optios
|
|
212
|
+
assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
|
|
213
|
+
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
|
|
214
|
+
assert_dom_equal %(<select id="people" multiple="multiple" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
|
|
215
|
+
assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def test_stringify_symbol_keys
|
|
219
|
+
actual = text_field_tag "title", "Hello!", :id => "admin"
|
|
220
|
+
expected = %(<input id="admin" name="title" type="text" value="Hello!" />)
|
|
221
|
+
assert_dom_equal expected, actual
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def test_submit_tag
|
|
225
|
+
assert_dom_equal(
|
|
226
|
+
%(<input name='commit' type='submit' value='Save' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
|
|
227
|
+
submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
|
|
228
|
+
)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def test_submit_tag_with_no_onclick_options
|
|
232
|
+
assert_dom_equal(
|
|
233
|
+
%(<input name='commit' type='submit' value='Save' onclick="if (window.hiddenCommit) { window.hiddenCommit.setAttribute('value', this.value); }else { hiddenCommit = this.cloneNode(false);hiddenCommit.setAttribute('type', 'hidden');this.form.appendChild(hiddenCommit); }this.setAttribute('originalValue', this.value);this.disabled = true;this.value='Saving...';result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue');this.disabled = false; }return result;" />),
|
|
234
|
+
submit_tag("Save", :disable_with => "Saving...")
|
|
235
|
+
)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def test_submit_tag_with_confirmation
|
|
239
|
+
assert_dom_equal(
|
|
240
|
+
%(<input name='commit' type='submit' value='Save' onclick="return confirm('Are you sure?');"/>),
|
|
241
|
+
submit_tag("Save", :confirm => "Are you sure?")
|
|
242
|
+
)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def test_pass
|
|
246
|
+
assert_equal 1, 1
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def test_field_set_tag
|
|
250
|
+
_erbout = ''
|
|
251
|
+
field_set_tag("Your details") { _erbout.concat "Hello world!" }
|
|
252
|
+
|
|
253
|
+
expected = %(<fieldset><legend>Your details</legend>Hello world!</fieldset>)
|
|
254
|
+
assert_dom_equal expected, _erbout
|
|
255
|
+
|
|
256
|
+
_erbout = ''
|
|
257
|
+
field_set_tag { _erbout.concat "Hello world!" }
|
|
258
|
+
|
|
259
|
+
expected = %(<fieldset>Hello world!</fieldset>)
|
|
260
|
+
assert_dom_equal expected, _erbout
|
|
261
|
+
|
|
262
|
+
_erbout = ''
|
|
263
|
+
field_set_tag('') { _erbout.concat "Hello world!" }
|
|
264
|
+
|
|
265
|
+
expected = %(<fieldset>Hello world!</fieldset>)
|
|
266
|
+
assert_dom_equal expected, _erbout
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def protect_against_forgery?
|
|
270
|
+
false
|
|
271
|
+
end
|
|
272
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class JavaScriptHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::JavaScriptHelper
|
|
5
|
+
|
|
6
|
+
def test_escape_javascript
|
|
7
|
+
assert_equal '', escape_javascript(nil)
|
|
8
|
+
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
|
|
9
|
+
assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) )
|
|
10
|
+
assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_link_to_function
|
|
14
|
+
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
|
15
|
+
link_to_function("Greeting", "alert('Hello world!')")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_link_to_function_with_existing_onclick
|
|
19
|
+
assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
|
|
20
|
+
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_link_to_function_with_href
|
|
24
|
+
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
|
25
|
+
link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_link_to_function_with_href
|
|
29
|
+
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
|
30
|
+
link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_button_to_function
|
|
34
|
+
assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
|
|
35
|
+
button_to_function("Greeting", "alert('Hello world!')")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_button_to_function_with_onclick
|
|
39
|
+
assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />",
|
|
40
|
+
button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_button_to_function_without_function
|
|
44
|
+
assert_dom_equal "<input onclick=\";\" type=\"button\" value=\"Greeting\" />",
|
|
45
|
+
button_to_function("Greeting")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_javascript_tag
|
|
49
|
+
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
|
50
|
+
javascript_tag("alert('hello')")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_javascript_tag_with_options
|
|
54
|
+
assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
|
55
|
+
javascript_tag("alert('hello')", :id => "the_js_tag")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_javascript_tag_with_block
|
|
59
|
+
_erbout = ''
|
|
60
|
+
javascript_tag { _erbout.concat "alert('hello')" }
|
|
61
|
+
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", _erbout
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_javascript_tag_with_block_and_options
|
|
65
|
+
_erbout = ''
|
|
66
|
+
javascript_tag(:id => "the_js_tag") { _erbout.concat "alert('hello')" }
|
|
67
|
+
assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", _erbout
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_javascript_cdata_section
|
|
71
|
+
assert_dom_equal "\n//<![CDATA[\nalert('hello')\n//]]>\n", javascript_cdata_section("alert('hello')")
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class NumberHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::NumberHelper
|
|
5
|
+
|
|
6
|
+
def test_number_to_phone
|
|
7
|
+
assert_equal("800-555-1212", number_to_phone(8005551212))
|
|
8
|
+
assert_equal("(800) 555-1212", number_to_phone(8005551212, {:area_code => true}))
|
|
9
|
+
assert_equal("800 555 1212", number_to_phone(8005551212, {:delimiter => " "}))
|
|
10
|
+
assert_equal("(800) 555-1212 x 123", number_to_phone(8005551212, {:area_code => true, :extension => 123}))
|
|
11
|
+
assert_equal("800-555-1212", number_to_phone(8005551212, :extension => " "))
|
|
12
|
+
assert_equal("800-555-1212", number_to_phone("8005551212"))
|
|
13
|
+
assert_equal("+1-800-555-1212", number_to_phone(8005551212, :country_code => 1))
|
|
14
|
+
assert_equal("+18005551212", number_to_phone(8005551212, :country_code => 1, :delimiter => ''))
|
|
15
|
+
assert_equal("22-555-1212", number_to_phone(225551212))
|
|
16
|
+
assert_equal("+45-22-555-1212", number_to_phone(225551212, :country_code => 45))
|
|
17
|
+
assert_equal("x", number_to_phone("x"))
|
|
18
|
+
assert_nil number_to_phone(nil)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_number_to_currency
|
|
22
|
+
assert_equal("$1,234,567,890.50", number_to_currency(1234567890.50))
|
|
23
|
+
assert_equal("$1,234,567,890.51", number_to_currency(1234567890.506))
|
|
24
|
+
assert_equal("$1,234,567,892", number_to_currency(1234567891.50, {:precision => 0}))
|
|
25
|
+
assert_equal("$1,234,567,890.5", number_to_currency(1234567890.50, {:precision => 1}))
|
|
26
|
+
assert_equal("£1234567890,50", number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""}))
|
|
27
|
+
assert_equal("$1,234,567,890.50", number_to_currency("1234567890.50"))
|
|
28
|
+
assert_equal("1,234,567,890.50 Kč", number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"}))
|
|
29
|
+
assert_equal("$x.", number_to_currency("x"))
|
|
30
|
+
assert_nil number_to_currency(nil)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_number_to_percentage
|
|
34
|
+
assert_equal("100.000%", number_to_percentage(100))
|
|
35
|
+
assert_equal("100%", number_to_percentage(100, {:precision => 0}))
|
|
36
|
+
assert_equal("302.06%", number_to_percentage(302.0574, {:precision => 2}))
|
|
37
|
+
assert_equal("100.000%", number_to_percentage("100"))
|
|
38
|
+
assert_equal("x%", number_to_percentage("x"))
|
|
39
|
+
assert_nil number_to_percentage(nil)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_number_with_delimiter
|
|
43
|
+
assert_equal("12,345,678", number_with_delimiter(12345678))
|
|
44
|
+
assert_equal("0", number_with_delimiter(0))
|
|
45
|
+
assert_equal("123", number_with_delimiter(123))
|
|
46
|
+
assert_equal("123,456", number_with_delimiter(123456))
|
|
47
|
+
assert_equal("123,456.78", number_with_delimiter(123456.78))
|
|
48
|
+
assert_equal("123,456.789", number_with_delimiter(123456.789))
|
|
49
|
+
assert_equal("123,456.78901", number_with_delimiter(123456.78901))
|
|
50
|
+
assert_equal("123,456,789.78901", number_with_delimiter(123456789.78901))
|
|
51
|
+
assert_equal("0.78901", number_with_delimiter(0.78901))
|
|
52
|
+
assert_equal("123,456.78", number_with_delimiter("123456.78"))
|
|
53
|
+
assert_equal("x", number_with_delimiter("x"))
|
|
54
|
+
assert_nil number_with_delimiter(nil)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_number_with_precision
|
|
58
|
+
assert_equal("111.235", number_with_precision(111.2346))
|
|
59
|
+
assert_equal("31.83", number_with_precision(31.825, 2))
|
|
60
|
+
assert_equal("111.23", number_with_precision(111.2346, 2))
|
|
61
|
+
assert_equal("111.00", number_with_precision(111, 2))
|
|
62
|
+
assert_equal("111.235", number_with_precision("111.2346"))
|
|
63
|
+
assert_equal("31.83", number_with_precision("31.825", 2))
|
|
64
|
+
assert_equal("112", number_with_precision(111.50, 0))
|
|
65
|
+
assert_equal("1234567892", number_with_precision(1234567891.50, 0))
|
|
66
|
+
|
|
67
|
+
# Return non-numeric params unchanged.
|
|
68
|
+
assert_equal("x", number_with_precision("x"))
|
|
69
|
+
assert_nil number_with_precision(nil)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_number_to_human_size
|
|
73
|
+
assert_equal '0 Bytes', number_to_human_size(0)
|
|
74
|
+
assert_equal '1 Byte', number_to_human_size(1)
|
|
75
|
+
assert_equal '3 Bytes', number_to_human_size(3.14159265)
|
|
76
|
+
assert_equal '123 Bytes', number_to_human_size(123.0)
|
|
77
|
+
assert_equal '123 Bytes', number_to_human_size(123)
|
|
78
|
+
assert_equal '1.2 KB', number_to_human_size(1234)
|
|
79
|
+
assert_equal '12.1 KB', number_to_human_size(12345)
|
|
80
|
+
assert_equal '1.2 MB', number_to_human_size(1234567)
|
|
81
|
+
assert_equal '1.1 GB', number_to_human_size(1234567890)
|
|
82
|
+
assert_equal '1.1 TB', number_to_human_size(1234567890123)
|
|
83
|
+
assert_equal '444 KB', number_to_human_size(444.kilobytes)
|
|
84
|
+
assert_equal '1023 MB', number_to_human_size(1023.megabytes)
|
|
85
|
+
assert_equal '3 TB', number_to_human_size(3.terabytes)
|
|
86
|
+
assert_equal '1.18 MB', number_to_human_size(1234567, 2)
|
|
87
|
+
assert_equal '3 Bytes', number_to_human_size(3.14159265, 4)
|
|
88
|
+
assert_equal("123 Bytes", number_to_human_size("123"))
|
|
89
|
+
assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, 2)
|
|
90
|
+
assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, 4)
|
|
91
|
+
assert_equal '10 KB', number_to_human_size(10.000.kilobytes, 4)
|
|
92
|
+
assert_equal '1 Byte', number_to_human_size(1.1)
|
|
93
|
+
assert_equal '10 Bytes', number_to_human_size(10)
|
|
94
|
+
assert_nil number_to_human_size('x')
|
|
95
|
+
assert_nil number_to_human_size(nil)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class Post
|
|
4
|
+
def id
|
|
5
|
+
45
|
|
6
|
+
end
|
|
7
|
+
def body
|
|
8
|
+
"What a wonderful world!"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class RecordTagHelperTest < ActionView::TestCase
|
|
13
|
+
tests ActionView::Helpers::RecordTagHelper
|
|
14
|
+
|
|
15
|
+
def setup
|
|
16
|
+
@post = Post.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_content_tag_for
|
|
20
|
+
_erbout = ''
|
|
21
|
+
expected = %(<li class="post bar" id="post_45"></li>)
|
|
22
|
+
actual = content_tag_for(:li, @post, :class => 'bar') { }
|
|
23
|
+
assert_dom_equal expected, actual
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_content_tag_for_prefix
|
|
27
|
+
_erbout = ''
|
|
28
|
+
expected = %(<ul class="post" id="archived_post_45"></ul>)
|
|
29
|
+
actual = content_tag_for(:ul, @post, :archived) { }
|
|
30
|
+
assert_dom_equal expected, actual
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_content_tag_for_with_extra_html_tags
|
|
34
|
+
_erbout = ''
|
|
35
|
+
expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>)
|
|
36
|
+
actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { }
|
|
37
|
+
assert_dom_equal expected, actual
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_block_works_with_content_tag_for
|
|
41
|
+
_erbout = ''
|
|
42
|
+
expected = %(<tr class="post" id="post_45">#{@post.body}</tr>)
|
|
43
|
+
actual = content_tag_for(:tr, @post) { _erbout.concat @post.body }
|
|
44
|
+
assert_dom_equal expected, actual
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_div_for
|
|
48
|
+
_erbout = ''
|
|
49
|
+
expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
|
|
50
|
+
actual = div_for(@post, :class => "bar") { _erbout.concat @post.body }
|
|
51
|
+
assert_dom_equal expected, actual
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|