Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4643

Show
Ignore:
Timestamp:
08/01/06 01:23:06 (2 years ago)
Author:
bitsweat
Message:

Nested resource testing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/resources.rb

    r4642 r4643  
    3535       
    3636      def nesting_path_prefix 
    37         "#{path_prefix}/#{plural}/:#{singular}_id" 
     37        "#{path}/:#{singular}_id" 
    3838      end 
    3939       
  • trunk/actionpack/test/controller/resources_test.rb

    r4642 r4643  
    11require File.dirname(__FILE__) + '/../abstract_unit' 
    22 
    3 class MessagesController < ActionController::Base 
     3class ResourcesController < ActionController::Base 
    44  def index() render :nothing => true end 
    55  def rescue_action(e) raise e end 
    66end 
    77 
    8 class CommentsController < ActionController::Base 
    9   def index() render :nothing => true end 
    10   def rescue_action(e) raise e end 
    11 end 
     8class ThreadsController  < ResourcesController; end 
     9class MessagesController < ResourcesController; end 
     10class CommentsController < ResourcesController; end 
     11 
    1212 
    1313class ResourcesTest < Test::Unit::TestCase 
     
    117117  def test_nested_restful_routes 
    118118    with_routing do |set| 
    119       set.draw do |map|  
    120         map.resources(:messages) do |map| 
    121           map.resources(:comments) 
    122         end 
    123       end 
    124  
    125       with_options(:controller => 'comments', :message_id => '1') do |controller| 
    126         controller.assert_routing "/messages/1/comments",        :action => 'index' 
    127         controller.assert_routing "/messages/1/comments.xml" ,   :action => 'index', :format => 'xml' 
    128         controller.assert_routing "/messages/1/comments/new",    :action => 'new' 
    129         controller.assert_routing "/messages/1/comments/1",      :action => 'show', :id => '1' 
    130         controller.assert_routing "/messages/1/comments/1;edit", :action => 'edit', :id => '1' 
    131         controller.assert_routing "/messages/1/comments/1.xml",  :action => 'show', :id => '1', :format => 'xml' 
    132       end 
     119      set.draw do |map| 
     120        map.resources :threads do |map| 
     121          map.resources :messages do |map| 
     122            map.resources :comments 
     123          end 
     124        end 
     125      end 
     126 
     127      assert_simply_restful_for :threads 
     128      assert_simply_restful_for :messages, 
     129        :path_prefix => 'threads/1/', 
     130        :options => { :thread_id => '1' } 
     131      assert_simply_restful_for :comments, 
     132        :path_prefix => 'threads/1/messages/2/', 
     133        :options => { :thread_id => '1', :message_id => '2' } 
    133134    end 
    134135  end