Closed excid3 closed 2 years ago
I think an integration test for this is overkill. It is true that we only need this change because of hotwire but I don't to exercise hotwire to make sure the response status we are sending in a 303 not a 302. We are probably better served with an unit test.
Also, I don't think we should change the behavior for all the applications. We should be returning 302 by default to not break other people tests, but if configured, we should return 303.
Closes #227
@rafaelfranca I was thinking the same thing. You got it. 👍
This has been refactored to a config variable and keeps the default of 302.
We will probably need Devise to configure the 303 status to be Hotwire compatible out of the box if it doesn't change in Responders. That was the main reason why I wanted to make these changes. It's frustrating that Devise doesn't work with Rails 7 by default.
We will probably need Devise to configure the 303 status to be Hotwire compatible out of the box if it doesn't change in Responders
I think that is fine. I didn't look on what is require to make devise work, but maybe even that needs to be configurable otherwise will be a breaking change.
This PR adds system tests for Responders with a dummy Rails app that's using Hotwire.
Hotwire currently handles non-GET requests slightly differently if you submit a form with a
_method
or if you have a link usingdata-turbo-method
. This adds a test for both of those cases to confirm that the redirect is handled correctly using a 303 to safely handle both cases.With a 302, the
data-turbo-method
will actually forward the request method to the redirect URL. This results in aDELETE /posts/1
redirecting toDELETE /posts
. A 303 will change the redirect to aGET /posts
correctly.Why is this necessary?
button_to
will generate a form withmethod="post"
and_method="delete"
as a hidden field. It sends a POST request to Rails, which then gets handled like aDELETE
.data-turbo-method="delete"
actually makes aDELETE
request. https://github.com/hotwired/turbo/blob/8221c1e5f2021c41c3ecada0dde55bae9ee18380/src/core/session.ts#L143-L147Related: heartcombo/devise#5410