From b79bfaadaf5b5c6d3e458c24184a0e846bd8cf55 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 6 Jul 2015 14:12:00 -0300 Subject: Use URL path extension as format in bad params exception handling --- actionpack/lib/action_dispatch/http/parameters.rb | 19 +++++++++++++++++-- actionpack/test/dispatch/show_exceptions_test.rb | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index c9df787351..5c20bc53c2 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -41,9 +41,9 @@ module ActionDispatch # Returns a hash with the \parameters used to form the \path of the request. # Returned hash keys are strings: # - # {'action' => 'my_action', 'controller' => 'my_controller'} + # {'action' => 'my_action', 'controller' => 'my_controller', format => 'html'} def path_parameters - get_header(PARAMETERS_KEY) || {} + get_header(PARAMETERS_KEY) || default_path_parameters end private @@ -66,6 +66,21 @@ module ActionDispatch def params_parsers ActionDispatch::Request.parameter_parsers end + + def default_path_parameters + if format = format_from_path_extension + { 'format' => format } + else + {} + end + end + + def format_from_path_extension + path = @env['action_dispatch.original_path'] + if match = path.match(/\.(\w+)$/) + match.captures.first + end + end end end end diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index ffdf775836..14894d4b82 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -8,7 +8,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest case req.path when "/not_found" raise AbstractController::ActionNotFound - when "/bad_params" + when "/bad_params", "/bad_params.json" begin raise StandardError.new rescue @@ -120,4 +120,18 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest assert_response 405 assert_equal "", body end + + test "bad params exception is returned in the correct format" do + @app = ProductionApp + + get "/bad_params", headers: { 'action_dispatch.show_exceptions' => true } + assert_equal "text/html; charset=utf-8", response.headers["Content-Type"] + assert_response 400 + assert_match(/400 error/, body) + + get "/bad_params.json", headers: { 'action_dispatch.show_exceptions' => true } + assert_equal "application/json; charset=utf-8", response.headers["Content-Type"] + assert_response 400 + assert_equal("{\"status\":400,\"error\":\"Bad Request\"}", body) + end end -- cgit v1.2.3 From 83b4e9073f0852afc065ef398bd3ad9b5a6db29c Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 6 Jul 2015 21:33:19 -0300 Subject: Response when error should be formatted properly in Rails API if local request --- actionpack/lib/action_dispatch/http/parameters.rb | 6 +++--- .../lib/action_dispatch/middleware/debug_exceptions.rb | 17 +++++++++++++++-- actionpack/test/controller/mime/respond_to_test.rb | 10 ++++++---- actionpack/test/dispatch/debug_exceptions_test.rb | 18 ++++++++++++++++++ actionpack/test/dispatch/routing_test.rb | 1 + .../lib/rails/application/default_middleware_stack.rb | 2 +- 6 files changed, 44 insertions(+), 10 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 5c20bc53c2..4084d78f49 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -69,15 +69,15 @@ module ActionDispatch def default_path_parameters if format = format_from_path_extension - { 'format' => format } + { format: format } else {} end end def format_from_path_extension - path = @env['action_dispatch.original_path'] - if match = path.match(/\.(\w+)$/) + path = @env['action_dispatch.original_path'] || @env['PATH_INFO'] + if match = path && path.match(/\.(\w+)$/) match.captures.first end end diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 66bb74b9c5..972410d806 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -38,9 +38,10 @@ module ActionDispatch end end - def initialize(app, routes_app = nil) + def initialize(app, routes_app = nil, api_only = false) @app = app @routes_app = routes_app + @api_only = api_only end def call(env) @@ -90,7 +91,19 @@ module ActionDispatch ) file = "rescues/#{wrapper.rescue_template}" - if request.xhr? + if @api_only + body = { + :status => wrapper.status_code, + :error => Rack::Utils::HTTP_STATUS_CODES.fetch(wrapper.status_code, Rack::Utils::HTTP_STATUS_CODES[500]), + :exception => wrapper.exception.inspect, + :traces => traces + } + if content_type = request.formats.first + to_format = "to_#{content_type.to_sym}" + body = body.public_send(to_format) + end + format = "application/json" + elsif request.xhr? body = template.render(template: file, layout: false, formats: [:text]) format = "text/plain" else diff --git a/actionpack/test/controller/mime/respond_to_test.rb b/actionpack/test/controller/mime/respond_to_test.rb index c025c7fa00..76e2d3ff43 100644 --- a/actionpack/test/controller/mime/respond_to_test.rb +++ b/actionpack/test/controller/mime/respond_to_test.rb @@ -661,10 +661,6 @@ class RespondToControllerTest < ActionController::TestCase end def test_variant_inline_syntax - get :variant_inline_syntax, format: :js - assert_equal "text/javascript", @response.content_type - assert_equal "js", @response.body - get :variant_inline_syntax assert_equal "text/html", @response.content_type assert_equal "none", @response.body @@ -674,6 +670,12 @@ class RespondToControllerTest < ActionController::TestCase assert_equal "phone", @response.body end + def test_variant_inline_syntax_with_format + get :variant_inline_syntax, format: :js + assert_equal "text/javascript", @response.content_type + assert_equal "js", @response.body + end + def test_variant_inline_syntax_without_block get :variant_inline_syntax_without_block, params: { v: :phone } assert_equal "text/html", @response.content_type diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 30772bd9ed..48eff700ce 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -75,6 +75,13 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end end + class BoomerAPI < Boomer + def call(env) + env['action_dispatch.show_detailed_exceptions'] = @detailed + raise "puke!" + end + end + RoutesApp = Struct.new(:routes).new(SharedTestRoutes) ProductionApp = ActionDispatch::DebugExceptions.new(Boomer.new(false), RoutesApp) DevelopmentApp = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp) @@ -155,6 +162,17 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest assert_match(/ActionController::ParameterMissing/, body) end + test "rescue with json on API request" do + @app = ActionDispatch::DebugExceptions.new(BoomerAPI.new(true), RoutesApp, true) + + get "/index.json", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 500 + assert_no_match(/
/, body) + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/RuntimeError: puke/, body) + end + test "rescue with text error for xhr request" do @app = DevelopmentApp xhr_request_env = {'action_dispatch.show_exceptions' => true, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'} diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 8972f3e74d..1b711e1bf8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3272,6 +3272,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest expected_params = { controller: 'downloads', action: 'show', + format: 'tar', id: '1' } diff --git a/railties/lib/rails/application/default_middleware_stack.rb b/railties/lib/rails/application/default_middleware_stack.rb index 5cb5bfb8b7..9201395091 100644 --- a/railties/lib/rails/application/default_middleware_stack.rb +++ b/railties/lib/rails/application/default_middleware_stack.rb @@ -57,7 +57,7 @@ module Rails # Must come after Rack::MethodOverride to properly log overridden methods middleware.use ::Rails::Rack::Logger, config.log_tags middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app - middleware.use ::ActionDispatch::DebugExceptions, app + middleware.use ::ActionDispatch::DebugExceptions, app, config.api_only middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies unless config.cache_classes -- cgit v1.2.3 From f43c05bff74df90f6b8ff90f92ad9f6d7652bd09 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 6 Jul 2015 22:03:40 -0300 Subject: Do not include web-console in Rails API apps --- railties/test/generators/api_app_generator_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index be2cd3a853..b5980746bb 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -40,6 +40,8 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_no_match(/gem 'jbuilder'/, content) assert_no_match(/gem 'web-console'/, content) assert_match(/gem 'active_model_serializers'/, content) + + assert_no_match(/gem 'web-console'/, content) end assert_file "config/application.rb" do |content| -- cgit v1.2.3 From 05d89410bf97d0778e78558db3c9fed275f8a614 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Tue, 7 Jul 2015 12:43:49 -0300 Subject: Fix some edge cases in AD::DebugExceptions in rails api apps --- .../action_dispatch/middleware/debug_exceptions.rb | 105 +++++++++++++-------- actionpack/test/dispatch/debug_exceptions_test.rb | 73 +++++++++++--- 2 files changed, 126 insertions(+), 52 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 972410d806..c81f52ec88 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -67,55 +67,78 @@ module ActionDispatch log_error(request, wrapper) if request.get_header('action_dispatch.show_detailed_exceptions') - traces = wrapper.traces - - trace_to_show = 'Application Trace' - if traces[trace_to_show].empty? && wrapper.rescue_template != 'routing_error' - trace_to_show = 'Full Trace' - end - - if source_to_show = traces[trace_to_show].first - source_to_show_id = source_to_show[:id] - end - - template = DebugView.new([RESCUES_TEMPLATE_PATH], - request: request, - exception: wrapper.exception, - traces: traces, - show_source_idx: source_to_show_id, - trace_to_show: trace_to_show, - routes_inspector: routes_inspector(exception), - source_extracts: wrapper.source_extracts, - line_number: wrapper.line_number, - file: wrapper.file - ) - file = "rescues/#{wrapper.rescue_template}" - if @api_only - body = { - :status => wrapper.status_code, - :error => Rack::Utils::HTTP_STATUS_CODES.fetch(wrapper.status_code, Rack::Utils::HTTP_STATUS_CODES[500]), - :exception => wrapper.exception.inspect, - :traces => traces - } - if content_type = request.formats.first - to_format = "to_#{content_type.to_sym}" - body = body.public_send(to_format) - end - format = "application/json" - elsif request.xhr? - body = template.render(template: file, layout: false, formats: [:text]) - format = "text/plain" + render_for_api_application(request, wrapper) else - body = template.render(template: file, layout: 'rescues/layout') - format = "text/html" + render_for_non_api_application(request, wrapper) end - render(wrapper.status_code, body, format) else raise exception end end + def render_for_non_api_application(request, wrapper) + template = create_template(request, wrapper) + + file = "rescues/#{wrapper.rescue_template}" + + if request.xhr? + body = template.render(template: file, layout: false, formats: [:text]) + format = "text/plain" + else + body = template.render(template: file, layout: 'rescues/layout') + format = "text/html" + end + render(wrapper.status_code, body, format) + end + + def render_for_api_application(request, wrapper) + body = { + :status => wrapper.status_code, + :error => Rack::Utils::HTTP_STATUS_CODES.fetch(wrapper.status_code, Rack::Utils::HTTP_STATUS_CODES[500]), + :exception => wrapper.exception.inspect, + :traces => wrapper.traces + } + + content_type = request.formats.first + to_format = "to_#{content_type.to_sym}" + + if content_type && body.respond_to?(to_format) + body = body.public_send(to_format) + format = content_type + else + body = body.to_json + format = Mime::JSON + end + + render(wrapper.status_code, body, format) + end + + def create_template(request, wrapper) + traces = wrapper.traces + + trace_to_show = 'Application Trace' + if traces[trace_to_show].empty? && wrapper.rescue_template != 'routing_error' + trace_to_show = 'Full Trace' + end + + if source_to_show = traces[trace_to_show].first + source_to_show_id = source_to_show[:id] + end + + DebugView.new([RESCUES_TEMPLATE_PATH], + request: request, + exception: wrapper.exception, + traces: traces, + show_source_idx: source_to_show_id, + trace_to_show: trace_to_show, + routes_inspector: routes_inspector(wrapper.exception), + source_extracts: wrapper.source_extracts, + line_number: wrapper.line_number, + file: wrapper.file + ) + end + def render(status, body, format) [status, {'Content-Type' => "#{format}; charset=#{Response.default_charset}", 'Content-Length' => body.bytesize.to_s}, [body]] end diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index 48eff700ce..d9c6233511 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -162,17 +162,6 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest assert_match(/ActionController::ParameterMissing/, body) end - test "rescue with json on API request" do - @app = ActionDispatch::DebugExceptions.new(BoomerAPI.new(true), RoutesApp, true) - - get "/index.json", headers: { 'action_dispatch.show_exceptions' => true } - assert_response 500 - assert_no_match(/
/, body) - assert_no_match(//, body) - assert_equal "application/json", response.content_type - assert_match(/RuntimeError: puke/, body) - end - test "rescue with text error for xhr request" do @app = DevelopmentApp xhr_request_env = {'action_dispatch.show_exceptions' => true, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'} @@ -223,6 +212,68 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest assert_match(/ActionController::ParameterMissing/, body) end + test "rescue with json error for API request" do + @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, true) + + get "/", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 500 + assert_no_match(/
/, body) + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/RuntimeError: puke/, body) + + get "/not_found", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 404 + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/#{AbstractController::ActionNotFound.name}/, body) + + get "/method_not_allowed", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 405 + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/ActionController::MethodNotAllowed/, body) + + get "/unknown_http_method", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 405 + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/ActionController::UnknownHttpMethod/, body) + + get "/bad_request", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 400 + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/ActionController::BadRequest/, body) + + get "/parameter_missing", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 400 + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/ActionController::ParameterMissing/, body) + end + + test "rescue with json on API request returns only allowed formats or json as a fallback" do + @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, true) + + get "/index.json", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 500 + assert_equal "application/json", response.content_type + assert_match(/RuntimeError: puke/, body) + + get "/index.html", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 500 + assert_no_match(/
/, body) + assert_no_match(//, body) + assert_equal "application/json", response.content_type + assert_match(/RuntimeError: puke/, body) + + get "/index.xml", headers: { 'action_dispatch.show_exceptions' => true } + assert_response 500 + assert_equal "application/xml", response.content_type + assert_match(/RuntimeError: puke/, body) + end + test "does not show filtered parameters" do @app = DevelopmentApp -- cgit v1.2.3 From a16ab35d34a3bc6440994fe20afc2eced096b618 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Tue, 7 Jul 2015 13:25:11 -0300 Subject: New hash syntax in AD::DebugExceptions --- actionpack/lib/action_dispatch/middleware/debug_exceptions.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index c81f52ec88..3093b6a8a6 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -94,10 +94,10 @@ module ActionDispatch def render_for_api_application(request, wrapper) body = { - :status => wrapper.status_code, - :error => Rack::Utils::HTTP_STATUS_CODES.fetch(wrapper.status_code, Rack::Utils::HTTP_STATUS_CODES[500]), - :exception => wrapper.exception.inspect, - :traces => wrapper.traces + status: wrapper.status_code, + error: Rack::Utils::HTTP_STATUS_CODES.fetch(wrapper.status_code, Rack::Utils::HTTP_STATUS_CODES[500]), + exception: wrapper.exception.inspect, + traces: wrapper.traces } content_type = request.formats.first -- cgit v1.2.3 From b75f5c278ad2bc51faf1ae8438afad0e794a5261 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Tue, 7 Jul 2015 13:37:52 -0300 Subject: Remove unneeded args in AD::DebugExceptions --- actionpack/lib/action_dispatch/middleware/debug_exceptions.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 3093b6a8a6..d93b5fd659 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -79,7 +79,6 @@ module ActionDispatch def render_for_non_api_application(request, wrapper) template = create_template(request, wrapper) - file = "rescues/#{wrapper.rescue_template}" if request.xhr? -- cgit v1.2.3 From d879c0ec5a7eebf9eed01c84c8f95566be2aedf4 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Tue, 7 Jul 2015 13:41:04 -0300 Subject: Minor cleanup in AD::DebugExceptions --- .../lib/action_dispatch/middleware/debug_exceptions.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index d93b5fd659..e5500ccdac 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -93,24 +93,27 @@ module ActionDispatch def render_for_api_application(request, wrapper) body = { - status: wrapper.status_code, - error: Rack::Utils::HTTP_STATUS_CODES.fetch(wrapper.status_code, Rack::Utils::HTTP_STATUS_CODES[500]), + status: wrapper.status_code, + error: Rack::Utils::HTTP_STATUS_CODES.fetch( + wrapper.status_code, + Rack::Utils::HTTP_STATUS_CODES[500] + ), exception: wrapper.exception.inspect, - traces: wrapper.traces + traces: wrapper.traces } content_type = request.formats.first to_format = "to_#{content_type.to_sym}" if content_type && body.respond_to?(to_format) - body = body.public_send(to_format) + formatted_body = body.public_send(to_format) format = content_type else - body = body.to_json + formatted_body = body.to_json format = Mime::JSON end - render(wrapper.status_code, body, format) + render(wrapper.status_code, formatted_body, format) end def create_template(request, wrapper) -- cgit v1.2.3 From 02c5c0d1565318668f8d3161374c4f4c269e6d33 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 20 Jul 2015 14:07:49 -0300 Subject: Improve regexp in AC::Http::Parameters --- actionpack/lib/action_dispatch/http/parameters.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 4084d78f49..9d450beae5 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -77,7 +77,7 @@ module ActionDispatch def format_from_path_extension path = @env['action_dispatch.original_path'] || @env['PATH_INFO'] - if match = path && path.match(/\.(\w+)$/) + if match = path && path.match(/\.(\w+)\z/) match.captures.first end end -- cgit v1.2.3 From 6fb2afed5284c7bc0157055609a0fde9ea4518d0 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 20 Jul 2015 14:09:16 -0300 Subject: Better name for method in DebugExceptions middleware --- actionpack/lib/action_dispatch/middleware/debug_exceptions.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index e5500ccdac..7912b5ce82 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -70,14 +70,14 @@ module ActionDispatch if @api_only render_for_api_application(request, wrapper) else - render_for_non_api_application(request, wrapper) + render_for_default_application(request, wrapper) end else raise exception end end - def render_for_non_api_application(request, wrapper) + def render_for_default_application(request, wrapper) template = create_template(request, wrapper) file = "rescues/#{wrapper.rescue_template}" -- cgit v1.2.3 From 668d94fff644e87d49004e4f48143f5561e8c9a0 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 20 Jul 2015 16:37:19 -0300 Subject: Add debug_exception_response_format config to configure DebugException behavior --- railties/lib/rails/application/configuration.rb | 61 +++++++++++----------- .../config/environments/development.rb.tt | 8 +++ railties/test/generators/api_app_generator_test.rb | 4 ++ 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 91ed835bd6..bb5f0a21d8 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -19,40 +19,41 @@ module Rails :beginning_of_week, :filter_redirect, :x attr_writer :log_level - attr_reader :encoding, :api_only, :static_cache_control + attr_reader :encoding, :api_only, :static_cache_control, :debug_exception_response_format def initialize(*) super self.encoding = "utf-8" - @allow_concurrency = nil - @consider_all_requests_local = false - @filter_parameters = [] - @filter_redirect = [] - @helpers_paths = [] - @public_file_server = ActiveSupport::OrderedOptions.new - @public_file_server.enabled = true - @public_file_server.index_name = "index" - @force_ssl = false - @ssl_options = {} - @session_store = :cookie_store - @session_options = {} - @time_zone = "UTC" - @beginning_of_week = :monday - @log_level = nil - @generators = app_generators - @cache_store = [ :file_store, "#{root}/tmp/cache/" ] - @railties_order = [:all] - @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] - @reload_classes_only_on_change = true - @file_watcher = file_update_checker - @exceptions_app = nil - @autoflush_log = true - @log_formatter = ActiveSupport::Logger::SimpleFormatter.new - @eager_load = nil - @secret_token = nil - @secret_key_base = nil - @api_only = false - @x = Custom.new + @allow_concurrency = nil + @consider_all_requests_local = false + @filter_parameters = [] + @filter_redirect = [] + @helpers_paths = [] + @public_file_server = ActiveSupport::OrderedOptions.new + @public_file_server.enabled = true + @public_file_server.index_name = "index" + @force_ssl = false + @ssl_options = {} + @session_store = :cookie_store + @session_options = {} + @time_zone = "UTC" + @beginning_of_week = :monday + @log_level = nil + @generators = app_generators + @cache_store = [ :file_store, "#{root}/tmp/cache/" ] + @railties_order = [:all] + @relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"] + @reload_classes_only_on_change = true + @file_watcher = file_update_checker + @exceptions_app = nil + @autoflush_log = true + @log_formatter = ActiveSupport::Logger::SimpleFormatter.new + @eager_load = nil + @secret_token = nil + @secret_key_base = nil + @api_only = false + @debug_exception_response_format = :default + @x = Custom.new end def static_cache_control=(value) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 4dd20a9d2e..eaa885671b 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -23,7 +23,15 @@ Rails.application.configure do config.action_controller.perform_caching = false config.cache_store = :null_store end + <%- if options[:api] -%> + # Return error responses in the format requested by the client + # or default to JSON format. + # This option is useful for Rails API only applications developers + # who prefer to render errors in the expected format instead of + # rendering a HTML page with debug info and web-console. + config.debug_exception_response_format = :api + <%- end -%> <%- unless options.skip_action_mailer? -%> # Don't care if the mailer can't send. diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index b5980746bb..7273c67a4e 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -48,6 +48,10 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_match(/config.api_only = true/, content) end + assert_file "config/environments/development.rb" do |content| + assert_match(/config.debug_exception_response_format = :api/, content) + end + assert_file "config/initializers/cors.rb" assert_file "config/initializers/wrap_parameters.rb" -- cgit v1.2.3 From 6fa2023c816e8dc8d2735a5fe87098ef5d8253f9 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 20 Jul 2015 16:38:09 -0300 Subject: DebugException initialize with a response_format value --- .../lib/action_dispatch/middleware/debug_exceptions.rb | 13 +++++++------ actionpack/test/dispatch/debug_exceptions_test.rb | 4 ++-- railties/lib/rails/application/default_middleware_stack.rb | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 7912b5ce82..642c7183cc 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -38,10 +38,10 @@ module ActionDispatch end end - def initialize(app, routes_app = nil, api_only = false) - @app = app - @routes_app = routes_app - @api_only = api_only + def initialize(app, routes_app = nil, response_format = :default) + @app = app + @routes_app = routes_app + @response_format = response_format end def call(env) @@ -67,9 +67,10 @@ module ActionDispatch log_error(request, wrapper) if request.get_header('action_dispatch.show_detailed_exceptions') - if @api_only + case @response_format + when :api render_for_api_application(request, wrapper) - else + when :default render_for_default_application(request, wrapper) end else diff --git a/actionpack/test/dispatch/debug_exceptions_test.rb b/actionpack/test/dispatch/debug_exceptions_test.rb index d9c6233511..159bf10545 100644 --- a/actionpack/test/dispatch/debug_exceptions_test.rb +++ b/actionpack/test/dispatch/debug_exceptions_test.rb @@ -213,7 +213,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end test "rescue with json error for API request" do - @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, true) + @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) get "/", headers: { 'action_dispatch.show_exceptions' => true } assert_response 500 @@ -254,7 +254,7 @@ class DebugExceptionsTest < ActionDispatch::IntegrationTest end test "rescue with json on API request returns only allowed formats or json as a fallback" do - @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, true) + @app = ActionDispatch::DebugExceptions.new(Boomer.new(true), RoutesApp, :api) get "/index.json", headers: { 'action_dispatch.show_exceptions' => true } assert_response 500 diff --git a/railties/lib/rails/application/default_middleware_stack.rb b/railties/lib/rails/application/default_middleware_stack.rb index 9201395091..ed6a1f82d3 100644 --- a/railties/lib/rails/application/default_middleware_stack.rb +++ b/railties/lib/rails/application/default_middleware_stack.rb @@ -57,7 +57,7 @@ module Rails # Must come after Rack::MethodOverride to properly log overridden methods middleware.use ::Rails::Rack::Logger, config.log_tags middleware.use ::ActionDispatch::ShowExceptions, show_exceptions_app - middleware.use ::ActionDispatch::DebugExceptions, app, config.api_only + middleware.use ::ActionDispatch::DebugExceptions, app, config.debug_exception_response_format middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies unless config.cache_classes -- cgit v1.2.3 From 6cb578c018b1136696f9c9d30ed1352c2c014f30 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 20 Jul 2015 16:46:21 -0300 Subject: Mention the debug_exception_response_format config in guides --- guides/source/api_app.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/guides/source/api_app.md b/guides/source/api_app.md index fb3127555e..17695c5db0 100644 --- a/guides/source/api_app.md +++ b/guides/source/api_app.md @@ -163,6 +163,14 @@ class definition: config.api_only = true ``` +Optionally, in `config/environments/development.rb` add the following line +to render error responses using the API format (JSON by default) when it +is a local request: + +```ruby +config.debug_exception_response_format = :api +``` + Finally, inside `app/controllers/application_controller.rb`, instead of: ```ruby -- cgit v1.2.3 From cd27e1fe35e02c2059c18327749f2372191bb65e Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Tue, 21 Jul 2015 12:01:18 -0300 Subject: Fix indent in generated Rails API env file --- .../app/templates/config/environments/development.rb.tt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index eaa885671b..238f45251e 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -25,12 +25,12 @@ Rails.application.configure do end <%- if options[:api] -%> - # Return error responses in the format requested by the client - # or default to JSON format. - # This option is useful for Rails API only applications developers - # who prefer to render errors in the expected format instead of - # rendering a HTML page with debug info and web-console. - config.debug_exception_response_format = :api + # Return error responses in the format requested by the client + # or default to JSON format. + # This option is useful for Rails API only applications developers + # who prefer to render errors in the expected format instead of + # rendering a HTML page with debug info and web-console. + config.debug_exception_response_format = :api <%- end -%> <%- unless options.skip_action_mailer? -%> -- cgit v1.2.3 From c97e71616b1689367d07044bbb67be12d7922a0d Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Tue, 21 Jul 2015 12:09:59 -0300 Subject: debug_exception_response_format needs to be writeable in Configuration --- railties/lib/rails/application/configuration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index bb5f0a21d8..071677848e 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -16,10 +16,10 @@ module Rails :railties_order, :relative_url_root, :secret_key_base, :secret_token, :ssl_options, :public_file_server, :session_options, :time_zone, :reload_classes_only_on_change, - :beginning_of_week, :filter_redirect, :x + :beginning_of_week, :filter_redirect, :debug_exception_response_format, :x attr_writer :log_level - attr_reader :encoding, :api_only, :static_cache_control, :debug_exception_response_format + attr_reader :encoding, :api_only, :static_cache_control def initialize(*) super -- cgit v1.2.3 From 290a536d284d49eafebff6685fdf3b56746cbdb7 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Mon, 3 Aug 2015 11:12:07 -0300 Subject: Update Changelog with the added response_format option in AD::DebugExceptions --- actionpack/CHANGELOG.md | 10 ++++++++++ railties/CHANGELOG.md | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index b8563d5076..271a57a7ad 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,13 @@ +* Add a `response_format` option to `ActionDispatch::DebugExceptions` + to configure the format of the response when errors occur in + development mode. + + If `response_format` is `:default` the debug info will be rendered + in an HTML page. In the other hand, if the provided value is `:api` + the debug info will be rendered in the original response format. + + *Jorge Bejar* + * Change the `protect_from_forgery` prepend default to `false` Per this comment diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index e6bee302a3..e5ab31005e 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,12 @@ +* `config.debug_exception_response_format` configures the format used + in responses when errors occur in development mode. + + Set `config.debug_exception_response_format` to render an HTML page with + debug info (using the value `:default`) or render debug info preserving + the response format (using the value `:api`). + + *Jorge Bejar* + * Fix setting exit status code for rake test tasks. The exit status code was not set when tests were fired with `rake`. Now, it is being set and it matches behavior of running tests via `rails` command (`rails test`), so no matter if -- cgit v1.2.3 From fa092512a00f6055326ae22e7b0d3218e8921a99 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Tue, 11 Aug 2015 14:26:35 -0300 Subject: Adjust comment in development.rb template file for app generator --- .../rails/app/templates/config/environments/development.rb.tt | 3 --- 1 file changed, 3 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 238f45251e..f91512b3af 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -27,9 +27,6 @@ Rails.application.configure do # Return error responses in the format requested by the client # or default to JSON format. - # This option is useful for Rails API only applications developers - # who prefer to render errors in the expected format instead of - # rendering a HTML page with debug info and web-console. config.debug_exception_response_format = :api <%- end -%> <%- unless options.skip_action_mailer? -%> -- cgit v1.2.3 From 84e8accd6fb83031e4c27e44925d7596655285f7 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Thu, 3 Dec 2015 15:19:25 -0300 Subject: Do not add format key to request_params I did this change but it is affecting how the request params end up after being processed by the router. To be in the safe side, I just take the format from the extension in the URL when is not present in those params and it's being used only for the `Request#formats` method --- .../lib/action_dispatch/http/mime_negotiation.rb | 9 +++++++++ actionpack/lib/action_dispatch/http/parameters.rb | 19 ++----------------- actionpack/test/dispatch/routing_test.rb | 1 - 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index 7acf91902d..004713ec1a 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -67,6 +67,8 @@ module ActionDispatch v = if params_readable Array(Mime[parameters[:format]]) + elsif format_from_path_extension + [Mime[format_from_path_extension]] elsif use_accept_header && valid_accept_header accepts elsif xhr? @@ -160,6 +162,13 @@ module ActionDispatch def use_accept_header !self.class.ignore_accept_header end + + def format_from_path_extension + path = @env['action_dispatch.original_path'] || @env['PATH_INFO'] + if match = path && path.match(/\.(\w+)\z/) + match.captures.first + end + end end end end diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 9d450beae5..c9df787351 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -41,9 +41,9 @@ module ActionDispatch # Returns a hash with the \parameters used to form the \path of the request. # Returned hash keys are strings: # - # {'action' => 'my_action', 'controller' => 'my_controller', format => 'html'} + # {'action' => 'my_action', 'controller' => 'my_controller'} def path_parameters - get_header(PARAMETERS_KEY) || default_path_parameters + get_header(PARAMETERS_KEY) || {} end private @@ -66,21 +66,6 @@ module ActionDispatch def params_parsers ActionDispatch::Request.parameter_parsers end - - def default_path_parameters - if format = format_from_path_extension - { format: format } - else - {} - end - end - - def format_from_path_extension - path = @env['action_dispatch.original_path'] || @env['PATH_INFO'] - if match = path && path.match(/\.(\w+)\z/) - match.captures.first - end - end end end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 1b711e1bf8..8972f3e74d 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3272,7 +3272,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest expected_params = { controller: 'downloads', action: 'show', - format: 'tar', id: '1' } -- cgit v1.2.3 From da5acae03266808fdbc9a59f43cf8cf7cf25a24e Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Thu, 3 Dec 2015 15:36:06 -0300 Subject: Avoid warning because of the mime type --- actionpack/lib/action_dispatch/middleware/debug_exceptions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb index 642c7183cc..b55c937e0c 100644 --- a/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb +++ b/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb @@ -111,7 +111,7 @@ module ActionDispatch format = content_type else formatted_body = body.to_json - format = Mime::JSON + format = Mime[:json] end render(wrapper.status_code, formatted_body, format) -- cgit v1.2.3 From 2430268f187332c2054c781be1d165dc8c269318 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Fri, 4 Dec 2015 18:04:48 -0300 Subject: Add tests for api_only configuration setting --- railties/test/application/configuration_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 5f3d1879eb..bb45018a86 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1393,5 +1393,20 @@ module ApplicationTests assert_equal 'unicorn', Rails.application.config.my_custom_config['key'] end + + test "api_only is false by default" do + app 'development' + refute Rails.application.config.api_only + end + + test "api_only generator config is set when api_only is set" do + add_to_config <<-RUBY + config.api_only = true + RUBY + app 'development' + + Rails.application.load_generators + assert Rails.configuration.api_only + end end end -- cgit v1.2.3 From a0343d11f1bf80a79e273c1d0cf9934ef2601e98 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Fri, 4 Dec 2015 18:05:45 -0300 Subject: Make debug_exception_response_format config depends on api_only when is not set --- railties/lib/rails/application/configuration.rb | 14 ++++++++++++-- railties/test/application/configuration_test.rb | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 071677848e..a5550df0de 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -16,7 +16,7 @@ module Rails :railties_order, :relative_url_root, :secret_key_base, :secret_token, :ssl_options, :public_file_server, :session_options, :time_zone, :reload_classes_only_on_change, - :beginning_of_week, :filter_redirect, :debug_exception_response_format, :x + :beginning_of_week, :filter_redirect, :x attr_writer :log_level attr_reader :encoding, :api_only, :static_cache_control @@ -52,7 +52,7 @@ module Rails @secret_token = nil @secret_key_base = nil @api_only = false - @debug_exception_response_format = :default + @debug_exception_response_format = nil @x = Custom.new end @@ -96,6 +96,16 @@ module Rails def api_only=(value) @api_only = value generators.api_only = value + + @debug_exception_response_format ||= :api + end + + def debug_exception_response_format + @debug_exception_response_format || :default + end + + def debug_exception_response_format=(value) + @debug_exception_response_format = value end def paths diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index bb45018a86..49f63d5d31 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1408,5 +1408,30 @@ module ApplicationTests Rails.application.load_generators assert Rails.configuration.api_only end + + test "debug_exception_response_format is :api by default if only_api is enabled" do + add_to_config <<-RUBY + config.api_only = true + RUBY + app 'development' + + assert_equal :api, Rails.configuration.debug_exception_response_format + end + + test "debug_exception_response_format can be override" do + add_to_config <<-RUBY + config.api_only = true + RUBY + + app_file 'config/environments/development.rb', <<-RUBY + Rails.application.configure do + config.debug_exception_response_format = :default + end + RUBY + + app 'development' + + assert_equal :default, Rails.configuration.debug_exception_response_format + end end end -- cgit v1.2.3 From 34bfca2fee65bc7b6bf8b64a890bd423595554c9 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Wed, 9 Dec 2015 10:48:59 -0300 Subject: We don't need to set config.debug_exception_response_format given that :api is the default value for only API apps --- .../rails/app/templates/config/environments/development.rb.tt | 6 ------ railties/test/generators/api_app_generator_test.rb | 4 ---- 2 files changed, 10 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index f91512b3af..2778dd8247 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -23,12 +23,6 @@ Rails.application.configure do config.action_controller.perform_caching = false config.cache_store = :null_store end - <%- if options[:api] -%> - - # Return error responses in the format requested by the client - # or default to JSON format. - config.debug_exception_response_format = :api - <%- end -%> <%- unless options.skip_action_mailer? -%> # Don't care if the mailer can't send. diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index 7273c67a4e..b5980746bb 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -48,10 +48,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_match(/config.api_only = true/, content) end - assert_file "config/environments/development.rb" do |content| - assert_match(/config.debug_exception_response_format = :api/, content) - end - assert_file "config/initializers/cors.rb" assert_file "config/initializers/wrap_parameters.rb" -- cgit v1.2.3 From 3a94ced8a15da6d046bc8fa30d69c944038e8ced Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Wed, 9 Dec 2015 10:49:59 -0300 Subject: Remove duplicated assertion from api_app_generator tests --- railties/test/generators/api_app_generator_test.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index b5980746bb..be2cd3a853 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -40,8 +40,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase assert_no_match(/gem 'jbuilder'/, content) assert_no_match(/gem 'web-console'/, content) assert_match(/gem 'active_model_serializers'/, content) - - assert_no_match(/gem 'web-console'/, content) end assert_file "config/application.rb" do |content| -- cgit v1.2.3 From cdb7a8477ff19f8ed6f549cedc901bd5934a61e8 Mon Sep 17 00:00:00 2001 From: Jorge Bejar Date: Wed, 9 Dec 2015 14:18:13 -0300 Subject: Avoid calling AD::MimeNegotiation#format_from_path_extension method twice --- actionpack/lib/action_dispatch/http/mime_negotiation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index 004713ec1a..0152c17ed4 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -67,8 +67,8 @@ module ActionDispatch v = if params_readable Array(Mime[parameters[:format]]) - elsif format_from_path_extension - [Mime[format_from_path_extension]] + elsif format = format_from_path_extension + Array(Mime[format]) elsif use_accept_header && valid_accept_header accepts elsif xhr? -- cgit v1.2.3