Skip to content

Strengthen Event and InspectorCompany specs (mutation-driven)#507

Merged
stefan-burke merged 1 commit into
mainfrom
claude/mutant-gem-testing-ll69r9
Jul 3, 2026
Merged

Strengthen Event and InspectorCompany specs (mutation-driven)#507
stefan-burke merged 1 commit into
mainfrom
claude/mutant-gem-testing-ll69r9

Conversation

@stefan-burke

Copy link
Copy Markdown
Member

Summary

Follow-up to #506 (which added the mutant mutation-testing engine). That run surfaced real gaps in two core models — behaviour that no test asserted on, so mutating the source didn't fail anything. This PR adds tests that close those gaps.

Changes

spec/models/event_spec.rb

  • .log — asserts every attribute (user, action, resource_type from resource.class.name, resource_id, details, changed_data, metadata) is mapped onto the created record, plus the nil defaults.
  • .log_system_event — asserts the system resource type and nil resource id.
  • #description — asserts details is used when present, and the generated fallback ("<email> <action> <type> <id>") otherwise.
  • #triggered_by? — true for the triggering user, false for another.
  • #resource_object — adds the positive case (returns the resource when it still exists).

spec/models/inspector_company_spec.rb

  • #pass_rate — asserts an actual computed, two-decimal-rounded percentage (previously only the zero-inspection case was tested).
  • #company_statistics — asserts the passed/failed/total counts and active_since, including the zero-of-a-status case.
  • #recent_inspections — asserts most-recent-first ordering, the limit, and the default argument.
  • .form_schema — asserts the notes field is included for admins and excluded for non-admins.
  • #logo_url — asserts it returns the logo when one is attached.

Mutation coverage impact

Subject Before After
Event 66.94% 95.87%
InspectorCompany 89.60% 96.80%

Remaining survivors are equivalent mutants (e.g. sendpublic_send, redundant guards masked by rescue, returnnil on a presence-validated field) — semantically identical code that no test can distinguish, so they're left as-is rather than chased with contrived assertions.

Only test files change; no production code is touched.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CLseCgvqE2jdan8K57ENJn


Generated by Claude Code

Mutation testing (mutant) surfaced untested behaviour in these core
models. Add tests that pin down the previously-unasserted logic:

Event: assert Event.log / .log_system_event map each attribute onto the
created record, that #description picks details over the generated
fallback, that #triggered_by? compares users, and that #resource_object
returns the resource when it exists.

InspectorCompany: assert #pass_rate computes and rounds an actual
percentage, #company_statistics counts passed/failed (including zero
cases), #recent_inspections orders and limits, .form_schema hides notes
from non-admins, and #logo_url returns an attached logo.

Raises mutation coverage from 66.9% -> 95.9% (Event) and
89.6% -> 96.8% (InspectorCompany); remaining survivors are equivalent
mutants.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CLseCgvqE2jdan8K57ENJn
@stefan-burke
stefan-burke added this pull request to the merge queue Jul 3, 2026
Merged via the queue into main with commit c0cd30e Jul 3, 2026
17 checks passed
@stefan-burke
stefan-burke deleted the claude/mutant-gem-testing-ll69r9 branch July 3, 2026 15:21
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.

2 participants