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,20 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/abstract_unit'
|
|
2
|
+
require 'action_mailer/adv_attr_accessor'
|
|
3
|
+
|
|
4
|
+
class AdvAttrTest < Test::Unit::TestCase
|
|
5
|
+
class Person
|
|
6
|
+
include ActionMailer::AdvAttrAccessor
|
|
7
|
+
adv_attr_accessor :name
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_adv_attr
|
|
11
|
+
bob = Person.new
|
|
12
|
+
assert_nil bob.name
|
|
13
|
+
bob.name 'Bob'
|
|
14
|
+
assert_equal 'Bob', bob.name
|
|
15
|
+
|
|
16
|
+
assert_raise(ArgumentError) {bob.name 'x', 'y'}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
# a controller class to facilitate the tests
|
|
4
|
+
class ActionPackAssertionsController < ActionController::Base
|
|
5
|
+
|
|
6
|
+
# this does absolutely nothing
|
|
7
|
+
def nothing() head :ok end
|
|
8
|
+
|
|
9
|
+
# a standard template
|
|
10
|
+
def hello_world() render :template => "test/hello_world"; end
|
|
11
|
+
|
|
12
|
+
# a standard template
|
|
13
|
+
def hello_xml_world() render :template => "test/hello_xml_world"; end
|
|
14
|
+
|
|
15
|
+
# a redirect to an internal location
|
|
16
|
+
def redirect_internal() redirect_to "/nothing"; end
|
|
17
|
+
|
|
18
|
+
def redirect_to_action() redirect_to :action => "flash_me", :id => 1, :params => { "panda" => "fun" }; end
|
|
19
|
+
|
|
20
|
+
def redirect_to_controller() redirect_to :controller => "elsewhere", :action => "flash_me"; end
|
|
21
|
+
|
|
22
|
+
def redirect_to_controller_with_symbol() redirect_to :controller => :elsewhere, :action => :flash_me; end
|
|
23
|
+
|
|
24
|
+
def redirect_to_path() redirect_to '/some/path' end
|
|
25
|
+
|
|
26
|
+
def redirect_to_named_route() redirect_to route_one_url end
|
|
27
|
+
|
|
28
|
+
# a redirect to an external location
|
|
29
|
+
def redirect_external() redirect_to "http://www.rubyonrails.org"; end
|
|
30
|
+
|
|
31
|
+
# a 404
|
|
32
|
+
def response404() head '404 AWOL' end
|
|
33
|
+
|
|
34
|
+
# a 500
|
|
35
|
+
def response500() head '500 Sorry' end
|
|
36
|
+
|
|
37
|
+
# a fictional 599
|
|
38
|
+
def response599() head '599 Whoah!' end
|
|
39
|
+
|
|
40
|
+
# putting stuff in the flash
|
|
41
|
+
def flash_me
|
|
42
|
+
flash['hello'] = 'my name is inigo montoya...'
|
|
43
|
+
render :text => "Inconceivable!"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# we have a flash, but nothing is in it
|
|
47
|
+
def flash_me_naked
|
|
48
|
+
flash.clear
|
|
49
|
+
render :text => "wow!"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# assign some template instance variables
|
|
53
|
+
def assign_this
|
|
54
|
+
@howdy = "ho"
|
|
55
|
+
render :inline => "Mr. Henke"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def render_based_on_parameters
|
|
59
|
+
render :text => "Mr. #{params[:name]}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def render_url
|
|
63
|
+
render :text => "<div>#{url_for(:action => 'flash_me', :only_path => true)}</div>"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def render_text_with_custom_content_type
|
|
67
|
+
render :text => "Hello!", :content_type => Mime::RSS
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# puts something in the session
|
|
71
|
+
def session_stuffing
|
|
72
|
+
session['xmas'] = 'turkey'
|
|
73
|
+
render :text => "ho ho ho"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# raises exception on get requests
|
|
77
|
+
def raise_on_get
|
|
78
|
+
raise "get" if request.get?
|
|
79
|
+
render :text => "request method: #{request.env['REQUEST_METHOD']}"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# raises exception on post requests
|
|
83
|
+
def raise_on_post
|
|
84
|
+
raise "post" if request.post?
|
|
85
|
+
render :text => "request method: #{request.env['REQUEST_METHOD']}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def get_valid_record
|
|
89
|
+
@record = Class.new do
|
|
90
|
+
def valid?
|
|
91
|
+
true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def errors
|
|
95
|
+
Class.new do
|
|
96
|
+
def full_messages; []; end
|
|
97
|
+
end.new
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end.new
|
|
101
|
+
|
|
102
|
+
render :nothing => true
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def get_invalid_record
|
|
107
|
+
@record = Class.new do
|
|
108
|
+
|
|
109
|
+
def valid?
|
|
110
|
+
false
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def errors
|
|
114
|
+
Class.new do
|
|
115
|
+
def full_messages; ['...stuff...']; end
|
|
116
|
+
end.new
|
|
117
|
+
end
|
|
118
|
+
end.new
|
|
119
|
+
|
|
120
|
+
render :nothing => true
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# 911
|
|
124
|
+
def rescue_action(e) raise; end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Used to test that assert_response includes the exception message
|
|
128
|
+
# in the failure message when an action raises and assert_response
|
|
129
|
+
# is expecting something other than an error.
|
|
130
|
+
class AssertResponseWithUnexpectedErrorController < ActionController::Base
|
|
131
|
+
def index
|
|
132
|
+
raise 'FAIL'
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def show
|
|
136
|
+
render :text => "Boom", :status => 500
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
class UserController < ActionController::Base
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
module Admin
|
|
144
|
+
class InnerModuleController < ActionController::Base
|
|
145
|
+
def index
|
|
146
|
+
render :nothing => true
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def redirect_to_index
|
|
150
|
+
redirect_to admin_inner_module_path
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def redirect_to_absolute_controller
|
|
154
|
+
redirect_to :controller => '/content'
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def redirect_to_fellow_controller
|
|
158
|
+
redirect_to :controller => 'user'
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def redirect_to_top_level_named_route
|
|
162
|
+
redirect_to top_level_url(:id => "foo")
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# ---------------------------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
# tell the controller where to find its templates but start from parent
|
|
171
|
+
# directory of test_request_response to simulate the behaviour of a
|
|
172
|
+
# production environment
|
|
173
|
+
ActionPackAssertionsController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
|
174
|
+
|
|
175
|
+
# a test case to exercise the new capabilities TestRequest & TestResponse
|
|
176
|
+
class ActionPackAssertionsControllerTest < Test::Unit::TestCase
|
|
177
|
+
# let's get this party started
|
|
178
|
+
def setup
|
|
179
|
+
ActionController::Routing::Routes.reload
|
|
180
|
+
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
|
|
181
|
+
@controller = ActionPackAssertionsController.new
|
|
182
|
+
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def teardown
|
|
186
|
+
ActionController::Routing::Routes.reload
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
# -- assertion-based testing ------------------------------------------------
|
|
190
|
+
|
|
191
|
+
def test_assert_tag_and_url_for
|
|
192
|
+
get :render_url
|
|
193
|
+
assert_tag :content => "/action_pack_assertions/flash_me"
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# test the get method, make sure the request really was a get
|
|
197
|
+
def test_get
|
|
198
|
+
assert_raise(RuntimeError) { get :raise_on_get }
|
|
199
|
+
get :raise_on_post
|
|
200
|
+
assert_equal @response.body, 'request method: GET'
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# test the get method, make sure the request really was a get
|
|
204
|
+
def test_post
|
|
205
|
+
assert_raise(RuntimeError) { post :raise_on_post }
|
|
206
|
+
post :raise_on_get
|
|
207
|
+
assert_equal @response.body, 'request method: POST'
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# the following test fails because the request_method is now cached on the request instance
|
|
211
|
+
# test the get/post switch within one test action
|
|
212
|
+
# def test_get_post_switch
|
|
213
|
+
# post :raise_on_get
|
|
214
|
+
# assert_equal @response.body, 'request method: POST'
|
|
215
|
+
# get :raise_on_post
|
|
216
|
+
# assert_equal @response.body, 'request method: GET'
|
|
217
|
+
# post :raise_on_get
|
|
218
|
+
# assert_equal @response.body, 'request method: POST'
|
|
219
|
+
# get :raise_on_post
|
|
220
|
+
# assert_equal @response.body, 'request method: GET'
|
|
221
|
+
# end
|
|
222
|
+
|
|
223
|
+
# test the redirection to a named route
|
|
224
|
+
def test_assert_redirect_to_named_route
|
|
225
|
+
with_routing do |set|
|
|
226
|
+
set.draw do |map|
|
|
227
|
+
map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing'
|
|
228
|
+
map.connect ':controller/:action/:id'
|
|
229
|
+
end
|
|
230
|
+
set.install_helpers
|
|
231
|
+
|
|
232
|
+
process :redirect_to_named_route
|
|
233
|
+
assert_redirected_to 'http://test.host/route_one'
|
|
234
|
+
assert_redirected_to route_one_url
|
|
235
|
+
assert_redirected_to :route_one_url
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def test_assert_redirect_to_named_route_failure
|
|
240
|
+
with_routing do |set|
|
|
241
|
+
set.draw do |map|
|
|
242
|
+
map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'one'
|
|
243
|
+
map.route_two 'route_two', :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
|
|
244
|
+
map.connect ':controller/:action/:id'
|
|
245
|
+
end
|
|
246
|
+
process :redirect_to_named_route
|
|
247
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
|
248
|
+
assert_redirected_to 'http://test.host/route_two'
|
|
249
|
+
end
|
|
250
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
|
251
|
+
assert_redirected_to :controller => 'action_pack_assertions', :action => 'nothing', :id => 'two'
|
|
252
|
+
end
|
|
253
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
|
254
|
+
assert_redirected_to route_two_url
|
|
255
|
+
end
|
|
256
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
|
257
|
+
assert_redirected_to :route_two_url
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def test_assert_redirect_to_nested_named_route
|
|
263
|
+
with_routing do |set|
|
|
264
|
+
set.draw do |map|
|
|
265
|
+
map.admin_inner_module 'admin/inner_module', :controller => 'admin/inner_module', :action => 'index'
|
|
266
|
+
map.connect ':controller/:action/:id'
|
|
267
|
+
end
|
|
268
|
+
@controller = Admin::InnerModuleController.new
|
|
269
|
+
process :redirect_to_index
|
|
270
|
+
# redirection is <{"action"=>"index", "controller"=>"admin/admin/inner_module"}>
|
|
271
|
+
assert_redirected_to admin_inner_module_path
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def test_assert_redirected_to_top_level_named_route_from_nested_controller
|
|
276
|
+
with_routing do |set|
|
|
277
|
+
set.draw do |map|
|
|
278
|
+
map.top_level '/action_pack_assertions/:id', :controller => 'action_pack_assertions', :action => 'index'
|
|
279
|
+
map.connect ':controller/:action/:id'
|
|
280
|
+
end
|
|
281
|
+
@controller = Admin::InnerModuleController.new
|
|
282
|
+
process :redirect_to_top_level_named_route
|
|
283
|
+
# assert_redirected_to "http://test.host/action_pack_assertions/foo" would pass because of exact match early return
|
|
284
|
+
assert_redirected_to "/action_pack_assertions/foo"
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def test_assert_redirected_to_top_level_named_route_with_same_controller_name_in_both_namespaces
|
|
289
|
+
with_routing do |set|
|
|
290
|
+
set.draw do |map|
|
|
291
|
+
# this controller exists in the admin namespace as well which is the only difference from previous test
|
|
292
|
+
map.top_level '/user/:id', :controller => 'user', :action => 'index'
|
|
293
|
+
map.connect ':controller/:action/:id'
|
|
294
|
+
end
|
|
295
|
+
@controller = Admin::InnerModuleController.new
|
|
296
|
+
process :redirect_to_top_level_named_route
|
|
297
|
+
# assert_redirected_to top_level_url('foo') would pass because of exact match early return
|
|
298
|
+
assert_redirected_to top_level_path('foo')
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# -- standard request/response object testing --------------------------------
|
|
303
|
+
|
|
304
|
+
# make sure that the template objects exist
|
|
305
|
+
def test_template_objects_alive
|
|
306
|
+
process :assign_this
|
|
307
|
+
assert !@response.has_template_object?('hi')
|
|
308
|
+
assert @response.has_template_object?('howdy')
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
# make sure we don't have template objects when we shouldn't
|
|
312
|
+
def test_template_object_missing
|
|
313
|
+
process :nothing
|
|
314
|
+
assert_nil @response.template_objects['howdy']
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# check the empty flashing
|
|
318
|
+
def test_flash_me_naked
|
|
319
|
+
process :flash_me_naked
|
|
320
|
+
assert !@response.has_flash?
|
|
321
|
+
assert !@response.has_flash_with_contents?
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# check if we have flash objects
|
|
325
|
+
def test_flash_haves
|
|
326
|
+
process :flash_me
|
|
327
|
+
assert @response.has_flash?
|
|
328
|
+
assert @response.has_flash_with_contents?
|
|
329
|
+
assert @response.has_flash_object?('hello')
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
# ensure we don't have flash objects
|
|
333
|
+
def test_flash_have_nots
|
|
334
|
+
process :nothing
|
|
335
|
+
assert !@response.has_flash?
|
|
336
|
+
assert !@response.has_flash_with_contents?
|
|
337
|
+
assert_nil @response.flash['hello']
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# check if we were rendered by a file-based template?
|
|
341
|
+
def test_rendered_action
|
|
342
|
+
process :nothing
|
|
343
|
+
assert !@response.rendered_with_file?
|
|
344
|
+
|
|
345
|
+
process :hello_world
|
|
346
|
+
assert @response.rendered_with_file?
|
|
347
|
+
assert 'hello_world', @response.rendered_file
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# check the redirection location
|
|
351
|
+
def test_redirection_location
|
|
352
|
+
process :redirect_internal
|
|
353
|
+
assert_equal 'http://test.host/nothing', @response.redirect_url
|
|
354
|
+
|
|
355
|
+
process :redirect_external
|
|
356
|
+
assert_equal 'http://www.rubyonrails.org', @response.redirect_url
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
def test_no_redirect_url
|
|
360
|
+
process :nothing
|
|
361
|
+
assert_nil @response.redirect_url
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
# check server errors
|
|
366
|
+
def test_server_error_response_code
|
|
367
|
+
process :response500
|
|
368
|
+
assert @response.server_error?
|
|
369
|
+
|
|
370
|
+
process :response599
|
|
371
|
+
assert @response.server_error?
|
|
372
|
+
|
|
373
|
+
process :response404
|
|
374
|
+
assert !@response.server_error?
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
# check a 404 response code
|
|
378
|
+
def test_missing_response_code
|
|
379
|
+
process :response404
|
|
380
|
+
assert @response.missing?
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
# check to see if our redirection matches a pattern
|
|
384
|
+
def test_redirect_url_match
|
|
385
|
+
process :redirect_external
|
|
386
|
+
assert @response.redirect?
|
|
387
|
+
assert @response.redirect_url_match?("rubyonrails")
|
|
388
|
+
assert @response.redirect_url_match?(/rubyonrails/)
|
|
389
|
+
assert !@response.redirect_url_match?("phpoffrails")
|
|
390
|
+
assert !@response.redirect_url_match?(/perloffrails/)
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
# check for a redirection
|
|
394
|
+
def test_redirection
|
|
395
|
+
process :redirect_internal
|
|
396
|
+
assert @response.redirect?
|
|
397
|
+
|
|
398
|
+
process :redirect_external
|
|
399
|
+
assert @response.redirect?
|
|
400
|
+
|
|
401
|
+
process :nothing
|
|
402
|
+
assert !@response.redirect?
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
# check a successful response code
|
|
406
|
+
def test_successful_response_code
|
|
407
|
+
process :nothing
|
|
408
|
+
assert @response.success?
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
# a basic check to make sure we have a TestResponse object
|
|
412
|
+
def test_has_response
|
|
413
|
+
process :nothing
|
|
414
|
+
assert_kind_of ActionController::TestResponse, @response
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
def test_render_based_on_parameters
|
|
418
|
+
process :render_based_on_parameters, "name" => "David"
|
|
419
|
+
assert_equal "Mr. David", @response.body
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def test_follow_redirect
|
|
423
|
+
process :redirect_to_action
|
|
424
|
+
assert_redirected_to :action => "flash_me"
|
|
425
|
+
|
|
426
|
+
assert_deprecated { follow_redirect }
|
|
427
|
+
assert_equal 1, @request.parameters["id"].to_i
|
|
428
|
+
|
|
429
|
+
assert "Inconceivable!", @response.body
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
def test_follow_redirect_outside_current_action
|
|
433
|
+
process :redirect_to_controller
|
|
434
|
+
assert_redirected_to :controller => "elsewhere", :action => "flash_me"
|
|
435
|
+
|
|
436
|
+
assert_raises(RuntimeError, "Can't follow redirects outside of current controller (elsewhere)") do
|
|
437
|
+
assert_deprecated { follow_redirect }
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def test_assert_redirection_fails_with_incorrect_controller
|
|
442
|
+
process :redirect_to_controller
|
|
443
|
+
assert_raise(Test::Unit::AssertionFailedError) do
|
|
444
|
+
assert_redirected_to :controller => "action_pack_assertions", :action => "flash_me"
|
|
445
|
+
end
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
def test_assert_redirection_with_extra_controller_option
|
|
449
|
+
get :redirect_to_action
|
|
450
|
+
assert_redirected_to :controller => 'action_pack_assertions', :action => "flash_me", :id => 1, :params => { :panda => 'fun' }
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
def test_redirected_to_url_leadling_slash
|
|
454
|
+
process :redirect_to_path
|
|
455
|
+
assert_redirected_to '/some/path'
|
|
456
|
+
end
|
|
457
|
+
def test_redirected_to_url_no_leadling_slash
|
|
458
|
+
process :redirect_to_path
|
|
459
|
+
assert_redirected_to 'some/path'
|
|
460
|
+
end
|
|
461
|
+
def test_redirected_to_url_full_url
|
|
462
|
+
process :redirect_to_path
|
|
463
|
+
assert_redirected_to 'http://test.host/some/path'
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
def test_assert_redirection_with_symbol
|
|
467
|
+
process :redirect_to_controller_with_symbol
|
|
468
|
+
assert_nothing_raised {
|
|
469
|
+
assert_redirected_to :controller => "elsewhere", :action => "flash_me"
|
|
470
|
+
}
|
|
471
|
+
process :redirect_to_controller_with_symbol
|
|
472
|
+
assert_nothing_raised {
|
|
473
|
+
assert_redirected_to :controller => :elsewhere, :action => :flash_me
|
|
474
|
+
}
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
def test_redirected_to_with_nested_controller
|
|
478
|
+
@controller = Admin::InnerModuleController.new
|
|
479
|
+
get :redirect_to_absolute_controller
|
|
480
|
+
assert_redirected_to :controller => 'content'
|
|
481
|
+
|
|
482
|
+
get :redirect_to_fellow_controller
|
|
483
|
+
assert_redirected_to :controller => 'admin/user'
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
def test_assert_valid
|
|
487
|
+
get :get_valid_record
|
|
488
|
+
assert_valid assigns('record')
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
def test_assert_valid_failing
|
|
492
|
+
get :get_invalid_record
|
|
493
|
+
|
|
494
|
+
begin
|
|
495
|
+
assert_valid assigns('record')
|
|
496
|
+
assert false
|
|
497
|
+
rescue Test::Unit::AssertionFailedError => e
|
|
498
|
+
end
|
|
499
|
+
end
|
|
500
|
+
|
|
501
|
+
def test_assert_response_uses_exception_message
|
|
502
|
+
@controller = AssertResponseWithUnexpectedErrorController.new
|
|
503
|
+
get :index
|
|
504
|
+
assert_response :success
|
|
505
|
+
flunk 'Expected non-success response'
|
|
506
|
+
rescue Test::Unit::AssertionFailedError => e
|
|
507
|
+
assert e.message.include?('FAIL')
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
def test_assert_response_failure_response_with_no_exception
|
|
511
|
+
@controller = AssertResponseWithUnexpectedErrorController.new
|
|
512
|
+
get :show
|
|
513
|
+
assert_response :success
|
|
514
|
+
flunk 'Expected non-success response'
|
|
515
|
+
rescue Test::Unit::AssertionFailedError
|
|
516
|
+
rescue
|
|
517
|
+
flunk "assert_response failed to handle failure response with missing, but optional, exception."
|
|
518
|
+
end
|
|
519
|
+
end
|
|
520
|
+
|
|
521
|
+
class ActionPackHeaderTest < Test::Unit::TestCase
|
|
522
|
+
def setup
|
|
523
|
+
@controller = ActionPackAssertionsController.new
|
|
524
|
+
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
def test_rendering_xml_sets_content_type
|
|
528
|
+
process :hello_xml_world
|
|
529
|
+
assert_equal('application/xml; charset=utf-8', @response.headers['type'])
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
def test_rendering_xml_respects_content_type
|
|
533
|
+
@response.headers['type'] = 'application/pdf'
|
|
534
|
+
process :hello_xml_world
|
|
535
|
+
assert_equal('application/pdf; charset=utf-8', @response.headers['type'])
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
def test_render_text_with_custom_content_type
|
|
540
|
+
get :render_text_with_custom_content_type
|
|
541
|
+
assert_equal 'application/rss+xml; charset=utf-8', @response.headers['type']
|
|
542
|
+
end
|
|
543
|
+
end
|