Skip to content

Validate utm_* inclusion and add Bluesky to UTM_SOURCES#37

Merged
etagwerker merged 2 commits into
mainfrom
feat/share-utm-inclusion-validations
May 17, 2026
Merged

Validate utm_* inclusion and add Bluesky to UTM_SOURCES#37
etagwerker merged 2 commits into
mainfrom
feat/share-utm-inclusion-validations

Conversation

@etagwerker
Copy link
Copy Markdown
Member

@etagwerker etagwerker commented May 16, 2026

Summary

  • Add Bluesky to Share::UTM_SOURCES so it appears in the dropdown and is accepted by the JSON create endpoint
  • Add inclusion validations for utm_source, utm_medium, utm_campaign, and utm_content, scoped to :create
  • Update the factory and existing request-spec setups to use values that are in the whitelist
  • Add Share model specs covering each new validation, Bluesky as a valid utm_source, and the :create-only contract

Why

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: :create keeps the new validations strict for new records while leaving existing rows untouched. The controller's assign_shortened_url flow does an update immediately after create, which won't be re-validated.

Test plan

  • bundle exec rspec spec/models/share_spec.rb
  • bundle exec rspec spec/requests/api_links_spec.rb
  • bundle exec rspec spec/controllers/shares_controller_spec.rb
  • CI green

🤖 Generated with Claude Code

etagwerker and others added 2 commits May 16, 2026 16:06
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>
@etagwerker etagwerker merged commit df96778 into main May 17, 2026
1 check passed
@etagwerker etagwerker deleted the feat/share-utm-inclusion-validations branch May 17, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant