Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid statement template compile error #42244

Merged
merged 1 commit into from Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 %>
Expand Down
23 changes: 23 additions & 0 deletions railties/test/application/middleware/exceptions_test.rb
Expand Up @@ -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 "<title>Action Controller: Exception caught</title>", last_response.body
assert_match "ActiveRecord::StatementInvalid", last_response.body

get "/foo", {}, { "HTTP_ACCEPT" => "text/plain", "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" }
Copy link
Contributor Author

@hahmed hahmed Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, but I was expecting this to work:

get "/foo", headers: { "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