From ad4272922d6a42ac1fed2282bcc7bd937c85bb30 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 14 Aug 2010 18:33:38 -0300 Subject: object/try should be required after abstract_unit to have AS in the load path --- actionpack/test/controller/resources_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 6c8f470fba..4505cdabae 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1,5 +1,5 @@ -require 'active_support/core_ext/object/try' require 'abstract_unit' +require 'active_support/core_ext/object/try' class ResourcesController < ActionController::Base def index() render :nothing => true end -- cgit v1.2.3 From 38a421b34d0b414564e919f67d339fac067a56e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Wed, 11 Aug 2010 21:56:22 +0200 Subject: Setup explicit requires for files with exceptions. Removed them from autoloading. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/controller/resources_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 4505cdabae..a7c02f4253 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/core_ext/object/try' +require 'action_controller/metal/exceptions' class ResourcesController < ActionController::Base def index() render :nothing => true end -- cgit v1.2.3 From 599e46bf24419a429ee0bb0ea02afd48f47aa4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 2 Sep 2010 21:10:29 +0200 Subject: Revert "Setup explicit requires for files with exceptions. Removed them from autoloading." Booting a new Rails application does not work after this commit [#5359 state:open] This reverts commit 38a421b34d0b414564e919f67d339fac067a56e6. --- actionpack/test/controller/resources_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index a7c02f4253..4505cdabae 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1,6 +1,5 @@ require 'abstract_unit' require 'active_support/core_ext/object/try' -require 'action_controller/metal/exceptions' class ResourcesController < ActionController::Base def index() render :nothing => true end -- cgit v1.2.3 From b3eb26a161acb23781e55fc6c37b948f160cd9b5 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 5 Aug 2010 15:44:23 +0200 Subject: Removed deprecated RouteSet API, still many tests fail --- actionpack/test/controller/resources_test.rb | 340 +++++++++++++-------------- 1 file changed, 168 insertions(+), 172 deletions(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 4505cdabae..86d854c962 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1,5 +1,6 @@ require 'abstract_unit' require 'active_support/core_ext/object/try' +require 'active_support/core_ext/object/with_options' class ResourcesController < ActionController::Base def index() render :nothing => true end @@ -32,36 +33,6 @@ module Backoffice end class ResourcesTest < ActionController::TestCase - def test_should_arrange_actions - resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, { - :collection => { :rss => :get, :reorder => :post, :csv => :post }, - :member => { :rss => :get, :atom => :get, :upload => :post, :fix => :post }, - :new => { :preview => :get, :draft => :get }}, {}) - - assert_resource_methods [:rss], resource, :collection, :get - assert_resource_methods [:csv, :reorder], resource, :collection, :post - assert_resource_methods [:edit, :rss, :atom], resource, :member, :get - assert_resource_methods [:upload, :fix], resource, :member, :post - assert_resource_methods [:new, :preview, :draft], resource, :new, :get - end - - def test_should_resource_controller_name_equal_resource_name_by_default - resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, {}, {}) - assert_equal 'messages', resource.controller - end - - def test_should_resource_controller_name_equal_controller_option - resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, {:controller => 'posts'}, {}) - assert_equal 'posts', resource.controller - end - - def test_should_all_singleton_paths_be_the_same - [ :path, :nesting_path_prefix, :member_path ].each do |method| - resource = ActionDispatch::Routing::DeprecatedMapper::SingletonResource.new(:messages, {:path_prefix => 'admin'}, {}) - assert_equal 'admin/messages', resource.send(method) - end - end - def test_default_restful_routes with_restful_routing :messages do assert_simply_restful_for :messages @@ -69,9 +40,9 @@ class ResourcesTest < ActionController::TestCase end def test_override_paths_for_member_and_collection_methods - collection_methods = { 'rss' => :get, 'reorder' => :post, 'csv' => :post } - member_methods = { 'rss' => :get, :atom => :get, :upload => :post, :fix => :post } - path_names = {:new => 'nuevo', 'rss' => 'canal', :fix => 'corrigir' } + collection_methods = { :rss => :get, :reorder => :post, :csv => :post } + member_methods = { :rss => :get, :atom => :get, :upload => :post, :fix => :post } + path_names = {:new => 'nuevo', :rss => 'canal', :fix => 'corrigir' } with_restful_routing :messages, :collection => collection_methods, @@ -89,7 +60,7 @@ class ResourcesTest < ActionController::TestCase end collection_methods.each do |action, method| - assert_recognizes(options.merge(:action => action), + assert_recognizes(options.merge(:action => action.to_s), :path => "/messages/#{path_names[action] || action}", :method => method) end @@ -112,12 +83,6 @@ class ResourcesTest < ActionController::TestCase end end - def test_override_paths_for_default_restful_actions - resource = ActionDispatch::Routing::DeprecatedMapper::Resource.new(:messages, { - :path_names => {:new => 'nuevo', :edit => 'editar'}}, {}) - assert_equal resource.new_path, "#{resource.path}/nuevo" - end - def test_multiple_default_restful_routes with_restful_routing :messages, :comments do assert_simply_restful_for :messages @@ -131,7 +96,7 @@ class ResourcesTest < ActionController::TestCase end end - def test_irregular_id_with_no_requirements_should_raise_error + def test_irregular_id_with_no_constraints_should_raise_error expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'} with_restful_routing :messages do @@ -141,25 +106,25 @@ class ResourcesTest < ActionController::TestCase end end - def test_irregular_id_with_requirements_should_pass + def test_irregular_id_with_constraints_should_pass expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'} - with_restful_routing(:messages, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}) do + with_restful_routing(:messages, :constraints => {:id => /[0-9]\.[0-9]\.[0-9]/}) do assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get) end end - def test_with_path_prefix_requirements + def test_with_path_prefix_constraints expected_options = {:controller => 'messages', :action => 'show', :thread_id => '1.1.1', :id => '1'} - with_restful_routing :messages, :path_prefix => '/thread/:thread_id', :requirements => {:thread_id => /[0-9]\.[0-9]\.[0-9]/} do + with_restful_routing :messages, :path_prefix => '/thread/:thread_id', :constraints => {:thread_id => /[0-9]\.[0-9]\.[0-9]/} do assert_recognizes(expected_options, :path => 'thread/1.1.1/messages/1', :method => :get) end end - def test_irregular_id_requirements_should_get_passed_to_member_actions + def test_irregular_id_constraints_should_get_passed_to_member_actions expected_options = {:controller => 'messages', :action => 'custom', :id => '1.1.1'} - with_restful_routing(:messages, :member => {:custom => :get}, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}) do + with_restful_routing(:messages, :member => {:custom => :get}, :constraints => {:id => /[0-9]\.[0-9]\.[0-9]/}) do assert_recognizes(expected_options, :path => 'messages/1.1.1/custom', :method => :get) end end @@ -274,7 +239,7 @@ class ResourcesTest < ActionController::TestCase def test_with_member_action_and_requirement expected_options = {:controller => 'messages', :action => 'mark', :id => '1.1.1'} - with_restful_routing(:messages, :requirements => {:id => /[0-9]\.[0-9]\.[0-9]/}, :member => { :mark => :get }) do + with_restful_routing(:messages, :constraints => {:id => /[0-9]\.[0-9]\.[0-9]/}, :member => { :mark => :get }) do assert_recognizes(expected_options, :path => 'messages/1.1.1/mark', :method => :get) end end @@ -411,10 +376,10 @@ class ResourcesTest < ActionController::TestCase def test_nested_restful_routes with_routing do |set| - set.draw do |map| - map.resources :threads do |map| - map.resources :messages do |map| - map.resources :comments + set.draw do + resources :threads do + resources :messages do + resources :comments end end end @@ -433,10 +398,10 @@ class ResourcesTest < ActionController::TestCase def test_nested_restful_routes_with_overwritten_defaults with_routing do |set| - set.draw do |map| - map.resources :threads do |map| - map.resources :messages, :name_prefix => nil do |map| - map.resources :comments, :name_prefix => nil + set.draw do + resources :threads do + resources :messages, :name_prefix => nil do + resources :comments, :name_prefix => nil end end end @@ -453,10 +418,10 @@ class ResourcesTest < ActionController::TestCase def test_shallow_nested_restful_routes with_routing do |set| - set.draw do |map| - map.resources :threads, :shallow => true do |map| - map.resources :messages do |map| - map.resources :comments + set.draw do + resources :threads, :shallow => true do + resources :messages do + resources :comments end end end @@ -478,11 +443,11 @@ class ResourcesTest < ActionController::TestCase def test_shallow_nested_restful_routes_with_namespaces with_routing do |set| - set.draw do |map| - map.namespace :backoffice do |map| - map.namespace :admin do |map| - map.resources :products, :shallow => true do |map| - map.resources :images + set.draw do + namespace :backoffice do + namespace :admin do + resources :products, :shallow => true do + resources :images end end end @@ -531,9 +496,9 @@ class ResourcesTest < ActionController::TestCase def test_should_create_nested_singleton_resource_routes with_routing do |set| - set.draw do |map| - map.resource :admin, :controller => 'admin' do |admin| - admin.resource :account + set.draw do + resource :admin, :controller => 'admin' do + resource :account end end @@ -544,8 +509,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_many_should_become_nested_resources with_routing do |set| - set.draw do |map| - map.resources :messages, :has_many => [ :comments, :authors ] + set.draw do + resources :messages, :has_many => [ :comments, :authors ] end assert_simply_restful_for :messages @@ -556,8 +521,8 @@ class ResourcesTest < ActionController::TestCase def test_resources_has_many_hash_should_become_nested_resources with_routing do |set| - set.draw do |map| - map.resources :threads, :has_many => { :messages => [ :comments, { :authors => :threads } ] } + set.draw do + resources :threads, :has_many => { :messages => [ :comments, { :authors => :threads } ] } end assert_simply_restful_for :threads @@ -570,8 +535,8 @@ class ResourcesTest < ActionController::TestCase def test_shallow_resource_has_many_should_become_shallow_nested_resources with_routing do |set| - set.draw do |map| - map.resources :messages, :has_many => [ :comments, :authors ], :shallow => true + set.draw do + resources :messages, :has_many => [ :comments, :authors ], :shallow => true end assert_simply_restful_for :messages, :shallow => true @@ -582,8 +547,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_one_should_become_nested_resources with_routing do |set| - set.draw do |map| - map.resources :messages, :has_one => :logo + set.draw do + resources :messages, :has_one => :logo end assert_simply_restful_for :messages @@ -593,8 +558,8 @@ class ResourcesTest < ActionController::TestCase def test_shallow_resource_has_one_should_become_shallow_nested_resources with_routing do |set| - set.draw do |map| - map.resources :messages, :has_one => :logo, :shallow => true + set.draw do + resources :messages, :has_one => :logo, :shallow => true end assert_simply_restful_for :messages, :shallow => true @@ -638,9 +603,9 @@ class ResourcesTest < ActionController::TestCase def test_should_nest_resources_in_singleton_resource with_routing do |set| - set.draw do |map| - map.resource :account do |account| - account.resources :messages + set.draw do + resource :account do + resources :messages end end @@ -651,9 +616,9 @@ class ResourcesTest < ActionController::TestCase def test_should_nest_resources_in_singleton_resource_with_path_prefix with_routing do |set| - set.draw do |map| - map.resource(:account, :path_prefix => ':site_id') do |account| - account.resources :messages + set.draw do + resource(:account, :path_prefix => ':site_id') do + resources :messages end end @@ -664,9 +629,9 @@ class ResourcesTest < ActionController::TestCase def test_should_nest_singleton_resource_in_resources with_routing do |set| - set.draw do |map| - map.resources :threads do |thread| - thread.resource :admin, :controller => 'admin' + set.draw do + resources :threads do + resource :admin, :controller => 'admin' end end @@ -694,8 +659,8 @@ class ResourcesTest < ActionController::TestCase def test_should_not_allow_invalid_head_method_for_member_routes with_routing do |set| assert_raise(ArgumentError) do - set.draw do |map| - map.resources :messages, :member => {:something => :head} + set.draw do + resources :messages, :member => {:something => :head} end end end @@ -704,8 +669,8 @@ class ResourcesTest < ActionController::TestCase def test_should_not_allow_invalid_http_methods_for_member_routes with_routing do |set| assert_raise(ArgumentError) do - set.draw do |map| - map.resources :messages, :member => {:something => :invalid} + set.draw do + resources :messages, :member => {:something => :invalid} end end end @@ -713,9 +678,9 @@ class ResourcesTest < ActionController::TestCase def test_resource_action_separator with_routing do |set| - set.draw do |map| - map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' - map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' + set.draw do + resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' + resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' end action_separator = ActionController::Base.resource_action_separator @@ -733,8 +698,8 @@ class ResourcesTest < ActionController::TestCase def test_new_style_named_routes_for_resource with_routing do |set| - set.draw do |map| - map.resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' + set.draw do + resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' end assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } assert_named_route "/threads/1/messages/search", "search_thread_messages_path", {} @@ -745,8 +710,8 @@ class ResourcesTest < ActionController::TestCase def test_new_style_named_routes_for_singleton_resource with_routing do |set| - set.draw do |map| - map.resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' + set.draw do + resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' end assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' assert_named_route "/admin/account/login", "login_admin_account_path", {} @@ -757,9 +722,9 @@ class ResourcesTest < ActionController::TestCase def test_resources_in_namespace with_routing do |set| - set.draw do |map| - map.namespace :backoffice do |backoffice| - backoffice.resources :products + set.draw do + namespace :backoffice do + resources :products end end @@ -769,9 +734,9 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_many_in_namespace with_routing do |set| - set.draw do |map| - map.namespace :backoffice do |backoffice| - backoffice.resources :products, :has_many => :tags + set.draw do + namespace :backoffice do + resources :products, :has_many => :tags end end @@ -782,9 +747,9 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_one_in_namespace with_routing do |set| - set.draw do |map| - map.namespace :backoffice do |backoffice| - backoffice.resources :products, :has_one => :manufacturer + set.draw do + namespace :backoffice do + resources :products, :has_one => :manufacturer end end @@ -795,10 +760,10 @@ class ResourcesTest < ActionController::TestCase def test_resources_in_nested_namespace with_routing do |set| - set.draw do |map| - map.namespace :backoffice do |backoffice| - backoffice.namespace :admin do |admin| - admin.resources :products + set.draw do + namespace :backoffice do + backoffice.namespace :admin do + resources :products end end end @@ -809,8 +774,8 @@ class ResourcesTest < ActionController::TestCase def test_resources_using_namespace with_routing do |set| - set.draw do |map| - map.resources :products, :namespace => "backoffice/" + set.draw do + resources :products, :namespace => "backoffice/" end assert_simply_restful_for :products, :controller => "backoffice/products" @@ -819,9 +784,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_resources_using_namespace with_routing do |set| - set.draw do |map| - map.namespace :backoffice do |backoffice| - backoffice.resources :products do |products| + set.draw do + namespace :backoffice do + resources :products do products.resources :images end end @@ -833,10 +798,10 @@ class ResourcesTest < ActionController::TestCase def test_nested_resources_in_nested_namespace with_routing do |set| - set.draw do |map| - map.namespace :backoffice do |backoffice| - backoffice.namespace :admin do |admin| - admin.resources :products do |products| + set.draw do + namespace :backoffice do + backoffice.namespace :admin do + resources :products do products.resources :images end end @@ -863,12 +828,12 @@ class ResourcesTest < ActionController::TestCase def test_multiple_with_path_segment_and_controller with_routing do |set| - set.draw do |map| - map.resources :products do |products| + set.draw do + resources :products do products.resources :product_reviews, :as => 'reviews', :controller => 'messages' end - map.resources :tutors do |tutors| - tutors.resources :tutor_reviews, :as => 'reviews', :controller => 'comments' + resources :tutors do + resources :tutor_reviews, :as => 'reviews', :controller => 'comments' end end @@ -877,17 +842,22 @@ class ResourcesTest < ActionController::TestCase end end - def test_with_path_segment_path_prefix_requirements + def test_with_path_segment_path_prefix_constraints expected_options = {:controller => 'messages', :action => 'show', :thread_id => '1.1.1', :id => '1'} - with_restful_routing :messages, :as => 'comments',:path_prefix => '/thread/:thread_id', :requirements => { :thread_id => /[0-9]\.[0-9]\.[0-9]/ } do + with_routing do |set| + set.draw do + scope '/thread/:thread_id', :constraints => { :thread_id => /[0-9]\.[0-9]\.[0-9]/ } do + resources :messages, :as => 'comments' + end + end assert_recognizes(expected_options, :path => 'thread/1.1.1/comments/1', :method => :get) end end def test_resource_has_only_show_action with_routing do |set| - set.draw do |map| - map.resources :products, :only => :show + set.draw do + resources :products, :only => :show end assert_resource_allowed_routes('products', {}, { :id => '1' }, :show, [:index, :new, :create, :edit, :update, :destroy]) @@ -897,8 +867,8 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_show_action with_routing do |set| - set.draw do |map| - map.resource :account, :only => :show + set.draw do + resource :account, :only => :show end assert_singleton_resource_allowed_routes('accounts', {}, :show, [:index, :new, :create, :edit, :update, :destroy]) @@ -908,8 +878,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_does_not_have_destroy_action with_routing do |set| - set.draw do |map| - map.resources :products, :except => :destroy + set.draw do + resources :products, :except => :destroy end assert_resource_allowed_routes('products', {}, { :id => '1' }, [:index, :new, :create, :show, :edit, :update], :destroy) @@ -919,8 +889,8 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_does_not_have_destroy_action with_routing do |set| - set.draw do |map| - map.resource :account, :except => :destroy + set.draw do + resource :account, :except => :destroy end assert_singleton_resource_allowed_routes('accounts', {}, [:new, :create, :show, :edit, :update], :destroy) @@ -930,8 +900,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_create_action_and_named_route with_routing do |set| - set.draw do |map| - map.resources :products, :only => :create + set.draw do + resources :products, :only => :create end assert_resource_allowed_routes('products', {}, { :id => '1' }, :create, [:index, :new, :show, :edit, :update, :destroy]) @@ -943,8 +913,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_update_action_and_named_route with_routing do |set| - set.draw do |map| - map.resources :products, :only => :update + set.draw do + resources :products, :only => :update end assert_resource_allowed_routes('products', {}, { :id => '1' }, :update, [:index, :new, :create, :show, :edit, :destroy]) @@ -956,8 +926,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_destroy_action_and_named_route with_routing do |set| - set.draw do |map| - map.resources :products, :only => :destroy + set.draw do + resources :products, :only => :destroy end assert_resource_allowed_routes('products', {}, { :id => '1' }, :destroy, [:index, :new, :create, :show, :edit, :update]) @@ -969,8 +939,8 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_create_action_and_named_route with_routing do |set| - set.draw do |map| - map.resource :account, :only => :create + set.draw do + resource :account, :only => :create end assert_singleton_resource_allowed_routes('accounts', {}, :create, [:new, :show, :edit, :update, :destroy]) @@ -982,8 +952,8 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_update_action_and_named_route with_routing do |set| - set.draw do |map| - map.resource :account, :only => :update + set.draw do + resource :account, :only => :update end assert_singleton_resource_allowed_routes('accounts', {}, :update, [:new, :create, :show, :edit, :destroy]) @@ -995,8 +965,8 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_destroy_action_and_named_route with_routing do |set| - set.draw do |map| - map.resource :account, :only => :destroy + set.draw do + resource :account, :only => :destroy end assert_singleton_resource_allowed_routes('accounts', {}, :destroy, [:new, :create, :show, :edit, :update]) @@ -1008,8 +978,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_collection_action with_routing do |set| - set.draw do |map| - map.resources :products, :except => :all, :collection => { :sale => :get } + set.draw do + resources :products, :except => :all, :collection => { :sale => :get } end assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) @@ -1022,8 +992,8 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_member_action with_routing do |set| - set.draw do |map| - map.resources :products, :except => :all, :member => { :preview => :get } + set.draw do + resources :products, :except => :all, :member => { :preview => :get } end assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) @@ -1036,8 +1006,8 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_member_action with_routing do |set| - set.draw do |map| - map.resource :account, :except => :all, :member => { :signup => :get } + set.draw do + resource :account, :except => :all, :member => { :signup => :get } end assert_singleton_resource_allowed_routes('accounts', {}, [], [:new, :create, :show, :edit, :update, :destroy]) @@ -1050,9 +1020,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_has_only_show_and_member_action with_routing do |set| - set.draw do |map| - map.resources :products, :only => [:index, :show] do |product| - product.resources :images, :member => { :thumbnail => :get }, :only => :show + set.draw do + resources :products, :only => [:index, :show] do + resources :images, :member => { :thumbnail => :get }, :only => :show end end @@ -1066,9 +1036,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_only_option with_routing do |set| - set.draw do |map| - map.resources :products, :only => :show do |product| - product.resources :images, :except => :destroy + set.draw do + resources :products, :only => :show do + resources :images, :except => :destroy end end @@ -1079,9 +1049,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_only_option_by_default with_routing do |set| - set.draw do |map| - map.resources :products, :only => :show do |product| - product.resources :images + set.draw do + resources :products, :only => :show do + resources :images end end @@ -1092,9 +1062,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_except_option with_routing do |set| - set.draw do |map| - map.resources :products, :except => :show do |product| - product.resources :images, :only => :destroy + set.draw do + resources :products, :except => :show do + resources :images, :only => :destroy end end @@ -1105,9 +1075,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_except_option_by_default with_routing do |set| - set.draw do |map| - map.resources :products, :except => :show do |product| - product.resources :images + set.draw do + resources :products, :except => :show do + resources :images end end @@ -1118,8 +1088,8 @@ class ResourcesTest < ActionController::TestCase def test_default_singleton_restful_route_uses_get with_routing do |set| - set.draw do |map| - map.resource :product + set.draw do + resource :product end assert_routing '/product', :controller => 'products', :action => 'show' @@ -1135,15 +1105,41 @@ class ResourcesTest < ActionController::TestCase protected def with_restful_routing(*args) + options = args.extract_options! + collection_methods = options.delete(:collection) + member_methods = options.delete(:member) + path_prefix = options.delete(:path_prefix) + args.push(options) + with_routing do |set| - set.draw { |map| map.resources(*args) } + set.draw do + scope(path_prefix || '') do + resources(*args) do + if collection_methods + collection do + collection_methods.each do |name, method| + send(method, name) + end + end + end + + if member_methods + member do + member_methods.each do |name, method| + send(method, name) + end + end + end + end + end + end yield end end def with_singleton_resources(*args) with_routing do |set| - set.draw { |map| map.resource(*args) } + set.draw {resource(*args) } yield end end @@ -1385,7 +1381,7 @@ class ResourcesTest < ActionController::TestCase end def distinct_routes? (r1, r2) - if r1.conditions == r2.conditions and r1.requirements == r2.requirements then + if r1.conditions == r2.conditions and r1.constraints == r2.constraints then if r1.segments.collect(&:to_s) == r2.segments.collect(&:to_s) then return false end -- cgit v1.2.3 From 415bacd7bf3c806cc12ffecabb4bd726dd052975 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 5 Aug 2010 18:10:53 +0200 Subject: Fixed almost all resources tests --- actionpack/test/controller/resources_test.rb | 372 +++++++++++++++------------ 1 file changed, 213 insertions(+), 159 deletions(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 86d854c962..d0c144d233 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -143,7 +143,7 @@ class ResourcesTest < ActionController::TestCase end def test_with_name_prefix - with_restful_routing :messages, :name_prefix => 'post_' do + with_restful_routing :messages, :as => 'post_messages' do assert_simply_restful_for :messages, :name_prefix => 'post_' end end @@ -151,7 +151,16 @@ class ResourcesTest < ActionController::TestCase def test_with_collection_actions actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete } - with_restful_routing :messages, :collection => actions do + with_routing do |set| + set.draw do + resources :messages do + get :a, :on => :collection + put :b, :on => :collection + post :c, :on => :collection + delete :d, :on => :collection + end + end + assert_restful_routes_for :messages do |options| actions.each do |action, method| assert_recognizes(options.merge(:action => action), :path => "/messages/#{action}", :method => method) @@ -169,7 +178,18 @@ class ResourcesTest < ActionController::TestCase def test_with_collection_actions_and_name_prefix actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete } - with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do + with_routing do |set| + set.draw do + scope '/threads/:thread_id' do + resources :messages, :as => 'thread_messages' do + get :a, :on => :collection + put :b, :on => :collection + post :c, :on => :collection + delete :d, :on => :collection + end + end + end + assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| actions.each do |action, method| assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method) @@ -187,7 +207,16 @@ class ResourcesTest < ActionController::TestCase def test_with_collection_actions_and_name_prefix_and_member_action_with_same_name actions = { 'a' => :get } - with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions, :member => actions do + with_routing do |set| + set.draw do + scope '/threads/:thread_id' do + resources :messages, :as => 'thread_messages' do + get :a, :on => :collection + get :a, :on => :member + end + end + end + assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| actions.each do |action, method| assert_recognizes(options.merge(:action => action), :path => "/threads/1/messages/#{action}", :method => method) @@ -205,7 +234,18 @@ class ResourcesTest < ActionController::TestCase def test_with_collection_action_and_name_prefix_and_formatted actions = { 'a' => :get, 'b' => :put, 'c' => :post, 'd' => :delete } - with_restful_routing :messages, :path_prefix => '/threads/:thread_id', :name_prefix => "thread_", :collection => actions do + with_routing do |set| + set.draw do + scope '/threads/:thread_id' do + resources :messages, :as => 'thread_messages' do + get :a, :on => :collection + put :b, :on => :collection + post :c, :on => :collection + delete :d, :on => :collection + end + end + end + assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| actions.each do |action, method| assert_recognizes(options.merge(:action => action, :format => 'xml'), :path => "/threads/1/messages/#{action}.xml", :method => method) @@ -285,7 +325,16 @@ class ResourcesTest < ActionController::TestCase def test_with_two_member_actions_with_same_method [:put, :post].each do |method| - with_restful_routing :messages, :member => { :mark => method, :unmark => method } do + with_routing do |set| + set.draw do + resources :messages do + member do + match :mark , :via => method + match :unmark, :via => method + end + end + end + %w(mark unmark).each do |action| action_options = {:action => action, :id => '1'} action_path = "/messages/1/#{action}" @@ -302,7 +351,19 @@ class ResourcesTest < ActionController::TestCase end def test_array_as_collection_or_member_method_value - with_restful_routing :messages, :collection => { :search => [:get, :post] }, :member => { :toggle => [:get, :post] } do + with_routing do |set| + set.draw do + resources :messages do + collection do + match :search, :via => [:post, :get] + end + + member do + match :toggle, :via => [:post, :get] + end + end + end + assert_restful_routes_for :messages do |options| [:get, :post].each do |method| assert_recognizes(options.merge(:action => 'search'), :path => "/messages/search", :method => method) @@ -315,7 +376,13 @@ class ResourcesTest < ActionController::TestCase end def test_with_new_action - with_restful_routing :messages, :new => { :preview => :post } do + with_routing do |set| + set.draw do + resources :messages do + post :preview, :on => :new + end + end + preview_options = {:action => 'preview'} preview_path = "/messages/new/preview" assert_restful_routes_for :messages do |options| @@ -329,7 +396,15 @@ class ResourcesTest < ActionController::TestCase end def test_with_new_action_with_name_prefix - with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do + with_routing do |set| + set.draw do + scope('/threads/:thread_id') do + resources :messages, :as => "thread_messages" do + post :preview, :on => :new + end + end + end + preview_options = {:action => 'preview', :thread_id => '1'} preview_path = "/threads/1/messages/new/preview" assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| @@ -343,7 +418,15 @@ class ResourcesTest < ActionController::TestCase end def test_with_formatted_new_action_with_name_prefix - with_restful_routing :messages, :new => { :preview => :post }, :path_prefix => '/threads/:thread_id', :name_prefix => 'thread_' do + with_routing do |set| + set.draw do + scope('/threads/:thread_id') do + resources :messages, :as => "thread_messages" do + post :preview, :on => :new + end + end + end + preview_options = {:action => 'preview', :thread_id => '1', :format => 'xml'} preview_path = "/threads/1/messages/new/preview.xml" assert_restful_routes_for :messages, :path_prefix => 'threads/1/', :name_prefix => 'thread_', :options => { :thread_id => '1' } do |options| @@ -366,7 +449,13 @@ class ResourcesTest < ActionController::TestCase end end - with_restful_routing :messages, :new => { :new => :any } do + with_routing do |set| + set.draw do + resources :messages do + match :new, :via => [:post, :get], :on => :new + end + end + assert_restful_routes_for :messages do |options| assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :post) assert_recognizes(options.merge(:action => "new"), :path => "/messages/new", :method => :get) @@ -377,9 +466,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_restful_routes with_routing do |set| set.draw do - resources :threads do - resources :messages do - resources :comments + resources :threads do + resources :messages do + resources :comments end end end @@ -399,9 +488,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_restful_routes_with_overwritten_defaults with_routing do |set| set.draw do - resources :threads do - resources :messages, :name_prefix => nil do - resources :comments, :name_prefix => nil + resources :threads do + resources :messages, :name_prefix => nil do + resources :comments, :name_prefix => nil end end end @@ -419,9 +508,9 @@ class ResourcesTest < ActionController::TestCase def test_shallow_nested_restful_routes with_routing do |set| set.draw do - resources :threads, :shallow => true do - resources :messages do - resources :comments + resources :threads, :shallow => true do + resources :messages do + resources :comments end end end @@ -444,10 +533,10 @@ class ResourcesTest < ActionController::TestCase def test_shallow_nested_restful_routes_with_namespaces with_routing do |set| set.draw do - namespace :backoffice do - namespace :admin do - resources :products, :shallow => true do - resources :images + namespace :backoffice do + namespace :admin do + resources :products, :shallow => true do + resources :images end end end @@ -497,7 +586,7 @@ class ResourcesTest < ActionController::TestCase def test_should_create_nested_singleton_resource_routes with_routing do |set| set.draw do - resource :admin, :controller => 'admin' do + resource :admin, :controller => 'admin' do resource :account end end @@ -507,69 +596,15 @@ class ResourcesTest < ActionController::TestCase end end - def test_resource_has_many_should_become_nested_resources - with_routing do |set| - set.draw do - resources :messages, :has_many => [ :comments, :authors ] - end - - assert_simply_restful_for :messages - assert_simply_restful_for :comments, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' } - assert_simply_restful_for :authors, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' } - end - end - - def test_resources_has_many_hash_should_become_nested_resources - with_routing do |set| - set.draw do - resources :threads, :has_many => { :messages => [ :comments, { :authors => :threads } ] } - end - - assert_simply_restful_for :threads - assert_simply_restful_for :messages, :name_prefix => "thread_", :path_prefix => 'threads/1/', :options => { :thread_id => '1' } - assert_simply_restful_for :comments, :name_prefix => "thread_message_", :path_prefix => 'threads/1/messages/1/', :options => { :thread_id => '1', :message_id => '1' } - assert_simply_restful_for :authors, :name_prefix => "thread_message_", :path_prefix => 'threads/1/messages/1/', :options => { :thread_id => '1', :message_id => '1' } - assert_simply_restful_for :threads, :name_prefix => "thread_message_author_", :path_prefix => 'threads/1/messages/1/authors/1/', :options => { :thread_id => '1', :message_id => '1', :author_id => '1' } - end - end - - def test_shallow_resource_has_many_should_become_shallow_nested_resources - with_routing do |set| - set.draw do - resources :messages, :has_many => [ :comments, :authors ], :shallow => true - end - - assert_simply_restful_for :messages, :shallow => true - assert_simply_restful_for :comments, :name_prefix => "message_", :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' } - assert_simply_restful_for :authors, :name_prefix => "message_", :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' } - end - end - - def test_resource_has_one_should_become_nested_resources - with_routing do |set| - set.draw do - resources :messages, :has_one => :logo - end - - assert_simply_restful_for :messages - assert_singleton_restful_for :logo, :name_prefix => 'message_', :path_prefix => 'messages/1/', :options => { :message_id => '1' } - end - end - - def test_shallow_resource_has_one_should_become_shallow_nested_resources - with_routing do |set| - set.draw do - resources :messages, :has_one => :logo, :shallow => true - end - - assert_simply_restful_for :messages, :shallow => true - assert_singleton_restful_for :logo, :name_prefix => 'message_', :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' } - end - end - def test_singleton_resource_with_member_action [:put, :post].each do |method| - with_singleton_resources :account, :member => { :reset => method } do + with_routing do |set| + set.draw do + resource :account do + match :reset, :on => :member, :via => method + end + end + reset_options = {:action => 'reset'} reset_path = "/account/reset" assert_singleton_routes_for :account do |options| @@ -585,7 +620,14 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_with_two_member_actions_with_same_method [:put, :post].each do |method| - with_singleton_resources :account, :member => { :reset => method, :disable => method } do + with_routing do |set| + set.draw do + resource :account do + match :reset, :on => :member, :via => method + match :disable, :on => :member, :via => method + end + end + %w(reset disable).each do |action| action_options = {:action => action} action_path = "/account/#{action}" @@ -604,7 +646,7 @@ class ResourcesTest < ActionController::TestCase def test_should_nest_resources_in_singleton_resource with_routing do |set| set.draw do - resource :account do + resource :account do resources :messages end end @@ -614,11 +656,13 @@ class ResourcesTest < ActionController::TestCase end end - def test_should_nest_resources_in_singleton_resource_with_path_prefix + def test_should_nest_resources_in_singleton_resource_with_path_scope with_routing do |set| set.draw do - resource(:account, :path_prefix => ':site_id') do - resources :messages + scope ':site_id' do + resource(:account) do + resources :messages + end end end @@ -630,7 +674,7 @@ class ResourcesTest < ActionController::TestCase def test_should_nest_singleton_resource_in_resources with_routing do |set| set.draw do - resources :threads do + resources :threads do resource :admin, :controller => 'admin' end end @@ -660,7 +704,9 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| assert_raise(ArgumentError) do set.draw do - resources :messages, :member => {:something => :head} + resources :messages do + match :something, :on => :member, :via => :head + end end end end @@ -670,7 +716,11 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| assert_raise(ArgumentError) do set.draw do - resources :messages, :member => {:something => :invalid} + resources :messages do + member do + match :something, :via => :invalid + end + end end end end @@ -679,8 +729,18 @@ class ResourcesTest < ActionController::TestCase def test_resource_action_separator with_routing do |set| set.draw do - resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' - resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' + scope '/threads/:thread_id' do + resources :messages, :as => :thread_messages do + get :search, :on => :collection + match :preview, :on => :new + end + end + scope '/admin' do + resource :account, :as => :admin_account do + get :login, :on => :member + match :preview, :on => :new + end + end end action_separator = ActionController::Base.resource_action_separator @@ -699,8 +759,14 @@ class ResourcesTest < ActionController::TestCase def test_new_style_named_routes_for_resource with_routing do |set| set.draw do - resources :messages, :collection => {:search => :get}, :new => {:preview => :any}, :name_prefix => 'thread_', :path_prefix => '/threads/:thread_id' + scope '/threads/:thread_id' do + resources :messages, :as => 'thread_messages' do + get :search, :on => :collection + match :preview, :on => :new + end + end end + assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } assert_named_route "/threads/1/messages/search", "search_thread_messages_path", {} assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} @@ -711,7 +777,12 @@ class ResourcesTest < ActionController::TestCase def test_new_style_named_routes_for_singleton_resource with_routing do |set| set.draw do - resource :account, :member => {:login => :get}, :new => {:preview => :any}, :name_prefix => 'admin_', :path_prefix => '/admin' + scope '/admin' do + resource :account, :as => :admin_account do + get :login, :on => :member + match :preview, :on => :new + end + end end assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' assert_named_route "/admin/account/login", "login_admin_account_path", {} @@ -723,7 +794,7 @@ class ResourcesTest < ActionController::TestCase def test_resources_in_namespace with_routing do |set| set.draw do - namespace :backoffice do + namespace :backoffice do resources :products end end @@ -732,37 +803,11 @@ class ResourcesTest < ActionController::TestCase end end - def test_resource_has_many_in_namespace - with_routing do |set| - set.draw do - namespace :backoffice do - resources :products, :has_many => :tags - end - end - - assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/' - assert_simply_restful_for :tags, :controller => "backoffice/tags", :name_prefix => "backoffice_product_", :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' } - end - end - - def test_resource_has_one_in_namespace - with_routing do |set| - set.draw do - namespace :backoffice do - resources :products, :has_one => :manufacturer - end - end - - assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/' - assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturers", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' } - end - end - def test_resources_in_nested_namespace with_routing do |set| set.draw do - namespace :backoffice do - backoffice.namespace :admin do + namespace :backoffice do + namespace :admin do resources :products end end @@ -775,7 +820,9 @@ class ResourcesTest < ActionController::TestCase def test_resources_using_namespace with_routing do |set| set.draw do - resources :products, :namespace => "backoffice/" + namespace :backoffice, :path => nil, :as => nil do + resources :products + end end assert_simply_restful_for :products, :controller => "backoffice/products" @@ -785,9 +832,9 @@ class ResourcesTest < ActionController::TestCase def test_nested_resources_using_namespace with_routing do |set| set.draw do - namespace :backoffice do + namespace :backoffice do resources :products do - products.resources :images + resources :images end end end @@ -799,10 +846,10 @@ class ResourcesTest < ActionController::TestCase def test_nested_resources_in_nested_namespace with_routing do |set| set.draw do - namespace :backoffice do - backoffice.namespace :admin do + namespace :backoffice do + namespace :admin do resources :products do - products.resources :images + resources :images end end end @@ -819,10 +866,13 @@ class ResourcesTest < ActionController::TestCase assert_recognizes({:controller => "messages", :action => "index"}, "/messages/") end - with_restful_routing :messages, :as => 'reviews' do - assert_simply_restful_for :messages, :as => 'reviews' - assert_recognizes({:controller => "messages", :action => "index"}, "/reviews") - assert_recognizes({:controller => "messages", :action => "index"}, "/reviews/") + with_routing do |set| + set.draw do + resources :messages, :path => 'reviews' + end + assert_simply_restful_for :messages, :as => 'reviews' + assert_recognizes({:controller => "messages", :action => "index"}, "/reviews") + assert_recognizes({:controller => "messages", :action => "index"}, "/reviews/") end end @@ -830,10 +880,10 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resources :products do - products.resources :product_reviews, :as => 'reviews', :controller => 'messages' + resources :product_reviews, :path => 'reviews', :controller => 'messages' end resources :tutors do - resources :tutor_reviews, :as => 'reviews', :controller => 'comments' + resources :tutor_reviews, :path => 'reviews', :controller => 'comments' end end @@ -847,7 +897,7 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do scope '/thread/:thread_id', :constraints => { :thread_id => /[0-9]\.[0-9]\.[0-9]/ } do - resources :messages, :as => 'comments' + resources :messages, :path => 'comments' end end assert_recognizes(expected_options, :path => 'thread/1.1.1/comments/1', :method => :get) @@ -857,7 +907,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_show_action with_routing do |set| set.draw do - resources :products, :only => :show + resources :products, :only => :show end assert_resource_allowed_routes('products', {}, { :id => '1' }, :show, [:index, :new, :create, :edit, :update, :destroy]) @@ -868,7 +918,7 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_show_action with_routing do |set| set.draw do - resource :account, :only => :show + resource :account, :only => :show end assert_singleton_resource_allowed_routes('accounts', {}, :show, [:index, :new, :create, :edit, :update, :destroy]) @@ -879,7 +929,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_does_not_have_destroy_action with_routing do |set| set.draw do - resources :products, :except => :destroy + resources :products, :except => :destroy end assert_resource_allowed_routes('products', {}, { :id => '1' }, [:index, :new, :create, :show, :edit, :update], :destroy) @@ -890,7 +940,7 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_does_not_have_destroy_action with_routing do |set| set.draw do - resource :account, :except => :destroy + resource :account, :except => :destroy end assert_singleton_resource_allowed_routes('accounts', {}, [:new, :create, :show, :edit, :update], :destroy) @@ -901,7 +951,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_create_action_and_named_route with_routing do |set| set.draw do - resources :products, :only => :create + resources :products, :only => :create end assert_resource_allowed_routes('products', {}, { :id => '1' }, :create, [:index, :new, :show, :edit, :update, :destroy]) @@ -914,7 +964,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_update_action_and_named_route with_routing do |set| set.draw do - resources :products, :only => :update + resources :products, :only => :update end assert_resource_allowed_routes('products', {}, { :id => '1' }, :update, [:index, :new, :create, :show, :edit, :destroy]) @@ -927,7 +977,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_destroy_action_and_named_route with_routing do |set| set.draw do - resources :products, :only => :destroy + resources :products, :only => :destroy end assert_resource_allowed_routes('products', {}, { :id => '1' }, :destroy, [:index, :new, :create, :show, :edit, :update]) @@ -940,7 +990,7 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_create_action_and_named_route with_routing do |set| set.draw do - resource :account, :only => :create + resource :account, :only => :create end assert_singleton_resource_allowed_routes('accounts', {}, :create, [:new, :show, :edit, :update, :destroy]) @@ -953,7 +1003,7 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_update_action_and_named_route with_routing do |set| set.draw do - resource :account, :only => :update + resource :account, :only => :update end assert_singleton_resource_allowed_routes('accounts', {}, :update, [:new, :create, :show, :edit, :destroy]) @@ -966,7 +1016,7 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_destroy_action_and_named_route with_routing do |set| set.draw do - resource :account, :only => :destroy + resource :account, :only => :destroy end assert_singleton_resource_allowed_routes('accounts', {}, :destroy, [:new, :create, :show, :edit, :update]) @@ -979,7 +1029,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_collection_action with_routing do |set| set.draw do - resources :products, :except => :all, :collection => { :sale => :get } + resources :products, :except => :all, :collection => { :sale => :get } end assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) @@ -993,7 +1043,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_member_action with_routing do |set| set.draw do - resources :products, :except => :all, :member => { :preview => :get } + resources :products, :except => :all, :member => { :preview => :get } end assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) @@ -1007,7 +1057,11 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_member_action with_routing do |set| set.draw do - resource :account, :except => :all, :member => { :signup => :get } + resource :account, :except => :all do + member do + get :signup + end + end end assert_singleton_resource_allowed_routes('accounts', {}, [], [:new, :create, :show, :edit, :update, :destroy]) @@ -1021,7 +1075,7 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_has_only_show_and_member_action with_routing do |set| set.draw do - resources :products, :only => [:index, :show] do + resources :products, :only => [:index, :show] do resources :images, :member => { :thumbnail => :get }, :only => :show end end @@ -1037,7 +1091,7 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_only_option with_routing do |set| set.draw do - resources :products, :only => :show do + resources :products, :only => :show do resources :images, :except => :destroy end end @@ -1050,7 +1104,7 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_only_option_by_default with_routing do |set| set.draw do - resources :products, :only => :show do + resources :products, :only => :show do resources :images end end @@ -1063,7 +1117,7 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_except_option with_routing do |set| set.draw do - resources :products, :except => :show do + resources :products, :except => :show do resources :images, :only => :destroy end end @@ -1076,7 +1130,7 @@ class ResourcesTest < ActionController::TestCase def test_nested_resource_does_not_inherit_except_option_by_default with_routing do |set| set.draw do - resources :products, :except => :show do + resources :products, :except => :show do resources :images end end @@ -1089,7 +1143,7 @@ class ResourcesTest < ActionController::TestCase def test_default_singleton_restful_route_uses_get with_routing do |set| set.draw do - resource :product + resource :product end assert_routing '/product', :controller => 'products', :action => 'show' -- cgit v1.2.3 From 8958f332bbb552e87fd9f8c78dd11bdeab7897fc Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 5 Aug 2010 23:16:08 +0200 Subject: Implemented resources :foos, :except => :all option --- actionpack/test/controller/resources_test.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index d0c144d233..3dc2429dae 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -1029,7 +1029,9 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_collection_action with_routing do |set| set.draw do - resources :products, :except => :all, :collection => { :sale => :get } + resources :products, :except => :all do + get :sale, :on => :collection + end end assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) @@ -1043,7 +1045,9 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_member_action with_routing do |set| set.draw do - resources :products, :except => :all, :member => { :preview => :get } + resources :products, :except => :all do + get :preview, :on => :member + end end assert_resource_allowed_routes('products', {}, { :id => '1' }, [], [:index, :new, :create, :show, :edit, :update, :destroy]) @@ -1076,7 +1080,9 @@ class ResourcesTest < ActionController::TestCase with_routing do |set| set.draw do resources :products, :only => [:index, :show] do - resources :images, :member => { :thumbnail => :get }, :only => :show + resources :images, :only => :show do + get :thumbnail, :on => :member + end end end -- cgit v1.2.3 From 3088b4f84f802fb84c4750ce25d8fe57c6c0a79e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 5 Aug 2010 23:58:12 +0200 Subject: raise error on invalid HTTP methods or :head passed with :via in routes --- actionpack/test/controller/resources_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 3dc2429dae..0573eac119 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -718,7 +718,7 @@ class ResourcesTest < ActionController::TestCase set.draw do resources :messages do member do - match :something, :via => :invalid + match :something, :via => [:invalid, :get] end end end -- cgit v1.2.3 From 8f2c0bf1a072a5f2e531bef65f13b8981e1ec181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Strza=C5=82kowski?= Date: Sat, 4 Sep 2010 16:18:13 +0200 Subject: This test is invalid for new router --- actionpack/test/controller/resources_test.rb | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 0573eac119..70d2ecdc3f 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -485,26 +485,6 @@ class ResourcesTest < ActionController::TestCase end end - def test_nested_restful_routes_with_overwritten_defaults - with_routing do |set| - set.draw do - resources :threads do - resources :messages, :name_prefix => nil do - resources :comments, :name_prefix => nil - end - end - end - - assert_simply_restful_for :threads - assert_simply_restful_for :messages, - :path_prefix => 'threads/1/', - :options => { :thread_id => '1' } - assert_simply_restful_for :comments, - :path_prefix => 'threads/1/messages/2/', - :options => { :thread_id => '1', :message_id => '2' } - end - end - def test_shallow_nested_restful_routes with_routing do |set| set.draw do -- cgit v1.2.3 From 8a3461b8c1cb6371c809618420de9e69a71d183f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 5 Sep 2010 15:59:25 +0200 Subject: Remove a few tests from old router that do not make sense with the new one. --- actionpack/test/controller/resources_test.rb | 54 ++-------------------------- 1 file changed, 3 insertions(+), 51 deletions(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 70d2ecdc3f..b59fd65a3e 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -301,28 +301,6 @@ class ResourcesTest < ActionController::TestCase end end - # def test_member_when_changed_default_restful_actions_and_path_names_not_specified - # default_path_names = ActionController::Base.resources_path_names - # ActionController::Base.resources_path_names = {:new => 'nuevo', :edit => 'editar'} - # - # with_restful_routing :messages do - # new_options = { :action => 'new', :controller => 'messages' } - # new_path = "/messages/nuevo" - # edit_options = { :action => 'edit', :id => '1', :controller => 'messages' } - # edit_path = "/messages/1/editar" - # - # assert_restful_routes_for :messages do |options| - # assert_recognizes(options.merge(new_options), :path => new_path, :method => :get) - # end - # - # assert_restful_routes_for :messages do |options| - # assert_recognizes(options.merge(edit_options), :path => edit_path, :method => :get) - # end - # end - # ensure - # ActionController::Base.resources_path_names = default_path_names - # end - def test_with_two_member_actions_with_same_method [:put, :post].each do |method| with_routing do |set| @@ -680,32 +658,6 @@ class ResourcesTest < ActionController::TestCase end end - def test_should_not_allow_invalid_head_method_for_member_routes - with_routing do |set| - assert_raise(ArgumentError) do - set.draw do - resources :messages do - match :something, :on => :member, :via => :head - end - end - end - end - end - - def test_should_not_allow_invalid_http_methods_for_member_routes - with_routing do |set| - assert_raise(ArgumentError) do - set.draw do - resources :messages do - member do - match :something, :via => [:invalid, :get] - end - end - end - end - end - end - def test_resource_action_separator with_routing do |set| set.draw do @@ -1009,7 +961,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_collection_action with_routing do |set| set.draw do - resources :products, :except => :all do + resources :products, :only => [] do get :sale, :on => :collection end end @@ -1025,7 +977,7 @@ class ResourcesTest < ActionController::TestCase def test_resource_has_only_member_action with_routing do |set| set.draw do - resources :products, :except => :all do + resources :products, :only => [] do get :preview, :on => :member end end @@ -1041,7 +993,7 @@ class ResourcesTest < ActionController::TestCase def test_singleton_resource_has_only_member_action with_routing do |set| set.draw do - resource :account, :except => :all do + resource :account, :only => [] do member do get :signup end -- cgit v1.2.3 From 11fccc5f06bc67353b895eeeb65cfab94cb4cd25 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sun, 5 Sep 2010 22:06:43 -0300 Subject: Cleanup deprecation warnings in Action Controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/controller/resources_test.rb | 30 ---------------------------- 1 file changed, 30 deletions(-) (limited to 'actionpack/test/controller/resources_test.rb') diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index b59fd65a3e..acb4617a60 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -658,36 +658,6 @@ class ResourcesTest < ActionController::TestCase end end - def test_resource_action_separator - with_routing do |set| - set.draw do - scope '/threads/:thread_id' do - resources :messages, :as => :thread_messages do - get :search, :on => :collection - match :preview, :on => :new - end - end - scope '/admin' do - resource :account, :as => :admin_account do - get :login, :on => :member - match :preview, :on => :new - end - end - end - - action_separator = ActionController::Base.resource_action_separator - - assert_simply_restful_for :messages, :name_prefix => 'thread_', :path_prefix => 'threads/1/', :options => { :thread_id => '1' } - assert_named_route "/threads/1/messages#{action_separator}search", "search_thread_messages_path", {} - assert_named_route "/threads/1/messages/new", "new_thread_message_path", {} - assert_named_route "/threads/1/messages/new#{action_separator}preview", "preview_new_thread_message_path", {} - assert_singleton_restful_for :account, :name_prefix => 'admin_', :path_prefix => 'admin/' - assert_named_route "/admin/account#{action_separator}login", "login_admin_account_path", {} - assert_named_route "/admin/account/new", "new_admin_account_path", {} - assert_named_route "/admin/account/new#{action_separator}preview", "preview_new_admin_account_path", {} - end - end - def test_new_style_named_routes_for_resource with_routing do |set| set.draw do -- cgit v1.2.3