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:
rickyandClaude Opus 5.5 committed 2026-11-04 17:59:08 -05:00
commit 38df19c331
264 files changed
+8365

No files matched your search

View File
Whitespace-only changes.
+104
View File
@@ -0,0 +1,104 @@
require "test_helper"
# Renders every page with realistic data to catch view/route errors.
class PagesTest < ActionDispatch::IntegrationTest
setup do
@owner = create_user("owner@example.com", admin: false)
@a = create_aircraft(owner: @owner, tail_number: "N100AB")
@engine = create_component(@a)
@oil = create_component(@a, component_type: component_type("Oil"), parent_component: @engine,
replacement_critical: true, replacement_hours: 50, hours_since_overhaul: 45, overhaul_date: Date.current)
@squawk = @a.squawks.create!(priority: 1, issue_reported: "Nav light out", reported_by: @owner)
@a.squawks.create!(priority: 3, issue_reported: "Old one", resolved: true, resolved_at: Time.current)
@note = @a.notes.create!(text: "Hangar 4", user: @owner, public: true)
@entry = @a.logbook_entries.create!(date: Date.current, text: "Oil changed", aircraft_hours_at_entry: 1000)
@collection = @a.document_collections.create!(name: "Logbooks", visibility: "status")
@doc = @a.documents.create!(name: "W&B", document_collection: @collection)
@doc.pages.attach(io: StringIO.new("hello"), filename: "wb.txt", content_type: "text/plain")
@itype = InspectionType.create!(name: "Annual", recurring: true, recurring_months: 12)
@itype.aircraft << @a
@irec = @a.inspection_records.create!(inspection_type: @itype, date: Date.current, aircraft_hours: 1000)
@ad = AirworthinessDirective.create!(name: "2020-01-01", short_description: "Check", recurring: true, recurring_hours: 100)
@ad.aircraft << @a
@adc = @ad.ad_compliances.create!(aircraft: @a, date_complied: Date.current, compliance_notes: "Done", next_due_at_time: 1100)
@major = @a.major_records.create!(record_type: "alteration", title: "LED lights", date_performed: Date.current)
@flight = @a.flight_logs.create!(date: Date.current, tach_time: 1.2)
@cr = @a.consumable_records.create!(record_type: "oil", date: Date.current, quantity_added: 1, flight_hours: 1000)
@token = @a.share_tokens.create!(privilege: "maintenance", label: "Mechanic")
@a.log_event!("aircraft", "Created", user: @owner)
sign_in @owner
end
test "owner can render every page" do
a = @a
paths = [
root_path, aircraft_path(a), new_aircraft_path, edit_aircraft_path(a),
aircraft_components_path(a), aircraft_components_path(a, disposed: 1), new_aircraft_component_path(a),
aircraft_component_path(a, @engine), edit_aircraft_component_path(a, @oil),
aircraft_squawks_path(a), new_aircraft_squawk_path(a), edit_aircraft_squawk_path(a, @squawk),
aircraft_notes_path(a), new_aircraft_note_path(a), edit_aircraft_note_path(a, @note),
aircraft_flight_logs_path(a), new_aircraft_flight_log_path(a), aircraft_flight_log_path(a, @flight),
aircraft_consumable_records_path(a), new_aircraft_consumable_record_path(a, type: "fuel"), edit_aircraft_consumable_record_path(a, @cr),
aircraft_logbook_entries_path(a), aircraft_logbook_entries_path(a, q: "oil", log_type: "AC"),
new_aircraft_logbook_entry_path(a), aircraft_logbook_entry_path(a, @entry), edit_aircraft_logbook_entry_path(a, @entry),
aircraft_documents_path(a), new_aircraft_document_path(a), aircraft_document_path(a, @doc), edit_aircraft_document_path(a, @doc),
new_aircraft_document_collection_path(a), edit_aircraft_document_collection_path(a, @collection),
aircraft_inspections_path(a), new_aircraft_inspection_type_path(a), edit_aircraft_inspection_type_path(a, @itype),
new_aircraft_inspection_record_path(a, inspection_type_id: @itype.id), edit_aircraft_inspection_record_path(a, @irec),
aircraft_airworthiness_directives_path(a), new_aircraft_airworthiness_directive_path(a),
edit_aircraft_airworthiness_directive_path(a, @ad), new_aircraft_ad_compliance_path(a, ad_id: @ad.id),
edit_aircraft_ad_compliance_path(a, @adc),
aircraft_major_records_path(a), new_aircraft_major_record_path(a), aircraft_major_record_path(a, @major),
edit_aircraft_major_record_path(a, @major),
aircraft_aircraft_roles_path(a), aircraft_events_path(a), aircraft_events_path(a, category: "aircraft"),
edit_profile_path
]
paths.each do |path|
get path
assert_response :success, "GET #{path} → #{response.status}"
end
end
test "maintenance share link renders without login and shows history" do
delete session_path
get shared_path(@token.token)
assert_response :success
assert_includes response.body, "N100AB"
assert_includes response.body, "Oil changed" # logbook
assert_includes response.body, "LED lights" # major records
assert_includes response.body, "Hangar 4" # public note
assert_includes response.body, "W&amp;B" # status-visible doc
end
test "status share link hides maintenance history" do
t = @a.share_tokens.create!(privilege: "status")
@a.notes.create!(text: "Secret combo", public: false)
delete session_path
get shared_path(t.token)
assert_response :success
assert_not_includes response.body, "Oil changed"
assert_not_includes response.body, "LED lights"
assert_not_includes response.body, "Secret combo"
assert_includes response.body, "Nav light out"
end
test "expired or unknown share link is 404" do
t = @a.share_tokens.create!(privilege: "status", expires_at: 1.minute.ago)
get shared_path(t.token)
assert_response :not_found
get shared_path("nope")
assert_response :not_found
end
test "admin pages" do
admin = create_user("boss@example.com", admin: true)
sign_in admin
[ admin_users_path, new_admin_user_path, edit_admin_user_path(@owner),
admin_component_types_path, new_admin_component_type_path ].each do |path|
get path
assert_response :success, path
end
get aircraft_path(@a) # admins see every aircraft
assert_response :success
end
end
+126
View File
@@ -0,0 +1,126 @@
require "test_helper"
class PermissionsTest < ActionDispatch::IntegrationTest
setup do
@owner = create_user
@pilot = create_user
@outsider = create_user
@a = create_aircraft(owner: @owner, pilot: @pilot, tach_time: 1000)
@engine = create_component(@a, hours_in_service: 100, hours_since_overhaul: 100)
end
test "outsider gets 404 for aircraft and nested resources" do
sign_in @outsider
get aircraft_path(@a)
assert_response :not_found
get aircraft_components_path(@a)
assert_response :not_found
patch hours_aircraft_path(@a), params: { tach_time: 2000 }
assert_response :not_found
assert_equal 1000, @a.reload.tach_time
end
test "fleet only lists accessible aircraft" do
other = create_aircraft(owner: @outsider, tail_number: "N999ZZ")
sign_in @pilot
get root_path
assert_includes response.body, @a.tail_number
assert_not_includes response.body, other.tail_number
end
test "pilot can update hours, log flights, report squawks, add notes and oil" do
sign_in @pilot
patch hours_aircraft_path(@a), params: { tach_time: "1010" }
assert_equal 1010, @a.reload.tach_time
assert_equal 110, @engine.reload.hours_in_service
post aircraft_flight_logs_path(@a), params: { flight_log: { date: Date.current, tach_out: 1010, tach_in: 1011.5, oil_added: 1 } }
assert_redirected_to aircraft_flight_logs_path(@a)
assert_equal 1011.5, @a.reload.tach_time
assert_equal 1, @a.consumable_records.oil.count
post aircraft_squawks_path(@a), params: { squawk: { priority: 0, issue_reported: "Mag drop" } }
assert_equal @pilot, @a.squawks.last.reported_by
assert_equal "RED", @a.reload.airworthiness.status
post aircraft_notes_path(@a), params: { aircraft_note: { text: "Low on fuel" } }
assert_equal 1, @a.notes.count
post aircraft_consumable_records_path(@a), params: { consumable_record: { record_type: "fuel", date: Date.current, quantity_added: 20, flight_hours: 1011.5 } }
assert_equal 1, @a.consumable_records.fuel.count
end
test "pilot cannot edit owner-level data" do
squawk = @a.squawks.create!(priority: 1, issue_reported: "x")
sign_in @pilot
patch resolve_aircraft_squawk_path(@a, squawk)
assert_not squawk.reload.resolved?
post aircraft_components_path(@a), params: { component: { component_type_id: component_type.id, manufacturer: "x", model: "y", date_in_service: Date.current } }
assert_equal 1, @a.components.count
delete aircraft_component_path(@a, @engine)
assert Component.exists?(@engine.id)
patch aircraft_path(@a), params: { aircraft: { tail_number: "HACKED" } }
assert_not_equal "HACKED", @a.reload.tail_number
post aircraft_share_tokens_path(@a), params: { share_token: { privilege: "maintenance" } }
assert_equal 0, @a.share_tokens.count
get aircraft_aircraft_roles_path(@a)
assert_response :redirect
post aircraft_logbook_entries_path(@a), params: { logbook_entry: { date: Date.current, text: "x" } }
assert_equal 0, @a.logbook_entries.count
end
test "owner manages roles with last-owner protection" do
sign_in @owner
owner_role = @a.roles.find_by(user: @owner)
patch aircraft_aircraft_role_path(@a, owner_role), params: { role: "pilot" }
assert_equal "owner", owner_role.reload.role
newbie = create_user("newbie@example.com")
post aircraft_aircraft_roles_path(@a), params: { email_address: "NewBie@example.com ", role: "owner" }
assert_equal "owner", @a.roles.find_by(user: newbie).role
delete aircraft_aircraft_role_path(@a, owner_role)
assert AircraftRole.exists?(owner_role.id), "can't remove self"
end
test "owner full workflow: component service, AD compliance, inspection" do
sign_in @owner
post reset_service_aircraft_component_path(@a, @engine), params: { reset_in_service: "1" }
assert_equal 0, @engine.reload.hours_in_service
post aircraft_airworthiness_directives_path(@a), params: {
airworthiness_directive: { name: "2024-05-05", short_description: "Muffler", recurring: "1", recurring_hours: 100 },
applies_to_airframe: "0", component_ids: [ @engine.id ]
}
ad = AirworthinessDirective.find_by!(name: "2024-05-05")
assert_equal [ @engine ], ad.components.to_a
assert_equal "RED", @a.reload.airworthiness.status
post aircraft_ad_compliances_path(@a), params: { ad_compliance: { airworthiness_directive_id: ad.id, date_complied: Date.current, compliance_notes: "Inspected", next_due_at_time: 1100 } }
assert_equal "GREEN", @a.reload.airworthiness.status
post aircraft_inspection_types_path(@a), params: { inspection_type: { name: "Annual", recurring: "1", recurring_months: 12, required: "1" }, applies_to_airframe: "1" }
assert_equal "RED", @a.reload.airworthiness.status
it = InspectionType.find_by!(name: "Annual")
post aircraft_inspection_records_path(@a), params: { inspection_record: { inspection_type_id: it.id, date: Date.current, aircraft_hours: 1000 } }
assert_equal "GREEN", @a.reload.airworthiness.status
delete aircraft_airworthiness_directive_path(@a, ad)
assert_not @a.reload.applicable_ads.exists?(ad.id)
end
test "owner cannot reach another aircraft's records through their own aircraft" do
other = create_aircraft(owner: @outsider)
other_engine = create_component(other)
sign_in @owner
get aircraft_component_path(@a, other_engine)
assert_response :not_found
end
end
+22
View File
@@ -0,0 +1,22 @@
require "test_helper"
class SetupTest < ActionDispatch::IntegrationTest
test "first run creates admin, then setup is closed" do
get root_path
assert_redirected_to new_setup_path
post setup_path, params: { user: { name: "Ricky", email_address: "a@b.com", password: "password123", password_confirmation: "password123" } }
assert_redirected_to root_path
assert User.last.admin?
get new_setup_path
assert_redirected_to root_path
end
test "create aircraft makes creator the owner" do
user = create_user
sign_in user
post aircraft_index_path, params: { aircraft: { tail_number: "N1", tach_time: 50 } }
a = Aircraft.find_by!(tail_number: "N1")
assert_redirected_to aircraft_path(a)
assert_equal "owner", user.role_for(a)
end
end