From 1be3277a7b7857bf5f72185daf3c01f2e23bf534 Mon Sep 17 00:00:00 2001 From: Haroon Ahmed Date: Sun, 16 May 2021 21:18:16 +0100 Subject: [PATCH] Fix invalid statement template compile error --- .../rescues/invalid_statement.text.erb | 1 + .../application/middleware/exceptions_test.rb | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb index 040573e32f0e4..d30facd3123c5 100644 --- a/actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb @@ -6,6 +6,7 @@ <%= @exception.message %> <% if defined?(ActiveStorage) && @exception.message.match?(%r{#{ActiveStorage::Blob.table_name}|#{ActiveStorage::Attachment.table_name}}) %> To resolve this issue run: bin/rails active_storage:install +<% end %> <% if defined?(ActionMailbox) && @exception.message.match?(%r{#{ActionMailbox::InboundEmail.table_name}}) %> To resolve this issue run: bin/rails action_mailbox:install <% end %> diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index 098f06254cd46..876646fefa3ec 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -171,5 +171,28 @@ def index assert_equal 400, last_response.status assert_match "Invalid query parameters", last_response.body end + + test "displays statement invalid template correctly" do + controller :foo, <<-RUBY + class FooController < ActionController::Base + def index + raise ActiveRecord::StatementInvalid + end + end + RUBY + app.config.action_dispatch.show_exceptions = true + app.config.consider_all_requests_local = true + app.config.action_dispatch.ignore_accept_header = false + + get "/foo" + assert_equal 500, last_response.status + assert_match "Action Controller: Exception caught", last_response.body + assert_match "ActiveRecord::StatementInvalid", last_response.body + + get "/foo", {}, { "HTTP_ACCEPT" => "text/plain", "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" } + assert_equal 500, last_response.status + assert_equal "text/plain", last_response.media_type + assert_match "ActiveRecord::StatementInvalid", last_response.body + end end end