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

Changeset 4255

Show
Ignore:
Timestamp:
04/23/06 18:16:51 (2 years ago)
Author:
rick
Message:

Diff compared routing options. Allow #assert_recognizes to take a second arg as a hash to specify optional request method [Rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r4248 r4255  
    11*SVN* 
     2 
     3* Diff compared routing options.  Allow #assert_recognizes to take a second arg as a hash to specify optional request method [Rick] 
     4 
     5    assert_recognizes({:controller => 'users', :action => 'index'}, 'users') 
     6    assert_recognizes({:controller => 'users', :action => 'create'}, {:path => 'users', :method => :post}) 
    27 
    38* Diff compared options with #assert_redirected_to [Rick] 
  • trunk/actionpack/lib/action_controller/assertions.rb

    r4250 r4255  
    142142 
    143143      # Asserts that the routing of the given path was handled correctly and that the parsed options match. 
     144      # 
     145      #   assert_recognizes({:controller => 'items', :action => 'index'}, 'items') 
     146      # 
     147      # Pass a hash in the second argument to specify the request method.  This is useful for routes 
     148      # requiring a specific method. 
     149      # 
     150      #   assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post}) 
     151      # 
    144152      def assert_recognizes(expected_options, path, extras={}, message=nil) 
     153        if path.is_a? Hash 
     154          request_method = path[:method] 
     155          path           = path[:path] 
     156        else 
     157          request_method = nil 
     158        end 
     159 
    145160        clean_backtrace do  
    146161          ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?  
    147           request = recognized_request_for(path
     162          request = recognized_request_for(path, request_method
    148163       
    149164          expected_options = expected_options.clone 
     
    151166       
    152167          expected_options.stringify_keys! 
    153           msg = build_message(message, "The recognized options <?> did not match <?>",  
    154               request.path_parameters, expected_options) 
     168          routing_diff = expected_options.diff(request.path_parameters) 
     169          msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>",  
     170              request.path_parameters, expected_options, expected_options.diff(request.path_parameters)) 
    155171          assert_block(msg) { request.path_parameters == expected_options } 
    156172        end 
     
    333349       
    334350      private 
    335         def recognized_request_for(path
     351        def recognized_request_for(path, request_method = nil
    336352          path = "/#{path}" unless path.first == '/' 
    337353 
    338354          # Assume given controller 
    339355          request = ActionController::TestRequest.new({}, {}, nil) 
    340           request.path = path 
     356          request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method 
     357          request.path   = path 
    341358          ActionController::Routing::Routes.recognize!(request) 
    342359          request