Changeset 5466
- Timestamp:
- 11/07/06 21:45:10 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/assertions/response_assertions.rb (modified) (7 diffs)
- trunk/actionpack/test/controller/new_render_test.rb (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r5442 r5466 1 1 *SVN* 2 3 * assert_response supports symbolic status codes. #6569 [Kevin Clark] 4 assert_response :ok 5 assert_response :not_found 6 assert_response :forbidden 2 7 3 8 * Cache parsed query parameters. #6559 [Stefan Kaes] trunk/actionpack/lib/action_controller/assertions/response_assertions.rb
r4935 r5466 6 6 module ResponseAssertions 7 7 # Asserts that the response is one of the following types: 8 # 8 # 9 9 # * <tt>:success</tt>: Status code was 200 10 10 # * <tt>:redirect</tt>: Status code was in the 300-399 range … … 12 12 # * <tt>:error</tt>: Status code was in the 500-599 range 13 13 # 14 # You can also pass an explicit status code number as the type, like assert_response(501) 14 # You can also pass an explicit status number like assert_response(501) 15 # or its symbolic equivalent assert_response(:not_implemented). 16 # See ActionController::StatusCodes for a full list. 15 17 def assert_response(type, message = nil) 16 18 clean_backtrace do … … 19 21 elsif type.is_a?(Fixnum) && @response.response_code == type 20 22 assert_block("") { true } # to count the assertion 23 elsif type.is_a?(Symbol) && @response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[type] 24 assert_block("") { true } # to count the assertion 21 25 else 22 26 assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false } 23 end 27 end 24 28 end 25 29 end 26 30 27 31 # Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, 28 # such that assert_redirected_to(:controller => "weblog") will also match the redirection of 32 # such that assert_redirected_to(:controller => "weblog") will also match the redirection of 29 33 # redirect_to(:controller => "weblog", :action => "show") and so on. 30 34 def assert_redirected_to(options = {}, message=nil) … … 67 71 if value.respond_to?(:[]) && value['controller'] 68 72 if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/') 69 value['controller'] = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path) 73 value['controller'] = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path) 70 74 end 71 75 value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash … … 73 77 url[key] = value 74 78 end 75 79 76 80 77 81 @response_diff = url[:expected].diff(url[:actual]) if url[:actual] 78 msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>), difference: <?>", 82 msg = build_message(message, "response is not a redirection to all of the options supplied (redirection is <?>), difference: <?>", 79 83 url[:actual], @response_diff) 80 84 81 85 assert_block(msg) do 82 86 url[:expected].keys.all? do |k| … … 95 99 96 100 assert_equal(eurl, url, msg) if eurl && url 97 assert_equal(epath, path, msg) if epath && path 101 assert_equal(epath, path, msg) if epath && path 98 102 end 99 103 end … … 111 115 expected == rendered 112 116 end 113 end 117 end 114 118 end 115 119 end trunk/actionpack/test/controller/new_render_test.rb
r5201 r5466 641 641 assert @response.body.blank? 642 642 assert_equal "/foo", @response.headers["Location"] 643 assert_response :ok 643 644 end 644 645 … … 647 648 assert @response.body.blank? 648 649 assert_equal "something", @response.headers["X-Custom-Header"] 650 assert_response :ok 649 651 end 650 652 … … 652 654 get :head_with_symbolic_status, :status => "ok" 653 655 assert_equal "200 OK", @response.headers["Status"] 656 assert_response :ok 654 657 655 658 get :head_with_symbolic_status, :status => "not_found" 656 659 assert_equal "404 Not Found", @response.headers["Status"] 660 assert_response :not_found 657 661 658 662 ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| 659 663 get :head_with_symbolic_status, :status => status.to_s 660 664 assert_equal code, @response.response_code 665 assert_response status 661 666 end 662 667 end … … 673 678 assert_equal 404, @response.response_code 674 679 assert_equal "Eat Dirt", @response.message 680 assert_response :not_found 675 681 end 676 682 … … 680 686 assert_equal "Forbidden", @response.message 681 687 assert_equal "something", @response.headers["X-Custom-Header"] 688 assert_response :forbidden 682 689 end 683 690 end