Changeset 4638
- Timestamp:
- 07/31/06 20:00:18 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/resources.rb (modified) (1 diff)
- trunk/actionpack/test/controller/resources_test.rb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r4637 r4638 1 1 *SVN* 2 3 * Fixed the new_#{resource}_url route and added named route tests for Simply Restful. [Rick Olson] 2 4 3 5 * Added map.resources from the Simply Restful plugin [DHH]. Examples (the API has changed to use plurals!): trunk/actionpack/lib/action_controller/resources.rb
r4637 r4638 137 137 actions.each do |action| 138 138 path = action == :new ? resource.new_path : "#{resource.new_path};#{action}" 139 name = "new_#{resource. plural}"139 name = "new_#{resource.singular}" 140 140 name = "#{action}_#{name}" unless action == :new 141 141 trunk/actionpack/test/controller/resources_test.rb
r4637 r4638 2 2 3 3 class MessagesController < ActionController::Base 4 def index() render :nothing => true end 4 5 def rescue_action(e) raise e end 5 6 end … … 12 13 def test_default_restful_routes 13 14 with_restful_routing :messages do 14 assert_restful_routes_for :messages do 15 routing_options = {:controller => '/messages'} 16 end 15 assert_simply_restful_for :messages 17 16 end 18 17 end … … 20 19 def test_with_path_prefix 21 20 with_restful_routing :messages, :path_prefix => '/thread/:thread_id' do 22 assert_ restful_routes_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }21 assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' } 23 22 end 24 23 end … … 26 25 def test_with_collection_action 27 26 with_restful_routing :messages, :collection => { :rss => :get } do 27 rss_options = {:action => 'rss'} 28 rss_path = "/messages;rss" 28 29 assert_restful_routes_for :messages do |options| 29 assert_routing "/messages;rss", options.merge(:action => 'rss') 30 assert_routing rss_path, options.merge(rss_options) 31 end 32 33 assert_restful_named_routes_for :messages do |options| 34 assert_named_route rss_path, :rss_messages_path, rss_options 30 35 end 31 36 end … … 35 40 [:put, :post].each do |method| 36 41 with_restful_routing :messages, :member => { :mark => method } do 42 mark_options = {:action => 'mark', :id => '1'} 43 mark_path = "/messages/1;mark" 37 44 assert_restful_routes_for :messages do |options| 38 assert_recognizes( 39 options.merge(:action => 'mark', :id => '1'), 40 {:path => "/messages/1;mark", :method => method}) 45 assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) 46 end 47 48 assert_restful_named_routes_for :messages do |options| 49 assert_named_route mark_path, :mark_message_path, mark_options 41 50 end 42 51 end … … 46 55 def test_with_new_action 47 56 with_restful_routing :messages, :new => { :preview => :post } do 57 preview_options = {:action => 'preview'} 58 preview_path = "/messages/new;preview" 48 59 assert_restful_routes_for :messages do |options| 49 assert_recognizes( 50 options.merge(:action => 'preview'), 51 {:path => "/messages/new;preview", :method => :post}) 60 assert_recognizes(options.merge(preview_options), :path => preview_path, :method => :post) 61 end 62 63 assert_restful_named_routes_for :messages do |options| 64 assert_named_route preview_path, :preview_new_message_path, preview_options 52 65 end 53 66 end … … 80 93 end 81 94 end 82 95 96 # runs assert_restful_routes_for and assert_restful_named_routes for on the controller_name and options, without passing a block. 97 def assert_simply_restful_for(controller_name, options = {}) 98 assert_restful_routes_for controller_name, options 99 assert_restful_named_routes_for controller_name, options 100 end 101 83 102 def assert_restful_routes_for(controller_name, options = {}) 84 103 (options[:options] ||= {})[:controller] = controller_name.to_s … … 104 123 options[:options].merge(:action => 'destroy', :id => '1'), 105 124 {:path => "/#{options[:path_prefix]}#{controller_name}/1", :method => :delete}) 106 125 107 126 yield options[:options] if block_given? 108 127 end 128 129 # test named routes like foo_path and foos_path map to the correct options. 130 def assert_restful_named_routes_for(controller_name, singular_name = nil, options = {}) 131 if singular_name.is_a?(Hash) 132 options = singular_name 133 singular_name = nil 134 end 135 singular_name ||= controller_name.to_s.singularize 136 (options[:options] ||= {})[:controller] = controller_name.to_s 137 @controller = "#{controller_name.to_s.camelize}Controller".constantize.new 138 @request = ActionController::TestRequest.new 139 @response = ActionController::TestResponse.new 140 get :index, options[:options] 141 options[:options].delete :action 142 143 full_prefix = "/#{options[:path_prefix]}#{controller_name}" 144 145 assert_named_route "#{full_prefix}", "#{controller_name}_path", options[:options] 146 assert_named_route "#{full_prefix}.xml", "formatted_#{controller_name}_path", options[:options].merge(:format => 'xml') 147 assert_named_route "#{full_prefix}/new", "new_#{singular_name}_path", options[:options] 148 assert_named_route "#{full_prefix}/1", "#{singular_name}_path", options[:options].merge(:id => '1') 149 assert_named_route "#{full_prefix}/1;edit", "edit_#{singular_name}_path", options[:options].merge(:id => '1') 150 assert_named_route "#{full_prefix}/1.xml", "formatted_#{singular_name}_path", options[:options].merge(:format => 'xml', :id => '1') 151 yield options[:options] if block_given? 152 end 153 154 def assert_named_route(expected, route, options) 155 actual = @controller.send(route, options) rescue $!.class.name 156 assert_equal expected, actual, "Error on route: #{route}(#{options.inspect})" 157 end 109 158 end