Skip to content

Add jscpd duplication check and merge duplicated signup spec - #1454

Open
diego-suarez wants to merge 1 commit into
mainfrom
add-jscpd-check
Open

diego-suarez wants to merge 1 commit into
mainfrom
add-jscpd-check

Conversation

@diego-suarez

@diego-suarez diego-suarez commented Oct 14, 2026 •

Copy link
Copy Markdown

Board:

  • N/A — internal cleanup / tooling, no ticket.

Description:

  • Running jscpd . over the repo found 17 clones (7.2% duplicated lines). Most are expected: doc/openapi.yaml is generated by rspec-openapi, public/*.html are Rails' self-contained error pages, and the GitHub Actions setup steps have to repeat per job.
  • The one real problem: spec/requests/api/v1/users/create_spec.rb and spec/requests/api/v1/registrations/create_spec.rb both tested the same endpoint (post user_registration_path → POST /api/v1/users). The registrations spec was also mislabelled POST api/v1/users/sign_up, a route that doesn't exist.
  • Merged both into spec/requests/api/v1/registrations/create_spec.rb, which matches API::V1::RegistrationsController like the sessions/ and passwords/ specs do. The more complete users/ version is the base, plus the two assertions that only the registrations spec had (valid client/access token, password-mismatch error message).
  • Added jscpd to the Linters CI job so new copy/paste gets caught. .jscpd.json ignores generated/static files and fails above 1% duplicated lines. Duplication after this PR is 0.65%.

Notes:

  • The spec couldn't be run locally (Ruby 4.0.5 not installed on the author's machine), so CI is the first run of the merged spec and RuboCop on it.
  • The OpenAPI docs aren't affected: the operation summary comes from the controller action, not the spec file or describe text.
  • knapsack_rspec_report.json timing entry renamed to the new spec path. It's regenerated by the Update Knapsack Report workflow anyway.
  • The 1% threshold leaves about 30 lines of headroom in the template. Projects built from it will grow, which makes the percentage more lenient. Raise it in .jscpd.json if it turns out to be noisy.
  • Remaining reported clones are intentional: CI setup steps across jobs, two Pundit policy specs with opposite expectations, and the user JSON assertions shared by the sessions and registrations specs.

Tasks:

  • Merge users/create_spec.rb into registrations/create_spec.rb and delete the duplicate
  • Add .jscpd.json (threshold 1%, ignore doc/openapi.yaml, public/*.html, knapsack_rspec_report.json)
  • Add Check for duplicated code step to the Linters job (npx --yes jscpd@5.4.1 .)
  • Document npx jscpd . in CLAUDE.md
  • Merged spec passes in CI

Risk:

  • Low — test-only and CI-only changes. The new CI step can fail PRs that add more than about 1% duplicated lines, which is intended.

Preview:

$ npx jscpd .
...
│ Total:     │ 161            │ 8936        │ 48167        │ 6            │ 58 (0.65%)       │ 467 (0.97%)       │
Found 6 clones.

$ npx jscpd . --threshold 0.1   # sanity check that the gate fails
ERROR: jscpd found too many duplicates (0.6%) over threshold (0.1%)
$ echo $?
1

🤖 Generated with Claude Code

spec/requests/api/v1/users/create_spec.rb and
spec/requests/api/v1/registrations/create_spec.rb both exercised
POST /api/v1/users (user_registration_path). Merge them into the
registrations spec, which matches the controller, and add jscpd to the
Linters CI job so new copy/paste is caught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the api_docs API Documentation label Oct 14, 2026
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api_docs API Documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant