application controller: fix bad file extension errors.

Fix requests with bad file extensions not always returning errors correctly:

* https://danbooru.donmai.us/posts.jpg
* https://danbooru.donmai.us/posts.blah
* https://danbooru.donmai.us/posts/bad.jpg
* https://danbooru.donmai.us/posts/bad.blah
This commit is contained in:
evazion
2019-08-08 22:16:39 -05:00
parent 8d706f4fd7
commit 35dfc704bc
3 changed files with 62 additions and 42 deletions

View File

@@ -0,0 +1,39 @@
require "test_helper"
class ApplicationControllerTest < ActionDispatch::IntegrationTest
context "The application controller" do
should "return 406 Not Acceptable for a bad file extension" do
get posts_path, params: { format: :jpg }
assert_response 406
get posts_path, params: { format: :blah }
assert_response 406
end
context "on a RecordNotFound error" do
should "return 404 Not Found even with a bad file extension" do
get post_path("bad.json")
assert_response 404
get post_path("bad.jpg")
assert_response 404
get post_path("bad.blah")
assert_response 404
end
end
context "on a PaginationError" do
should "return 410 Gone even with a bad file extension" do
get posts_path, params: { page: 999999999 }, as: :json
assert_response 410
get posts_path, params: { page: 999999999 }, as: :jpg
assert_response 410
get posts_path, params: { page: 999999999 }, as: :blah
assert_response 410
end
end
end
end