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

Ticket #6569: assert_response_can_use_symbolic_status_codes.diff

File assert_response_can_use_symbolic_status_codes.diff, 1.2 kB (added by kevinclark, 2 years ago)

Diff attached

  • lib/action_controller/assertions/response_assertions.rb

    old new  
    1212      # * <tt>:error</tt>:  Status code was in the 500-599 range 
    1313      # 
    1414      # You can also pass an explicit status code number as the type, like assert_response(501) 
     15      # Supports symbolic status codes 
    1516      def assert_response(type, message = nil) 
    1617        clean_backtrace do 
    1718          if [ :success, :missing, :redirect, :error ].include?(type) && @response.send("#{type}?") 
    1819            assert_block("") { true } # to count the assertion 
    1920          elsif type.is_a?(Fixnum) && @response.response_code == type 
    2021            assert_block("") { true } # to count the assertion 
     22          elsif type.is_a?(Symbol) && @response.response_code == ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[type] 
     23            assert_block("") { true } # to count the assertion 
    2124          else 
    2225            assert_block(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code)) { false } 
    2326          end