Validate utm_* inclusion and add Bluesky to UTM_SOURCES#37
Merged
Conversation
Until now the UTM_SOURCES, UTM_MEDIUMS, UTM_CAMPAIGN and UTM_CONTENT constants were only dropdown options in the share form. The API and any direct callers could store arbitrary strings. This change: - Adds Bluesky to UTM_SOURCES so it shows up in the dropdown and is accepted by the new JSON create endpoint - Adds inclusion validations for utm_source, utm_medium, utm_campaign, and utm_content scoped to :create. Existing rows are left untouched on update so legacy values do not block future edits - Updates the factory and api_links_spec setups to use values that are in the whitelist, so the validations do not break those tests - Adds Share model specs covering each new validation, Bluesky as a valid utm_source, and the :create-only contract Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The "update with legacy utm_source" spec calls `create(:share)`, which persists a Link. Link has an `after_create` callback that calls `fetch_social_media_snippets`, which talks to OpenAI. In CI there is no OpenAI access token so the test fails with `OpenAI::ConfigurationError`. Match the pattern already used in `shares_controller_spec.rb` and `api_links_spec.rb`: stub `fetch_social_media_snippets` to return an empty array in a top-level `before` block so the callback is a no-op across every example in the file. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
BlueskytoShare::UTM_SOURCESso it appears in the dropdown and is accepted by the JSON create endpointutm_source,utm_medium,utm_campaign, andutm_content, scoped to:createutm_source, and the:create-only contractWhy
The UTM constants existed but were only dropdown options. The new JSON API (and the original HTML form) would happily accept any string. This PR makes the constants the source of truth for new shares so typos and out-of-list values are caught at creation time.
on: :createkeeps the new validations strict for new records while leaving existing rows untouched. The controller'sassign_shortened_urlflow does anupdateimmediately after create, which won't be re-validated.Test plan
bundle exec rspec spec/models/share_spec.rbbundle exec rspec spec/requests/api_links_spec.rbbundle exec rspec spec/controllers/shares_controller_spec.rb🤖 Generated with Claude Code