Files
simple-aircraft-manager-rails/test/integration/air_trail_export_flow_test.rb
T
2026-11-11 20:52:52 -05:00

32 lines
1.3 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
require "test_helper"
class AirTrailExportFlowTest < ActionDispatch::IntegrationTest
setup do
@pilot = create_user("jane@example.com")
@a = create_aircraft(pilot: @pilot, owner: create_user, tail_number: "N12345")
@a.flight_logs.create!(date: Date.current, departure_location: "KOQU", destination_location: "KBID", tach_time: 0.5)
sign_in @pilot
end
test "pilot downloads the AirTrail file" do
get aircraft_flight_logs_path(@a)
assert_select "a[href='#{new_aircraft_air_trail_export_path(@a)}']", text: "Export for AirTrail"
get new_aircraft_air_trail_export_path(@a)
assert_response :success
assert_select "input[name='username'][value='jane']"
assert_select "form[data-turbo='false']"
post aircraft_air_trail_export_path(@a), params: { username: "jane", aircraft_type: "C150", scope: "all" }
assert_response :success
assert_equal "application/json", response.media_type
assert_match(/attachment; filename="n12345-airtrail-.*\.json"/, response.headers["Content-Disposition"])
assert_equal "KBID", JSON.parse(response.body)["flights"].first["to"]["code"]
end
test "invalid username re-renders the form" do
post aircraft_air_trail_export_path(@a), params: { username: "x" }
assert_response :unprocessable_entity
assert_match "3–20 letters", response.body
end
end