This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the testing category.
Last Updated: 2024-11-21
I modified the findByUuid
scope (something that generates SQL) on a website to do
eager loading (load associated records to avoid N+1 issues).
When I tested it against my (single) seed record, the correct $advisor
showed up in the browser, the one matching the UUID in my URL:
serp/5d13819b-ae70-4254-9baf-9a1ac66fa8da?
However, later a colleague played with the code and noticed that no matter what
UUID he gave it, the same $advisor
page showed.
Behind the scenes, it turned out that I had misunderstood the eager-loading API and was always returning the first entity in the database
You don't get much info testing finder logic against a single record. For that you need to test against two different ones and ensure both display correctly.