-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do no raise exceptions for JSON requests
This PR will eliminate application errors being raised when JSON requests come through. Fixes #763
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe "Errors", type: :request do | ||
describe "unmatched routes" do | ||
before do | ||
get "/nonexistent_resource" | ||
end | ||
|
||
it "has an http status of 404" do | ||
expect(response).to have_http_status(:not_found) | ||
end | ||
|
||
it "redirects to the custom not_found error page" do | ||
expect(response.body).to include("The page you requested doesn't exist") | ||
end | ||
end | ||
|
||
# Blacklight::Exceptions::RecordNotFound | ||
describe "record not found" do | ||
it "renders a 404 page" do | ||
params = { id: "unknown_work" } | ||
get "/catalog/#{params[:id]}" | ||
|
||
expect(response.status).to eq(404) | ||
expect(response.body).to include("The page you requested doesn't exist") | ||
end | ||
end | ||
|
||
describe "json requests for the main page" do | ||
it "returns a 404 status code response" do | ||
get "/", params: { format: :json } | ||
expect(response.status).to eq 404 | ||
end | ||
end | ||
end |