0
@@ -379,6 +379,31 @@ class ResourcesTest < Test::Unit::TestCase
0
+ def test_shallow_nested_restful_routes
0
+ map.resources :threads, :shallow => true do |map|
0
+ map.resources :messages do |map|
0
+ map.resources :comments
0
+ assert_simply_restful_for :threads,
0
+ assert_simply_restful_for :messages,
0
+ :name_prefix => 'thread_',
0
+ :path_prefix => 'threads/1/',
0
+ :options => { :thread_id => '1' }
0
+ assert_simply_restful_for :comments,
0
+ :name_prefix => 'message_',
0
+ :path_prefix => 'messages/2/',
0
+ :options => { :message_id => '2' }
0
def test_restful_routes_dont_generate_duplicates
0
with_restful_routing :messages do
0
routes = ActionController::Routing::Routes.routes
0
@@ -429,6 +454,32 @@ class ResourcesTest < Test::Unit::TestCase
0
+ def test_resources_has_many_hash_should_become_nested_resources
0
+ map.resources :threads, :has_many => { :messages => [ :comments, { :authors => :threads } ] }
0
+ assert_simply_restful_for :threads
0
+ assert_simply_restful_for :messages, :name_prefix => "thread_", :path_prefix => 'threads/1/', :options => { :thread_id => '1' }
0
+ assert_simply_restful_for :comments, :name_prefix => "thread_message_", :path_prefix => 'threads/1/messages/1/', :options => { :thread_id => '1', :message_id => '1' }
0
+ assert_simply_restful_for :authors, :name_prefix => "thread_message_", :path_prefix => 'threads/1/messages/1/', :options => { :thread_id => '1', :message_id => '1' }
0
+ 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' }
0
+ def test_shallow_resource_has_many_should_become_shallow_nested_resources
0
+ map.resources :messages, :has_many => [ :comments, :authors ], :shallow => true
0
+ assert_simply_restful_for :messages, :shallow => true
0
+ assert_simply_restful_for :comments, :name_prefix => "message_", :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' }
0
+ assert_simply_restful_for :authors, :name_prefix => "message_", :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' }
0
def test_resource_has_one_should_become_nested_resources
0
@@ -440,6 +491,17 @@ class ResourcesTest < Test::Unit::TestCase
0
+ def test_shallow_resource_has_one_should_become_shallow_nested_resources
0
+ map.resources :messages, :has_one => :logo, :shallow => true
0
+ assert_simply_restful_for :messages, :shallow => true
0
+ assert_singleton_restful_for :logo, :name_prefix => 'message_', :path_prefix => 'messages/1/', :shallow => true, :options => { :message_id => '1' }
0
def test_singleton_resource_with_member_action
0
[:put, :post].each do |method|
0
with_singleton_resources :account, :member => { :reset => method } do
0
@@ -744,6 +806,13 @@ class ResourcesTest < Test::Unit::TestCase
0
options[:options] ||= {}
0
options[:options][:controller] = options[:controller] || controller_name.to_s
0
+ options[:shallow_options] ||= {}
0
+ options[:shallow_options][:controller] = options[:options][:controller]
0
+ options[:shallow_options] = options[:options]
0
new_action = ActionController::Base.resources_path_names[:new] || "new"
0
edit_action = ActionController::Base.resources_path_names[:edit] || "edit"
0
if options[:path_names]
0
@@ -751,8 +820,10 @@ class ResourcesTest < Test::Unit::TestCase
0
edit_action = options[:path_names][:edit] if options[:path_names][:edit]
0
- collection_path = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
0
- member_path = "#{collection_path}/1"
0
+ path = "#{options[:as] || controller_name}"
0
+ collection_path = "/#{options[:path_prefix]}#{path}"
0
+ shallow_path = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
0
+ member_path = "#{shallow_path}/1"
0
new_path = "#{collection_path}/#{new_action}"
0
edit_member_path = "#{member_path}/#{edit_action}"
0
formatted_edit_member_path = "#{member_path}/#{edit_action}.xml"
0
@@ -760,10 +831,13 @@ class ResourcesTest < Test::Unit::TestCase
0
with_options(options[:options]) do |controller|
0
controller.assert_routing collection_path, :action => 'index'
0
controller.assert_routing new_path, :action => 'new'
0
- controller.assert_routing member_path, :action => 'show', :id => '1'
0
- controller.assert_routing edit_member_path, :action => 'edit', :id => '1'
0
controller.assert_routing "#{collection_path}.xml", :action => 'index', :format => 'xml'
0
controller.assert_routing "#{new_path}.xml", :action => 'new', :format => 'xml'
0
+ with_options(options[:shallow_options]) do |controller|
0
+ controller.assert_routing member_path, :action => 'show', :id => '1'
0
+ controller.assert_routing edit_member_path, :action => 'edit', :id => '1'
0
controller.assert_routing "#{member_path}.xml", :action => 'show', :id => '1', :format => 'xml'
0
controller.assert_routing formatted_edit_member_path, :action => 'edit', :id => '1', :format => 'xml'
0
@@ -771,18 +845,18 @@ class ResourcesTest < Test::Unit::TestCase
0
assert_recognizes(options[:options].merge(:action => 'index'), :path => collection_path, :method => :get)
0
assert_recognizes(options[:options].merge(:action => 'new'), :path => new_path, :method => :get)
0
assert_recognizes(options[:options].merge(:action => 'create'), :path => collection_path, :method => :post)
0
- assert_recognizes(options[:options].merge(:action => 'show', :id => '1'), :path => member_path, :method => :get)
0
- assert_recognizes(options[:options].merge(:action => 'edit', :id => '1'), :path => edit_member_path, :method => :get)
0
- assert_recognizes(options[:options].merge(:action => 'update', :id => '1'), :path => member_path, :method => :put)
0
- assert_recognizes(options[:options].merge(:action => 'destroy', :id => '1'), :path => member_path, :method => :delete)
0
- assert_recognizes(options[:options].merge(:action => 'index', :format => 'xml'), :path => "#{collection_path}.xml", :method => :get)
0
- assert_recognizes(options[:options].merge(:action => 'new', :format => 'xml'), :path => "#{new_path}.xml", :method => :get)
0
- assert_recognizes(options[:options].merge(:action => 'create', :format => 'xml'), :path => "#{collection_path}.xml", :method => :post)
0
- assert_recognizes(options[:options].merge(:action => 'show', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :get)
0
- assert_recognizes(options[:options].merge(:action => 'edit', :id => '1', :format => 'xml'), :path => formatted_edit_member_path, :method => :get)
0
- assert_recognizes(options[:options].merge(:action => 'update', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :put)
0
- assert_recognizes(options[:options].merge(:action => 'destroy', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :delete)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'show', :id => '1'), :path => member_path, :method => :get)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'edit', :id => '1'), :path => edit_member_path, :method => :get)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'update', :id => '1'), :path => member_path, :method => :put)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'destroy', :id => '1'), :path => member_path, :method => :delete)
0
+ assert_recognizes(options[:options].merge(:action => 'index', :format => 'xml'), :path => "#{collection_path}.xml", :method => :get)
0
+ assert_recognizes(options[:options].merge(:action => 'new', :format => 'xml'), :path => "#{new_path}.xml", :method => :get)
0
+ assert_recognizes(options[:options].merge(:action => 'create', :format => 'xml'), :path => "#{collection_path}.xml", :method => :post)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'show', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :get)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'edit', :id => '1', :format => 'xml'), :path => formatted_edit_member_path, :method => :get)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'update', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :put)
0
+ assert_recognizes(options[:shallow_options].merge(:action => 'destroy', :id => '1', :format => 'xml'), :path => "#{member_path}.xml", :method => :delete)
0
yield options[:options] if block_given?
0
@@ -798,14 +872,24 @@ class ResourcesTest < Test::Unit::TestCase
0
options[:options] ||= {}
0
options[:options][:controller] = options[:controller] || controller_name.to_s
0
+ options[:shallow_options] ||= {}
0
+ options[:shallow_options][:controller] = options[:options][:controller]
0
+ options[:shallow_options] = options[:options]
0
@controller = "#{options[:options][:controller].camelize}Controller".constantize.new
0
@request = ActionController::TestRequest.new
0
@response = ActionController::TestResponse.new
0
get :index, options[:options]
0
options[:options].delete :action
0
- full_prefix = "/#{options[:path_prefix]}#{options[:as] || controller_name}"
0
+ path = "#{options[:as] || controller_name}"
0
+ shallow_path = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
0
+ full_path = "/#{options[:path_prefix]}#{path}"
0
name_prefix = options[:name_prefix]
0
+ shallow_prefix = "#{options[:name_prefix] unless options[:shallow]}"
0
@@ -814,15 +898,15 @@ class ResourcesTest < Test::Unit::TestCase
0
edit_action = options[:path_names][:edit] || "edit"
0
- assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options]
0
- assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml')
0
- assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
0
- assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
0
+ assert_named_route "#{full_path}", "#{name_prefix}#{controller_name}_path", options[:options]
0
+ assert_named_route "#{full_path}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge(:format => 'xml')
0
+ assert_named_route "#{shallow_path}/1", "#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1')
0
+ assert_named_route "#{shallow_path}/1.xml", "formatted_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1', :format => 'xml')
0
- assert_named_route "#{full_prefix}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", options[:options]
0
- assert_named_route "#{full_prefix}/#{new_action}.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml')
0
- assert_named_route "#{full_prefix}/1/#{edit_action}", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1')
0
- assert_named_route "#{full_prefix}/1/#{edit_action}.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml')
0
+ assert_named_route "#{full_path}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", options[:options]
0
+ assert_named_route "#{full_path}/#{new_action}.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge(:format => 'xml')
0
+ assert_named_route "#{shallow_path}/1/#{edit_action}", "edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1')
0
+ assert_named_route "#{shallow_path}/1/#{edit_action}.xml", "formatted_edit_#{shallow_prefix}#{singular_name}_path", options[:shallow_options].merge(:id => '1', :format => 'xml')
0
yield options[:options] if block_given?
AWESOME. Does this already exist as a plugin? If not, I might have a crack at it.
AWESOME. Does this already exist as a plugin? If not, I might have a crack at it.
argh. sorry for the double post, timed out on the first.
This is cool! But new_{resource}_path is not supported for the nested resource, can we add that too?