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

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  
    389389 
    390390      def action_options_for(action, resource, method = nil) 
    391391        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}]+") } } 
    393393        case default_options[:action] 
    394394          when "index", "new" : default_options.merge(conditions_for(method || :get)) 
    395395          when "create"       : default_options.merge(conditions_for(method || :post)) 
  • test/controller/resources_test.rb

    old new  
    5757    end 
    5858  end 
    5959 
     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 
    6078  def test_with_path_prefix 
    6179    with_restful_routing :messages, :path_prefix => '/thread/:thread_id' do 
    6280      assert_simply_restful_for :messages, :path_prefix => 'thread/5/', :options => { :thread_id => '5' }