mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
New Oil Analysis tab: one record per oil sample with dates, hours, the lab's verdict and comments, ppm results for 12 wear metals with the lab's averages, and the report PDF. Shows wear-metal trends, a side-by-side history table, and flags readings 1.5x or more above the lab average. AvLab report PDFs can be imported: every sample on the report (current and previous) is added unless already recorded, the engine is matched by serial number, and reports for another tail number are refused. The parser reads positioned text and drops the hidden color-code layer that overlaps results. Adds the pdf-reader gem. Test fixture is a rebuilt report with a dummy header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
27 lines
968 B
Ruby
27 lines
968 B
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(iron: 60, iron_avg: 35, copper: 10, copper_avg: 20, silicon: 20, silicon_avg: 13.3, tin: 5)
|
||
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 "validates status, non-negative results, and engine on this aircraft" do
|
||
assert analysis.valid?
|
||
refute analysis(status: "bad").valid?
|
||
refute analysis(iron: -1).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
|
||
end
|