mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- Oil analysis: Blackstone PDF import (20 elements, oil properties, universal averages), results stored per element, oil type, "leave out of trends", the original app's statuses; AvLab fixes (multi-line comments, unrelated labels no longer steal values). Existing records migrate. - Aircraft archives in the original app's .sam.zip format (schema v2): export from Access & Sharing, background import from the Fleet page, rake tasks. Archives move both ways between this app and the original. - Scanned logbook pages (images or PDFs) upload as a document; with ANTHROPIC_API_KEY set, Claude transcribes them into logbook entries. - Fix: deleting a component or aircraft failed when AD compliances or inspection records pointed at a component. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.0 KiB
Ruby
49 lines
2.0 KiB
Ruby
require "test_helper"
|
||
|
||
class OilAnalysisTest < ActiveSupport::TestCase
|
||
setup { @a = create_aircraft }
|
||
|
||
def analysis(**attrs) = @a.oil_analyses.new({ sample_date: Date.current }.merge(attrs))
|
||
|
||
test "flags readings well above the lab average" do
|
||
a = analysis(elements: { iron: 60, copper: 10, silicon: 20, tin: 5 },
|
||
element_averages: { iron: 35, copper: 20, silicon: 13.3 })
|
||
assert a.flagged?("iron")
|
||
refute a.flagged?("copper")
|
||
assert a.flagged?("silicon") # exactly 1.5×
|
||
refute a.flagged?("tin") # no average to compare
|
||
assert_equal %w[iron silicon], a.flagged_elements
|
||
end
|
||
|
||
test "results from a form: blanks dropped, numbers kept, unknown keys ignored" do
|
||
a = analysis(elements: { "iron" => "30.5", "copper" => "", "unobtainium" => "9" },
|
||
oil_properties: { "flashpoint_f" => "445", "water_percent" => "0" })
|
||
assert a.valid?
|
||
assert_equal({ "iron" => 30.5 }, a.elements)
|
||
assert_equal({ "flashpoint_f" => 445.0, "water_percent" => 0.0 }, a.oil_properties)
|
||
a.save!
|
||
assert_equal({ "iron" => 30.5 }, a.reload.elements)
|
||
end
|
||
|
||
test "validates status, non-negative numeric results, and engine on this aircraft" do
|
||
assert analysis.valid?
|
||
assert analysis(status: "").valid? # not rated
|
||
assert analysis(status: "monitor").valid?
|
||
refute analysis(status: "bad").valid?
|
||
a = analysis(elements: { iron: "-1", copper: "lots" })
|
||
refute a.valid?
|
||
assert_match "Iron and Copper", a.errors[:elements].first
|
||
refute analysis(oil_properties: { fuel_percent: "x" }).valid?
|
||
other_engine = create_component(create_aircraft)
|
||
a = analysis(component: other_engine)
|
||
refute a.valid?
|
||
assert_includes a.errors[:component], "must be on this aircraft"
|
||
end
|
||
|
||
test "elements_in lists elements any sample has, in display order" do
|
||
a = analysis(elements: { lead: 900, iron: 30 })
|
||
b = analysis(elements: { zinc: 4 })
|
||
assert_equal %w[iron lead zinc], OilAnalysis.elements_in([ a, b ])
|
||
end
|
||
end
|