mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Part 91 inspection rules: limitations, annual as 100-hour, overrun, clock
- Inspection types say what overdue means: grounds the aircraft, no IFR
(91.411), no transponder (91.413) or advisory. Overdue limitations show
as a new LIMITED status ("VFR only", "No transponder") and don't block
flights under airworthiness enforcement
- "Also counts as": an annual satisfies the 100-hour (91.409(b))
- Overrun allowance: a 100-hour done within 10 hrs of due counts the next
one from when it was due; done early, from when it was done
- Per-aircraft maintenance clock (tach or Hobbs) for time in service; new
records default to it (fixes the tach-offset mismatch)
- Status labels Current / Due soon / limitation / Grounded, with the
91.7 pilot-in-command note
- Migration converts existing types by name; archives carry the new fields
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef7cd2efba
commit
a4b72cf2c1
28 files changed
+371
-63
No files matched your search
@@ -0,0 +1,37 @@
|
||||
require "test_helper"
|
||||
|
||||
class InspectionRulesFlowTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@owner = create_user("owner@example.com")
|
||||
@a = create_aircraft(owner: @owner)
|
||||
sign_in @owner
|
||||
end
|
||||
|
||||
test "owner sets what overdue means, the overrun allowance and what an inspection also counts as" do
|
||||
hundred = InspectionType.create!(name: "100-hour", recurring: true, recurring_hours: 100).tap { _1.aircraft << @a }
|
||||
elsewhere = InspectionType.create!(name: "Other aircraft's", recurring: true).tap { _1.aircraft << create_aircraft }
|
||||
post aircraft_inspection_types_path(@a), params: { inspection_type: {
|
||||
name: "Annual", recurring: "1", recurring_months: 12, effect: "grounds", satisfies_id: hundred.id } }
|
||||
annual = InspectionType.find_by!(name: "Annual")
|
||||
assert_equal hundred, annual.satisfies
|
||||
|
||||
patch aircraft_inspection_type_path(@a, hundred), params: { inspection_type: { hours_tolerance: "10", satisfies_id: elsewhere.id } }
|
||||
assert_equal [ 10, nil ], [ hundred.reload.hours_tolerance.to_i, hundred.satisfies_id ] # other aircraft's types can't be chosen
|
||||
|
||||
get edit_aircraft_inspection_type_path(@a, hundred)
|
||||
assert_select "select[name='inspection_type[effect]'] option[value=no_ifr]"
|
||||
get aircraft_inspections_path(@a)
|
||||
assert_includes response.body, "Also counts as 100-hour"
|
||||
end
|
||||
|
||||
test "maintenance clock on the aircraft form; new records default to time in service" do
|
||||
patch aircraft_path(@a), params: { aircraft: { time_basis: "hobbs", hobbs_time_offset: 0 } }
|
||||
@a.update_columns(hobbs_time: 1234.5)
|
||||
assert_equal "hobbs", @a.reload.time_basis
|
||||
get new_aircraft_inspection_record_path(@a)
|
||||
assert_select "input[name='inspection_record[aircraft_hours]'][value='1234.5']"
|
||||
get aircraft_path(@a)
|
||||
assert_includes response.body, "pilot in command decides whether the aircraft is airworthy"
|
||||
assert_select ".badge-green", text: "Current"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,91 @@
|
||||
require "test_helper"
|
||||
|
||||
# Part 91 inspection rules: what an overdue inspection means, the annual
|
||||
# counting as the 100-hour, the 100-hour's 10-hour allowance, and which clock
|
||||
# is time in service.
|
||||
class InspectionRulesTest < ActiveSupport::TestCase
|
||||
setup { @a = create_aircraft(tach_time: 1150) }
|
||||
|
||||
def type(name, **attrs)
|
||||
InspectionType.create!({ name: name, recurring: true }.merge(attrs)).tap { _1.aircraft << @a }
|
||||
end
|
||||
|
||||
def done(type, date, hours = nil) = @a.inspection_records.create!(inspection_type: type, date: date, aircraft_hours: hours)
|
||||
|
||||
test "overdue transponder or pitot-static checks limit the aircraft instead of grounding it" do
|
||||
xpdr = type("Transponder (91.413)", recurring_months: 24, effect: "no_transponder")
|
||||
done(xpdr, 3.years.ago.to_date)
|
||||
aw = @a.reload.airworthiness
|
||||
assert [ aw.limited?, aw.can_fly? ].all?
|
||||
assert_equal "No transponder", aw.label
|
||||
assert_equal "LIMITED", aw.issues.sole.severity
|
||||
|
||||
pitot = type("Pitot-static (91.411)", recurring_months: 24, effect: "no_ifr")
|
||||
done(pitot, 3.years.ago.to_date)
|
||||
assert_equal "No transponder · VFR only", @a.reload.airworthiness.label
|
||||
|
||||
@a.update!(airworthiness_enforcement: true) # flying isn't blocked by limitations
|
||||
assert_nothing_raised { HoursService.new(@a).enforce_airworthiness! }
|
||||
|
||||
annual = type("Annual", recurring_months: 12)
|
||||
done(annual, 13.months.ago.to_date)
|
||||
aw = @a.reload.airworthiness
|
||||
assert_equal [ "RED", "Grounded", false ], [ aw.status, aw.label, aw.can_fly? ]
|
||||
assert_raises(AircraftGroundedError) { HoursService.new(@a).enforce_airworthiness! }
|
||||
end
|
||||
|
||||
test "advisory inspections never affect the status; a fresh aircraft reads Current" do
|
||||
done(type("Wash", recurring_days: 30, effect: "advisory"), 1.year.ago.to_date)
|
||||
aw = @a.reload.airworthiness
|
||||
assert_equal [ "GREEN", "Current" ], [ aw.status, aw.label ]
|
||||
refute InspectionType.last.required? # kept in step for archives
|
||||
end
|
||||
|
||||
test "an annual also counts as the 100-hour" do
|
||||
hundred = type("100-hour", recurring_hours: 100, hours_tolerance: 10)
|
||||
annual = type("Annual", recurring_months: 12, satisfies: hundred)
|
||||
done(hundred, 4.months.ago.to_date, 1000)
|
||||
assert_equal 1100, Compliance.inspection_status(hundred, hundred.records_for(@a), @a.current_hours).next_due_hours
|
||||
assert @a.reload.airworthiness.red? # 150 hrs since the 100-hour
|
||||
|
||||
done(annual, 1.month.ago.to_date, 1090)
|
||||
row = Compliance.inspection_rows(@a).find { _1.type == hundred }
|
||||
assert_equal [ "compliant", 1190 ], [ row.status, row.next_due_hours ]
|
||||
assert_equal annual, row.latest.inspection_type
|
||||
refute @a.reload.airworthiness.red?
|
||||
end
|
||||
|
||||
test "the 100-hour's 10-hour allowance counts toward the next interval; early gets no credit" do
|
||||
hundred = type("100-hour", recurring_hours: 100, hours_tolerance: 10)
|
||||
done(hundred, 300.days.ago.to_date, 1000) # due at 1100
|
||||
next_due = ->(records) { Compliance.next_due_hours(hundred, records) }
|
||||
|
||||
late = done(hundred, 200.days.ago.to_date, 1105)
|
||||
assert_equal 1200, next_due.(hundred.records_for(@a)) # counted from 1100, not 1105
|
||||
late.update!(aircraft_hours: 1115) # past the allowance: from when done
|
||||
assert_equal 1215, next_due.(hundred.records_for(@a))
|
||||
late.update!(aircraft_hours: 1080) # early: from when done
|
||||
assert_equal 1180, next_due.(hundred.records_for(@a))
|
||||
end
|
||||
|
||||
test "overdue within the allowance says what 91.409(b) allows" do
|
||||
hundred = type("100-hour", recurring_hours: 100, hours_tolerance: 10)
|
||||
done(hundred, 100.days.ago.to_date, 1045) # due 1145, now 1150
|
||||
issue = @a.reload.airworthiness.issues.sole
|
||||
assert_match "up to 10 hrs past due only to reach a place where it can be done", issue.description
|
||||
@a.update!(tach_time: 1170)
|
||||
assert_equal "Inspection overdue.", @a.reload.airworthiness.issues.sole.description
|
||||
end
|
||||
|
||||
test "Hobbs as the maintenance clock" do
|
||||
@a.update!(hobbs_time: 1300, hobbs_time_offset: 20, time_basis: "hobbs")
|
||||
assert_equal 1280, @a.current_hours
|
||||
engine = create_component(@a, hours_since_overhaul: 500, hours_in_service: 500)
|
||||
HoursService.new(@a).log_flight!(@a.flight_logs.new(date: Date.current, tach_time: 1.0, hobbs_time: 1.3))
|
||||
assert_equal 501.3, engine.reload.hours_since_overhaul.to_f
|
||||
assert_equal [ 1151, 1301.3 ], [ @a.reload.tach_time.to_f, @a.hobbs_time.to_f ]
|
||||
|
||||
HoursService.new(@a).update_hours!(tach_time: 1152, hobbs_time: 1302.5)
|
||||
assert_equal 502.5, engine.reload.hours_since_overhaul.to_f
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user