Strengthen Event and InspectorCompany specs (mutation-driven)#507
Merged
Conversation
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
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
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_typefromresource.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— assertsdetailsis 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 andactive_since, including the zero-of-a-status case.#recent_inspections— asserts most-recent-first ordering, the limit, and the default argument..form_schema— asserts thenotesfield is included for admins and excluded for non-admins.#logo_url— asserts it returns the logo when one is attached.Mutation coverage impact
EventInspectorCompanyRemaining survivors are equivalent mutants (e.g.
send↔public_send, redundant guards masked byrescue,return↔nilon 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