Files
simple-aircraft-manager-rails/test/integration/engine_data_flow_test.rb
T
rickyandClaude Opus 5.5 6c6e7af8e6 Add engine monitor data (CGR-30P/CGR-30C) to flight logs
Attach a CGR-30 flight recording when logging a flight or later from the
flight page. The flight page shows engine run time, fuel burned, tach and
engine hours, peak RPM/EGT/CHT/oil/fuel flow, and charts per cylinder.
Unreadable files are rejected; recordings from another tail are flagged.

Also replace the real tail number in test data with N12345.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 20:25:18 -05:00

72 lines
3.1 KiB
Ruby

require "test_helper"
class EngineDataFlowTest < ActionDispatch::IntegrationTest
setup do
@owner = create_user
@pilot = create_user
@other_pilot = create_user
@aircraft = create_aircraft(owner: @owner, pilot: @pilot, tail_number: "N12345", tach_time: 7149.7)
@aircraft.roles.create!(user: @other_pilot, role: "pilot")
end
def upload(name = "cgr30p.csv") = fixture_file_upload("engine_data/#{name}", "text/csv")
test "pilot logs a flight with engine data and sees the summary and charts" do
sign_in @pilot
post aircraft_flight_logs_path(@aircraft), params: { flight_log: { date: "2025-07-14", tach_out: 7149.7, tach_in: 7149.8, engine_data: upload } }
flight = @aircraft.flight_logs.last
assert flight.engine_data.attached?
get aircraft_flight_logs_path(@aircraft)
assert_includes response.body, "Engine data attached"
get aircraft_flight_log_path(@aircraft, flight)
assert_response :success
assert_includes response.body, "8m 39s"
assert_includes response.body, "7149.77 → 7149.81 (0.04)"
assert_includes response.body, "EGT (cyl 4)"
assert_includes response.body, "No (ground run)"
assert_includes response.body, "Chartkick"
refute_includes response.body, "This recording is from"
end
test "an unreadable file is rejected when logging" do
sign_in @pilot
post aircraft_flight_logs_path(@aircraft), params: { flight_log: { date: "2025-07-14", tach_time: 0.1,
engine_data: fixture_file_upload("flights.csv", "text/csv") } }
assert_response :unprocessable_entity
assert_includes response.body, "Not a recognized engine monitor file"
assert_equal 0, @aircraft.flight_logs.count
end
test "attach to and remove from an existing flight; only owners or the flight's pilot" do
flight = @aircraft.flight_logs.create!(date: Date.current, tach_time: 0.1, user: @pilot)
sign_in @other_pilot
patch engine_data_aircraft_flight_log_path(@aircraft, flight), params: { flight_log: { engine_data: upload } }
assert_redirected_to aircraft_flight_log_path(@aircraft, flight)
refute flight.reload.engine_data.attached?
get aircraft_flight_log_path(@aircraft, flight)
refute_includes response.body, "Attach engine monitor data"
sign_in @pilot
get aircraft_flight_log_path(@aircraft, flight)
assert_includes response.body, "Attach engine monitor data"
patch engine_data_aircraft_flight_log_path(@aircraft, flight), params: { flight_log: { engine_data: upload } }
assert flight.reload.engine_data.attached?
sign_in @owner
delete engine_data_aircraft_flight_log_path(@aircraft, flight)
perform_enqueued_jobs
refute flight.reload.engine_data.attached?
end
test "warns when the recording is from another aircraft" do
@aircraft.update!(tail_number: "N54321")
flight = @aircraft.flight_logs.create!(date: Date.current, tach_time: 0.1, engine_data: upload)
sign_in @owner
get aircraft_flight_log_path(@aircraft, flight)
assert_includes response.body, "This recording is from <strong>N12345</strong>"
end
end