Skip to content

Fix nil pointer bugs in version lookups and permissions#27

Merged
dadachi merged 1 commit intomainfrom
fix/nil-pointer-version-lookups-and-permissions
Mar 16, 2026
Merged

Fix nil pointer bugs in version lookups and permissions#27
dadachi merged 1 commit intomainfrom
fix/nil-pointer-version-lookups-and-permissions

Conversation

@dadachi
Copy link
Copy Markdown
Contributor

@dadachi dadachi commented Mar 16, 2026

Summary

  • Fix AppVersion.current_version, PrivacyVersion.current_version, TermsVersion.current_version.first.version crashes with NoMethodError when no matching record exists. Use &.version for nil safety.
  • Fix AppVersion.current_version scope chaining — AppVersion.current started a new query chain, losing any previously chained scopes (e.g. forced_update). Changed to current (relative) so chained scopes are preserved.
  • Simplify AccountsShopkeeper#permissions — replace 12-line if/elsif chain with active_roles.first + find_by! for clearer code and better error on missing role data.

Test plan

  • All 405 tests pass (803 assertions, 0 failures)
  • New tests for nil-safety: current_version returns nil when no records match
  • New test for scope chaining: unforced_update.current_version respects chained scope
  • Existing permission tests (6 roles) pass with refactored permissions method
  • RuboCop clean, Brakeman clean

🤖 Generated with Claude Code

- AppVersion/PrivacyVersion/TermsVersion: .first.version crashes with
  NoMethodError when no matching record exists. Use safe navigation
  operator (&.) to return nil instead.
- AppVersion: use `current` instead of `AppVersion.current` so chained
  scopes (e.g. forced_update.current_version) are preserved.
- AccountsShopkeeper#permissions: simplify role-to-permissions lookup
  using active_roles.first with find_by! for clearer error on missing
  role data.
- Add tests for nil-safety edge cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dadachi dadachi merged commit c1dce48 into main Mar 16, 2026
3 checks passed
@dadachi dadachi deleted the fix/nil-pointer-version-lookups-and-permissions branch March 16, 2026 08:11
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