mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
Nested resource testing.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4643 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -34,7 +34,7 @@ module ActionController
|
||||
end
|
||||
|
||||
def nesting_path_prefix
|
||||
"#{path_prefix}/#{plural}/:#{singular}_id"
|
||||
"#{path}/:#{singular}_id"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
require File.dirname(__FILE__) + '/../abstract_unit'
|
||||
|
||||
class MessagesController < ActionController::Base
|
||||
class ResourcesController < ActionController::Base
|
||||
def index() render :nothing => true end
|
||||
def rescue_action(e) raise e end
|
||||
end
|
||||
|
||||
class CommentsController < ActionController::Base
|
||||
def index() render :nothing => true end
|
||||
def rescue_action(e) raise e end
|
||||
end
|
||||
class ThreadsController < ResourcesController; end
|
||||
class MessagesController < ResourcesController; end
|
||||
class CommentsController < ResourcesController; end
|
||||
|
||||
|
||||
class ResourcesTest < Test::Unit::TestCase
|
||||
def test_should_arrange_actions
|
||||
@@ -116,20 +116,21 @@ class ResourcesTest < Test::Unit::TestCase
|
||||
|
||||
def test_nested_restful_routes
|
||||
with_routing do |set|
|
||||
set.draw do |map|
|
||||
map.resources(:messages) do |map|
|
||||
map.resources(:comments)
|
||||
set.draw do |map|
|
||||
map.resources :threads do |map|
|
||||
map.resources :messages do |map|
|
||||
map.resources :comments
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
with_options(:controller => 'comments', :message_id => '1') do |controller|
|
||||
controller.assert_routing "/messages/1/comments", :action => 'index'
|
||||
controller.assert_routing "/messages/1/comments.xml" , :action => 'index', :format => 'xml'
|
||||
controller.assert_routing "/messages/1/comments/new", :action => 'new'
|
||||
controller.assert_routing "/messages/1/comments/1", :action => 'show', :id => '1'
|
||||
controller.assert_routing "/messages/1/comments/1;edit", :action => 'edit', :id => '1'
|
||||
controller.assert_routing "/messages/1/comments/1.xml", :action => 'show', :id => '1', :format => 'xml'
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user