Ticket #7633: allow_regexp_for_id_in_map_resources.diff
| File allow_regexp_for_id_in_map_resources.diff, 2.0 kB (added by quixoten, 2 years ago) |
|---|
-
lib/action_controller/resources.rb
old new 389 389 390 390 def action_options_for(action, resource, method = nil) 391 391 default_options = { :action => action.to_s } 392 require_id = resource.kind_of?(SingletonResource) ? {} : { :requirements => { :id => Regexp.new("[^#{Routing::SEPARATORS.join}]+") } }392 require_id = resource.kind_of?(SingletonResource) ? {} : { :requirements => { :id => resource.options[:id] || Regexp.new("[^#{Routing::SEPARATORS.join}]+") } } 393 393 case default_options[:action] 394 394 when "index", "new" : default_options.merge(conditions_for(method || :get)) 395 395 when "create" : default_options.merge(conditions_for(method || :post)) -
test/controller/resources_test.rb
old new 57 57 end 58 58 end 59 59 60 def test_irregular_id_with_no_regexp_should_raise_error 61 expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'} 62 63 with_restful_routing :messages do 64 assert_raises(ActionController::RoutingError) do 65 assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get) 66 end 67 end 68 end 69 70 def test_irregular_id_with_regexp_should_pass 71 expected_options = {:controller => 'messages', :action => 'show', :id => '1.1.1'} 72 73 with_restful_routing(:messages, :id => /[0-9]\.[0-9]\.[0-9]/) do 74 assert_recognizes(expected_options, :path => 'messages/1.1.1', :method => :get) 75 end 76 end 77 60 78 def test_with_path_prefix 61 79 with_restful_routing :messages, :path_prefix => '/thread/:thread_id' do 62 80 assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }