Skip to content

Commit

Permalink
Merge pull request #54 from ninoseki/add-redirection
Browse files Browse the repository at this point in the history
feat: add redirection for 404 errors
  • Loading branch information
ninoseki committed Jun 18, 2019
2 parents 4a20e77 + d9401e6 commit 19e5a06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/ayashige/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ class Application < Sinatra::Base
[item[:updated_on], item[:domain]]
end.to_json
end

not_found do
redirect "/"
end
end
end
12 changes: 10 additions & 2 deletions spec/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def app
end

describe "GET /" do
it "should return 200 OK" do
it "returns 200 OK" do
get "/"
expect(last_response).to be_ok
end
Expand All @@ -25,7 +25,7 @@ def app
)
end

it "should return 200 OK and JSON response" do
it "returns 200 OK and JSON response" do
get "/feed"
expect(last_response).to be_ok
array = JSON.parse(last_response.body.to_s)
Expand All @@ -44,4 +44,12 @@ def app
expect(last["source"]).to be_a(String)
end
end

describe "GET /404" do
it "redirects to the root" do
get "/404"
expect(last_response.status).to eq(302)
expect(last_response.headers["Location"]).to eq("http://example.org/")
end
end
end

0 comments on commit 19e5a06

Please sign in to comment.