search: fix search timeout error page not appearing.

Bug: when a search timed out we got the generic failbooru page instead
of the search timeout error page.

Cause: when rendering the <link rel="next"> / <link rel="prev"> tags in
the header, we may need to evaluate the search to determine the next or
previous page, but if the searches times out then this fails, which
caused Rails to throw a ActionView::Template::Error because an exception
was thrown while rendering the template.

Likewise, rendering the attributes for the <body> tag could fail with an
ActionView::Template::Error because the call to `current_item.present?`
forced evaluation of the search.
This commit is contained in:
evazion
2020-07-03 12:42:04 -05:00
parent e822d5f16e
commit f97c62c71d
6 changed files with 49 additions and 19 deletions

View File

@@ -380,6 +380,28 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
assert_select "title", text: "1girl Art | Safebooru"
end
end
context "for a search that times out" do
context "during numbered pagination" do
should "show the search timeout error page" do
Post::const_get(:ActiveRecord_Relation).any_instance.stubs(:records).raises(ActiveRecord::QueryCanceled)
get posts_path(page: "1")
assert_response 500
assert_select "h1", text: "Search Timeout"
end
end
context "during sequential pagination" do
should "show the search timeout error page" do
Post::const_get(:ActiveRecord_Relation).any_instance.stubs(:records).raises(ActiveRecord::QueryCanceled)
get posts_path(page: "a0")
assert_response 500
assert_select "h1", text: "Search Timeout"
end
end
end
end
context "show_seq action" do