diff --git a/app/models/logbook_template.rb b/app/models/logbook_template.rb index 5d0031c..4b987de 100644 --- a/app/models/logbook_template.rb +++ b/app/models/logbook_template.rb @@ -22,7 +22,7 @@ class LogbookTemplate < ApplicationRecord existing = pluck(:name).to_set next_position = (maximum(:position) || 0) + 1 added = defaults.reject { existing.include?(_1["name"]) } - added.each_with_index { |d, i| create!(d.slice("name", "reference", "text", "log_type", "certificate_type").merge("position" => next_position + i)) } + added.each_with_index { |d, i| create!(d.slice("name", "reference", "text", "entry_type", "log_type", "certificate_type").merge("position" => next_position + i)) } added.size end diff --git a/config/logbook_templates.yml b/config/logbook_templates.yml index 81c288a..a513208 100644 --- a/config/logbook_templates.yml +++ b/config/logbook_templates.yml @@ -85,11 +85,13 @@ reference: "Part 43 App. A (c)(29)" text: "Removed, checked and reinstalled the magnetic chip detector: no particles found. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(29)." certificate_type: PILOT +# Not maintenance (14 CFR 43.3(k)), so no entry is required and it isn't +# signed off as preventive maintenance; this just keeps a note of it. - name: "Updating the navigation database" - reference: "Part 43 App. A (c)(31)" - text: "Updated the __ navigation database to cycle __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(31)." - certificate_type: PILOT + reference: "14 CFR 43.3(k)" + text: "Updated the __ navigation database to cycle __ from the flight deck, per the manufacturer's instructions, without tools or disassembly. Database update under 14 CFR 43.3(k); not maintenance." + entry_type: OTHER - name: "Swapping a tray-mounted nav/com unit" - reference: "Part 43 App. A (c)(32)" - text: "Removed and reinstalled the tray-mounted __ unit. Checked operation. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(32)." + reference: "Part 43 App. A (c)(31)" + text: "Removed and reinstalled the self-contained, panel-mounted, tray-mounted __ unit per the manufacturer's instructions. Performed an operational check before use. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(31)." certificate_type: PILOT diff --git a/db/migrate/20261116030000_fix_avionics_template_citations.rb b/db/migrate/20261116030000_fix_avionics_template_citations.rb new file mode 100644 index 0000000..d991344 --- /dev/null +++ b/db/migrate/20261116030000_fix_avionics_template_citations.rb @@ -0,0 +1,37 @@ +# Two built-in logbook templates cited the wrong rule. A tray-mounted nav/com +# swap is Part 43 Appendix A (c)(31), not (c)(32) (which doesn't exist), and a +# navigation database update isn't preventive maintenance at all: 14 CFR +# 43.3(k) says it isn't maintenance. Copies already in the database are fixed +# where an admin hasn't changed their text; edited ones are left alone. +class FixAvionicsTemplateCitations < ActiveRecord::Migration[8.1] + class Template < ActiveRecord::Base + self.table_name = "logbook_templates" + end + + FIXES = [ + { name: "Swapping a tray-mounted nav/com unit", + old_reference: "Part 43 App. A (c)(32)", + old_text: "Removed and reinstalled the tray-mounted __ unit. Checked operation. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(32).", + new: { reference: "Part 43 App. A (c)(31)", + text: "Removed and reinstalled the self-contained, panel-mounted, tray-mounted __ unit per the manufacturer's instructions. Performed an operational check before use. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(31)." } }, + { name: "Updating the navigation database", + old_reference: "Part 43 App. A (c)(31)", + old_text: "Updated the __ navigation database to cycle __. Preventive maintenance per 14 CFR 43.3(g), Part 43 Appendix A paragraph (c)(31).", + new: { reference: "14 CFR 43.3(k)", + text: "Updated the __ navigation database to cycle __ from the flight deck, per the manufacturer's instructions, without tools or disassembly. Database update under 14 CFR 43.3(k); not maintenance.", + entry_type: "OTHER", certificate_type: nil } } + ].freeze + + def up + FIXES.each do |fix| + Template.where(name: fix[:name], reference: fix[:old_reference], text: fix[:old_text]).update_all(fix[:new].merge(updated_at: Time.current)) + end + end + + def down + FIXES.each do |fix| + Template.where(name: fix[:name], reference: fix[:new][:reference], text: fix[:new][:text]) + .update_all(reference: fix[:old_reference], text: fix[:old_text], entry_type: "MAINTENANCE", certificate_type: "PILOT", updated_at: Time.current) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b41cd6f..ee99310 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2026_11_16_020000) do +ActiveRecord::Schema[8.1].define(version: 2026_11_16_030000) do create_table "access_invitation_redemptions", force: :cascade do |t| t.integer "access_invitation_id", null: false t.integer "user_id", null: false diff --git a/test/models/logbook_template_test.rb b/test/models/logbook_template_test.rb new file mode 100644 index 0000000..6f060e1 --- /dev/null +++ b/test/models/logbook_template_test.rb @@ -0,0 +1,31 @@ +require "test_helper" + +class LogbookTemplateTest < ActiveSupport::TestCase + test "every built-in template is valid and cites an existing Appendix A paragraph" do + LogbookTemplate.defaults.each do |d| + template = LogbookTemplate.new(d) + assert template.valid?, "#{d['name']}: #{template.errors.full_messages.to_sentence}" + # Part 43 Appendix A paragraph (c) runs from (1) to (31). + d.values_at("reference", "text").join(" ").scan(/\(c\)\((\d+)\)/).flatten.each do |n| + assert_includes 1..31, n.to_i, "#{d['name']} cites Appendix A (c)(#{n})" + end + end + end + + test "the tray-mounted nav/com swap cites (c)(31)" do + LogbookTemplate.restore_defaults! + swap = LogbookTemplate.find_by!(name: "Swapping a tray-mounted nav/com unit") + assert_equal "Part 43 App. A (c)(31)", swap.reference + assert_includes swap.text, "paragraph (c)(31)" + assert_equal "PILOT", swap.certificate_type + end + + test "a navigation database update is recorded as a note, not preventive maintenance" do + LogbookTemplate.restore_defaults! + update = LogbookTemplate.find_by!(name: "Updating the navigation database") + assert_equal "14 CFR 43.3(k)", update.reference + assert_equal "OTHER", update.entry_type + assert_nil update.certificate_type + assert_not_includes update.text, "Preventive maintenance" + end +end