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
data/RUNNING_UNIT_TESTS
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
== Running with Rake
|
|
2
|
+
|
|
3
|
+
The easiest way to run the unit tests is through Rake. The default task runs
|
|
4
|
+
the entire test suite for all classes. For more information, checkout the
|
|
5
|
+
full array of rake tasks with "rake -T"
|
|
6
|
+
|
|
7
|
+
Rake can be found at http://rake.rubyforge.org
|
|
8
|
+
|
|
9
|
+
== Running by hand
|
|
10
|
+
|
|
11
|
+
If you only want to run a single test suite, or don't want to bother with Rake,
|
|
12
|
+
you can do so with something like:
|
|
13
|
+
|
|
14
|
+
ruby controller/base_tests.rb
|
|
15
|
+
|
|
16
|
+
== Dependency on ActiveRecord and database setup
|
|
17
|
+
|
|
18
|
+
Test cases in the test/controller/active_record/ directory depend on having
|
|
19
|
+
activerecord and sqlite installed. If ActiveRecord is not in
|
|
20
|
+
actionpack/../activerecord directory, or the sqlite rubygem is not installed,
|
|
21
|
+
these tests are skipped.
|
|
22
|
+
|
|
23
|
+
Other tests are runnable from a fresh copy of actionpack without any configuration.
|
|
24
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
require 'rake/rdoctask'
|
|
5
|
+
require 'rake/packagetask'
|
|
6
|
+
require 'rake/gempackagetask'
|
|
7
|
+
require 'rake/contrib/sshpublisher'
|
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
|
9
|
+
|
|
10
|
+
require File.join(File.dirname(__FILE__), 'lib', 'action_pack', 'version')
|
|
11
|
+
|
|
12
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
|
13
|
+
PKG_NAME = 'eactionpack'
|
|
14
|
+
PKG_VERSION = ActionPack::VERSION::STRING + PKG_BUILD
|
|
15
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
|
16
|
+
|
|
17
|
+
RELEASE_NAME = "REL #{PKG_VERSION}"
|
|
18
|
+
|
|
19
|
+
RUBY_FORGE_PROJECT = "eactionpack"
|
|
20
|
+
RUBY_FORGE_USER = "DAddYE"
|
|
21
|
+
|
|
22
|
+
desc "Default Task"
|
|
23
|
+
task :default => [ :test ]
|
|
24
|
+
|
|
25
|
+
# Run the unit tests
|
|
26
|
+
|
|
27
|
+
desc "Run all unit tests"
|
|
28
|
+
task :test => [:test_action_pack, :test_active_record_integration]
|
|
29
|
+
|
|
30
|
+
Rake::TestTask.new(:test_action_pack) { |t|
|
|
31
|
+
t.libs << "test"
|
|
32
|
+
# make sure we include the tests in alphabetical order as on some systems
|
|
33
|
+
# this will not happen automatically and the tests (as a whole) will error
|
|
34
|
+
t.test_files=Dir.glob( "test/[cft]*/**/*_test.rb" ).sort
|
|
35
|
+
# t.pattern = 'test/*/*_test.rb'
|
|
36
|
+
t.verbose = true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
desc 'ActiveRecord Integration Tests'
|
|
40
|
+
Rake::TestTask.new(:test_active_record_integration) do |t|
|
|
41
|
+
t.libs << "test"
|
|
42
|
+
t.test_files = Dir.glob("test/activerecord/*_test.rb")
|
|
43
|
+
t.verbose = true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Genereate the RDoc documentation
|
|
48
|
+
|
|
49
|
+
Rake::RDocTask.new { |rdoc|
|
|
50
|
+
rdoc.rdoc_dir = 'doc'
|
|
51
|
+
rdoc.title = "Enhanced Action Pack -- On rails from request to response"
|
|
52
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
53
|
+
rdoc.options << '--charset' << 'utf-8'
|
|
54
|
+
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
|
|
55
|
+
if ENV['DOC_FILES']
|
|
56
|
+
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
|
57
|
+
else
|
|
58
|
+
rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
|
|
59
|
+
rdoc.rdoc_files.include(Dir['lib/**/*.rb'] -
|
|
60
|
+
Dir['lib/*/vendor/**/*.rb'])
|
|
61
|
+
rdoc.rdoc_files.exclude('lib/actionpack.rb')
|
|
62
|
+
end
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# Create compressed packages
|
|
66
|
+
dist_dirs = [ "lib", "test" ]
|
|
67
|
+
|
|
68
|
+
spec = Gem::Specification.new do |s|
|
|
69
|
+
s.platform = Gem::Platform::RUBY
|
|
70
|
+
s.name = PKG_NAME
|
|
71
|
+
s.version = PKG_VERSION
|
|
72
|
+
s.summary = "Web-flow and rendering framework putting the VC in MVC."
|
|
73
|
+
s.description = %q{Eases web-request routing, handling, and response as a half-way front, half-way page controller. Implemented with specific emphasis on enabling easy unit/integration testing that doesn't require a browser.} #'
|
|
74
|
+
|
|
75
|
+
s.author = "Davide D'Agostino"
|
|
76
|
+
s.email = "d.dagostino@lipsiasoft.com"
|
|
77
|
+
s.rubyforge_project = "eactionpack"
|
|
78
|
+
s.homepage = "http://www.lipsiasoft.com"
|
|
79
|
+
|
|
80
|
+
s.has_rdoc = true
|
|
81
|
+
s.requirements << 'none'
|
|
82
|
+
|
|
83
|
+
s.add_dependency('activesupport', '= 2.1.2' + PKG_BUILD)
|
|
84
|
+
|
|
85
|
+
s.require_path = 'lib'
|
|
86
|
+
s.autorequire = 'action_controller'
|
|
87
|
+
|
|
88
|
+
s.files = [ "Rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG", "MIT-LICENSE" ]
|
|
89
|
+
dist_dirs.each do |dir|
|
|
90
|
+
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
Rake::GemPackageTask.new(spec) do |p|
|
|
95
|
+
p.gem_spec = spec
|
|
96
|
+
p.need_tar = true
|
|
97
|
+
p.need_zip = true
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
task :lines do
|
|
101
|
+
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
|
102
|
+
|
|
103
|
+
for file_name in FileList["lib/**/*.rb"]
|
|
104
|
+
next if file_name =~ /vendor/
|
|
105
|
+
f = File.open(file_name)
|
|
106
|
+
|
|
107
|
+
while line = f.gets
|
|
108
|
+
lines += 1
|
|
109
|
+
next if line =~ /^\s*$/
|
|
110
|
+
next if line =~ /^\s*#/
|
|
111
|
+
codelines += 1
|
|
112
|
+
end
|
|
113
|
+
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
|
114
|
+
|
|
115
|
+
total_lines += lines
|
|
116
|
+
total_codelines += codelines
|
|
117
|
+
|
|
118
|
+
lines, codelines = 0, 0
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Publishing ------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
desc "Publish the API documentation"
|
|
127
|
+
task :pgem => [:package] do
|
|
128
|
+
Rake::SshFilePublisher.new("root@server1.lipsiasoft.com", "/var/www/apps/erails/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
desc "Publish the API documentation"
|
|
132
|
+
task :pdoc => [:rdoc] do
|
|
133
|
+
Rake::SshDirPublisher.new("root@server1.lipsiasoft.com", "/var/www/apps/erails/api", "doc").upload
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
desc "Publish the release files to RubyForge."
|
|
137
|
+
task :release => [ :package ] do
|
|
138
|
+
require 'rubyforge'
|
|
139
|
+
require 'rake/contrib/rubyforgepublisher'
|
|
140
|
+
|
|
141
|
+
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
|
|
142
|
+
|
|
143
|
+
rubyforge = RubyForge.new
|
|
144
|
+
rubyforge.login
|
|
145
|
+
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
|
|
146
|
+
end
|
data/install.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'rbconfig'
|
|
2
|
+
require 'find'
|
|
3
|
+
require 'ftools'
|
|
4
|
+
|
|
5
|
+
include Config
|
|
6
|
+
|
|
7
|
+
# this was adapted from rdoc's install.rb by way of Log4r
|
|
8
|
+
|
|
9
|
+
$sitedir = CONFIG["sitelibdir"]
|
|
10
|
+
unless $sitedir
|
|
11
|
+
version = CONFIG["MAJOR"] + "." + CONFIG["MINOR"]
|
|
12
|
+
$libdir = File.join(CONFIG["libdir"], "ruby", version)
|
|
13
|
+
$sitedir = $:.find {|x| x =~ /site_ruby/ }
|
|
14
|
+
if !$sitedir
|
|
15
|
+
$sitedir = File.join($libdir, "site_ruby")
|
|
16
|
+
elsif $sitedir !~ Regexp.quote(version)
|
|
17
|
+
$sitedir = File.join($sitedir, version)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# the actual gruntwork
|
|
22
|
+
Dir.chdir("lib")
|
|
23
|
+
|
|
24
|
+
Find.find("action_controller", "action_controller.rb", "action_view", "action_view.rb") { |f|
|
|
25
|
+
if f[-3..-1] == ".rb"
|
|
26
|
+
File::install(f, File.join($sitedir, *f.split(/\//)), 0644, true)
|
|
27
|
+
else
|
|
28
|
+
File::makedirs(File.join($sitedir, *f.split(/\//)))
|
|
29
|
+
end
|
|
30
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#--
|
|
2
|
+
# Copyright (c) 2004-2008 David Heinemeier Hansson
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
# a copy of this software and associated documentation files (the
|
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
# the following conditions:
|
|
11
|
+
#
|
|
12
|
+
# The above copyright notice and this permission notice shall be
|
|
13
|
+
# included in all copies or substantial portions of the Software.
|
|
14
|
+
#
|
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
#++
|
|
23
|
+
|
|
24
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
|
25
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
26
|
+
|
|
27
|
+
unless defined?(ActiveSupport)
|
|
28
|
+
begin
|
|
29
|
+
$:.unshift "#{File.dirname(__FILE__)}/../../activesupport/lib"
|
|
30
|
+
require 'active_support'
|
|
31
|
+
rescue LoadError
|
|
32
|
+
require 'rubygems'
|
|
33
|
+
gem 'activesupport'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
$:.unshift "#{File.dirname(__FILE__)}/action_controller/vendor/html-scanner"
|
|
38
|
+
|
|
39
|
+
require 'action_controller/base'
|
|
40
|
+
require 'action_controller/request'
|
|
41
|
+
require 'action_controller/rescue'
|
|
42
|
+
require 'action_controller/benchmarking'
|
|
43
|
+
require 'action_controller/flash'
|
|
44
|
+
require 'action_controller/filters'
|
|
45
|
+
require 'action_controller/layout'
|
|
46
|
+
require 'action_controller/mime_responds'
|
|
47
|
+
require 'action_controller/helpers'
|
|
48
|
+
require 'action_controller/cookies'
|
|
49
|
+
require 'action_controller/cgi_process'
|
|
50
|
+
require 'action_controller/caching'
|
|
51
|
+
require 'action_controller/verification'
|
|
52
|
+
require 'action_controller/streaming'
|
|
53
|
+
require 'action_controller/session_management'
|
|
54
|
+
require 'action_controller/http_authentication'
|
|
55
|
+
require 'action_controller/components'
|
|
56
|
+
require 'action_controller/record_identifier'
|
|
57
|
+
require 'action_controller/request_forgery_protection'
|
|
58
|
+
require 'action_controller/headers'
|
|
59
|
+
|
|
60
|
+
require 'action_view'
|
|
61
|
+
|
|
62
|
+
ActionController::Base.class_eval do
|
|
63
|
+
include ActionController::Flash
|
|
64
|
+
include ActionController::Filters
|
|
65
|
+
include ActionController::Layout
|
|
66
|
+
include ActionController::Benchmarking
|
|
67
|
+
include ActionController::Rescue
|
|
68
|
+
include ActionController::MimeResponds
|
|
69
|
+
include ActionController::Helpers
|
|
70
|
+
include ActionController::Cookies
|
|
71
|
+
include ActionController::Caching
|
|
72
|
+
include ActionController::Verification
|
|
73
|
+
include ActionController::Streaming
|
|
74
|
+
include ActionController::SessionManagement
|
|
75
|
+
include ActionController::HttpAuthentication::Basic::ControllerMethods
|
|
76
|
+
include ActionController::Components
|
|
77
|
+
include ActionController::RecordIdentifier
|
|
78
|
+
include ActionController::RequestForgeryProtection
|
|
79
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'test/unit/assertions'
|
|
2
|
+
|
|
3
|
+
module ActionController #:nodoc:
|
|
4
|
+
# In addition to these specific assertions, you also have easy access to various collections that the regular test/unit assertions
|
|
5
|
+
# can be used against. These collections are:
|
|
6
|
+
#
|
|
7
|
+
# * assigns: Instance variables assigned in the action that are available for the view.
|
|
8
|
+
# * session: Objects being saved in the session.
|
|
9
|
+
# * flash: The flash objects currently in the session.
|
|
10
|
+
# * cookies: Cookies being sent to the user on this request.
|
|
11
|
+
#
|
|
12
|
+
# These collections can be used just like any other hash:
|
|
13
|
+
#
|
|
14
|
+
# assert_not_nil assigns(:person) # makes sure that a @person instance variable was set
|
|
15
|
+
# assert_equal "Dave", cookies[:name] # makes sure that a cookie called :name was set as "Dave"
|
|
16
|
+
# assert flash.empty? # makes sure that there's nothing in the flash
|
|
17
|
+
#
|
|
18
|
+
# For historic reasons, the assigns hash uses string-based keys. So assigns[:person] won't work, but assigns["person"] will. To
|
|
19
|
+
# appease our yearning for symbols, though, an alternative accessor has been devised using a method call instead of index referencing.
|
|
20
|
+
# So assigns(:person) will work just like assigns["person"], but again, assigns[:person] will not work.
|
|
21
|
+
#
|
|
22
|
+
# On top of the collections, you have the complete url that a given action redirected to available in redirect_to_url.
|
|
23
|
+
#
|
|
24
|
+
# For redirects within the same controller, you can even call follow_redirect and the redirect will be followed, triggering another
|
|
25
|
+
# action call which can then be asserted against.
|
|
26
|
+
#
|
|
27
|
+
# == Manipulating the request collections
|
|
28
|
+
#
|
|
29
|
+
# The collections described above link to the response, so you can test if what the actions were expected to do happened. But
|
|
30
|
+
# sometimes you also want to manipulate these collections in the incoming request. This is really only relevant for sessions
|
|
31
|
+
# and cookies, though. For sessions, you just do:
|
|
32
|
+
#
|
|
33
|
+
# @request.session[:key] = "value"
|
|
34
|
+
#
|
|
35
|
+
# For cookies, you need to manually create the cookie, like this:
|
|
36
|
+
#
|
|
37
|
+
# @request.cookies["key"] = CGI::Cookie.new("key", "value")
|
|
38
|
+
#
|
|
39
|
+
# == Testing named routes
|
|
40
|
+
#
|
|
41
|
+
# If you're using named routes, they can be easily tested using the original named routes' methods straight in the test case.
|
|
42
|
+
# Example:
|
|
43
|
+
#
|
|
44
|
+
# assert_redirected_to page_url(:title => 'foo')
|
|
45
|
+
module Assertions
|
|
46
|
+
def self.included(klass)
|
|
47
|
+
%w(response selector tag dom routing model).each do |kind|
|
|
48
|
+
require "action_controller/assertions/#{kind}_assertions"
|
|
49
|
+
klass.module_eval { include const_get("#{kind.camelize}Assertions") }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def clean_backtrace(&block)
|
|
54
|
+
yield
|
|
55
|
+
rescue Test::Unit::AssertionFailedError => error
|
|
56
|
+
framework_path = Regexp.new(File.expand_path("#{File.dirname(__FILE__)}/assertions"))
|
|
57
|
+
error.backtrace.reject! { |line| File.expand_path(line) =~ framework_path }
|
|
58
|
+
raise
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
module Test #:nodoc:
|
|
64
|
+
module Unit #:nodoc:
|
|
65
|
+
class TestCase #:nodoc:
|
|
66
|
+
include ActionController::Assertions
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module ActionController
|
|
2
|
+
module Assertions
|
|
3
|
+
module DomAssertions
|
|
4
|
+
# Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
|
|
5
|
+
#
|
|
6
|
+
# ==== Examples
|
|
7
|
+
#
|
|
8
|
+
# # assert that the referenced method generates the appropriate HTML string
|
|
9
|
+
# assert_dom_equal '<a href="http://www.example.com">Apples</a>', link_to("Apples", "http://www.example.com")
|
|
10
|
+
#
|
|
11
|
+
def assert_dom_equal(expected, actual, message = "")
|
|
12
|
+
clean_backtrace do
|
|
13
|
+
expected_dom = HTML::Document.new(expected).root
|
|
14
|
+
actual_dom = HTML::Document.new(actual).root
|
|
15
|
+
full_message = build_message(message, "<?> expected to be == to\n<?>.", expected_dom.to_s, actual_dom.to_s)
|
|
16
|
+
|
|
17
|
+
assert_block(full_message) { expected_dom == actual_dom }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# The negated form of +assert_dom_equivalent+.
|
|
22
|
+
#
|
|
23
|
+
# ==== Examples
|
|
24
|
+
#
|
|
25
|
+
# # assert that the referenced method does not generate the specified HTML string
|
|
26
|
+
# assert_dom_not_equal '<a href="http://www.example.com">Apples</a>', link_to("Oranges", "http://www.example.com")
|
|
27
|
+
#
|
|
28
|
+
def assert_dom_not_equal(expected, actual, message = "")
|
|
29
|
+
clean_backtrace do
|
|
30
|
+
expected_dom = HTML::Document.new(expected).root
|
|
31
|
+
actual_dom = HTML::Document.new(actual).root
|
|
32
|
+
full_message = build_message(message, "<?> expected to be != to\n<?>.", expected_dom.to_s, actual_dom.to_s)
|
|
33
|
+
|
|
34
|
+
assert_block(full_message) { expected_dom != actual_dom }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module ActionController
|
|
2
|
+
module Assertions
|
|
3
|
+
module ModelAssertions
|
|
4
|
+
# Ensures that the passed record is valid by Active Record standards and
|
|
5
|
+
# returns any error messages if it is not.
|
|
6
|
+
#
|
|
7
|
+
# ==== Examples
|
|
8
|
+
#
|
|
9
|
+
# # assert that a newly created record is valid
|
|
10
|
+
# model = Model.new
|
|
11
|
+
# assert_valid(model)
|
|
12
|
+
#
|
|
13
|
+
def assert_valid(record)
|
|
14
|
+
clean_backtrace do
|
|
15
|
+
assert record.valid?, record.errors.full_messages.join("\n")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
require 'rexml/document'
|
|
2
|
+
require 'html/document'
|
|
3
|
+
|
|
4
|
+
module ActionController
|
|
5
|
+
module Assertions
|
|
6
|
+
# A small suite of assertions that test responses from Rails applications.
|
|
7
|
+
module ResponseAssertions
|
|
8
|
+
# Asserts that the response is one of the following types:
|
|
9
|
+
#
|
|
10
|
+
# * <tt>:success</tt> - Status code was 200
|
|
11
|
+
# * <tt>:redirect</tt> - Status code was in the 300-399 range
|
|
12
|
+
# * <tt>:missing</tt> - Status code was 404
|
|
13
|
+
# * <tt>:error</tt> - Status code was in the 500-599 range
|
|
14
|
+
#
|
|
15
|
+
# You can also pass an explicit status number like assert_response(501)
|
|
16
|
+
# or its symbolic equivalent assert_response(:not_implemented).
|
|
17
|
+
# See ActionController::StatusCodes for a full list.
|
|
18
|
+
#
|
|
19
|
+
# ==== Examples
|
|
20
|
+
#
|
|
21
|
+
# # assert that the response was a redirection
|
|
22
|
+
# assert_response :redirect
|
|
23
|
+
#
|
|
24
|
+
# # assert that the response code was status code 401 (unauthorized)
|
|
25
|
+
# assert_response 401
|
|
26
|
+
#
|
|
27
|
+
def assert_response(type, message = nil)
|
|
28
|
+
clean_backtrace do
|
|
29
|
+
if [ :success, :missing, :redirect, :error ].include?(type) && @response.send("#{type}?")
|
|
30
|
+
assert_block("") { true } # to count the assertion
|
|
31
|
+
elsif type.is_a?(Fixnum) && @response.response_code == type
|
|
32
|
+
assert_block("") { true } # to count the assertion
|
|
33
|
+
elsif type.is_a?(Symbol) && @response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[type]
|
|
34
|
+
assert_block("") { true } # to count the assertion
|
|
35
|
+
else
|
|
36
|
+
if @response.error?
|
|
37
|
+
exception = @response.template.instance_variable_get(:@exception)
|
|
38
|
+
exception_message = exception && exception.message
|
|
39
|
+
assert_block(build_message(message, "Expected response to be a <?>, but was <?>\n<?>", type, @response.response_code, exception_message.to_s)) { false }
|
|
40
|
+
else
|
|
41
|
+
assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Assert that the redirection options passed in match those of the redirect called in the latest action.
|
|
48
|
+
# This match can be partial, such that assert_redirected_to(:controller => "weblog") will also
|
|
49
|
+
# match the redirection of redirect_to(:controller => "weblog", :action => "show") and so on.
|
|
50
|
+
#
|
|
51
|
+
# ==== Examples
|
|
52
|
+
#
|
|
53
|
+
# # assert that the redirection was to the "index" action on the WeblogController
|
|
54
|
+
# assert_redirected_to :controller => "weblog", :action => "index"
|
|
55
|
+
#
|
|
56
|
+
# # assert that the redirection was to the named route login_url
|
|
57
|
+
# assert_redirected_to login_url
|
|
58
|
+
#
|
|
59
|
+
def assert_redirected_to(options = {}, message=nil)
|
|
60
|
+
clean_backtrace do
|
|
61
|
+
assert_response(:redirect, message)
|
|
62
|
+
return true if options == @response.redirected_to
|
|
63
|
+
ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?
|
|
64
|
+
|
|
65
|
+
begin
|
|
66
|
+
url = {}
|
|
67
|
+
original = { :expected => options, :actual => @response.redirected_to.is_a?(Symbol) ? @response.redirected_to : @response.redirected_to.dup }
|
|
68
|
+
original.each do |key, value|
|
|
69
|
+
if value.is_a?(Symbol)
|
|
70
|
+
value = @controller.respond_to?(value, true) ? @controller.send(value) : @controller.send("hash_for_#{value}_url")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
unless value.is_a?(Hash)
|
|
74
|
+
request = case value
|
|
75
|
+
when NilClass then nil
|
|
76
|
+
when /^\w+:\/\// then recognized_request_for(%r{^(\w+://.*?(/|$|\?))(.*)$} =~ value ? $3 : nil)
|
|
77
|
+
else recognized_request_for(value)
|
|
78
|
+
end
|
|
79
|
+
value = request.path_parameters if request
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if value.is_a?(Hash) # stringify 2 levels of hash keys
|
|
83
|
+
if name = value.delete(:use_route)
|
|
84
|
+
route = ActionController::Routing::Routes.named_routes[name]
|
|
85
|
+
value.update(route.parameter_shell)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
value.stringify_keys!
|
|
89
|
+
value.values.select { |v| v.is_a?(Hash) }.collect { |v| v.stringify_keys! }
|
|
90
|
+
if key == :expected && value['controller'] == @controller.controller_name && original[:actual].is_a?(Hash)
|
|
91
|
+
original[:actual].stringify_keys!
|
|
92
|
+
value.delete('controller') if original[:actual]['controller'].nil? || original[:actual]['controller'] == value['controller']
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
if value.respond_to?(:[]) && value['controller']
|
|
97
|
+
value['controller'] = value['controller'].to_s
|
|
98
|
+
if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/')
|
|
99
|
+
new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path)
|
|
100
|
+
value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) && @response.redirected_to.is_a?(Hash)
|
|
101
|
+
end
|
|
102
|
+
value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash
|
|
103
|
+
end
|
|
104
|
+
url[key] = value
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
@response_diff = url[:actual].diff(url[:expected]) if url[:actual]
|
|
108
|
+
msg = build_message(message, "expected a redirect to <?>, found one to <?>, a difference of <?> ", url[:expected], url[:actual], @response_diff)
|
|
109
|
+
|
|
110
|
+
assert_block(msg) do
|
|
111
|
+
url[:expected].keys.all? do |k|
|
|
112
|
+
if k == :controller then url[:expected][k] == ActionController::Routing.controller_relative_to(url[:actual][k], @controller.class.controller_path)
|
|
113
|
+
else parameterize(url[:expected][k]) == parameterize(url[:actual][k])
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
rescue ActionController::RoutingError # routing failed us, so match the strings only.
|
|
118
|
+
msg = build_message(message, "expected a redirect to <?>, found one to <?>", options, @response.redirect_url)
|
|
119
|
+
url_regexp = %r{^(\w+://.*?(/|$|\?))(.*)$}
|
|
120
|
+
eurl, epath, url, path = [options, @response.redirect_url].collect do |url|
|
|
121
|
+
u, p = (url_regexp =~ url) ? [$1, $3] : [nil, url]
|
|
122
|
+
[u, (p.first == '/') ? p : '/' + p]
|
|
123
|
+
end.flatten
|
|
124
|
+
|
|
125
|
+
assert_equal(eurl, url, msg) if eurl && url
|
|
126
|
+
assert_equal(epath, path, msg) if epath && path
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Asserts that the request was rendered with the appropriate template file.
|
|
132
|
+
#
|
|
133
|
+
# ==== Examples
|
|
134
|
+
#
|
|
135
|
+
# # assert that the "new" view template was rendered
|
|
136
|
+
# assert_template "new"
|
|
137
|
+
#
|
|
138
|
+
def assert_template(expected = nil, message=nil)
|
|
139
|
+
clean_backtrace do
|
|
140
|
+
rendered = expected ? @response.rendered_file(!expected.include?('/')) : @response.rendered_file
|
|
141
|
+
msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
|
|
142
|
+
assert_block(msg) do
|
|
143
|
+
if expected.nil?
|
|
144
|
+
!@response.rendered_with_file?
|
|
145
|
+
else
|
|
146
|
+
expected == rendered
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
# Recognizes the route for a given path.
|
|
154
|
+
def recognized_request_for(path, request_method = nil)
|
|
155
|
+
path = "/#{path}" unless path.first == '/'
|
|
156
|
+
|
|
157
|
+
# Assume given controller
|
|
158
|
+
request = ActionController::TestRequest.new({}, {}, nil)
|
|
159
|
+
request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
|
|
160
|
+
request.path = path
|
|
161
|
+
|
|
162
|
+
ActionController::Routing::Routes.recognize(request)
|
|
163
|
+
request
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Proxy to to_param if the object will respond to it.
|
|
167
|
+
def parameterize(value)
|
|
168
|
+
value.respond_to?(:to_param) ? value.to_param : value
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|