mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
AD search: also look for the engine/propeller model family (O-200A -> O-200)
ADs usually name the family or spell the suffix differently (O-200-A), so an exact-model search could miss them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
350914bddc
commit
0fd795440d
2 files changed
+17
-5
No files matched your search
@@ -19,9 +19,17 @@ class AdWatch
|
||||
# Model names to search for: the owner's list, or the aircraft, engine and
|
||||
# propeller models.
|
||||
def self.default_terms(aircraft)
|
||||
models = [ aircraft.model ] + aircraft.components.in_use.includes(:component_type)
|
||||
.select { _1.component_type&.name.to_s.match?(/engine|propell?er|\bprop\b/i) }.map(&:model)
|
||||
models.compact_blank.map { _1.strip }.uniq
|
||||
engines = aircraft.components.in_use.includes(:component_type)
|
||||
.select { _1.component_type&.name.to_s.match?(/engine|propell?er|\bprop\b/i) }.map(&:model).compact_blank.map(&:strip)
|
||||
([ aircraft.model.to_s.strip ] + engines.flat_map { [ _1, model_family(_1) ] }).compact_blank.uniq
|
||||
end
|
||||
|
||||
# The engine family ADs often name instead of the exact model, and that also
|
||||
# catches a different spelling of the suffix: "O-200A" and "O-200-A" -> "O-200",
|
||||
# "IO-550-N" -> "IO-550". Nil when there's no family to add.
|
||||
def self.model_family(model)
|
||||
family = model.to_s.upcase[/\A([A-Z]{1,5}-\d{3,4})(?=-?[A-Z0-9])/, 1]
|
||||
family unless family.nil? || family == model.to_s.upcase
|
||||
end
|
||||
|
||||
def terms
|
||||
|
||||
@@ -167,7 +167,11 @@ class GroupFourTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test "newly published ADs are found, tracked or dismissed, and reported weekly" do
|
||||
create_component(@a, component_type: component_type("Engine"), model: "O-320-H2AD")
|
||||
assert_equal [ "172N", "O-320-H2AD" ], AdWatch.default_terms(@a)
|
||||
assert_equal [ "172N", "O-320-H2AD", "O-320" ], AdWatch.default_terms(@a) # engine family too
|
||||
assert_equal "O-200", AdWatch.model_family("O-200A")
|
||||
assert_equal "IO-550", AdWatch.model_family("IO-550-N")
|
||||
assert_nil AdWatch.model_family("O-200")
|
||||
assert_nil AdWatch.model_family("1A102/OCM6948")
|
||||
known = AirworthinessDirective.create!(name: "2020-01-01", short_description: "Already tracked")
|
||||
known.aircraft << @a
|
||||
stub = stub_request(:get, %r{\Ahttps://www\.federalregister\.gov/api/v1/documents\.json}).to_return(status: 200, body: FR_RESPONSE)
|
||||
@@ -175,7 +179,7 @@ class GroupFourTest < ActionDispatch::IntegrationTest
|
||||
sign_in @owner
|
||||
post check_aircraft_ad_alerts_path(@a)
|
||||
assert_redirected_to aircraft_airworthiness_directives_path(@a, anchor: "new-ads")
|
||||
assert_requested stub, times: 2 # one search per term
|
||||
assert_requested stub, times: 3 # one search per term (model, engine model, engine family)
|
||||
alert = @a.ad_alerts.sole # already-tracked and non-AD documents skipped
|
||||
assert_equal [ "2026-17-10", "39-23454", "new" ], [ alert.ad_number, alert.amendment, alert.status ]
|
||||
get aircraft_airworthiness_directives_path(@a)
|
||||
|
||||
Reference in new issue
Block a user