actionpack 1.13.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +1400 -20
- data/MIT-LICENSE +1 -1
- data/README +5 -5
- data/RUNNING_UNIT_TESTS +4 -5
- data/Rakefile +5 -6
- data/install.rb +2 -2
- data/lib/action_controller.rb +11 -15
- data/lib/action_controller/assertions.rb +12 -25
- data/lib/action_controller/assertions/dom_assertions.rb +18 -4
- data/lib/action_controller/assertions/model_assertions.rb +8 -1
- data/lib/action_controller/assertions/response_assertions.rb +35 -12
- data/lib/action_controller/assertions/routing_assertions.rb +56 -12
- data/lib/action_controller/assertions/selector_assertions.rb +105 -38
- data/lib/action_controller/assertions/tag_assertions.rb +28 -15
- data/lib/action_controller/base.rb +318 -250
- data/lib/action_controller/benchmarking.rb +33 -29
- data/lib/action_controller/caching.rb +130 -64
- data/lib/action_controller/cgi_ext.rb +16 -0
- data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
- data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
- data/lib/action_controller/cgi_ext/session.rb +73 -0
- data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
- data/lib/action_controller/cgi_process.rb +34 -57
- data/lib/action_controller/components.rb +19 -36
- data/lib/action_controller/cookies.rb +10 -9
- data/lib/action_controller/dispatcher.rb +195 -0
- data/lib/action_controller/filters.rb +35 -34
- data/lib/action_controller/flash.rb +30 -35
- data/lib/action_controller/helpers.rb +121 -47
- data/lib/action_controller/http_authentication.rb +126 -0
- data/lib/action_controller/integration.rb +105 -101
- data/lib/action_controller/layout.rb +59 -47
- data/lib/action_controller/mime_responds.rb +57 -68
- data/lib/action_controller/mime_type.rb +43 -80
- data/lib/action_controller/mime_types.rb +20 -0
- data/lib/action_controller/polymorphic_routes.rb +88 -0
- data/lib/action_controller/record_identifier.rb +91 -0
- data/lib/action_controller/request.rb +553 -88
- data/lib/action_controller/request_forgery_protection.rb +126 -0
- data/lib/action_controller/request_profiler.rb +138 -0
- data/lib/action_controller/rescue.rb +185 -69
- data/lib/action_controller/resources.rb +211 -172
- data/lib/action_controller/response.rb +49 -8
- data/lib/action_controller/routing.rb +359 -236
- data/lib/action_controller/routing_optimisation.rb +119 -0
- data/lib/action_controller/session/active_record_store.rb +3 -2
- data/lib/action_controller/session/cookie_store.rb +161 -0
- data/lib/action_controller/session/mem_cache_store.rb +9 -16
- data/lib/action_controller/session_management.rb +17 -8
- data/lib/action_controller/streaming.rb +6 -3
- data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
- data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
- data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
- data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
- data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
- data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
- data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
- data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
- data/lib/action_controller/test_case.rb +53 -0
- data/lib/action_controller/test_process.rb +59 -46
- data/lib/action_controller/url_rewriter.rb +48 -24
- data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
- data/lib/action_controller/verification.rb +27 -21
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +4 -4
- data/lib/action_view.rb +2 -3
- data/lib/action_view/base.rb +218 -63
- data/lib/action_view/compiled_templates.rb +1 -2
- data/lib/action_view/helpers/active_record_helper.rb +35 -17
- data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
- data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
- data/lib/action_view/helpers/benchmark_helper.rb +12 -5
- data/lib/action_view/helpers/cache_helper.rb +29 -0
- data/lib/action_view/helpers/capture_helper.rb +97 -63
- data/lib/action_view/helpers/date_helper.rb +295 -35
- data/lib/action_view/helpers/debug_helper.rb +6 -2
- data/lib/action_view/helpers/form_helper.rb +354 -111
- data/lib/action_view/helpers/form_options_helper.rb +171 -109
- data/lib/action_view/helpers/form_tag_helper.rb +332 -76
- data/lib/action_view/helpers/javascript_helper.rb +35 -11
- data/lib/action_view/helpers/javascripts/controls.js +484 -354
- data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
- data/lib/action_view/helpers/javascripts/effects.js +396 -364
- data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
- data/lib/action_view/helpers/number_helper.rb +84 -60
- data/lib/action_view/helpers/prototype_helper.rb +419 -43
- data/lib/action_view/helpers/record_identification_helper.rb +20 -0
- data/lib/action_view/helpers/record_tag_helper.rb +59 -0
- data/lib/action_view/helpers/sanitize_helper.rb +223 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
- data/lib/action_view/helpers/tag_helper.rb +69 -39
- data/lib/action_view/helpers/text_helper.rb +221 -148
- data/lib/action_view/helpers/url_helper.rb +283 -165
- data/lib/action_view/partials.rb +134 -62
- data/lib/action_view/template_error.rb +4 -12
- data/lib/actionpack.rb +1 -0
- data/test/abstract_unit.rb +21 -1
- data/test/action_view_test.rb +26 -0
- data/test/active_record_unit.rb +12 -20
- data/test/activerecord/active_record_store_test.rb +2 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
- data/test/controller/action_pack_assertions_test.rb +21 -152
- data/test/controller/addresses_render_test.rb +2 -7
- data/test/controller/assert_select_test.rb +120 -14
- data/test/controller/base_test.rb +11 -13
- data/test/controller/caching_test.rb +125 -5
- data/test/controller/capture_test.rb +23 -16
- data/test/controller/cgi_test.rb +66 -391
- data/test/controller/components_test.rb +31 -42
- data/test/controller/content_type_test.rb +1 -1
- data/test/controller/cookie_test.rb +42 -14
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
- data/test/controller/dispatcher_test.rb +123 -0
- data/test/controller/fake_models.rb +5 -0
- data/test/controller/filters_test.rb +44 -7
- data/test/controller/flash_test.rb +46 -2
- data/test/controller/fragment_store_setting_test.rb +10 -8
- data/test/controller/helper_test.rb +19 -2
- data/test/controller/html-scanner/document_test.rb +124 -0
- data/test/controller/html-scanner/node_test.rb +69 -0
- data/test/controller/html-scanner/sanitizer_test.rb +250 -0
- data/test/controller/html-scanner/tag_node_test.rb +239 -0
- data/test/controller/html-scanner/text_node_test.rb +51 -0
- data/test/controller/html-scanner/tokenizer_test.rb +125 -0
- data/test/controller/http_authentication_test.rb +54 -0
- data/test/controller/integration_test.rb +12 -26
- data/test/controller/layout_test.rb +64 -12
- data/test/controller/mime_responds_test.rb +193 -38
- data/test/controller/mime_type_test.rb +30 -8
- data/test/controller/new_render_test.rb +104 -22
- data/test/controller/polymorphic_routes_test.rb +98 -0
- data/test/controller/record_identifier_test.rb +103 -0
- data/test/controller/redirect_test.rb +120 -18
- data/test/controller/render_test.rb +195 -45
- data/test/controller/request_forgery_protection_test.rb +217 -0
- data/test/controller/request_test.rb +545 -27
- data/test/controller/rescue_test.rb +501 -0
- data/test/controller/resources_test.rb +258 -132
- data/test/controller/routing_test.rb +502 -106
- data/test/controller/selector_test.rb +5 -5
- data/test/controller/send_file_test.rb +17 -7
- data/test/controller/session/cookie_store_test.rb +246 -0
- data/test/controller/session/mem_cache_store_test.rb +182 -0
- data/test/controller/session_fixation_test.rb +8 -11
- data/test/controller/session_management_test.rb +7 -7
- data/test/controller/test_test.rb +150 -38
- data/test/controller/url_rewriter_test.rb +87 -12
- data/test/controller/verification_test.rb +11 -0
- data/test/controller/view_paths_test.rb +137 -0
- data/test/controller/webservice_test.rb +11 -75
- data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
- data/test/fixtures/db_definitions/sqlite.sql +2 -1
- data/test/fixtures/developer.rb +2 -0
- data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
- data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
- data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
- data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
- data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
- data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/bracketed_param +5 -0
- data/test/fixtures/override/test/hello_world.erb +1 -0
- data/test/fixtures/override2/layouts/test/sub.erb +1 -0
- data/test/fixtures/post_test/layouts/post.html.erb +1 -0
- data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
- data/test/fixtures/post_test/post/index.html.erb +1 -0
- data/test/fixtures/post_test/post/index.iphone.erb +1 -0
- data/test/fixtures/post_test/super_post/index.html.erb +1 -0
- data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
- data/test/fixtures/public/404.html +1 -0
- data/test/fixtures/public/500.html +1 -0
- data/test/fixtures/public/javascripts/application.js +0 -1
- data/test/fixtures/public/javascripts/bank.js +1 -0
- data/test/fixtures/public/javascripts/robber.js +1 -0
- data/test/fixtures/public/stylesheets/bank.css +1 -0
- data/test/fixtures/public/stylesheets/robber.css +1 -0
- data/test/fixtures/replies.yml +2 -0
- data/test/fixtures/reply.rb +2 -1
- data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
- data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
- data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
- data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
- data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
- data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
- data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
- data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
- data/test/fixtures/test/_hash_greeting.erb +1 -0
- data/test/fixtures/test/_hash_object.erb +2 -0
- data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
- data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
- data/test/fixtures/test/_partial.erb +1 -0
- data/test/fixtures/test/_partial.html.erb +1 -0
- data/test/fixtures/test/_partial.js.erb +1 -0
- data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
- data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
- data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
- data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
- data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
- data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
- data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
- data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
- data/test/fixtures/test/content_for_concatenated.erb +3 -0
- data/test/fixtures/test/content_for_with_parameter.erb +2 -0
- data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
- data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.builder +1 -0
- data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
- data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
- data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
- data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
- data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
- data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
- data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
- data/test/fixtures/test/list.erb +1 -0
- data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
- data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
- data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
- data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
- data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
- data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
- data/test/fixtures/topic.rb +1 -1
- data/test/template/active_record_helper_test.rb +67 -20
- data/test/template/asset_tag_helper_test.rb +222 -54
- data/test/template/atom_feed_helper_test.rb +101 -0
- data/test/template/benchmark_helper_test.rb +2 -2
- data/test/template/compiled_templates_test.rb +76 -32
- data/test/template/date_helper_test.rb +125 -9
- data/test/template/form_helper_test.rb +326 -33
- data/test/template/form_options_helper_test.rb +822 -15
- data/test/template/form_tag_helper_test.rb +96 -30
- data/test/template/javascript_helper_test.rb +61 -13
- data/test/template/number_helper_test.rb +12 -11
- data/test/template/prototype_helper_test.rb +185 -24
- data/test/template/sanitize_helper_test.rb +49 -0
- data/test/template/scriptaculous_helper_test.rb +9 -3
- data/test/template/tag_helper_test.rb +13 -2
- data/test/template/text_helper_test.rb +38 -52
- data/test/template/url_helper_test.rb +216 -46
- metadata +144 -116
- data/examples/.htaccess +0 -24
- data/examples/address_book/index.rhtml +0 -33
- data/examples/address_book/layout.rhtml +0 -8
- data/examples/address_book_controller.cgi +0 -9
- data/examples/address_book_controller.fcgi +0 -6
- data/examples/address_book_controller.rb +0 -52
- data/examples/address_book_controller.rbx +0 -4
- data/examples/benchmark.rb +0 -52
- data/examples/benchmark_with_ar.fcgi +0 -89
- data/examples/blog_controller.cgi +0 -53
- data/examples/debate/index.rhtml +0 -14
- data/examples/debate/new_topic.rhtml +0 -22
- data/examples/debate/topic.rhtml +0 -32
- data/examples/debate_controller.cgi +0 -57
- data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
- data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
- data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
- data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
- data/lib/action_controller/deprecated_dependencies.rb +0 -65
- data/lib/action_controller/deprecated_redirects.rb +0 -17
- data/lib/action_controller/deprecated_request_methods.rb +0 -34
- data/lib/action_controller/macros/auto_complete.rb +0 -53
- data/lib/action_controller/macros/in_place_editing.rb +0 -33
- data/lib/action_controller/pagination.rb +0 -408
- data/lib/action_controller/scaffolding.rb +0 -189
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
- data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
- data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
- data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
- data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
- data/lib/action_controller/vendor/xml_node.rb +0 -97
- data/lib/action_view/helpers/deprecated_helper.rb +0 -37
- data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
- data/lib/action_view/helpers/pagination_helper.rb +0 -86
- data/test/activerecord/active_record_assertions_test.rb +0 -92
- data/test/activerecord/pagination_test.rb +0 -165
- data/test/controller/deprecated_instance_variables_test.rb +0 -48
- data/test/controller/raw_post_test.rb +0 -68
- data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
- data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
- data/test/fixtures/test/_hash_object.rhtml +0 -1
- data/test/fixtures/test/list.rhtml +0 -1
- data/test/template/deprecated_helper_test.rb +0 -36
- data/test/template/deprecated_instance_variables_test.rb +0 -43
- data/test/template/java_script_macros_helper_test.rb +0 -109
@@ -9,12 +9,37 @@ end
|
|
9
9
|
class ThreadsController < ResourcesController; end
|
10
10
|
class MessagesController < ResourcesController; end
|
11
11
|
class CommentsController < ResourcesController; end
|
12
|
+
class AuthorsController < ResourcesController; end
|
13
|
+
class LogosController < ResourcesController; end
|
12
14
|
|
13
|
-
class
|
14
|
-
class AdminController
|
15
|
-
|
15
|
+
class AccountsController < ResourcesController; end
|
16
|
+
class AdminController < ResourcesController; end
|
17
|
+
|
18
|
+
module Backoffice
|
19
|
+
class ProductsController < ResourcesController; end
|
20
|
+
class TagsController < ResourcesController; end
|
21
|
+
class ManufacturersController < ResourcesController; end
|
22
|
+
class ImagesController < ResourcesController; end
|
23
|
+
|
24
|
+
module Admin
|
25
|
+
class ProductsController < ResourcesController; end
|
26
|
+
class ImagesController < ResourcesController; end
|
27
|
+
end
|
28
|
+
end
|
16
29
|
|
17
30
|
class ResourcesTest < Test::Unit::TestCase
|
31
|
+
|
32
|
+
|
33
|
+
# The assertions in these tests are incompatible with the hash method
|
34
|
+
# optimisation. This could indicate user level problems
|
35
|
+
def setup
|
36
|
+
ActionController::Base.optimise_named_routes = false
|
37
|
+
end
|
38
|
+
|
39
|
+
def tear_down
|
40
|
+
ActionController::Base.optimise_named_routes = true
|
41
|
+
end
|
42
|
+
|
18
43
|
def test_should_arrange_actions
|
19
44
|
resource = ActionController::Resources::Resource.new(:messages,
|
20
45
|
:collection => { :rss => :get, :reorder => :post, :csv => :post },
|
@@ -58,6 +83,37 @@ class ResourcesTest < Test::Unit::TestCase
|
|
58
83
|
end
|
59
84
|
end
|
60
85
|
|
86
|
+
def test_with_custom_conditions
|
87
|
+
with_restful_routing :messages, :conditions => { :subdomain => 'app' } do
|
88
|
+
assert_equal 'app', ActionController::Routing::Routes.named_routes.routes[:messages].conditions[:subdomain]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_irregular_id_with_no_requirements_should_raise_error
|
93
|
+
expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'}
|
94
|
+
|
95
|
+
with_restful_routing :messages do
|
96
|
+
assert_raises(ActionController::RoutingError) do
|
97
|
+
assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_irregular_id_with_requirements_should_pass
|
103
|
+
expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'}
|
104
|
+
|
105
|
+
with_restful_routing(:messages, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}) do
|
106
|
+
assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_with_path_prefix_requirements
|
111
|
+
expected_options = {:controller => 'messages', :action => 'show', :thread_id => '1.1.1', :id => '1'}
|
112
|
+
with_restful_routing :messages, :path_prefix => '/thread/:thread_id', :requirements => {:thread_id => /[0-9]\.[0-9]\.[0-9]/} do
|
113
|
+
assert_recognizes(expected_options, :path => 'thread/1.1.1/messages/1', :method => :get)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
61
117
|
def test_with_path_prefix
|
62
118
|
with_restful_routing :messages, :path_prefix => '/thread/:thread_id' do
|
63
119
|
assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }
|
@@ -77,22 +133,17 @@ class ResourcesTest < Test::Unit::TestCase
|
|
77
133
|
end
|
78
134
|
end
|
79
135
|
|
80
|
-
def
|
81
|
-
|
82
|
-
rss_path = "/messages/rss"
|
83
|
-
actions = { 'a' => :put, 'b' => :post, 'c' => :delete }
|
136
|
+
def test_with_collection_actions
|
137
|
+
actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete }
|
84
138
|
|
85
|
-
with_restful_routing :messages, :collection =>
|
139
|
+
with_restful_routing :messages, :collection => actions do
|
86
140
|
assert_restful_routes_for :messages do |options|
|
87
|
-
assert_routing rss_path, options.merge(rss_options)
|
88
|
-
|
89
141
|
actions.each do |action, method|
|
90
142
|
assert_recognizes(options.merge(:action => action), :path => "/messages/#{action}", :method => method)
|
91
143
|
end
|
92
144
|
end
|
93
145
|
|
94
146
|
assert_restful_named_routes_for :messages do |options|
|
95
|
-
assert_named_route rss_path, :rss_messages_path, rss_options
|
96
147
|
actions.keys.each do |action|
|
97
148
|
assert_named_route "/messages/#{action}", "#{action}_messages_path", :action => action
|
98
149
|
end
|
@@ -100,6 +151,42 @@ class ResourcesTest < Test::Unit::TestCase
|
|
100
151
|
end
|
101
152
|
end
|
102
153
|
|
154
|
+
def test_with_collection_actions_and_name_prefix
|
155
|
+
actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete }
|
156
|
+
|
157
|
+
with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do
|
158
|
+
assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
159
|
+
actions.each do |action, method|
|
160
|
+
assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
165
|
+
actions.keys.each do |action|
|
166
|
+
assert_named_route "/threads/1/messages/#{action}", "#{action}_thread_messages_path", :action => action
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_with_collection_action_and_name_prefix_and_formatted
|
173
|
+
actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete }
|
174
|
+
|
175
|
+
with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do
|
176
|
+
assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
177
|
+
actions.each do |action, method|
|
178
|
+
assert_recognizes(options.merge(:action => action, :format => 'xml'), :path => "/threads/1/messages/#{action}.xml", :method => method)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
183
|
+
actions.keys.each do |action|
|
184
|
+
assert_named_route "/threads/1/messages/#{action}.xml", "formatted_#{action}_thread_messages_path", :action => action, :format => 'xml'
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
103
190
|
def test_with_member_action
|
104
191
|
[:put, :post].each do |method|
|
105
192
|
with_restful_routing :messages, :member => { :mark => method } do
|
@@ -147,12 +234,40 @@ class ResourcesTest < Test::Unit::TestCase
|
|
147
234
|
end
|
148
235
|
end
|
149
236
|
end
|
237
|
+
|
238
|
+
def test_with_new_action_with_name_prefix
|
239
|
+
with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do
|
240
|
+
preview_options = {:action => 'preview', :thread_id => '1'}
|
241
|
+
preview_path = "/threads/1/messages/new/preview"
|
242
|
+
assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
243
|
+
assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post)
|
244
|
+
end
|
245
|
+
|
246
|
+
assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
247
|
+
assert_named_route preview_path, :preview_new_thread_message_path, preview_options
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_with_formatted_new_action_with_name_prefix
|
253
|
+
with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do
|
254
|
+
preview_options = {:action => 'preview', :thread_id => '1', :format => 'xml'}
|
255
|
+
preview_path = "/threads/1/messages/new/preview.xml"
|
256
|
+
assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
257
|
+
assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post)
|
258
|
+
end
|
150
259
|
|
260
|
+
assert_restful_named_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options|
|
261
|
+
assert_named_route preview_path, :formatted_preview_new_thread_message_path, preview_options
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
151
266
|
def test_override_new_method
|
152
267
|
with_restful_routing :messages do
|
153
268
|
assert_restful_routes_for :messages do |options|
|
154
269
|
assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get)
|
155
|
-
assert_raises(ActionController::
|
270
|
+
assert_raises(ActionController::MethodNotAllowed) do
|
156
271
|
ActionController::Routing::Routes.recognize_path("/messages/new", :method => :post)
|
157
272
|
end
|
158
273
|
end
|
@@ -178,12 +293,32 @@ class ResourcesTest < Test::Unit::TestCase
|
|
178
293
|
|
179
294
|
assert_simply_restful_for :threads
|
180
295
|
assert_simply_restful_for :messages,
|
181
|
-
:path_prefix => 'threads/1/',
|
182
296
|
:name_prefix => 'thread_',
|
297
|
+
:path_prefix => 'threads/1/',
|
183
298
|
:options => { :thread_id => '1' }
|
184
299
|
assert_simply_restful_for :comments,
|
185
|
-
:path_prefix => 'threads/1/messages/2/',
|
186
300
|
:name_prefix => 'thread_message_',
|
301
|
+
:path_prefix => 'threads/1/messages/2/',
|
302
|
+
:options => { :thread_id => '1', :message_id => '2' }
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_nested_restful_routes_with_overwritten_defaults
|
307
|
+
with_routing do |set|
|
308
|
+
set.draw do |map|
|
309
|
+
map.resources :threads do |map|
|
310
|
+
map.resources :messages, :name_prefix => nil do |map|
|
311
|
+
map.resources :comments, :name_prefix => nil
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
assert_simply_restful_for :threads
|
317
|
+
assert_simply_restful_for :messages,
|
318
|
+
:path_prefix => 'threads/1/',
|
319
|
+
:options => { :thread_id => '1' }
|
320
|
+
assert_simply_restful_for :comments,
|
321
|
+
:path_prefix => 'threads/1/messages/2/',
|
187
322
|
:options => { :thread_id => '1', :message_id => '2' }
|
188
323
|
end
|
189
324
|
end
|
@@ -207,22 +342,45 @@ class ResourcesTest < Test::Unit::TestCase
|
|
207
342
|
end
|
208
343
|
|
209
344
|
def test_should_create_multiple_singleton_resource_routes
|
210
|
-
with_singleton_resources :account, :
|
345
|
+
with_singleton_resources :account, :logo do
|
211
346
|
assert_singleton_restful_for :account
|
212
|
-
assert_singleton_restful_for :
|
347
|
+
assert_singleton_restful_for :logo
|
213
348
|
end
|
214
349
|
end
|
215
350
|
|
216
351
|
def test_should_create_nested_singleton_resource_routes
|
217
352
|
with_routing do |set|
|
218
353
|
set.draw do |map|
|
219
|
-
map.resource :admin do |admin|
|
354
|
+
map.resource :admin, :controller => 'admin' do |admin|
|
220
355
|
admin.resource :account
|
221
356
|
end
|
222
357
|
end
|
223
358
|
|
224
|
-
assert_singleton_restful_for :admin
|
225
|
-
assert_singleton_restful_for :account, :
|
359
|
+
assert_singleton_restful_for :admin, :controller => 'admin'
|
360
|
+
assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => 'admin/'
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_resource_has_many_should_become_nested_resources
|
365
|
+
with_routing do |set|
|
366
|
+
set.draw do |map|
|
367
|
+
map.resources :messages, :has_many => [ :comments, :authors ]
|
368
|
+
end
|
369
|
+
|
370
|
+
assert_simply_restful_for :messages
|
371
|
+
assert_simply_restful_for :comments, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' }
|
372
|
+
assert_simply_restful_for :authors, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' }
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def test_resource_has_one_should_become_nested_resources
|
377
|
+
with_routing do |set|
|
378
|
+
set.draw do |map|
|
379
|
+
map.resources :messages, :has_one => :logo
|
380
|
+
end
|
381
|
+
|
382
|
+
assert_simply_restful_for :messages
|
383
|
+
assert_singleton_restful_for :logo, :name_prefix => 'message_', :path_prefix => 'messages/1/', :options => { :message_id => '1' }
|
226
384
|
end
|
227
385
|
end
|
228
386
|
|
@@ -269,7 +427,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|
269
427
|
end
|
270
428
|
|
271
429
|
assert_singleton_restful_for :account
|
272
|
-
assert_simply_restful_for :messages, :
|
430
|
+
assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => 'account/'
|
273
431
|
end
|
274
432
|
end
|
275
433
|
|
@@ -282,7 +440,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|
282
440
|
end
|
283
441
|
|
284
442
|
assert_singleton_restful_for :account, :path_prefix => '7/', :options => { :site_id => '7' }
|
285
|
-
assert_simply_restful_for :messages, :
|
443
|
+
assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => '7/account/', :options => { :site_id => '7' }
|
286
444
|
end
|
287
445
|
end
|
288
446
|
|
@@ -290,12 +448,12 @@ class ResourcesTest < Test::Unit::TestCase
|
|
290
448
|
with_routing do |set|
|
291
449
|
set.draw do |map|
|
292
450
|
map.resources :threads do |thread|
|
293
|
-
thread.resource :admin
|
451
|
+
thread.resource :admin, :controller => 'admin'
|
294
452
|
end
|
295
453
|
end
|
296
454
|
|
297
455
|
assert_simply_restful_for :threads
|
298
|
-
assert_singleton_restful_for :admin, :
|
456
|
+
assert_singleton_restful_for :admin, :controller => 'admin', :name_prefix => 'thread_', :path_prefix => 'threads/5/', :options => { :thread_id => '5' }
|
299
457
|
end
|
300
458
|
end
|
301
459
|
|
@@ -305,11 +463,11 @@ class ResourcesTest < Test::Unit::TestCase
|
|
305
463
|
options = { :controller => controller_name.to_s }
|
306
464
|
collection_path = "/#{controller_name}"
|
307
465
|
|
308
|
-
assert_raises(ActionController::
|
466
|
+
assert_raises(ActionController::MethodNotAllowed) do
|
309
467
|
assert_recognizes(options.merge(:action => 'update'), :path => collection_path, :method => :put)
|
310
468
|
end
|
311
469
|
|
312
|
-
assert_raises(ActionController::
|
470
|
+
assert_raises(ActionController::MethodNotAllowed) do
|
313
471
|
assert_recognizes(options.merge(:action => 'destroy'), :path => collection_path, :method => :delete)
|
314
472
|
end
|
315
473
|
end
|
@@ -321,9 +479,9 @@ class ResourcesTest < Test::Unit::TestCase
|
|
321
479
|
map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id'
|
322
480
|
map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin'
|
323
481
|
end
|
324
|
-
|
482
|
+
|
325
483
|
action_separator = ActionController::Base.resource_action_separator
|
326
|
-
|
484
|
+
|
327
485
|
assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
|
328
486
|
assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {}
|
329
487
|
assert_named_route "/threads/1/messages/new", "new_thread_message_path", {}
|
@@ -359,134 +517,95 @@ class ResourcesTest < Test::Unit::TestCase
|
|
359
517
|
end
|
360
518
|
end
|
361
519
|
|
362
|
-
def
|
520
|
+
def test_resources_in_namespace
|
363
521
|
with_routing do |set|
|
364
522
|
set.draw do |map|
|
365
|
-
map.
|
366
|
-
|
367
|
-
|
368
|
-
assert_deprecated do
|
369
|
-
assert_named_route "/threads/1/messages/search", "thread_search_messages_path", {}
|
370
|
-
assert_named_route "/threads/1/messages/new", "thread_new_message_path", {}
|
371
|
-
assert_named_route "/threads/1/messages/new/preview", "thread_preview_new_message_path", {}
|
523
|
+
map.namespace :backoffice do |backoffice|
|
524
|
+
backoffice.resources :products
|
525
|
+
end
|
372
526
|
end
|
527
|
+
|
528
|
+
assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
|
373
529
|
end
|
374
530
|
end
|
375
531
|
|
376
|
-
def
|
532
|
+
def test_resource_has_many_in_namespace
|
377
533
|
with_routing do |set|
|
378
534
|
set.draw do |map|
|
379
|
-
map.
|
380
|
-
|
381
|
-
|
382
|
-
assert_deprecated do
|
383
|
-
assert_named_route "/admin/account/login", "admin_login_account_path", {}
|
384
|
-
assert_named_route "/admin/account/new", "admin_new_account_path", {}
|
385
|
-
assert_named_route "/admin/account/new/preview", "admin_preview_new_account_path", {}
|
535
|
+
map.namespace :backoffice do |backoffice|
|
536
|
+
backoffice.resources :products, :has_many => :tags
|
537
|
+
end
|
386
538
|
end
|
539
|
+
|
540
|
+
assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
|
541
|
+
assert_simply_restful_for :tags, :controller => "backoffice/tags", :name_prefix => "backoffice_product_", :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' }
|
387
542
|
end
|
388
543
|
end
|
389
544
|
|
390
|
-
def
|
545
|
+
def test_resource_has_one_in_namespace
|
391
546
|
with_routing do |set|
|
392
547
|
set.draw do |map|
|
393
|
-
map.
|
394
|
-
|
395
|
-
map.resources :comments
|
396
|
-
end
|
548
|
+
map.namespace :backoffice do |backoffice|
|
549
|
+
backoffice.resources :products, :has_one => :manufacturer
|
397
550
|
end
|
398
551
|
end
|
399
552
|
|
400
|
-
assert_simply_restful_for :
|
401
|
-
|
402
|
-
:path_prefix => 'threads/1/',
|
403
|
-
:name_prefix => 'thread_',
|
404
|
-
:options => { :thread_id => '1' }
|
405
|
-
assert_simply_restful_for :comments,
|
406
|
-
:path_prefix => 'threads/1/messages/2/',
|
407
|
-
:name_prefix => 'thread_message_',
|
408
|
-
:options => { :thread_id => '1', :message_id => '2' }
|
409
|
-
|
410
|
-
assert_deprecated do
|
411
|
-
assert_named_route "/threads/1/messages", "messages_path", {}
|
412
|
-
assert_named_route "/threads/1/messages/1", "message_path", {:thread_id => '1', :id => '1'}
|
413
|
-
assert_named_route "/threads/1/messages/new", "new_message_path", {:thread_id => '1'}
|
414
|
-
assert_named_route "/threads/1/messages/1/edit", "edit_message_path", {:thread_id => '1', :id => '1'}
|
415
|
-
end
|
553
|
+
assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
|
554
|
+
assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturers", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' }
|
416
555
|
end
|
417
556
|
end
|
418
557
|
|
419
|
-
def
|
558
|
+
def test_resources_in_nested_namespace
|
420
559
|
with_routing do |set|
|
421
560
|
set.draw do |map|
|
422
|
-
map.
|
423
|
-
|
561
|
+
map.namespace :backoffice do |backoffice|
|
562
|
+
backoffice.namespace :admin do |admin|
|
563
|
+
admin.resources :products
|
564
|
+
end
|
424
565
|
end
|
425
566
|
end
|
426
567
|
|
427
|
-
|
428
|
-
assert_singleton_restful_for :account, :path_prefix => 'admin/', :name_prefix => 'admin_'
|
429
|
-
|
430
|
-
assert_deprecated do
|
431
|
-
assert_named_route "/admin/account", "account_path", {}
|
432
|
-
assert_named_route "/admin/account/new", "new_account_path", {}
|
433
|
-
assert_named_route "/admin/account/edit", "edit_account_path", {}
|
434
|
-
end
|
568
|
+
assert_simply_restful_for :products, :controller => "backoffice/admin/products", :name_prefix => 'backoffice_admin_', :path_prefix => 'backoffice/admin/'
|
435
569
|
end
|
436
570
|
end
|
437
571
|
|
438
|
-
def
|
572
|
+
def test_resources_using_namespace
|
439
573
|
with_routing do |set|
|
440
574
|
set.draw do |map|
|
441
|
-
map.
|
442
|
-
account.resources :messages
|
443
|
-
end
|
575
|
+
map.resources :products, :namespace => "backoffice/"
|
444
576
|
end
|
445
577
|
|
446
|
-
|
447
|
-
assert_simply_restful_for :messages, :path_prefix => 'account/', :name_prefix => 'account_'
|
448
|
-
|
449
|
-
assert_deprecated do
|
450
|
-
assert_named_route "/account/messages", "messages_path", {}
|
451
|
-
assert_named_route "/account/messages/1", "message_path", {:id => '1'}
|
452
|
-
assert_named_route "/account/messages/new", "new_message_path", {}
|
453
|
-
assert_named_route "/account/messages/1/edit", "edit_message_path", {:id => '1'}
|
454
|
-
end
|
578
|
+
assert_simply_restful_for :products, :controller => "backoffice/products"
|
455
579
|
end
|
456
580
|
end
|
457
|
-
|
458
|
-
def
|
581
|
+
|
582
|
+
def test_nested_resources_using_namespace
|
459
583
|
with_routing do |set|
|
460
584
|
set.draw do |map|
|
461
|
-
map.
|
462
|
-
|
585
|
+
map.namespace :backoffice do |backoffice|
|
586
|
+
backoffice.resources :products do |products|
|
587
|
+
products.resources :images
|
588
|
+
end
|
463
589
|
end
|
464
590
|
end
|
465
591
|
|
466
|
-
assert_simply_restful_for :
|
467
|
-
assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :name_prefix => 'thread_', :options => { :thread_id => '5' }
|
468
|
-
|
469
|
-
assert_deprecated do
|
470
|
-
assert_named_route "/threads/5/admin", "admin_path", {}
|
471
|
-
assert_named_route "/threads/5/admin/new", "new_admin_path", {}
|
472
|
-
assert_named_route "/threads/5/admin/edit", "edit_admin_path", {}
|
473
|
-
end
|
592
|
+
assert_simply_restful_for :images, :controller => "backoffice/images", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => {:product_id => '1'}
|
474
593
|
end
|
475
594
|
end
|
476
595
|
|
477
|
-
def
|
596
|
+
def test_nested_resources_in_nested_namespace
|
478
597
|
with_routing do |set|
|
479
598
|
set.draw do |map|
|
480
|
-
map.
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
assert_singleton_restful_for :account do |options|
|
488
|
-
assert_recognizes options.merge({ :action => 'icon', :format => 'jpg' }), :path => '/account.jpg;icon', :method => :get
|
599
|
+
map.namespace :backoffice do |backoffice|
|
600
|
+
backoffice.namespace :admin do |admin|
|
601
|
+
admin.resources :products do |products|
|
602
|
+
products.resources :images
|
603
|
+
end
|
604
|
+
end
|
605
|
+
end
|
489
606
|
end
|
607
|
+
|
608
|
+
assert_simply_restful_for :images, :controller => "backoffice/admin/images", :name_prefix => 'backoffice_admin_product_', :path_prefix => 'backoffice/admin/products/1/', :options => {:product_id => '1'}
|
490
609
|
end
|
491
610
|
end
|
492
611
|
|
@@ -508,7 +627,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|
508
627
|
# runs assert_restful_routes_for and assert_restful_named_routes for on the controller_name and options, without passing a block.
|
509
628
|
def assert_simply_restful_for(controller_name, options = {})
|
510
629
|
assert_restful_routes_for controller_name, options
|
511
|
-
assert_restful_named_routes_for controller_name, options
|
630
|
+
assert_restful_named_routes_for controller_name, nil, options
|
512
631
|
end
|
513
632
|
|
514
633
|
def assert_singleton_restful_for(singleton_name, options = {})
|
@@ -517,7 +636,8 @@ class ResourcesTest < Test::Unit::TestCase
|
|
517
636
|
end
|
518
637
|
|
519
638
|
def assert_restful_routes_for(controller_name, options = {})
|
520
|
-
|
639
|
+
options[:options] ||= {}
|
640
|
+
options[:options][:controller] = options[:controller] || controller_name.to_s
|
521
641
|
|
522
642
|
collection_path = "/#{options[:path_prefix]}#{controller_name}"
|
523
643
|
member_path = "#{collection_path}/1"
|
@@ -562,8 +682,11 @@ class ResourcesTest < Test::Unit::TestCase
|
|
562
682
|
singular_name = nil
|
563
683
|
end
|
564
684
|
singular_name ||= controller_name.to_s.singularize
|
565
|
-
|
566
|
-
|
685
|
+
|
686
|
+
options[:options] ||= {}
|
687
|
+
options[:options][:controller] = options[:controller] || controller_name.to_s
|
688
|
+
|
689
|
+
@controller = "#{options[:options][:controller].camelize}Controller".constantize.new
|
567
690
|
@request = ActionController::TestRequest.new
|
568
691
|
@response = ActionController::TestResponse.new
|
569
692
|
get :index, options[:options]
|
@@ -571,20 +694,23 @@ class ResourcesTest < Test::Unit::TestCase
|
|
571
694
|
|
572
695
|
full_prefix = "/#{options[:path_prefix]}#{controller_name}"
|
573
696
|
name_prefix = options[:name_prefix]
|
574
|
-
|
697
|
+
|
575
698
|
assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options]
|
576
|
-
assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options]
|
577
|
-
assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
|
578
|
-
assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
|
579
699
|
assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml')
|
580
|
-
assert_named_route "#{full_prefix}/
|
700
|
+
assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
|
581
701
|
assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
|
702
|
+
|
703
|
+
assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options]
|
704
|
+
assert_named_route "#{full_prefix}/new.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml')
|
705
|
+
assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
|
582
706
|
assert_named_route "#{full_prefix}/1/edit.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
|
707
|
+
|
583
708
|
yield options[:options] if block_given?
|
584
709
|
end
|
585
|
-
|
710
|
+
|
586
711
|
def assert_singleton_routes_for(singleton_name, options = {})
|
587
|
-
|
712
|
+
options[:options] ||= {}
|
713
|
+
options[:options][:controller] = options[:controller] || singleton_name.to_s.pluralize
|
588
714
|
|
589
715
|
full_path = "/#{options[:path_prefix]}#{singleton_name}"
|
590
716
|
new_path = "#{full_path}/new"
|
@@ -618,7 +744,7 @@ class ResourcesTest < Test::Unit::TestCase
|
|
618
744
|
end
|
619
745
|
|
620
746
|
def assert_singleton_named_routes_for(singleton_name, options = {})
|
621
|
-
(options[:options] ||= {})[:controller] ||= singleton_name.to_s
|
747
|
+
(options[:options] ||= {})[:controller] ||= singleton_name.to_s.pluralize
|
622
748
|
@controller = "#{options[:options][:controller].camelize}Controller".constantize.new
|
623
749
|
@request = ActionController::TestRequest.new
|
624
750
|
@response = ActionController::TestResponse.new
|
@@ -626,21 +752,22 @@ class ResourcesTest < Test::Unit::TestCase
|
|
626
752
|
options[:options].delete :action
|
627
753
|
|
628
754
|
full_path = "/#{options[:path_prefix]}#{singleton_name}"
|
629
|
-
|
755
|
+
name_prefix = options[:name_prefix]
|
630
756
|
|
631
|
-
assert_named_route "#{full_path}", "#{
|
632
|
-
assert_named_route "#{full_path}
|
633
|
-
|
634
|
-
assert_named_route "#{full_path}
|
635
|
-
assert_named_route "#{full_path}/new.xml", "formatted_new_#{
|
636
|
-
assert_named_route "#{full_path}/edit
|
757
|
+
assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", options[:options]
|
758
|
+
assert_named_route "#{full_path}.xml", "formatted_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml')
|
759
|
+
|
760
|
+
assert_named_route "#{full_path}/new", "new_#{name_prefix}#{singleton_name}_path", options[:options]
|
761
|
+
assert_named_route "#{full_path}/new.xml", "formatted_new_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml')
|
762
|
+
assert_named_route "#{full_path}/edit", "edit_#{name_prefix}#{singleton_name}_path", options[:options]
|
763
|
+
assert_named_route "#{full_path}/edit.xml", "formatted_edit_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml')
|
637
764
|
end
|
638
765
|
|
639
766
|
def assert_named_route(expected, route, options)
|
640
767
|
actual = @controller.send(route, options) rescue $!.class.name
|
641
768
|
assert_equal expected, actual, "Error on route: #{route}(#{options.inspect})"
|
642
769
|
end
|
643
|
-
|
770
|
+
|
644
771
|
def assert_resource_methods(expected, resource, action_method, method)
|
645
772
|
assert_equal expected.length, resource.send("#{action_method}_methods")[method].size, "#{resource.send("#{action_method}_methods")[method].inspect}"
|
646
773
|
expected.each do |action|
|
@@ -657,5 +784,4 @@ class ResourcesTest < Test::Unit::TestCase
|
|
657
784
|
end
|
658
785
|
true
|
659
786
|
end
|
660
|
-
|
661
|
-
end
|
787
|
+
end
|