Repository navigation
Validate time zones against the Rails time zone list - #155
Merged
Merged
Conversation
Shop and Shopkeeper accepted any time_zone string. Nothing in this API looks the zone up, so a bogus value was stored silently (200) rather than crashing, but the apps would then show or send a zone their pickers do not know. Both models now require a name from ActiveSupport::TimeZone.all, so unknown zones (and IANA ids such as "Asia/Tokyo", which TimeZone[] would resolve but the apps never send) get 422. A guard test pins ActiveSupport::TimeZone.all (name and label) to test/fixtures/files/rails_time_zones.tsv, the list the iOS and Android apps embed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YDK5huvuRECyVrsQEdTN9q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YDK5huvuRECyVrsQEdTN9q
A stored zone that is not a Rails name (from an app generated before this check) would otherwise block every later save of that record, even one that does not touch the zone. Matches myturntagapi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YDK5huvuRECyVrsQEdTN9q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Shop#time_zoneandShopkeeper#time_zoneaccepted any string. In the sibling app myturntagapi an unknown zone reachedActiveSupport::TimeZone[time_zone].somethingand returned 500. This repo has no such lookup (grep time_zone app/only finds permits, serializers, madmin andAccount#create_default_shop!copying the owner's zone), so here a bogus value was not a crash: it was stored and returned with 200. It is still invalid data the iOS/Android time zone pickers cannot show, and generated apps that add a lookup would 500, so this adds the validation anyway.validates :time_zone, inclusion: {in: ->(_) { ActiveSupport::TimeZone.all.map(&:name) }}onShopandShopkeeper(same style as the existinglocalevalidation).time_zone).ActiveSupport::TimeZone["Asia/Tokyo"]does resolve (to a zone namedAsia/Tokyo), but it is not inActiveSupport::TimeZone.all, and the apps send Rails names (Tokyo).test/config/time_zones_test.rb:ActiveSupport::TimeZone.all.map { |z| [z.name, z.to_s] }must equaltest/fixtures/files/rails_time_zones.tsv(152 lines, activesupport 8.1.4). The iOS (TimeZoneData.swift/TimeZoneDataTest) and Android (TimeZones.kt/TimeZonesTest) apps embed the same list; when the test fails after a Rails or tzdata upgrade, update the fixture and both apps.Tests (red, then green)
New tests failed before the validation (5 failures, all "accepted"/200 instead of rejected/422; no 500):
ShopTest/ShopkeeperTest: everyActiveSupport::TimeZone.allname accepted;"Bogus","","Asia/Tokyo"rejectedShopsControllerTest:PATCHwithtime_zone: "Bogus"returns 422 and leaves the zone unchangedRegistrationsControllerTest:PATCH /shopkeeper_authand sign-up with"Bogus"return 422 (sign-up creates no shopkeeper, account or shop)All pass with the validation. The guard test was broken deliberately (
Tokyolabel edited toTokioin the fixture) and failed, then restored.Existing data: fixtures and seeds use
Tokyo,Osakaand the schema defaultLondon, all valid; the dev database has 0 invalid shops/shopkeepers. This repo is a template with no production data. A generated app with existing invalid rows would see saves of those records fail until the zone is fixed (andAccount#create_default_shop!would raise for an owner with an invalid zone), so such apps should clean up data first.bin/cipasses locally (rubocop, erb_lint, bundler-audit, brakeman, 622 tests, seeds).🤖 Generated with Claude Code
https://claude.ai/code/session_01YDK5huvuRECyVrsQEdTN9q