This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the architecture category.
Last Updated: 2024-11-23
I had a toy web app I built without tests initially. This toy app included Google Analytics as follows:
<!--application.html.erb -->
<%= render 'layouts/google_tracking' %>
I knew at the time that this would need modification when I would add tests later (specifically I would want a separate GA tracker ID for the test environment). So I added a comment:
<!--TODO: When testing, add a separate tracker ID-->
<%= render 'layouts/google_tracking' %>
Nine months later I added tests. After adding these tests, I realized I'd made a mess in my production Google Analytics Account (e.g. hits to URLs that don't exist; conversions that never happened). I had missed the comment.
I should have set myself a reminder that cannot be missed as follows:
<!--application.html.erb -->
<% raise "needs separate GA id" if Rails.env.test? %>
<%= render 'layouts/google_tracking' %>