Use Turbo Streams for token create/destroy and add system tests#41
Use Turbo Streams for token create/destroy and add system tests#41HamptonMakes merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b49bcfd3ce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <%= render "form" %> | ||
| <% end %> | ||
|
|
||
| <%= turbo_stream.prepend "tokens-list" do %> |
There was a problem hiding this comment.
Replace empty-state card instead of prepending missing target
When a user creates their first token, this stream prepends into tokens-list, but index.html.erb only renders <tbody id="tokens-list"> when @api_tokens.any? is true. In the empty-state path there is no target element, so Turbo ignores the prepend and the new token row does not appear until a full reload, which makes the create flow look broken for new users.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed! Removed the empty-state conditional entirely — the table always renders (with an empty tbody). The turbo_stream prepend into #tokens-list now works regardless of whether it's the first token or not.
Also added a dedicated system test for the empty-state flow to keep this covered.
The tokens controller was returning a redirect after create, which Turbo Drive rejected with 'Form responses must redirect to another location' because the redirect target matched the form action URL. The token reveal section and flash never appeared — the form just stayed stuck in a busy state. Fix by responding with Turbo Streams for both create and destroy actions: - create: updates the token reveal, resets the form, prepends the new row - destroy: replaces the row in-place with revoked state Extract shared partials (_token_row, _token_reveal, _form) so there is zero HTML duplication between the index view and turbo_stream templates. Add system tests covering both create and revoke flows to catch Turbo integration issues that request specs miss. Update existing request specs to match the new redirect behavior. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019cd872-3abe-7556-8927-9966fe044b6c
b49bcfd to
420472e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
The tokens page form submission was broken with Turbo Drive. After creating a token, Turbo rejected the response with
Form responses must redirect to another locationbecause the redirect target matched the form action URL. The token reveal (with the raw token value) never appeared — the form stayed stuck in a loading state.Fix
Respond with Turbo Streams for both
createanddestroyactions instead of redirecting:Extracted shared partials (
_token_row,_token_reveal,_form) — zero HTML duplication between the index view and turbo_stream templates. HTML fallback preserved for non-Turbo clients.Also removed the empty-state conditional so the table always renders — this ensures the turbo_stream prepend works even when creating the first token.
System tests
Added Capybara + headless Chrome system tests covering:
Updated existing request specs to match redirect/auth behavior.
Test results
All 389 specs passing.