Understanding Rails · On the job
Ticket 001: Notes vanish sometimes
A ticket as it arrived in Switchback, a small Rails app. Before you fix anything, make it ready to work: ask the reporter what you need to know, write what done looks like, then compare with how a senior refined it.
Helps to know first
1. The ticket, as it arrived
From: The product manager, forwarding the support inbox
Can someone look at this? A few people have said something like it.
I posted a long note about the washout on Granite Switchbacks last night. It said "Note posted," but when I looked for it this morning it wasn't there. This is the second time. Are you deleting notes?
Dana, a regular hiker
2. Ask the reporter
Dana reported it. She's a hiker, not an engineer. Ask what you need to know; each question shows the answer. Some answers narrow the cause, and some don't.
Which browser were you using?
Dana: Chrome, on my laptop. Same as always.
Did you see an error when you posted?
Dana: No error. It said "Note posted." at the top, like it always does. That's why I thought it went through.
Which trail was the note about?
Dana: Granite Switchbacks, last night. The first one that went missing was about Eagle Ridge Loop, a couple of weeks back.
Did you try refreshing the page?
Dana: Lots of times, last night and again this morning. Still not there.
Were the notes that vanished long?
Dana: Yes, both were long. I write a lot, especially after a washout. Last night's was the whole crossing, start to finish.
Are you sure you were signed in?
Dana: Yes. My name was up in the corner, and my other notes are all there under it.
Were you on Wi-Fi, or on a phone signal?
Dana: Wi-Fi, at home. There's no signal up on the trail, so I always post once I'm back.
Do your short notes stay?
Dana: Yes, those are all still there. Quick ones like "Mud past the creek, wear boots" never go anywhere.
Did anyone else see the note?
Dana: No. My hiking group looked for it this morning, and nobody ever saw it.
Write the ticket
What must be true when this is done? And what will this ticket leave alone? It stays in your browser.
3. Compare
Compare with the refined ticket
The refined ticket
A note over 500 characters is lost without an error
Story: As a hiker who writes long trail notes, I want to be told when my note is too long, and keep what I wrote, so I don't lose a long report.
How to reproduce: Sign in, open any trail, and post a note longer than 500 characters. The page says "Note posted.", and the note isn't in the list. Nothing deletes notes: this one was never saved.
Cause: NotesController#create ignores whether save worked and always redirects with "Note posted."
What you wrote
Acceptance criteria
Out of scope
What the refined ticket says
Acceptance criteria
- A note over 500 characters isn't saved, and the hiker is told why.
- The hiker's words stay in the form, so nothing they wrote is lost.
- The page answers 422 Unprocessable Content, so Turbo shows the form again.
- "Note posted." shows only when a note was saved.
- A note of 500 characters still posts as before.
Criterion 3 doesn't come from the reporter. It's how Turbo works: after a form posts, Turbo draws the page it gets back only when the status says the form failed (422) or when it's a redirect. A plain 200 leaves the old page in place, so the hiker sees nothing happen. The form posts as HTML, so the answer is an HTML page, not a Turbo Stream.
Out of scope
- Changing the 500-character limit.
- Showing the limit, or a character counter, before the hiker hits it. A good next ticket.
- Getting back notes already lost. They were never saved, so there's nothing to restore.
What a senior asked first, and why
- Did you see an error when you posted? It said "Note posted." and nothing was kept. So the app told Dana something that wasn't true. That points at the code that answers her post, not at something deleting notes later.
- Were the notes that vanished long? Her complaint says "a long note." When only some posts fail, ask what is different about them. Length is the first thing that stands out.
- Do your short notes stay? This one says it's the length. Short notes stay and long ones go, so look for a limit on length: a validation.
- Did anyone else see the note? Nobody ever saw it, so it was most likely never saved. That rules out deleting, which is what Dana feared.
The browser, the trail, refreshing, signing in and Wi-Fi are fair questions. Dana answered each one honestly, but none of them narrows the cause. A senior asks them only if the first questions don't crack it.
Work it
Now fix it, in your own copy of Switchback.
The branch is 001-notes-vanish.
- Fork Switchback on GitHub, then clone your fork. Use mise, rbenv or asdf to get the Ruby in .ruby-version.
- Set it up. Sign in as [email protected] with the password switchback-hiker.
bin/setup
- Make a branch named for the ticket. The review finds the ticket by the number the branch starts with.
git switch -c 001-notes-vanish
- Write a test that fails because of the bug. Then fix the bug, and commit with a message that says why.
- In your fork on GitHub, open the Actions tab and turn workflows on. GitHub leaves them off in a new fork.
- Push the branch and open a pull request inside your fork, from 001-notes-vanish into your fork's master. GitHub suggests the original Switchback as the base: change the base repository to your fork, or the review can't comment. With the GitHub CLI, run gh repo set-default with your fork's name once first.
git push -u origin 001-notes-vanish
- A GitHub Action runs the ticket's acceptance tests on your pull request and comments with what passes, what fails and what crashed, and once all five pass, the questions a reviewer would still ask. Push again and the same comment updates.
4. Watch a senior work it
Once you've tried it, see how a senior refines and fixes the same ticket, dead ends and all.
Watch episode 101