mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- AD compliance "next due at tach reading" is prefilled from the AD's hour recurrence (hours at compliance + interval), recalculates live as the AD/date/hours change, keeps a typed-in override, and is filled server-side when left blank. - Live "Next due" preview on AD compliance and inspection record forms (hours and/or end-of-month date, whichever comes first), mirroring Compliance.next_due so preview and status agree. - Reject an interval entered as the next-due reading (e.g. "100" for "every 100 hours"), which made a complied AD show as overdue. - ADs table shows hours remaining next to the due tach reading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.2 KiB
Ruby
53 lines
2.2 KiB
Ruby
require "test_helper"
|
|
|
|
class AdComplianceTest < ActiveSupport::TestCase
|
|
setup do
|
|
@aircraft = create_aircraft(tach_time: 7290.3)
|
|
@ad = AirworthinessDirective.create!(name: "2011-10-09", short_description: "Seat rails")
|
|
@ad.aircraft << @aircraft
|
|
end
|
|
|
|
def comply(**attrs)
|
|
@ad.ad_compliances.new({ aircraft: @aircraft, date_complied: Date.current, compliance_notes: "Done" }.merge(attrs))
|
|
end
|
|
|
|
test "rejects an interval entered as the next-due reading" do
|
|
c = comply(aircraft_hours_at_compliance: 7243.4, next_due_at_time: 100)
|
|
assert_not c.valid?
|
|
assert_match "enter 7343.4, not 100", c.errors[:next_due_at_time].first
|
|
end
|
|
|
|
test "falls back to current tach when compliance hours are blank" do
|
|
assert_not comply(next_due_at_time: 100).valid?
|
|
assert comply(next_due_at_time: 7390.3).valid?
|
|
end
|
|
|
|
test "accepts a future reading, zero, or permanent" do
|
|
assert comply(aircraft_hours_at_compliance: 7243.4, next_due_at_time: 7343.4).valid?
|
|
assert comply(aircraft_hours_at_compliance: 7243.4, next_due_at_time: 0).valid?
|
|
assert comply(aircraft_hours_at_compliance: 7243.4, next_due_at_time: 100, permanent: true).valid?
|
|
end
|
|
|
|
test "a correct reading makes the aircraft airworthy again" do
|
|
comply(aircraft_hours_at_compliance: 7243.4, next_due_at_time: 7343.4).save!
|
|
assert_equal "GREEN", Airworthiness.new(@aircraft).call.status
|
|
end
|
|
|
|
test "next due is calculated from the AD's hour recurrence when left blank" do
|
|
@ad.update!(recurring: true, recurring_hours: 100)
|
|
c = comply(aircraft_hours_at_compliance: 7243.4)
|
|
c.save!
|
|
assert_equal BigDecimal("7343.4"), c.next_due_at_time
|
|
end
|
|
|
|
test "a typed-in reading wins over the calculation, permanent never gets one" do
|
|
@ad.update!(recurring: true, recurring_hours: 100)
|
|
assert_equal BigDecimal("7300"), comply(aircraft_hours_at_compliance: 7243.4, next_due_at_time: 7300).tap(&:save!).next_due_at_time
|
|
assert_equal 0, comply(aircraft_hours_at_compliance: 7243.4, permanent: true).tap(&:save!).next_due_at_time
|
|
end
|
|
|
|
test "one-time AD gets no hour-based next due" do
|
|
assert_equal 0, comply(aircraft_hours_at_compliance: 7243.4).tap(&:save!).next_due_at_time
|
|
end
|
|
end
|