diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-27 16:58:36 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-04-27 16:58:36 +0000 |
commit | 8326a15784550f8a909e140f828dc0b1c83d617c (patch) | |
tree | 7c57a4c50944c6a2df6a5af63e2dd11a0fd2215b /actionpack/test/controller | |
parent | f985bfd8f8854a3d27da39237ce410d12955595a (diff) | |
download | rails-8326a15784550f8a909e140f828dc0b1c83d617c.tar.gz rails-8326a15784550f8a909e140f828dc0b1c83d617c.tar.bz2 rails-8326a15784550f8a909e140f828dc0b1c83d617c.zip |
Added map.namespace to deal with the common situation of admin sections and the like [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6594 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/resources_test.rb | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 337dd4abce..45e4003021 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -15,6 +15,10 @@ class LogoController < ResourcesController; end class AccountController < ResourcesController; end class AdminController < ResourcesController; end +module Backoffice + class ProductsController < ResourcesController; end +end + class ResourcesTest < Test::Unit::TestCase def test_should_arrange_actions resource = ActionController::Resources::Resource.new(:messages, @@ -384,6 +388,28 @@ class ResourcesTest < Test::Unit::TestCase end end + def test_resources_in_namespace + with_routing do |set| + set.draw do |map| + map.namespace :backoffice do |backoffice| + backoffice.resources :products + end + end + + assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/' + end + end + + def test_resources_using_namespace + with_routing do |set| + set.draw do |map| + map.resources :products, :namespace => "backoffice/" + end + + assert_simply_restful_for :products, :controller => "backoffice/products" + end + end + protected def with_restful_routing(*args) with_routing do |set| @@ -402,7 +428,7 @@ class ResourcesTest < Test::Unit::TestCase # runs assert_restful_routes_for and assert_restful_named_routes for on the controller_name and options, without passing a block. def assert_simply_restful_for(controller_name, options = {}) assert_restful_routes_for controller_name, options - assert_restful_named_routes_for controller_name, options + assert_restful_named_routes_for controller_name, nil, options end def assert_singleton_restful_for(singleton_name, options = {}) @@ -411,7 +437,8 @@ class ResourcesTest < Test::Unit::TestCase end def assert_restful_routes_for(controller_name, options = {}) - (options[:options] ||= {})[:controller] = controller_name.to_s + options[:options] ||= {} + options[:options][:controller] = options[:controller] || controller_name.to_s collection_path = "/#{options[:path_prefix]}#{controller_name}" member_path = "#{collection_path}/1" @@ -456,8 +483,11 @@ class ResourcesTest < Test::Unit::TestCase singular_name = nil end singular_name ||= controller_name.to_s.singularize - (options[:options] ||= {})[:controller] = controller_name.to_s - @controller = "#{controller_name.to_s.camelize}Controller".constantize.new + + options[:options] ||= {} + options[:options][:controller] = options[:controller] || controller_name.to_s + + @controller = "#{options[:options][:controller].camelize}Controller".constantize.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new get :index, options[:options] |