-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turbo compatibility: return status unprocessable_entity #1880
Conversation
Thank you for that PR @jankeesvw! Would you be able to add spec examples for both |
I tried adding a spec, but my expectation is failing. Not sure why, because it works in practice. @pablobm do you have some time to help me? This is my current .patch with a failing spec: diff --git a/spec/controllers/admin/log_entries_controller_spec.rb b/spec/controllers/admin/log_entries_controller_spec.rb
index 729fbef..162eefb 100644
--- a/spec/controllers/admin/log_entries_controller_spec.rb
+++ b/spec/controllers/admin/log_entries_controller_spec.rb
@@ -135,6 +135,7 @@ describe Admin::LogEntriesController, type: :controller do
expect(page).to be_instance_of(Administrate::Page::Form)
expect(page.resource).to eq(log_entry)
expect(page.resource.action).to eq(new_action)
+ expect(response).to have_http_status(:unprocessable_entity)
end
end
end |
Uh, you are right. For some strange reason, it tries to render the template for |
Are you willing to merge before we improved the tests, now people won't see errors when using Turbo. |
I looked into this today. After some head scratching, I realised what was going on. This controller test doesn't actually run Rails's test rendering code. Instead it captures the call to The capture is done with To compound the problem, I don't think there is a standard way of achieving this. It's possible to test For now, I'm going to accept this MR, as it fixes the problem at hand and its intent I think is obvious enough. Meanwhile I'll file a separate issue to see how we can address this problem properly and provide better tests. |
Thanks for looking into this! |
@pablobm can you make a new gem release with this change, would be great to get this out. |
We are using Administrate quite a lot in our project, and a few weeks ago we upgraded from Turbolinks to Turbo. I noticed that our validations weren't triggering anymore in Administrate.
Then I noticed that the Administrate base class doesn't return the right status code when the record can't be saved.
From the Hotwire docs:
This pull request returns the correct status codes when saving a record.