Deferrals, expirations, standard inspections, reminders, squawk fixes

- Squawks: defer an inoperative item under 91.213(d) once each condition
  is confirmed (pilots may too); deferred items stop grounding and are
  listed for awareness. Resolving can record the fix as a logbook entry
  (43.9 fields) or link an existing one
- Expiration dates on components (ELT battery, 91.207(c)) and documents;
  new document types (registration, airworthiness certificate, insurance,
  radio license). Expired replacement-critical parts and an expired
  registration (91.203) ground; others warn; registration warns 90 days out
- Standard inspections: one click adds annual, 100-hour, 91.411, 91.413,
  ELT (91.207(d)) and VOR (91.171) checks with the right rules, skipping
  ones already tracked and linking annual to 100-hour
- Weekly Monday reminder email to owners when something needs attention;
  profile opt-out; admin "send me this week's reminder"
- README feature table updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 10:24:33 -05:00
1 parent a4ec7a691e
commit 61c3749793
41 files changed
+649 -48

No files matched your search

@@ -0,0 +1,97 @@
require "test_helper"
# Expiring parts and documents, the standard inspection set, and the weekly
# reminder email.
class MaintenanceTrackingTest < ActionDispatch::IntegrationTest
include ActionMailer::TestHelper
setup do
@owner = create_user("owner@example.com")
@a = create_aircraft(owner: @owner, tail_number: "N12345")
end
test "an expired ELT battery grounds; other expiring parts and documents warn; an expired registration grounds" do
battery = create_component(@a, component_type: component_type("ELT Battery"), replacement_critical: true, expires_on: 10.days.from_now.to_date)
assert_equal [ "ORANGE", "ELT Battery - Expires Soon" ], [ @a.reload.airworthiness.status, @a.airworthiness.issues.sole.title ]
battery.update!(expires_on: 1.day.ago.to_date)
assert_equal "ELT Battery - Expired", @a.reload.airworthiness.issues.sole.title
assert @a.airworthiness.red?
battery.update!(expires_on: Date.current) # usable through the marked date
refute @a.reload.airworthiness.red?
battery.update!(expires_on: 5.years.from_now.to_date)
insurance = @a.documents.create!(name: "Insurance", doc_type: "INSURANCE", expires_on: 1.day.ago.to_date)
aw = @a.reload.airworthiness
assert_equal [ "ORANGE", "Insurance - Expired" ], [ aw.status, aw.issues.sole.title ]
insurance.destroy!
registration = @a.documents.create!(name: "Registration", doc_type: "REGISTRATION", expires_on: 60.days.from_now.to_date)
assert_equal "Registration - Expires Soon", @a.reload.airworthiness.issues.sole.title # 90-day warning
registration.update!(expires_on: 1.day.ago.to_date)
assert @a.reload.airworthiness.red?
assert_match "91.203", @a.airworthiness.issues.sole.description
sign_in @owner
get aircraft_documents_path(@a)
assert_select ".badge-red", text: /Expired/
patch aircraft_component_path(@a, battery), params: { component: { expires_on: "2030-06-30" } }
assert_equal Date.new(2030, 6, 30), battery.reload.expires_on
end
test "standard inspections add the right rules once, linking the annual to the 100-hour" do
InspectionType.create!(name: "Transponder & encoder", recurring: true, recurring_months: 24).aircraft << @a
sign_in @owner
get new_aircraft_standard_inspections_path(@a)
assert_select "input[type=checkbox][value=transponder][disabled]"
assert_includes response.body, "Already tracked as “Transponder &amp; encoder”"
post aircraft_standard_inspections_path(@a), params: { templates: %w[annual hundred transponder pitot_static elt vor] }
assert_redirected_to aircraft_inspections_path(@a)
types = @a.reload.inspection_types.index_by(&:name)
assert_equal 6, types.size # five added, the existing transponder kept
hundred = types["100-hour inspection (91.409(b))"]
assert_equal [ 100, 10 ], [ hundred.recurring_hours.to_i, hundred.hours_tolerance.to_i ]
assert_equal hundred, types["Annual inspection (91.409(a))"].satisfies
assert_equal [ "no_ifr", 24 ], types["Altimeter and static system check (91.411)"].then { [ _1.effect, _1.recurring_months ] }
assert_equal [ "no_ifr", 30 ], types["VOR check (91.171)"].then { [ _1.effect, _1.recurring_days ] }
other = create_aircraft(owner: @owner)
StandardInspections.add!(other, %w[annual])
assert_equal types["Annual inspection (91.409(a))"], other.inspection_types.sole # shared, not duplicated
post aircraft_standard_inspections_path(@a), params: { templates: %w[annual] }
assert_redirected_to new_aircraft_standard_inspections_path(@a)
end
test "weekly reminders go to owners with something due, not to those who opted out" do
annual = InspectionType.create!(name: "Annual", recurring: true, recurring_months: 12).tap { _1.aircraft << @a }
@a.inspection_records.create!(inspection_type: annual, date: 13.months.ago.to_date)
@a.squawks.create!(priority: 2, issue_reported: "Nav light inop", deferred_at: Time.current, deferred_by_name: "J",
deferred_by_role: "pilot", deferral_action: "deactivated")
quiet = create_user("quiet@example.com")
create_aircraft(owner: quiet) # nothing due
opted_out = create_user("optout@example.com")
opted_out.update!(reminder_emails: false)
@a.roles.create!(user: opted_out, role: "owner")
assert_emails 1 do
WeeklyReminderJob.perform_now
end
mail = ActionMailer::Base.deliveries.last
assert_equal [ [ "owner@example.com" ], "1 item overdue: N12345" ], [ mail.to, mail.subject ]
body = mail.text_part.body.to_s
assert_includes body, "Overdue: Annual - Overdue"
assert_includes body, "Deferred: Inoperative: Nav light inop"
sign_in @owner
patch profile_path, params: { user: { reminder_emails: "0" } }
refute @owner.reload.reminder_emails?
assert_no_emails { WeeklyReminderJob.perform_now }
admin = create_user("admin@example.com", admin: true)
@a.roles.create!(user: admin, role: "owner")
sign_in admin
assert_emails 1 do
post admin_test_reminder_path
end
assert_equal "Reminder sent to admin@example.com.", flash[:notice]
end
end
+72
View File
@@ -0,0 +1,72 @@
require "test_helper"
# Deferring inoperative equipment (91.213(d)) and recording a squawk's fix
# in the logbook (43.9).
class SquawkWorkflowTest < ActionDispatch::IntegrationTest
setup do
@owner = create_user("owner@example.com")
@pilot = create_user("pilot@example.com")
@a = create_aircraft(owner: @owner, pilot: @pilot)
@squawk = @a.squawks.create!(priority: 0, issue_reported: "Left landing light inop", reported_by: @pilot)
end
test "a pilot defers an inoperative item once every 91.213(d) condition is confirmed" do
assert @a.reload.airworthiness.red?
sign_in @pilot
get aircraft_squawks_path(@a)
assert_select "a[href='#{deferral_aircraft_squawk_path(@a, @squawk)}']", text: "Defer"
get deferral_aircraft_squawk_path(@a, @squawk)
assert_select "input[name='checks[]']", Squawk::DEFERRAL_CHECKS.size
patch defer_aircraft_squawk_path(@a, @squawk), params: { checks: Squawk::DEFERRAL_CHECKS.keys.first(3),
deferral_action: "deactivated", deferred_by_name: "Jane Pilot", deferred_by_role: "pilot" }
assert_response :unprocessable_entity
assert_includes response.body, "Confirm: A pilot or certificated mechanic has determined"
refute @squawk.reload.deferred?
patch defer_aircraft_squawk_path(@a, @squawk), params: { checks: Squawk::DEFERRAL_CHECKS.keys,
deferral_action: "deactivated", deferred_by_name: "Jane Pilot", deferred_by_role: "pilot", deferral_notes: "Breaker collared" }
assert_redirected_to aircraft_squawks_path(@a)
@squawk.reload
assert [ @squawk.deferred?, !@squawk.grounding? ].all?
assert_equal "Deferred (91.213(d))", @squawk.priority_label
aw = @a.reload.airworthiness
assert_equal "GREEN", aw.status # listed, but no longer grounding
assert_equal [ "INFO", "Inoperative: Left landing light inop" ], [ aw.issues.sole.severity, aw.issues.sole.title ]
patch undefer_aircraft_squawk_path(@a, @squawk) # only owners undo
assert @squawk.reload.deferred?
sign_in @owner
patch undefer_aircraft_squawk_path(@a, @squawk)
refute @squawk.reload.deferred?
assert @a.reload.airworthiness.red?
end
test "resolving records the fix as a logbook entry, links an existing one, or neither" do
sign_in @owner
get resolution_aircraft_squawk_path(@a, @squawk)
assert_select "textarea[name='logbook_entry[text]']", text: /Corrected: Left landing light inop/
patch resolve_aircraft_squawk_path(@a, @squawk), params: { logbook: "new", logbook_entry: {
date: "2026-11-01", log_type: "AC", text: "Replaced left landing light lamp P/N 4509", aircraft_hours_at_entry: 1000,
signoff_person: "Sam Mechanic", signoff_certificate_type: "AP", signoff_certificate_number: "7654321" } }
assert_redirected_to aircraft_squawks_path(@a)
entry = @squawk.reload.logbook_entry
assert @squawk.resolved?
assert_equal [ "MAINTENANCE", "AP", "7654321", [] ], [ entry.entry_type, entry.signoff_certificate_type, entry.signoff_certificate_number, entry.missing_record_items ]
get aircraft_squawks_path(@a)
assert_select "a[href='#{aircraft_logbook_entry_path(@a, entry)}']", text: "Logbook 2026-11-01"
other = @a.squawks.create!(priority: 2, issue_reported: "Chipped paint")
patch resolve_aircraft_squawk_path(@a, other), params: { logbook: "existing", logbook_entry_id: entry.id }
assert_equal entry, other.reload.logbook_entry
third = @a.squawks.create!(priority: 3, issue_reported: "Not a defect")
patch resolve_aircraft_squawk_path(@a, third), params: { logbook: "none", resolution_notes: "Normal for type" }
assert [ third.reload.resolved?, third.logbook_entry.nil? ].all?
bad = @a.squawks.create!(priority: 1, issue_reported: "Bad")
patch resolve_aircraft_squawk_path(@a, bad), params: { logbook: "new", logbook_entry: { date: "", text: "" } }
assert_response :unprocessable_entity
refute bad.reload.resolved?
end
end