mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
Initial commit: Rails port of Simple Aircraft Manager
Rails 8.1 + SQLite rewrite of marbindrakon/simple-aircraft-manager, designed to self-host as a single container (Solid Queue/Cache/Cable, Active Storage on disk, Hotwire + importmap, Tailwind). - Airworthiness engine ported from health/services.py (ADs, grounding squawks, inspection recurrency, component replacement) - Hours updates and flight logs cascading to in-service components, optional airworthiness enforcement - Components, squawks, ADs, inspections, logbook, documents, major records, oil/fuel consumption stats and charts, activity log - Admin/owner/pilot RBAC and public share links (status/maintenance) - Docker Compose and Kamal deployment, env-driven production config - Service and integration tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
38df19c331
264 files changed
+8365
No files matched your search
@@ -0,0 +1,92 @@
|
||||
require "test_helper"
|
||||
|
||||
class AirworthinessTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@aircraft = create_aircraft(tach_time: 1000)
|
||||
end
|
||||
|
||||
test "clean aircraft is green" do
|
||||
assert_equal "GREEN", @aircraft.airworthiness.status
|
||||
end
|
||||
|
||||
test "unresolved priority-0 squawk grounds aircraft" do
|
||||
@aircraft.squawks.create!(priority: 0, issue_reported: "Flat tire")
|
||||
assert_equal "RED", Airworthiness.new(@aircraft).call.status
|
||||
end
|
||||
|
||||
test "lower-priority squawk does not affect status" do
|
||||
@aircraft.squawks.create!(priority: 1, issue_reported: "Light out")
|
||||
assert_equal "GREEN", Airworthiness.new(@aircraft).call.status
|
||||
end
|
||||
|
||||
test "required inspection never completed is red" do
|
||||
InspectionType.create!(name: "Annual", recurring: true, recurring_months: 12).aircraft << @aircraft
|
||||
result = Airworthiness.new(@aircraft).call
|
||||
assert_equal "RED", result.status
|
||||
assert_match "Never Completed", result.issues.first.title
|
||||
end
|
||||
|
||||
test "annual due at end of month, orange within 30 days" do
|
||||
type = InspectionType.create!(name: "Annual", recurring: true, recurring_months: 12)
|
||||
type.aircraft << @aircraft
|
||||
@aircraft.inspection_records.create!(inspection_type: type, date: Date.new(2025, 6, 10), aircraft_hours: 900)
|
||||
|
||||
assert_equal "GREEN", Airworthiness.new(@aircraft, today: Date.new(2026, 5, 30)).call.status
|
||||
assert_equal "ORANGE", Airworthiness.new(@aircraft, today: Date.new(2026, 6, 15)).call.status
|
||||
assert_equal "ORANGE", Airworthiness.new(@aircraft, today: Date.new(2026, 6, 30)).call.status
|
||||
assert_equal "RED", Airworthiness.new(@aircraft, today: Date.new(2026, 7, 1)).call.status
|
||||
end
|
||||
|
||||
test "hour-based inspection uses current hours minus offset" do
|
||||
type = InspectionType.create!(name: "100 hr", recurring: true, recurring_hours: 100)
|
||||
type.aircraft << @aircraft
|
||||
@aircraft.inspection_records.create!(inspection_type: type, date: Date.current, aircraft_hours: 950)
|
||||
|
||||
assert_equal "GREEN", Airworthiness.new(@aircraft).call.status # 50 hrs since
|
||||
@aircraft.update!(tach_time: 1045)
|
||||
assert_equal "ORANGE", Airworthiness.new(@aircraft).call.status # 95 since, within 10
|
||||
@aircraft.update!(tach_time: 1050)
|
||||
assert_equal "RED", Airworthiness.new(@aircraft).call.status # 100 since
|
||||
@aircraft.update!(tach_time_offset: 10)
|
||||
assert_equal "ORANGE", Airworthiness.new(@aircraft).call.status # offset → 90 since
|
||||
end
|
||||
|
||||
test "AD without compliance is red; hour-based due soon is orange; permanent is green" do
|
||||
ad = AirworthinessDirective.create!(name: "2020-01-01", short_description: "Check thing")
|
||||
ad.aircraft << @aircraft
|
||||
assert_equal "RED", Airworthiness.new(@aircraft).call.status
|
||||
|
||||
c = ad.ad_compliances.create!(aircraft: @aircraft, date_complied: Date.current, compliance_notes: "Done",
|
||||
next_due_at_time: 1005)
|
||||
assert_equal "ORANGE", Airworthiness.new(@aircraft).call.status
|
||||
c.update!(permanent: true)
|
||||
assert_equal "GREEN", Airworthiness.new(@aircraft).call.status
|
||||
end
|
||||
|
||||
test "conditional and non-mandatory ADs never affect status" do
|
||||
AirworthinessDirective.create!(name: "C", short_description: "x", compliance_type: "conditional").aircraft << @aircraft
|
||||
AirworthinessDirective.create!(name: "S", short_description: "x", bulletin_type: "sb", mandatory: false).aircraft << @aircraft
|
||||
assert_equal "GREEN", Airworthiness.new(@aircraft).call.status
|
||||
end
|
||||
|
||||
test "AD applied via component counts for the aircraft" do
|
||||
engine = create_component(@aircraft)
|
||||
AirworthinessDirective.create!(name: "ENG", short_description: "x").components << engine
|
||||
assert_equal "RED", Airworthiness.new(@aircraft).call.status
|
||||
end
|
||||
|
||||
test "replacement-critical component overdue by hours or days" do
|
||||
oil = create_component(@aircraft, component_type: component_type("Oil"), replacement_critical: true,
|
||||
replacement_hours: 50, hours_since_overhaul: 45, overhaul_date: Date.current)
|
||||
assert_equal "ORANGE", Airworthiness.new(@aircraft).call.status
|
||||
oil.update!(hours_since_overhaul: 50)
|
||||
assert_equal "RED", Airworthiness.new(@aircraft).call.status
|
||||
oil.update!(hours_since_overhaul: 0, replacement_days: 120, overhaul_date: 121.days.ago.to_date)
|
||||
assert_equal "RED", Airworthiness.new(@aircraft).call.status
|
||||
end
|
||||
|
||||
test "spare components are ignored" do
|
||||
create_component(@aircraft, status: "SPARE", replacement_critical: true, replacement_hours: 10, hours_since_overhaul: 50)
|
||||
assert_equal "GREEN", Airworthiness.new(@aircraft).call.status
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
require "test_helper"
|
||||
|
||||
class ConsumptionStatsTest < ActiveSupport::TestCase
|
||||
test "oil hrs/qt average excludes IQR outliers and excluded records" do
|
||||
a = create_aircraft
|
||||
a.consumable_records.create!(record_type: "oil", date: Date.current, quantity_added: 1, flight_hours: 100)
|
||||
hours = 100.0
|
||||
# interval values (hrs/qt): 10, 11, 9, 10, 1 (outlier), 12, 10 (manually excluded)
|
||||
[ [ 10, false ], [ 11, false ], [ 9, false ], [ 10, false ], [ 1, false ], [ 12, false ], [ 10, true ] ].each do |dh, excl|
|
||||
hours += dh
|
||||
a.consumable_records.create!(record_type: "oil", date: Date.current, quantity_added: 1, flight_hours: hours,
|
||||
excluded_from_averages: excl)
|
||||
end
|
||||
stats = ConsumptionStats.new(a, "oil")
|
||||
assert_equal 7, stats.points.size
|
||||
assert_equal 10.4, stats.average # (10+11+9+10+12)/5
|
||||
end
|
||||
|
||||
test "zero spread disables outlier filtering (matches original)" do
|
||||
a = create_aircraft
|
||||
[ 100, 110, 120, 130, 131, 141 ].each do |h|
|
||||
a.consumable_records.create!(record_type: "oil", date: Date.current, quantity_added: 1, flight_hours: h)
|
||||
end
|
||||
assert_equal 8.2, ConsumptionStats.new(a, "oil").average
|
||||
end
|
||||
|
||||
test "fuel gal/hr" do
|
||||
a = create_aircraft
|
||||
a.consumable_records.create!(record_type: "fuel", date: Date.current, quantity_added: 40, flight_hours: 100)
|
||||
a.consumable_records.create!(record_type: "fuel", date: Date.current, quantity_added: 17, flight_hours: 102)
|
||||
assert_equal 8.5, ConsumptionStats.new(a, "fuel").average
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,58 @@
|
||||
require "test_helper"
|
||||
|
||||
class HoursServiceTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@user = create_user
|
||||
@aircraft = create_aircraft(owner: @user, tach_time: 1000, hobbs_time: 1200)
|
||||
@engine = create_component(@aircraft, hours_in_service: 500, hours_since_overhaul: 300)
|
||||
@spare = create_component(@aircraft, status: "SPARE", hours_in_service: 10, hours_since_overhaul: 10)
|
||||
end
|
||||
|
||||
test "hours update cascades delta to in-use components only and logs event" do
|
||||
HoursService.new(@aircraft, user: @user).update_hours!(tach_time: "1012.5", hobbs_time: "1214")
|
||||
assert_equal 1012.5, @aircraft.reload.tach_time
|
||||
assert_equal 1214, @aircraft.hobbs_time
|
||||
assert_equal 512.5, @engine.reload.hours_in_service
|
||||
assert_equal 312.5, @engine.hours_since_overhaul
|
||||
assert_equal 10, @spare.reload.hours_in_service
|
||||
assert_equal "hours", @aircraft.events.first.category
|
||||
end
|
||||
|
||||
test "downward correction clamps component hours at zero" do
|
||||
@engine.update!(hours_since_overhaul: 2)
|
||||
HoursService.new(@aircraft, user: @user).update_hours!(tach_time: "995")
|
||||
assert_equal 0, @engine.reload.hours_since_overhaul
|
||||
assert_equal 495, @engine.hours_in_service
|
||||
end
|
||||
|
||||
test "flight log increments hours and creates consumable records" do
|
||||
flight = @aircraft.flight_logs.new(date: Date.current, tach_out: 1000, tach_in: 1001.8, hobbs_time: 2.1,
|
||||
oil_added: 1, fuel_added: 20, departure_location: "KPVD", destination_location: "KBID")
|
||||
HoursService.new(@aircraft, user: @user).log_flight!(flight)
|
||||
assert_equal 1.8, flight.tach_time
|
||||
assert_equal 1001.8, @aircraft.reload.tach_time
|
||||
assert_equal 1202.1, @aircraft.hobbs_time
|
||||
assert_equal 501.8, @engine.reload.hours_in_service
|
||||
assert_equal %w[fuel oil], @aircraft.consumable_records.pluck(:record_type).sort
|
||||
assert_equal 1001.8, @aircraft.consumable_records.first.flight_hours
|
||||
assert_includes @aircraft.events.pluck(:event_name), "Flight logged: 1.8 hrs (KPVD → KBID)"
|
||||
end
|
||||
|
||||
test "enforcement blocks flights on red aircraft only when enabled" do
|
||||
@aircraft.squawks.create!(priority: 0, issue_reported: "Engine rough")
|
||||
HoursService.new(@aircraft).update_hours!(tach_time: 1001) # allowed: enforcement off
|
||||
|
||||
@aircraft.update!(airworthiness_enforcement: true)
|
||||
assert_raises(AircraftGroundedError) { HoursService.new(@aircraft).update_hours!(tach_time: 1002) }
|
||||
assert_equal 1001, @aircraft.reload.tach_time
|
||||
end
|
||||
|
||||
test "component service reset" do
|
||||
@engine.reset_service!
|
||||
assert_equal 0, @engine.hours_since_overhaul
|
||||
assert_equal 500, @engine.hours_in_service
|
||||
@engine.reset_service!(reset_in_service: true)
|
||||
assert_equal 0, @engine.hours_in_service
|
||||
assert_equal Date.current, @engine.date_in_service
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user