From 772a151cfb855020c03a7c7d725f286f77c4f3dc Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 4 Jun 2024 15:08:54 +0200 Subject: [PATCH] fix(RoutingConstraints): Allow Turbo Stream requests `rails-turbo` [registers a new request format](https://github.com/hotwired/turbo-rails/blob/e376852bfb273f69f4ebb54cf516b99fcbaa7acb/lib/turbo/engine.rb#L82-L89) text/vnd.turbo-stream.html which is used whenever Turbo redirects. In order to handle those requests from - for example the messages controller - we need to allow this mime type to route into Alchemy as well. --- lib/alchemy/routing_constraints.rb | 2 +- spec/routing/routing_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/alchemy/routing_constraints.rb b/lib/alchemy/routing_constraints.rb index 9de3fdf521..ffe6b9681b 100644 --- a/lib/alchemy/routing_constraints.rb +++ b/lib/alchemy/routing_constraints.rb @@ -27,7 +27,7 @@ def matches?(request) # because it could be a legacy route that needs to be redirected. # def handable_format? - @request.format.symbol.nil? || (@request.format.symbol == :html) + @request.format.symbol.nil? || @request.format.html? end # We don't want to handle the Rails info routes. diff --git a/spec/routing/routing_spec.rb b/spec/routing/routing_spec.rb index 36c6f1aac8..47aebbfca0 100644 --- a/spec/routing/routing_spec.rb +++ b/spec/routing/routing_spec.rb @@ -194,6 +194,14 @@ end end + describe "Turbo stream requests" do + it do + expect({ + get: "/contact/thanks.turbo_stream" + }).to be_routable + end + end + context "for admin interface" do context "default" do it "should route to admin dashboard" do