Skip to content

Commit

Permalink
Nested resource testing.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4643 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Aug 1, 2006
1 parent a247d72 commit c9417dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/resources.rb
Expand Up @@ -34,7 +34,7 @@ def member_path
end

def nesting_path_prefix
"#{path_prefix}/#{plural}/:#{singular}_id"
"#{path}/:#{singular}_id"
end

private
Expand Down
33 changes: 17 additions & 16 deletions actionpack/test/controller/resources_test.rb
@@ -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
Expand Down Expand Up @@ -116,20 +116,21 @@ def test_with_new_action

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

Expand Down

0 comments on commit c9417dc

Please sign in to comment.