Skip to content

fix: show all court report topic sections in creation order (#6601)#7006

Open
augustocbx wants to merge 1 commit into
rubyforgood:mainfrom
augustocbx:6601-court-report-show-all-topic-sections-in-order
Open

fix: show all court report topic sections in creation order (#6601)#7006
augustocbx wants to merge 1 commit into
rubyforgood:mainfrom
augustocbx:6601-court-report-show-all-topic-sections-in-order

Conversation

@augustocbx

Copy link
Copy Markdown

What github issue is this PR for, if any?

Resolves #6601

What changed, and why?

CaseCourtReportContext#court_topics built the report's topic sections from an inner join on contact_topic_answers, which caused two problems visible in generated court reports:

  1. Missing sections — a contact topic with no answered case contacts in the reporting period was dropped from the report entirely.
  2. Unstable section order — sections appeared in the order of their first answer's occurred_at, so the questions came out in a different order on every report instead of the order the topics were defined.

Now the section list is built from the org's contact topics themselves, ordered by creation (id), matching the order of db/seeds/default_contact_topics.yml and the ordering already used by CaseContactsExportCsvService. Answers in the date range are grouped per topic and attached to their section; topics without answers render with an empty answer list so the question and details still appear in the report.

Behavior preserved/tightened along the way:

  • Topics flagged exclude_from_court_report stay out of the report (existing spec still passes).
  • Inactive/soft-deleted topics that have answers in the range still show their data (as before); inactive topics with no answers are not added.
  • Topics are now explicitly scoped to the case's casa_org.

Verified against the two production templates attached to the issue by @compwron (Montgomery and Prince George's): both render with all sections present and in order, including sections with no answers.

How is this tested? (please write rspec and jest tests!) 💖💪

Six new examples in spec/models/case_court_report_context_spec.rb covering: unanswered topics included with empty answers, creation-order sorting regardless of answer dates, inactive/excluded unanswered topics filtered out, inactive-with-answers preserved, and cross-org isolation. All six fail on main and pass with this change.

bundle exec rspec spec/models/case_court_report_context_spec.rb   # 34 examples, 0 failures
bundle exec rspec spec/models/case_court_report_spec.rb spec/requests/case_court_reports_spec.rb   # 68 examples, 0 failures
bundle exec rspec spec/system/case_court_reports   # 21 examples, 0 failures
bundle exec standardrb app/models/case_court_report_context.rb spec/models/case_court_report_context_spec.rb   # no offenses

Screenshots please :)

No UI change — the fix is in the docx generation context. The rendered output was verified by generating reports from the two production templates attached to the issue and confirming all topic sections appear in creation order, including ones with no case contacts.

@github-actions github-actions Bot added 🧪 Tests Tests ruby Touches Ruby code labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Touches Ruby code 🧪 Tests Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: should show all court report sections in order, and also all sections even if there are not case contacts in them

1 participant