]> cat aescling's git repositories - mastodon.git/commitdiff
Ignore implied formats for catch all route requests (#1340)
authorMatt Jankowski <mjankowski@thoughtbot.com>
Sun, 9 Apr 2017 12:39:41 +0000 (08:39 -0400)
committerEugen <eugen@zeonfederated.com>
Sun, 9 Apr 2017 12:39:41 +0000 (14:39 +0200)
A request to `/test` would show the custom 404 page, but a request to
`/test.test` would return a 404 with an empty body.

This change ignores the format on incoming catch all route requests, so that the
html 404 page is returned on these requests.

config/routes.rb
spec/requests/catch_all_route_request_spec.rb [new file with mode: 0644]

index 9cbecf07797b95f3211d6f6dc83f89823f1ded9e..66b0ed8303adafb37b9ee660e4448dc6facfecd2 100644 (file)
@@ -194,5 +194,8 @@ Rails.application.routes.draw do
 
   root 'home#index'
 
-  match '*unmatched_route', via: :all, to: 'application#raise_not_found'
+  match '*unmatched_route',
+    via: :all,
+    to: 'application#raise_not_found',
+    format: false
 end
diff --git a/spec/requests/catch_all_route_request_spec.rb b/spec/requests/catch_all_route_request_spec.rb
new file mode 100644 (file)
index 0000000..22ce1cf
--- /dev/null
@@ -0,0 +1,21 @@
+require "rails_helper"
+
+describe "The catch all route" do
+  describe "with a simple value" do
+    it "returns a 404 page as html" do
+      get "/test"
+
+      expect(response.status).to eq 404
+      expect(response.content_type).to eq "text/html"
+    end
+  end
+
+  describe "with an implied format" do
+    it "returns a 404 page as html" do
+      get "/test.test"
+
+      expect(response.status).to eq 404
+      expect(response.content_type).to eq "text/html"
+    end
+  end
+end