Changeset 4255
- Timestamp:
- 04/23/06 18:16:51 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/assertions.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r4248 r4255 1 1 *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}) 2 7 3 8 * Diff compared options with #assert_redirected_to [Rick] trunk/actionpack/lib/action_controller/assertions.rb
r4250 r4255 142 142 143 143 # 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 # 144 152 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 145 160 clean_backtrace do 146 161 ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? 147 request = recognized_request_for(path )162 request = recognized_request_for(path, request_method) 148 163 149 164 expected_options = expected_options.clone … … 151 166 152 167 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)) 155 171 assert_block(msg) { request.path_parameters == expected_options } 156 172 end … … 333 349 334 350 private 335 def recognized_request_for(path )351 def recognized_request_for(path, request_method = nil) 336 352 path = "/#{path}" unless path.first == '/' 337 353 338 354 # Assume given controller 339 355 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 341 358 ActionController::Routing::Routes.recognize!(request) 342 359 request