From 5e0f9522dfd3269b5838a66c1d7ed93501c256c7 Mon Sep 17 00:00:00 2001 From: sbashamoni <138054633+sbashamoni@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:42:35 -0500 Subject: [PATCH] release/FY25Q1.3.0 (#23456) (#23475) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔀 Squash merge jcroteau/APPEALS-54136-zeitwerk-autoloader-transition * 🔀 Squash merge jcroteau/APPEALS-60112-fix-db-migrate-up-and-down-tasks Co-authored-by: Jeremy Croteau --- .codeclimate.yml | 37 +++--- .gitignore | 1 + .rubocop.yml | 15 ++- .../top_level_constants_per_file.rb | 30 +++++ Gemfile | 2 +- Gemfile.lock | 4 +- .../v3/issues/vacols/veterans_controller.rb | 4 +- .../schedule_hearing_tasks_controller.rb | 2 +- .../{ => test}/test_seeds_controller.rb | 0 app/controllers/user_info_controller.rb | 2 +- app/exceptions/standard_error.rb | 7 -- app/jobs/application_job.rb | 2 - app/jobs/file_number_not_found_fix_job.rb | 23 ++-- app/models/appeal.rb | 2 +- app/models/bgs_attorney.rb | 2 +- app/models/bgs_power_of_attorney.rb | 2 +- app/models/concerns/appeal_concern.rb | 2 +- app/models/concerns/associated_bgs_record.rb | 2 +- ...{bgs_service.rb => bgs_service_concern.rb} | 2 +- app/models/end_product_update.rb | 2 +- .../hearings/schedule_hearing_task_pager.rb | 2 +- app/models/legacy_appeal.rb | 2 +- app/models/organization.rb | 1 - app/models/organizations/business_line.rb | 2 - app/models/person.rb | 2 +- app/models/power_of_attorney.rb | 2 +- app/models/queue_tab.rb | 9 -- app/models/tasks/colocated_task.rb | 19 --- app/models/tasks/hearing_admin_action_task.rb | 9 -- app/models/tasks/mail_task.rb | 22 ---- app/models/user.rb | 2 +- app/models/vanotify/appeal_state.rb | 6 - .../issues/vacols/vacols_issue_serializer.rb | 2 +- .../issues/vacols/vbms_vacols_dto_builder.rb | 4 +- .../claim_history_event.rb | 12 +- app/services/external_api/vbms_service.rb | 21 ---- app/services/vbms_caseflow_logger.rb | 20 ++++ config/application.rb | 111 +++++++++++++++++- config/environments/development.rb | 6 +- config/environments/production.rb | 3 +- config/environments/test.rb | 2 +- config/initializers/activerecord_types.rb | 20 ++-- config/initializers/bgs.rb | 1 - config/initializers/bgs_service.rb | 3 + config/initializers/constants.rb | 58 ++++----- config/initializers/copy.rb | 8 +- config/initializers/deprecation_warnings.rb | 33 ------ config/initializers/efolder.rb | 6 - config/initializers/efolder_service.rb | 8 ++ config/initializers/fake_dependencies.rb | 4 +- config/initializers/gov_delivery.rb | 5 - config/initializers/gov_delivery_service.rb | 7 ++ config/initializers/mpi.rb | 1 - config/initializers/mpi_service.rb | 3 + config/initializers/oci8.rb | 7 ++ config/initializers/pacman.rb | 1 - config/initializers/pacman_service.rb | 3 + config/initializers/paper_trail.rb | 12 +- config/initializers/pexip.rb | 1 - config/initializers/pexip_service.rb | 3 + config/initializers/rails_erd.rb | 18 +-- config/initializers/s3.rb | 3 - config/initializers/s3_service.rb | 5 + config/initializers/scheduled_jobs.rb | 111 +++++++++--------- config/initializers/standard_error.rb | 9 ++ config/initializers/va_dot_gov.rb | 1 - config/initializers/va_dot_gov_service.rb | 3 + config/initializers/va_notify.rb | 6 - config/initializers/va_notify_service.rb | 8 ++ config/initializers/vacols_request_spy.rb | 78 ++++++------ config/initializers/vbms.rb | 6 - config/initializers/vbms_service.rb | 8 ++ config/initializers/warmup_vacols.rb | 65 ---------- config/initializers/webex.rb | 4 +- config/routes.rb | 4 +- .../20241007132413_no_op_migration.rb | 6 + db/etl_schema.rb | 2 +- db/migrate/20241007131619_no_op_migration.rb | 6 + db/seeds/facols.rb | 2 - .../deprecation_warnings.rb | 18 ++- lib/fakes/vbms_service.rb | 17 --- lib/generators/legacy_appeal_v2.rb | 2 +- lib/generators/vacols/case.rb | 18 +-- lib/generators/vacols/case_hearing.rb | 2 +- lib/generators/vacols/case_issue.rb | 2 +- lib/generators/vacols/correspondent.rb | 2 +- lib/generators/vacols/decass.rb | 2 +- lib/generators/vacols/folder.rb | 2 +- lib/generators/vacols/note.rb | 2 +- lib/generators/vacols/representative.rb | 2 +- lib/generators/vacols/staff.rb | 2 +- .../vacols/travel_board_schedule.rb | 2 +- lib/helpers/association_wrapper.rb | 2 +- ...ansforms.rb => sanitization_transforms.rb} | 0 lib/helpers/sanitized_json_configuration.rb | 10 +- lib/helpers/sanitizers.rb | 2 +- ...taDooDescriptionRemediationByReportLoad.rb | 0 .../{ => war_room}/claim_label_change.rb | 0 ...pp_ep_claims_sync_status_update_can_clr.rb | 0 .../{ => war_room}/hearings_info_migration.rb | 0 .../{ => war_room}/payee_code_update.rb | 0 lib/helpers/{ => war_room}/poa_access.rb | 0 .../{ => war_room}/pre_docket_ihp_tasks.rb | 0 .../remand_dta_or_doo_higher_level_review.rb | 0 .../report_load_end_product_sync.rb | 0 .../{ => war_room}/unrecognized_appellant.rb | 0 .../additional_legacy_remanded_appeals.rake | 16 +-- lib/tasks/appeal_state_synchronizer.rake | 2 - lib/tasks/db.rake | 66 ++++++++++- lib/tasks/local/vacols.rake | 5 +- lib/tasks/remediations/appellant_change.rake | 2 - .../cancel_vrr_tasks_open_for_vre.rake | 2 - .../sync_attributes_with_bgs.rake | 2 - lib/tasks/seed_legacy_appeals.rake | 16 +-- lib/tasks/seed_legacy_hearing.rake | 10 +- lib/tasks/spec.rake | 2 - .../jailer_polymorphic_associations.rb | 2 +- spec/config/sti_model_preloading_spec.rb | 33 ++++++ spec/config/zeitwerk_spec.rb | 7 ++ .../tasks/change_type_controller_spec.rb | 2 - .../asyncable_jobs_index_spec.rb | 4 +- spec/feature/reader/logs_controller_spec.rb | 2 +- spec/feature/reader/logs_spec.rb | 2 +- spec/feature/reader/reader_spec.rb | 2 +- .../test_docket_case_seeds_spec.rb | 2 +- .../cancel_tasks_and_descendants_spec.rb | 1 - .../sync_decided_appeals_helper_spec.rb | 2 - .../file_number_not_found_fix_job_spec.rb | 2 +- spec/jobs/nightly_syncs_job_spec.rb | 2 +- spec/lib/deprecation_warnings_spec.rb | 68 +++++++++++ spec/lib/helpers/appellant_change_spec.rb | 2 - spec/lib/helpers/association_wrapper_spec.rb | 10 +- ..._claims_sync_status_update_can_clr_spec.rb | 2 - spec/lib/helpers/poa_access_spec.rb | 2 - .../helpers/sanitized_json_exporter_spec.rb | 2 +- .../helpers/sync_attributes_with_bgs_spec.rb | 2 - spec/models/hearing_day_spec.rb | 2 +- .../schedule_hearing_task_pager_spec.rb | 6 +- .../issues/vacols/veterans_controller_spec.rb | 6 +- spec/requests/hearing_day_spec.rb | 12 +- .../top_level_constants_per_file_spec.rb | 55 +++++++++ .../vacols/vacols_issue_serializer_spec.rb | 4 +- .../claim_history_event_spec.rb | 6 +- .../production_handler_spec.rb | 71 ----------- 144 files changed, 806 insertions(+), 648 deletions(-) create mode 100644 .rubocop/custom_cop/top_level_constants_per_file.rb rename app/controllers/{ => test}/test_seeds_controller.rb (100%) delete mode 100644 app/exceptions/standard_error.rb rename app/models/concerns/{bgs_service.rb => bgs_service_concern.rb} (91%) delete mode 100644 app/models/vanotify/appeal_state.rb create mode 100644 app/services/vbms_caseflow_logger.rb delete mode 100644 config/initializers/bgs.rb create mode 100644 config/initializers/bgs_service.rb delete mode 100644 config/initializers/deprecation_warnings.rb delete mode 100644 config/initializers/efolder.rb create mode 100644 config/initializers/efolder_service.rb delete mode 100644 config/initializers/gov_delivery.rb create mode 100644 config/initializers/gov_delivery_service.rb delete mode 100644 config/initializers/mpi.rb create mode 100644 config/initializers/mpi_service.rb create mode 100644 config/initializers/oci8.rb delete mode 100644 config/initializers/pacman.rb create mode 100644 config/initializers/pacman_service.rb delete mode 100644 config/initializers/pexip.rb create mode 100644 config/initializers/pexip_service.rb delete mode 100644 config/initializers/s3.rb create mode 100644 config/initializers/s3_service.rb create mode 100644 config/initializers/standard_error.rb delete mode 100644 config/initializers/va_dot_gov.rb create mode 100644 config/initializers/va_dot_gov_service.rb delete mode 100644 config/initializers/va_notify.rb create mode 100644 config/initializers/va_notify_service.rb delete mode 100644 config/initializers/vbms.rb create mode 100644 config/initializers/vbms_service.rb delete mode 100644 config/initializers/warmup_vacols.rb create mode 100644 db/etl_migrate/20241007132413_no_op_migration.rb create mode 100644 db/migrate/20241007131619_no_op_migration.rb rename app/services/deprecation_warnings/production_handler.rb => lib/deprecation_warnings.rb (74%) rename lib/helpers/{sanitation_transforms.rb => sanitization_transforms.rb} (100%) rename lib/helpers/{ => war_room}/DtaDooDescriptionRemediationByReportLoad.rb (100%) rename lib/helpers/{ => war_room}/claim_label_change.rb (100%) rename lib/helpers/{ => war_room}/dupp_ep_claims_sync_status_update_can_clr.rb (100%) rename lib/helpers/{ => war_room}/hearings_info_migration.rb (100%) rename lib/helpers/{ => war_room}/payee_code_update.rb (100%) rename lib/helpers/{ => war_room}/poa_access.rb (100%) rename lib/helpers/{ => war_room}/pre_docket_ihp_tasks.rb (100%) rename lib/helpers/{ => war_room}/remand_dta_or_doo_higher_level_review.rb (100%) rename lib/helpers/{ => war_room}/report_load_end_product_sync.rb (100%) rename lib/helpers/{ => war_room}/unrecognized_appellant.rb (100%) create mode 100644 spec/config/sti_model_preloading_spec.rb create mode 100644 spec/config/zeitwerk_spec.rb create mode 100644 spec/lib/deprecation_warnings_spec.rb create mode 100644 spec/rubocop/custom_cop/top_level_constants_per_file_spec.rb delete mode 100644 spec/services/deprecation_warnings/production_handler_spec.rb diff --git a/.codeclimate.yml b/.codeclimate.yml index f16d7d860f0..9ca4b373125 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -41,6 +41,8 @@ checks: plugins: brakeman: enabled: true + exclude_patterns: + - 'lib/helpers/war_room/DtaDooDescriptionRemediationByReportLoad.rb' bundler-audit: enabled: true duplication: @@ -51,13 +53,13 @@ plugins: javascript: mass_threshold: 81 exclude_patterns: - - 'db/migrate/*' - - 'db/etl_migrate/*' - 'app/controllers/idt/api/v2/appeals_controller.rb' - - 'spec/controllers/idt/api/v2/appeals_controller_spec.rb' + - 'db/etl_migrate/*' + - 'db/migrate/*' + - 'spec/controllers/decision_reviews_controller_spec.rb' - 'spec/controllers/idt/api/appeals_controller_spec.rb' + - 'spec/controllers/idt/api/v2/appeals_controller_spec.rb' - 'spec/controllers/tasks_controller_spec.rb' - - 'spec/controllers/decision_reviews_controller_spec.rb' - 'spec/models/hearings/conference_link_spec.rb' eslint: enabled: true @@ -79,10 +81,18 @@ plugins: Attribute: enabled: false exclude_patterns: - - 'db/migrate/*' - - 'db/etl_migrate/*' - 'app/jobs/dispatch_email_job.rb' - 'app/mailers/dispatch_mailer.rb' + - 'db/etl_migrate/*' + - 'db/migrate/*' + - 'lib/helpers/sanitizers.rb' + - 'lib/helpers/war_room/claim_label_change.rb' + - 'lib/helpers/war_room/DtaDooDescriptionRemediationByReportLoad.rb' + - 'lib/helpers/war_room/dupp_ep_claims_sync_status_update_can_clr.rb' + - 'lib/helpers/war_room/hearings_info_migration.rb' + - 'lib/helpers/war_room/payee_code_update.rb' + - 'lib/helpers/war_room/remand_dta_or_doo_higher_level_review.rb' + - 'lib/helpers/war_room/report_load_end_product_sync.rb' rubocop: enabled: true channel: rubocop-0-83 @@ -116,15 +126,14 @@ plugins: - "spec/feature/**/*.rb" exclude_patterns: - - 'db/schema.rb' - - 'db/etl_schema.rb' - - 'db/seeds.rb' - - 'db/scripts/*' - - 'node_modules/**/*' - 'app/mappers/zip_code_to_lat_lng_mapper.rb' - - 'tmp/**/*' - 'app/assets/**/*' - - 'client/test/data/camoQueueConfigData.js' - 'client/app/intake/components/mockData/issueListProps.js' + - 'client/test/data/camoQueueConfigData.js' + - 'db/etl_schema.rb' + - 'db/schema.rb' + - 'db/scripts/*' + - 'db/seeds.rb' - 'db/seeds/*' - + - 'node_modules/**/*' + - 'tmp/**/*' diff --git a/.gitignore b/.gitignore index 18884fd4e16..c3dce4e93eb 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ tags !.dockerignore !.fasterer.yml !.reek.yml +!.rubocop !/.circleci/config.yml # React on Rails diff --git a/.rubocop.yml b/.rubocop.yml index 68a4a88ff03..3c826658f0f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ require: - rubocop-performance - rubocop-rails + - .rubocop/custom_cop/top_level_constants_per_file.rb AllCops: Exclude: @@ -102,9 +103,9 @@ Metrics/MethodLength: Max: 20 Exclude: - app/jobs/middleware/job_sentry_scope_middleware.rb - - lib/helpers/unrecognized_appellant.rb + - lib/helpers/war_room/unrecognized_appellant.rb - lib/helpers/duplicate_veteran_checker.rb - - lib/helpers/report_load_end_product_sync.rb + - lib/helpers/war_room/report_load_end_product_sync.rb - lib/helpers/claim_label_change.rb - "spec/**/*" @@ -213,7 +214,7 @@ Layout/LineLength: Max: 120 Exclude: - lib/helpers/duplicate_veteran_checker.rb - - lib/helpers/report_load_end_product_sync.rb + - lib/helpers/war_room/report_load_end_product_sync.rb Layout/MultilineMethodCallIndentation: @@ -224,3 +225,11 @@ Layout/EmptyLinesAroundAttributeAccessor: Layout/SpaceAroundMethodCallOperator: Enabled: true + +CustomCop/TopLevelConstantsPerFile: + Enabled: true + Include: + - 'app/**/*' + - 'lib/**/*' + Exclude: + - '**/*[^.rb]' # exclude non-.rb files (ex: .rake files) diff --git a/.rubocop/custom_cop/top_level_constants_per_file.rb b/.rubocop/custom_cop/top_level_constants_per_file.rb new file mode 100644 index 00000000000..315fa78a756 --- /dev/null +++ b/.rubocop/custom_cop/top_level_constants_per_file.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module RuboCop + module CustomCop + class TopLevelConstantsPerFile < RuboCop::Cop::Cop + MSG = "Multiple top-level constants detected in one file. The autoloader expects one top-level constant per file." + + def investigate(processed_source) + return unless processed_source + + # If more than one top-level constant in the file, add offense on the second one + if top_level_constant_nodes.size > 1 + add_offense(top_level_constant_nodes[1], message: MSG) + end + end + + private + + def top_level_constant_nodes + @top_level_constant_nodes ||= + processed_source.ast.each_node(:class, :module).select { |node| top_level_constant?(node) } + end + + def top_level_constant?(node) + # node is not nested within a class or module node? + node.ancestors.none? { |ancestor| ancestor.class_type? || ancestor.module_type? } + end + end + end +end diff --git a/Gemfile b/Gemfile index ee62f560cca..403ba59e03e 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem "bgs", git: "https://github.com/department-of-veterans-affairs/ruby-bgs.git" gem "bootsnap", require: false gem "browser" gem "business_time", "~> 0.9.3" -gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", ref: "9bd3635fbd8094d25160669f38d8699e2f1d7a98" +gem "caseflow", git: "https://github.com/department-of-veterans-affairs/caseflow-commons", ref: "dbd86859856d161d84b0bba4d67a8b62e4684996" gem "connect_mpi", git: "https://github.com/department-of-veterans-affairs/connect-mpi.git", ref: "a3a58c64f85b980a8b5ea6347430dd73a99ea74c" gem "connect_vbms", git: "https://github.com/department-of-veterans-affairs/connect_vbms.git", ref: "9807d9c9f0f3e3494a60b6693dc4f455c1e3e922" gem "console_tree_renderer", git: "https://github.com/department-of-veterans-affairs/console-tree-renderer.git", tag: "v0.1.1" diff --git a/Gemfile.lock b/Gemfile.lock index e6db09febdc..83acdc0af9d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://github.com/department-of-veterans-affairs/caseflow-commons - revision: 9bd3635fbd8094d25160669f38d8699e2f1d7a98 - ref: 9bd3635fbd8094d25160669f38d8699e2f1d7a98 + revision: dbd86859856d161d84b0bba4d67a8b62e4684996 + ref: dbd86859856d161d84b0bba4d67a8b62e4684996 specs: caseflow (0.4.8) aws-sdk-s3 diff --git a/app/controllers/api/v3/issues/vacols/veterans_controller.rb b/app/controllers/api/v3/issues/vacols/veterans_controller.rb index 9195012b213..e525024db3b 100644 --- a/app/controllers/api/v3/issues/vacols/veterans_controller.rb +++ b/app/controllers/api/v3/issues/vacols/veterans_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # :reek:InstanceVariableAssumption -class Api::V3::Issues::Vacols::VeteransController < Api::V3::BaseController +class Api::V3::Issues::VACOLS::VeteransController < Api::V3::BaseController # The max amount of Issues that can be paginated on a single page DEFAULT_UPPER_BOUND_PER_PAGE = ENV["REQUEST_ISSUE_DEFAULT_UPPER_BOUND_PER_PAGE"].to_i include ApiV3FeatureToggleConcern @@ -56,7 +56,7 @@ def show # Disallow page(0) since page(0) == page(1) in kaminari. This is to avoid confusion. (page.nil? || page <= 0) ? page = 1 : page ||= 1 - render_vacols_issues(Api::V3::Issues::Vacols::VbmsVacolsDtoBuilder.new(@veteran, page, + render_vacols_issues(Api::V3::Issues::VACOLS::VbmsVacolsDtoBuilder.new(@veteran, page, per_page)) end end diff --git a/app/controllers/hearings/schedule_hearing_tasks_controller.rb b/app/controllers/hearings/schedule_hearing_tasks_controller.rb index c08db574a28..de91a0de902 100644 --- a/app/controllers/hearings/schedule_hearing_tasks_controller.rb +++ b/app/controllers/hearings/schedule_hearing_tasks_controller.rb @@ -9,7 +9,7 @@ class Hearings::ScheduleHearingTasksController < ApplicationController before_action :verify_edit_hearing_schedule_access def index - task_pager = Hearings::ScheduleHearingTaskPager.new( + task_pager = ScheduleHearingTaskPager.new( assignee: HearingsManagement.singleton, tab_name: allowed_params[Constants.QUEUE_CONFIG.TAB_NAME_REQUEST_PARAM], page: allowed_params[Constants.QUEUE_CONFIG.PAGE_NUMBER_REQUEST_PARAM].to_i, diff --git a/app/controllers/test_seeds_controller.rb b/app/controllers/test/test_seeds_controller.rb similarity index 100% rename from app/controllers/test_seeds_controller.rb rename to app/controllers/test/test_seeds_controller.rb diff --git a/app/controllers/user_info_controller.rb b/app/controllers/user_info_controller.rb index 261a7fd4ee3..74b6e1fcc94 100644 --- a/app/controllers/user_info_controller.rb +++ b/app/controllers/user_info_controller.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class UserInfoController < ApplicationController - include BgsService + include BGSServiceConcern before_action :deny_non_bva_admins, only: [:represented_organizations] diff --git a/app/exceptions/standard_error.rb b/app/exceptions/standard_error.rb deleted file mode 100644 index 2f44e0264d0..00000000000 --- a/app/exceptions/standard_error.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class StandardError - def ignorable? - false - end -end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 548d9c7a81e..53a3beb92d3 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative "../exceptions/standard_error" - class ApplicationJob < ActiveJob::Base class InvalidJobPriority < StandardError; end diff --git a/app/jobs/file_number_not_found_fix_job.rb b/app/jobs/file_number_not_found_fix_job.rb index 61cbc062bbe..3486119b62c 100644 --- a/app/jobs/file_number_not_found_fix_job.rb +++ b/app/jobs/file_number_not_found_fix_job.rb @@ -1,15 +1,20 @@ # frozen_string_literal: true -require_relative "../../lib/helpers/fix_file_number_wizard" -require_relative "../../lib/helpers/duplicate_veteran_checker" - class FileNumberNotFoundFixJob < CaseflowJob include MasterSchedulerInterface - ASSOCIATED_OBJECTS = FixFileNumberWizard::ASSOCIATIONS queue_with_priority :low_priority application_attr :intake + class FixfileNumberCollections + ASSOCIATED_OBJECTS = FixFileNumberWizard::ASSOCIATIONS + def self.get_collections(veteran) + ASSOCIATED_OBJECTS.map do |klass| + FixFileNumberWizard::Collection.new(klass, veteran.ssn) + end + end + end + def initialize @stuck_job_report_service = StuckJobReportService.new @start_time = nil @@ -109,13 +114,3 @@ def self.call(ssn) end end end - -# created this class below so as to mock FixFileNumberWizard::Collection instance -class FixfileNumberCollections - ASSOCIATED_OBJECTS = FixFileNumberWizard::ASSOCIATIONS - def self.get_collections(veteran) - ASSOCIATED_OBJECTS.map do |klass| - FixFileNumberWizard::Collection.new(klass, veteran.ssn) - end - end -end diff --git a/app/models/appeal.rb b/app/models/appeal.rb index 4691f672563..f74482c399b 100644 --- a/app/models/appeal.rb +++ b/app/models/appeal.rb @@ -10,7 +10,7 @@ # rubocop:disable Metrics/ClassLength class Appeal < DecisionReview include BeaamAppealConcern - include BgsService + include BGSServiceConcern include Taskable include PrintsTaskTree include HasTaskHistory diff --git a/app/models/bgs_attorney.rb b/app/models/bgs_attorney.rb index 91964d493e3..696eddb7948 100644 --- a/app/models/bgs_attorney.rb +++ b/app/models/bgs_attorney.rb @@ -4,7 +4,7 @@ # who might not already be associated with a record (hence the use of a different model/table) class BgsAttorney < CaseflowRecord - include BgsService + include BGSServiceConcern delegate :address, :address_line_1, diff --git a/app/models/bgs_power_of_attorney.rb b/app/models/bgs_power_of_attorney.rb index 049438ea9ad..ef6d40ca12f 100644 --- a/app/models/bgs_power_of_attorney.rb +++ b/app/models/bgs_power_of_attorney.rb @@ -2,7 +2,7 @@ class BgsPowerOfAttorney < CaseflowRecord include AssociatedBgsRecord - include BgsService + include BGSServiceConcern has_many :claimants, primary_key: :claimant_participant_id, foreign_key: :participant_id has_one :representative, primary_key: :poa_participant_id, foreign_key: :participant_id diff --git a/app/models/concerns/appeal_concern.rb b/app/models/concerns/appeal_concern.rb index d7e28da2689..8f17bca11ed 100644 --- a/app/models/concerns/appeal_concern.rb +++ b/app/models/concerns/appeal_concern.rb @@ -113,7 +113,7 @@ def accessible? # this is used for calling BGSService.can_access? to fix VSO access that is being blocked # by BGS returning false for veteran.accessible? when they should indeed have access to the appeal. # does this VSO have access to this appeal? check if current user is one of the reps on the appeal. - # if so return true, if not then do the BgsService.can_access? path. + # if so return true, if not then do the BGSService.can_access? path. user = RequestStore[:current_user] assigned_to_vso?(user) || user_represents_claimant_not_veteran?(user) || bgs.can_access?(veteran_file_number) end diff --git a/app/models/concerns/associated_bgs_record.rb b/app/models/concerns/associated_bgs_record.rb index ee4107f5fec..5acdd1708b4 100644 --- a/app/models/concerns/associated_bgs_record.rb +++ b/app/models/concerns/associated_bgs_record.rb @@ -3,7 +3,7 @@ module AssociatedBgsRecord extend ActiveSupport::Concern - include BgsService + include BGSServiceConcern module ClassMethods # bgs_attr_accessor will lazy load the underlying data from BGS upon first call diff --git a/app/models/concerns/bgs_service.rb b/app/models/concerns/bgs_service_concern.rb similarity index 91% rename from app/models/concerns/bgs_service.rb rename to app/models/concerns/bgs_service_concern.rb index 5c92b47a80b..b56fe64b35f 100644 --- a/app/models/concerns/bgs_service.rb +++ b/app/models/concerns/bgs_service_concern.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module BgsService +module BGSServiceConcern extend ActiveSupport::Concern private diff --git a/app/models/end_product_update.rb b/app/models/end_product_update.rb index 3eb3c8777a4..9b5e9a41dc9 100644 --- a/app/models/end_product_update.rb +++ b/app/models/end_product_update.rb @@ -3,7 +3,7 @@ # This is for updating the claim label for end products established from Caseflow class EndProductUpdate < CaseflowRecord - include BgsService + include BGSServiceConcern belongs_to :end_product_establishment, optional: false belongs_to :original_decision_review, polymorphic: true, optional: false diff --git a/app/models/hearings/schedule_hearing_task_pager.rb b/app/models/hearings/schedule_hearing_task_pager.rb index 1d6ad09f28b..7db8932933b 100644 --- a/app/models/hearings/schedule_hearing_task_pager.rb +++ b/app/models/hearings/schedule_hearing_task_pager.rb @@ -3,7 +3,7 @@ ## # Basically the TaskPager, but has a required filter by regional key. -class Hearings::ScheduleHearingTaskPager < TaskPager +class ScheduleHearingTaskPager < TaskPager attr_accessor :regional_office_key def initialize(args) diff --git a/app/models/legacy_appeal.rb b/app/models/legacy_appeal.rb index 6d30eab2ca4..eb511a5bb55 100644 --- a/app/models/legacy_appeal.rb +++ b/app/models/legacy_appeal.rb @@ -10,7 +10,7 @@ class LegacyAppeal < CaseflowRecord include AppealConcern include AssociatedVacolsModel - include BgsService + include BGSServiceConcern include CachedAttributes include AddressMapper include Taskable diff --git a/app/models/organization.rb b/app/models/organization.rb index 20808069ad5..312cc59d922 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -7,7 +7,6 @@ class Organization < CaseflowRecord has_many :users, through: :organizations_users has_many :membership_requests has_many :non_admin_users, -> { non_admin }, class_name: "OrganizationsUser" - require_dependency "dvc_team" validates :name, presence: true validates :url, presence: true, uniqueness: true diff --git a/app/models/organizations/business_line.rb b/app/models/organizations/business_line.rb index 23628e730c7..c65765176fb 100644 --- a/app/models/organizations/business_line.rb +++ b/app/models/organizations/business_line.rb @@ -1085,5 +1085,3 @@ def where_clause_from_array(table_class, column, values_array) end # rubocop:enable Metrics/ClassLength end - -require_dependency "vha_business_line" diff --git a/app/models/person.rb b/app/models/person.rb index 94866057eb4..1f0ac7ad0b5 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -2,7 +2,7 @@ class Person < CaseflowRecord include AssociatedBgsRecord - include BgsService + include BGSServiceConcern include EventConcern has_many :advance_on_docket_motions diff --git a/app/models/power_of_attorney.rb b/app/models/power_of_attorney.rb index bb316c36b07..7d26f98ec90 100644 --- a/app/models/power_of_attorney.rb +++ b/app/models/power_of_attorney.rb @@ -14,7 +14,7 @@ class PowerOfAttorney include ActiveModel::Model include AssociatedVacolsModel - include BgsService + include BGSServiceConcern vacols_attr_accessor :vacols_representative_type, :vacols_representative_name, diff --git a/app/models/queue_tab.rb b/app/models/queue_tab.rb index 230a981f2f0..e72f6bcf566 100644 --- a/app/models/queue_tab.rb +++ b/app/models/queue_tab.rb @@ -235,12 +235,3 @@ def assignee_is_organization errors.add(:assignee, COPY::QUEUE_TAB_NON_ORGANIZATION_ASSIGNEE_MESSAGE) unless assignee.is_a?(Organization) end end - -require_dependency "assigned_tasks_tab" -require_dependency "completed_tasks_tab" -require_dependency "on_hold_tasks_tab" -require_dependency "organization_assigned_tasks_tab" -require_dependency "organization_completed_tasks_tab" -require_dependency "organization_on_hold_tasks_tab" -require_dependency "organization_tracking_tasks_tab" -require_dependency "organization_unassigned_tasks_tab" diff --git a/app/models/tasks/colocated_task.rb b/app/models/tasks/colocated_task.rb index 6645998239a..2697ab78070 100644 --- a/app/models/tasks/colocated_task.rb +++ b/app/models/tasks/colocated_task.rb @@ -220,22 +220,3 @@ def task_is_unique end end end - -require_dependency "poa_clarification_colocated_task" -require_dependency "ihp_colocated_task" -require_dependency "hearing_clarification_colocated_task" -require_dependency "aoj_colocated_task" -require_dependency "extension_colocated_task" -require_dependency "missing_hearing_transcripts_colocated_task" -require_dependency "unaccredited_rep_colocated_task" -require_dependency "foia_colocated_task" -require_dependency "retired_vlj_colocated_task" -require_dependency "arneson_colocated_task" -require_dependency "new_rep_arguments_colocated_task" -require_dependency "pending_scanning_vbms_colocated_task" -require_dependency "address_verification_colocated_task" -require_dependency "schedule_hearing_colocated_task" -require_dependency "stayed_appeal_colocated_task" -require_dependency "missing_records_colocated_task" -require_dependency "translation_colocated_task" -require_dependency "other_colocated_task" diff --git a/app/models/tasks/hearing_admin_action_task.rb b/app/models/tasks/hearing_admin_action_task.rb index 69854ad066c..215464e1464 100644 --- a/app/models/tasks/hearing_admin_action_task.rb +++ b/app/models/tasks/hearing_admin_action_task.rb @@ -48,12 +48,3 @@ def actions_allowable?(user) (HearingsManagement.singleton.user_has_access?(user) || HearingAdmin.singleton.user_has_access?(user)) && super end end - -require_dependency "hearing_admin_action_contested_claimant_task" -require_dependency "hearing_admin_action_foia_privacy_request_task" -require_dependency "hearing_admin_action_foreign_veteran_case_task" -require_dependency "hearing_admin_action_incarcerated_veteran_task" -require_dependency "hearing_admin_action_missing_forms_task" -require_dependency "hearing_admin_action_other_task" -require_dependency "hearing_admin_action_verify_address_task" -require_dependency "hearing_admin_action_verify_poa_task" diff --git a/app/models/tasks/mail_task.rb b/app/models/tasks/mail_task.rb index 88ef64e573c..4bf7cb8c76a 100644 --- a/app/models/tasks/mail_task.rb +++ b/app/models/tasks/mail_task.rb @@ -135,25 +135,3 @@ def create_twin_of_type(params) ) end end - -require_dependency "address_change_mail_task" -require_dependency "aod_motion_mail_task" -require_dependency "appeal_withdrawal_mail_task" -require_dependency "cavc_correspondence_mail_task" -require_dependency "clear_and_unmistakeable_error_mail_task" -require_dependency "congressional_interest_mail_task" -require_dependency "controlled_correspondence_mail_task" -require_dependency "death_certificate_mail_task" -require_dependency "docket_switch_mail_task" -require_dependency "evidence_or_argument_mail_task" -require_dependency "extension_request_mail_task" -require_dependency "foia_request_mail_task" -require_dependency "hearing_related_mail_task" -require_dependency "other_motion_mail_task" -require_dependency "power_of_attorney_related_mail_task" -require_dependency "privacy_act_request_mail_task" -require_dependency "privacy_complaint_mail_task" -require_dependency "reconsideration_motion_mail_task" -require_dependency "returned_undeliverable_correspondence_mail_task" -require_dependency "status_inquiry_mail_task" -require_dependency "vacate_motion_mail_task" diff --git a/app/models/user.rb b/app/models/user.rb index d218be4b0fc..0cb2d8021de 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class User < CaseflowRecord # rubocop:disable Metrics/ClassLength - include BgsService + include BGSServiceConcern include ConferenceableConcern include EventConcern diff --git a/app/models/vanotify/appeal_state.rb b/app/models/vanotify/appeal_state.rb deleted file mode 100644 index a30ce4707c9..00000000000 --- a/app/models/vanotify/appeal_state.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -class AppealState < CaseflowRecord - include HasAppealUpdatedSince - include AppealStateBelongsToPolymorphicAppealConcern -end diff --git a/app/serializers/api/v3/issues/vacols/vacols_issue_serializer.rb b/app/serializers/api/v3/issues/vacols/vacols_issue_serializer.rb index d3526984c50..7569e1eb28b 100644 --- a/app/serializers/api/v3/issues/vacols/vacols_issue_serializer.rb +++ b/app/serializers/api/v3/issues/vacols/vacols_issue_serializer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Api::V3::Issues::Vacols::VacolsIssueSerializer +class Api::V3::Issues::VACOLS::VacolsIssueSerializer include FastJsonapi::ObjectSerializer # attributes :vacols_issue diff --git a/app/services/api/v3/issues/vacols/vbms_vacols_dto_builder.rb b/app/services/api/v3/issues/vacols/vbms_vacols_dto_builder.rb index 7d65a3db422..dd61226a166 100644 --- a/app/services/api/v3/issues/vacols/vbms_vacols_dto_builder.rb +++ b/app/services/api/v3/issues/vacols/vbms_vacols_dto_builder.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true #:reek:TooManyInstanceVariables -class Api::V3::Issues::Vacols::VbmsVacolsDtoBuilder +class Api::V3::Issues::VACOLS::VbmsVacolsDtoBuilder attr_reader :hash_response, :vacols_issue_count def initialize(veteran, page, per_page) @@ -32,7 +32,7 @@ def serialized_vacols_issues(page = @page, offset = @offset) vacols_issues.push(AppealRepository.issues(id)) end - serialized_data = Api::V3::Issues::Vacols::VacolsIssueSerializer.new( + serialized_data = Api::V3::Issues::VACOLS::VacolsIssueSerializer.new( Kaminari.paginate_array(vacols_issues.flatten).page(page).per(offset) ).serializable_hash[:data] diff --git a/app/services/claim_change_history/claim_history_event.rb b/app/services/claim_change_history/claim_history_event.rb index fd80259e661..47fae3453c0 100644 --- a/app/services/claim_change_history/claim_history_event.rb +++ b/app/services/claim_change_history/claim_history_event.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -class InvalidEventType < StandardError - def initialize(event_type) - super("Invalid event type: #{event_type}") - end -end - # :reek:TooManyInstanceVariables # :reek:TooManyConstants # rubocop:disable Metrics/ClassLength class ClaimHistoryEvent + class InvalidEventType < StandardError + def initialize(event_type) + super("Invalid event type: #{event_type}") + end + end + attr_reader :task_id, :event_type, :event_date, :assigned_at, :days_waiting, :veteran_file_number, :claim_type, :claimant_name, :user_facility, :benefit_type, :issue_type, :issue_description, :decision_date, diff --git a/app/services/external_api/vbms_service.rb b/app/services/external_api/vbms_service.rb index 96b2b5354e2..ac1100903a6 100644 --- a/app/services/external_api/vbms_service.rb +++ b/app/services/external_api/vbms_service.rb @@ -1,26 +1,5 @@ # frozen_string_literal: true -# :nocov: -class VBMSCaseflowLogger - def log(event, data) - case event - when :request - status = data[:response_code] - - if status != 200 - Rails.logger.error( - "VBMS HTTP Error #{status} (#{data.pretty_inspect})" - ) - else - Rails.logger.info( - "VBMS HTTP Success #{status} (#{data.pretty_inspect})" - ) - end - end - end -end -# :nocov: - class ExternalApi::VBMSService def self.fetch_document_file(document) DBService.release_db_connections diff --git a/app/services/vbms_caseflow_logger.rb b/app/services/vbms_caseflow_logger.rb new file mode 100644 index 00000000000..6eb42e3c1a2 --- /dev/null +++ b/app/services/vbms_caseflow_logger.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class VBMSCaseflowLogger + def log(event, data) + case event + when :request + status = data[:response_code] + + if status != 200 + Rails.logger.error( + "VBMS HTTP Error #{status} (#{data.pretty_inspect})" + ) + else + Rails.logger.info( + "VBMS HTTP Success #{status} (#{data.pretty_inspect})" + ) + end + end + end +end diff --git a/config/application.rb b/config/application.rb index fba36ffb18a..44d7991b8f4 100644 --- a/config/application.rb +++ b/config/application.rb @@ -13,7 +13,6 @@ module CaseflowCertification class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.1 - config.autoloader = :classic # Configuration for the application, engines, and railties goes here. # @@ -135,9 +134,113 @@ class Application < Rails::Application # setup the deploy env environment variable ENV['DEPLOY_ENV'] ||= Rails.env - config.eager_load_paths << Rails.root.join('lib') - config.eager_load_paths += Dir[Rails.root.join('app', 'models', '{**}', '{**}')] - config.eager_load_paths += Dir[Rails.root.join('app', 'serializers', '{**}')] + # ------------------------------------------------------------------------------------------------------------------ + # Autoloading & Eager loading + # ------------------------------------------------------------------------------------------------------------------ + + # Uncomment the line below to enable autoloader logging for troubleshooting + # Rails.autoloaders.log! + + Rails.autoloaders.each do |autoloader| + autoloader.inflector.inflect( + "amo_metrics_report_job" => "AMOMetricsReportJob", + "appeals_for_poa" => "AppealsForPOA", + "bgs_service" => "BGSService", + "bgs_service_concern" => "BGSServiceConcern", + "bgs_service_grants" => "BGSServiceGrants", + "bgs_service_poa" => "BGSServicePOA", + "bgs_service_record_maker" => "BGSServiceRecordMaker", + "bva_appeal_status" => "BVAAppealStatus", + "cavc_case_decision" => "CAVCCaseDecision", + "cavc_decision" => "CAVCDecision", + "cavc_decision_repository" => "CAVCDecisionRepository", + "cda_control_group" => "CDAControlGroup", + "db_service" => "DBService", + "decision_review_polymorphic_sti_helper" => "DecisionReviewPolymorphicSTIHelper", + "duplicate_veteran_participant_id_finder" => "DuplicateVeteranParticipantIDFinder", + "etl" => "ETL", + "etl_builder_job" => "ETLBuilderJob", + "etl_classes" => "ETLClasses", + "hlr_status_serializer" => "HLRStatusSerializer", + "mpi_service" => "MPIService", + "sc_status_serializer" => "SCStatusSerializer", + "sync_attributes_with_bgs" => "SyncAttributesWithBGS", + "update_poa_concern" => "UpdatePOAConcern", + "va_dot_gov_service" => "VADotGovService", + "va_notify_send_message_template" => "VANotifySendMessageTemplate", + "va_notify_service" => "VANotifyService", + "vacols" => "VACOLS", + "vacols_csv_reader" => "VacolsCSVReader", + "vbms_caseflow_logger" => "VBMSCaseflowLogger", + "vbms_request" => "VBMSRequest", + "vbms_service" => "VBMSService", + "veteran_record_requests_open_for_vre_query" => "VeteranRecordRequestsOpenForVREQuery", + ) + end + + config.autoload_paths += [ + "#{root}/lib", + ] + + config.eager_load_paths += [ + "#{root}/lib", + ] + + # Ensure that all STI models are eager loaded, even when eager loading is disabled for the environment. + # Single Table Inheritance doesn't play well with lazy loading: Active Record has to be aware of STI hierarchies + # to work correctly, but when lazy loading, classes are only loaded only on demand. + # To address this fundamental mismatch, we need to preload STIs when eager loading is disabled. + # + # See https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#single-table-inheritance + unless config.eager_load + Rails.application.config.to_prepare do + # [TECH DEBT] Because we have so many STI models, it was deemed more pragmatic in the moment to just preload the + # entire models directory. In the future, we may wish to consider a more targeted approach, such as moving all + # STI models into their own dedicated sub-directories and then selectively preloading them instead. + Rails.autoloaders.main.eager_load_dir("#{Rails.root}/app/models") + end + end + + Rails.autoloaders.main.collapse( + "#{root}/app/jobs/batch_processes", + "#{root}/app/models/batch_processes", + "#{root}/app/models/dockets", + "#{root}/app/models/events", + "#{root}/app/models/external_models", + "#{root}/app/models/hearings", + "#{root}/app/models/hearings/forms", + "#{root}/app/models/legacy_tasks", + "#{root}/app/models/mixins", + "#{root}/app/models/organizations", + "#{root}/app/models/prepend", + "#{root}/app/models/prepend/va_notify", + "#{root}/app/models/priority_queues", + "#{root}/app/models/queue_tabs", + "#{root}/app/models/queues", + "#{root}/app/models/serializers", + "#{root}/app/models/tasks", + "#{root}/app/models/tasks/docket_switch", + "#{root}/app/models/tasks/hearing_mail_tasks", + "#{root}/app/models/tasks/pre_docket", + "#{root}/app/models/tasks/special_case_movement", + "#{root}/app/models/validators", + "#{root}/app/models/vanotify", + "#{root}/app/serializers/case_distribution", + "#{root}/app/serializers/hearings", + "#{root}/app/services/claim_change_history", + "#{root}/lib/helpers", + ) + + Rails.autoloaders.main.ignore( + "#{root}/app/jobs/middleware", + "#{root}/lib/assets", + "#{root}/lib/pdfs", + "#{root}/lib/tasks", + "#{root}/lib/deprecation_warnings.rb", + "#{root}/lib/helpers/console_methods.rb" + ) + + # ================================================================================================================== config.exceptions_app = self.routes diff --git a/config/environments/development.rb b/config/environments/development.rb index 28728d3da24..f850fc36a4d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,5 +1,5 @@ require "active_support/core_ext/integer/time" -require_relative "../../config/initializers/deprecation_warnings" +require_relative "../../lib/deprecation_warnings" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -14,8 +14,8 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Eager load code on boot. - config.eager_load = true + # Do not eager load code on boot. + config.eager_load = false # Show full error reports. config.consider_all_requests_local = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 7b727b5a6ff..7d3394a853f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,6 +1,5 @@ require "active_support/core_ext/integer/time" -require_relative "../../app/services/deprecation_warnings/production_handler" -require_relative "../../config/initializers/deprecation_warnings" +require_relative "../../lib/deprecation_warnings" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/environments/test.rb b/config/environments/test.rb index 449d8849b23..2db5f9fadff 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,6 +1,6 @@ require "active_support/core_ext/integer/time" require "fileutils" -require_relative "../../config/initializers/deprecation_warnings" +require_relative "../../lib/deprecation_warnings" # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that diff --git a/config/initializers/activerecord_types.rb b/config/initializers/activerecord_types.rb index a6bf1be9411..25a62b75671 100644 --- a/config/initializers/activerecord_types.rb +++ b/config/initializers/activerecord_types.rb @@ -1,16 +1,16 @@ # frozen_string_literal: true -# Custom column types, particularly for VACOLS +Rails.application.config.to_prepare do + # Custom column types, particularly for VACOLS -require "helpers/ascii_converter" + class AsciiString < ActiveRecord::Type::Text + private -class AsciiString < ActiveRecord::Type::Text - private - - def cast_value(value) - ascii_value = AsciiConverter.new(string: value.to_s).convert - limit ? ascii_value[0, limit] : ascii_value + def cast_value(value) + ascii_value = AsciiConverter.new(string: value.to_s).convert + limit ? ascii_value[0, limit] : ascii_value + end end -end -ActiveRecord::Type.register(:ascii_string, AsciiString) + ActiveRecord::Type.register(:ascii_string, AsciiString) +end diff --git a/config/initializers/bgs.rb b/config/initializers/bgs.rb deleted file mode 100644 index 4275648de68..00000000000 --- a/config/initializers/bgs.rb +++ /dev/null @@ -1 +0,0 @@ -BGSService = (!ApplicationController.dependencies_faked? ? ExternalApi::BGSService : Fakes::BGSService) \ No newline at end of file diff --git a/config/initializers/bgs_service.rb b/config/initializers/bgs_service.rb new file mode 100644 index 00000000000..c549e75e7f4 --- /dev/null +++ b/config/initializers/bgs_service.rb @@ -0,0 +1,3 @@ +Rails.application.config.to_prepare do + BGSService = (!ApplicationController.dependencies_faked? ? ExternalApi::BGSService : Fakes::BGSService) +end diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 6f7480873f2..473dab5a448 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -1,40 +1,42 @@ # frozen_string_literal: true -# https://stackoverflow.com/questions/26809848/convert-hash-to-object -class Subconstant - class << self - def build_constants_module(module_name:, path_attributes:) - Object.const_set(module_name, Module.new) - constants_module = Object.const_get(module_name) - Dir.glob(File.join(Rails.root, *path_attributes)).each do |filepath| - constant_name = filepath.split("/").last.split(".").first - file_contents = JSON.parse(File.read(filepath)) +Rails.application.config.before_initialize do + # https://stackoverflow.com/questions/26809848/convert-hash-to-object + class Subconstant + class << self + def build_constants_module(module_name:, path_attributes:) + Object.const_set(module_name, Module.new) + constants_module = Object.const_get(module_name) + Dir.glob(File.join(Rails.root, *path_attributes)).each do |filepath| + constant_name = filepath.split("/").last.split(".").first + file_contents = JSON.parse(File.read(filepath)) - # Access via hash (i.e. Constants::BENEFIT_TYPES["compensation"]) to access keys. - constants_module.const_set(constant_name.to_s, file_contents) + # Access via hash (i.e. Constants::BENEFIT_TYPES["compensation"]) to access keys. + constants_module.const_set(constant_name.to_s, file_contents) - # Access via methods (i.e. Constants.BENEFIT_TYPES.compensation) to throw errors - # when incorrectly addressing constants. - constants_module.define_singleton_method(constant_name) { Subconstant.new(file_contents) } + # Access via methods (i.e. Constants.BENEFIT_TYPES.compensation) to throw errors + # when incorrectly addressing constants. + constants_module.define_singleton_method(constant_name) { Subconstant.new(file_contents) } + end end end - end - def initialize(hash_in) - hash_in.each do |hash_key, hash_value| - define_singleton_method(hash_key) { hash_value.is_a?(Hash) ? Subconstant.new(hash_value) : hash_value } + def initialize(hash_in) + hash_in.each do |hash_key, hash_value| + define_singleton_method(hash_key) { hash_value.is_a?(Hash) ? Subconstant.new(hash_value) : hash_value } + end end - end - def to_h - hash_out = {} - singleton_methods.each do |method_name| - call_value = singleton_method(method_name).call - hash_out[method_name] = call_value.is_a?(Subconstant) ? call_value.to_h : call_value + def to_h + hash_out = {} + singleton_methods.each do |method_name| + call_value = singleton_method(method_name).call + hash_out[method_name] = call_value.is_a?(Subconstant) ? call_value.to_h : call_value + end + hash_out end - hash_out end -end -Subconstant.build_constants_module(module_name: "Constants", path_attributes: ["client", "constants", "*"]) -Subconstant.build_constants_module(module_name: "FakeConstants", path_attributes: ["lib", "fakes", "constants", "*"]) + Subconstant.build_constants_module(module_name: "Constants", path_attributes: ["client", "constants", "*"]) + Subconstant.build_constants_module(module_name: "FakeConstants", path_attributes: ["lib", "fakes", "constants", "*"]) +end diff --git a/config/initializers/copy.rb b/config/initializers/copy.rb index cf726dcce24..8416e6017c1 100644 --- a/config/initializers/copy.rb +++ b/config/initializers/copy.rb @@ -1,4 +1,6 @@ -COPY = Module.new +Rails.application.config.before_initialize do + COPY = Module.new -json_obj = JSON.parse(File.read(File.join(Rails.root, "client", "COPY.json"))) -json_obj.each_key { |k| COPY.const_set(k, json_obj[k]) } + json_obj = JSON.parse(File.read(File.join(Rails.root, "client", "COPY.json"))) + json_obj.each_key { |k| COPY.const_set(k, json_obj[k]) } +end diff --git a/config/initializers/deprecation_warnings.rb b/config/initializers/deprecation_warnings.rb deleted file mode 100644 index 4d102c4e702..00000000000 --- a/config/initializers/deprecation_warnings.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -module DeprecationWarnings - # Regular expressions for custom deprecation warnings that we have addressed in the codebase - CUSTOM_DEPRECATION_WARNING_REGEXES = [ - /Caseflow::Migration is deprecated/ - ].freeze - - # Regular expressions for Rails 6.0 deprecation warnings that we have addressed in the codebase - RAILS_6_0_FIXED_DEPRECATION_WARNING_REGEXES = [ - /Dangerous query method \(method whose arguments are used as raw SQL\) called with non\-attribute argument\(s\)/, - /The success\? predicate is deprecated and will be removed in Rails 6\.0/ - ].freeze - - # Regular expressions for Rails 6.1 deprecation warnings that we have addressed in the codebase - RAILS_6_1_FIXED_DEPRECATION_WARNING_REGEXES = [ - /update_attributes is deprecated and will be removed from Rails 6\.1/, - /ActionView::Base instances should be constructed with a lookup context, assignments, and a controller./, - /ActionView::Base instances must implement `compiled_method_container`/, - /render file: should be given the absolute path to a file/, - /`ActiveRecord::Result#to_hash` has been renamed to `to_a`/, - /Class level methods will no longer inherit scoping/, - /Controller-level `force_ssl` is deprecated and will be removed from Rails 6\.1/, - /NOT conditions will no longer behave as NOR in Rails 6\.1/ - ].freeze - - # Regular expressions for deprecation warnings that should raise an exception on detection - DISALLOWED_DEPRECATION_WARNING_REGEXES = [ - *CUSTOM_DEPRECATION_WARNING_REGEXES, - *RAILS_6_0_FIXED_DEPRECATION_WARNING_REGEXES, - *RAILS_6_1_FIXED_DEPRECATION_WARNING_REGEXES - ].freeze -end diff --git a/config/initializers/efolder.rb b/config/initializers/efolder.rb deleted file mode 100644 index 661649fd3ae..00000000000 --- a/config/initializers/efolder.rb +++ /dev/null @@ -1,6 +0,0 @@ -EFolderService = - if !ApplicationController.dependencies_faked? || Rails.application.config.use_efolder_locally - ExternalApi::EfolderService - else - Fakes::VBMSService - end diff --git a/config/initializers/efolder_service.rb b/config/initializers/efolder_service.rb new file mode 100644 index 00000000000..e7ee597531d --- /dev/null +++ b/config/initializers/efolder_service.rb @@ -0,0 +1,8 @@ +Rails.application.config.to_prepare do + EFolderService = + if !ApplicationController.dependencies_faked? || Rails.application.config.use_efolder_locally + ExternalApi::EfolderService + else + Fakes::VBMSService + end +end diff --git a/config/initializers/fake_dependencies.rb b/config/initializers/fake_dependencies.rb index 938ec118585..d932a9e1325 100644 --- a/config/initializers/fake_dependencies.rb +++ b/config/initializers/fake_dependencies.rb @@ -1 +1,3 @@ -Fakes::Initializer.app_init!(Rails.env) +Rails.application.config.after_initialize do + Fakes::Initializer.app_init!(Rails.env) +end diff --git a/config/initializers/gov_delivery.rb b/config/initializers/gov_delivery.rb deleted file mode 100644 index f940a5a771d..00000000000 --- a/config/initializers/gov_delivery.rb +++ /dev/null @@ -1,5 +0,0 @@ -GovDeliveryService = if ApplicationController.dependencies_faked? - Fakes::GovDeliveryService - else - ExternalApi::GovDeliveryService - end diff --git a/config/initializers/gov_delivery_service.rb b/config/initializers/gov_delivery_service.rb new file mode 100644 index 00000000000..ab37618c113 --- /dev/null +++ b/config/initializers/gov_delivery_service.rb @@ -0,0 +1,7 @@ +Rails.application.config.to_prepare do + GovDeliveryService = if ApplicationController.dependencies_faked? + Fakes::GovDeliveryService + else + ExternalApi::GovDeliveryService + end +end diff --git a/config/initializers/mpi.rb b/config/initializers/mpi.rb deleted file mode 100644 index 5f92806c458..00000000000 --- a/config/initializers/mpi.rb +++ /dev/null @@ -1 +0,0 @@ -MPIService = (!ApplicationController.dependencies_faked? ? ExternalApi::MPIService : Fakes::MPIService) diff --git a/config/initializers/mpi_service.rb b/config/initializers/mpi_service.rb new file mode 100644 index 00000000000..43774dc1ebd --- /dev/null +++ b/config/initializers/mpi_service.rb @@ -0,0 +1,3 @@ +Rails.application.config.to_prepare do + MPIService = (!ApplicationController.dependencies_faked? ? ExternalApi::MPIService : Fakes::MPIService) +end diff --git a/config/initializers/oci8.rb b/config/initializers/oci8.rb new file mode 100644 index 00000000000..e906590c58f --- /dev/null +++ b/config/initializers/oci8.rb @@ -0,0 +1,7 @@ +# configure timeouts, in seconds, for underlying socket in environments that use Oracle +if defined? OCI8 + OCI8.properties[:tcp_connect_timeout] = 10 + OCI8.properties[:connect_timeout] = 10 + OCI8.properties[:send_timeout] = 10 + OCI8.properties[:recv_timeout] = 20 +end diff --git a/config/initializers/pacman.rb b/config/initializers/pacman.rb deleted file mode 100644 index 481795e510d..00000000000 --- a/config/initializers/pacman.rb +++ /dev/null @@ -1 +0,0 @@ -PacmanService = (ApplicationController.dependencies_faked? ? Fakes::PacmanService : ExternalApi::PacmanService) diff --git a/config/initializers/pacman_service.rb b/config/initializers/pacman_service.rb new file mode 100644 index 00000000000..9cca48ed324 --- /dev/null +++ b/config/initializers/pacman_service.rb @@ -0,0 +1,3 @@ +Rails.application.config.to_prepare do + PacmanService = (ApplicationController.dependencies_faked? ? Fakes::PacmanService : ExternalApi::PacmanService) +end diff --git a/config/initializers/paper_trail.rb b/config/initializers/paper_trail.rb index f38a3c6b716..20784a8330a 100644 --- a/config/initializers/paper_trail.rb +++ b/config/initializers/paper_trail.rb @@ -1,7 +1,11 @@ -module PaperTrail - class Version < ActiveRecord::Base - def user - User.find(whodunnit.to_i) +Rails.application.config.to_prepare do + require "paper_trail" + + module PaperTrail + class Version < ActiveRecord::Base + def user + User.find(whodunnit.to_i) + end end end end diff --git a/config/initializers/pexip.rb b/config/initializers/pexip.rb deleted file mode 100644 index 0cc6eb3bd58..00000000000 --- a/config/initializers/pexip.rb +++ /dev/null @@ -1 +0,0 @@ -PexipService = (ApplicationController.dependencies_faked? ? Fakes::PexipService : ExternalApi::PexipService) diff --git a/config/initializers/pexip_service.rb b/config/initializers/pexip_service.rb new file mode 100644 index 00000000000..ac85e8e5b3b --- /dev/null +++ b/config/initializers/pexip_service.rb @@ -0,0 +1,3 @@ +Rails.application.config.to_prepare do + PexipService = (ApplicationController.dependencies_faked? ? Fakes::PexipService : ExternalApi::PexipService) +end diff --git a/config/initializers/rails_erd.rb b/config/initializers/rails_erd.rb index 4489663a9dd..e9d9f51cc51 100644 --- a/config/initializers/rails_erd.rb +++ b/config/initializers/rails_erd.rb @@ -1,10 +1,14 @@ -module RailsERD - class Domain - class << self - # since we have 3 dbs we must override to specify a specific base class (NOT ActiveRecord::Base) - def generate(options = {}) - base_class = ENV.fetch("ERD_BASE", "ApplicationRecord").constantize - new base_class.descendants, options +Rails.application.config.after_initialize do + require "rails-erd" + + module RailsERD + class Domain + class << self + # since we have 3 dbs we must override to specify a specific base class (NOT ActiveRecord::Base) + def generate(options = {}) + base_class = ENV.fetch("ERD_BASE", "ApplicationRecord").constantize + new base_class.descendants, options + end end end end diff --git a/config/initializers/s3.rb b/config/initializers/s3.rb deleted file mode 100644 index 6de397ef207..00000000000 --- a/config/initializers/s3.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'caseflow' - -S3Service = (Rails.application.config.s3_enabled ? Caseflow::S3Service : Caseflow::Fakes::S3Service) \ No newline at end of file diff --git a/config/initializers/s3_service.rb b/config/initializers/s3_service.rb new file mode 100644 index 00000000000..b9168d07710 --- /dev/null +++ b/config/initializers/s3_service.rb @@ -0,0 +1,5 @@ +Rails.application.config.to_prepare do + require 'caseflow' + + S3Service = (Rails.application.config.s3_enabled ? Caseflow::S3Service : Caseflow::Fakes::S3Service) +end diff --git a/config/initializers/scheduled_jobs.rb b/config/initializers/scheduled_jobs.rb index 47b15b656ae..21a3fa6624e 100644 --- a/config/initializers/scheduled_jobs.rb +++ b/config/initializers/scheduled_jobs.rb @@ -1,56 +1,55 @@ -require "./app/jobs/batch_processes/priority_ep_sync_batch_process_job.rb" -require "./app/jobs/batch_processes/batch_process_rescue_job.rb" - -SCHEDULED_JOBS = { - "amo_metrics_report" => AMOMetricsReportJob, - "annual_metrics" => AnnualMetricsReportJob, - "priority_ep_sync_batch_process_job" => PriorityEpSyncBatchProcessJob, - "batch_process_rescue_job" => BatchProcessRescueJob, - "create_establish_claim" => CreateEstablishClaimTasksJob, - "data_integrity_checks" => DataIntegrityChecksJob, - "delete_conferences_job" => VirtualHearings::DeleteConferencesJob, - "delete_conference_link_job" => VirtualHearings::DeleteConferenceLinkJob, - "dependencies_check" => DependenciesCheckJob, - "dependencies_report_service_log" => DependenciesReportServiceLogJob, - "docket_range_job" => DocketRangeJob, - "duplicate_ep_remediation_job" => DuplicateEpRemediationJob, - "etl_builder" => ETLBuilderJob, - "fetch_hearing_locations_for_veterans_job" => FetchHearingLocationsForVeteransJob, - "foreign_key_polymorphic_association_job" => ForeignKeyPolymorphicAssociationJob, - "hearing_disposition_change_job" => HearingDispositionChangeJob, - "hearing_email_status_job" => Hearings::HearingEmailStatusJob, - "heartbeat" => HeartbeatTasksJob, - "incomplete_distributions_job" => IncompleteDistributionsJob, - "monthly_metrics" => MonthlyMetricsReportJob, - "nightly_syncs" => NightlySyncsJob, - "out_of_service_reminder" => OutOfServiceReminderJob, - "prepare_establish_claim" => PrepareEstablishClaimTasksJob, - "push_priority_appeals_to_judges" => PushPriorityAppealsToJudgesJob, - "quarterly_metrics" => QuarterlyMetricsReportJob, - "quarterly_notifications_job" => QuarterlyNotificationsJob, - "reassign_old_tasks" => ReassignOldTasksJob, - "retrieve_documents_for_reader" => RetrieveDocumentsForReaderJob, - "send_reminder_emails_job" => Hearings::SendReminderEmailsJob, - "set_appeal_age_aod" => SetAppealAgeAodJob, - "stats_collector" => StatsCollectorJob, - "sync_intake" => SyncIntakeJob, - "sync_reviews" => SyncReviewsJob, - "take_docket_snapshot" => TakeDocketSnapshotJob, - "task_timer_job" => TaskTimerJob, - "update_appellant_representation_job" => UpdateAppellantRepresentationJob, - "update_cached_appeals_attributes_job" => UpdateCachedAppealsAttributesJob, - "warm_bgs_caches_job" => WarmBgsCachesJob, - "poll_docketed_legacy_appeals_job" => PollDocketedLegacyAppealsJob, - "retrieve_and_cache_reader_documents_job" => RetrieveAndCacheReaderDocumentsJob, - "travel_board_hearing_sync_job" => Hearings::TravelBoardHearingSyncJob, - "ama_notification_efolder_sync_job" => AmaNotificationEfolderSyncJob, - "legacy_notification_efolder_sync_job" => LegacyNotificationEfolderSyncJob, - "change_hearing_request_type_task_cancellation_job" => ChangeHearingRequestTypeTaskCancellationJob, - "cannot_delete_contention_remediation_job" => CannotDeleteContentionRemediationJob, - "contention_not_found_remediation_job" => ContentionNotFoundRemediationJob, - "process_notification_status_updates_job" => ProcessNotificationStatusUpdatesJob, - "stuck_job_scheduler_job" => StuckJobSchedulerJob, - "fetch_webex_rooms_list_job" => Hearings::FetchWebexRoomsListJob, - "refresh_webex_access_token_job" => Hearings::RefreshWebexAccessTokenJob, - "ineligible_judges_job" => IneligibleJudgesJob -}.freeze +Rails.application.config.to_prepare do + SCHEDULED_JOBS = { + "amo_metrics_report" => AMOMetricsReportJob, + "annual_metrics" => AnnualMetricsReportJob, + "priority_ep_sync_batch_process_job" => PriorityEpSyncBatchProcessJob, + "batch_process_rescue_job" => BatchProcessRescueJob, + "create_establish_claim" => CreateEstablishClaimTasksJob, + "data_integrity_checks" => DataIntegrityChecksJob, + "delete_conferences_job" => VirtualHearings::DeleteConferencesJob, + "delete_conference_link_job" => VirtualHearings::DeleteConferenceLinkJob, + "dependencies_check" => DependenciesCheckJob, + "dependencies_report_service_log" => DependenciesReportServiceLogJob, + "docket_range_job" => DocketRangeJob, + "duplicate_ep_remediation_job" => DuplicateEpRemediationJob, + "etl_builder" => ETLBuilderJob, + "fetch_hearing_locations_for_veterans_job" => FetchHearingLocationsForVeteransJob, + "foreign_key_polymorphic_association_job" => ForeignKeyPolymorphicAssociationJob, + "hearing_disposition_change_job" => HearingDispositionChangeJob, + "hearing_email_status_job" => Hearings::HearingEmailStatusJob, + "heartbeat" => HeartbeatTasksJob, + "incomplete_distributions_job" => IncompleteDistributionsJob, + "monthly_metrics" => MonthlyMetricsReportJob, + "nightly_syncs" => NightlySyncsJob, + "out_of_service_reminder" => OutOfServiceReminderJob, + "prepare_establish_claim" => PrepareEstablishClaimTasksJob, + "push_priority_appeals_to_judges" => PushPriorityAppealsToJudgesJob, + "quarterly_metrics" => QuarterlyMetricsReportJob, + "quarterly_notifications_job" => QuarterlyNotificationsJob, + "reassign_old_tasks" => ReassignOldTasksJob, + "retrieve_documents_for_reader" => RetrieveDocumentsForReaderJob, + "send_reminder_emails_job" => Hearings::SendReminderEmailsJob, + "set_appeal_age_aod" => SetAppealAgeAodJob, + "stats_collector" => StatsCollectorJob, + "sync_intake" => SyncIntakeJob, + "sync_reviews" => SyncReviewsJob, + "take_docket_snapshot" => TakeDocketSnapshotJob, + "task_timer_job" => TaskTimerJob, + "update_appellant_representation_job" => UpdateAppellantRepresentationJob, + "update_cached_appeals_attributes_job" => UpdateCachedAppealsAttributesJob, + "warm_bgs_caches_job" => WarmBgsCachesJob, + "poll_docketed_legacy_appeals_job" => PollDocketedLegacyAppealsJob, + "retrieve_and_cache_reader_documents_job" => RetrieveAndCacheReaderDocumentsJob, + "travel_board_hearing_sync_job" => Hearings::TravelBoardHearingSyncJob, + "ama_notification_efolder_sync_job" => AmaNotificationEfolderSyncJob, + "legacy_notification_efolder_sync_job" => LegacyNotificationEfolderSyncJob, + "change_hearing_request_type_task_cancellation_job" => ChangeHearingRequestTypeTaskCancellationJob, + "cannot_delete_contention_remediation_job" => CannotDeleteContentionRemediationJob, + "contention_not_found_remediation_job" => ContentionNotFoundRemediationJob, + "process_notification_status_updates_job" => ProcessNotificationStatusUpdatesJob, + "stuck_job_scheduler_job" => StuckJobSchedulerJob, + "fetch_webex_rooms_list_job" => Hearings::FetchWebexRoomsListJob, + "refresh_webex_access_token_job" => Hearings::RefreshWebexAccessTokenJob, + "ineligible_judges_job" => IneligibleJudgesJob + }.freeze +end diff --git a/config/initializers/standard_error.rb b/config/initializers/standard_error.rb new file mode 100644 index 00000000000..c9b13f2703d --- /dev/null +++ b/config/initializers/standard_error.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +Rails.application.config.before_initialize do + class StandardError + def ignorable? + false + end + end +end diff --git a/config/initializers/va_dot_gov.rb b/config/initializers/va_dot_gov.rb deleted file mode 100644 index ab6aa3bb1b5..00000000000 --- a/config/initializers/va_dot_gov.rb +++ /dev/null @@ -1 +0,0 @@ -VADotGovService = (ApplicationController.dependencies_faked? ? Fakes::VADotGovService : ExternalApi::VADotGovService) diff --git a/config/initializers/va_dot_gov_service.rb b/config/initializers/va_dot_gov_service.rb new file mode 100644 index 00000000000..13e443f1304 --- /dev/null +++ b/config/initializers/va_dot_gov_service.rb @@ -0,0 +1,3 @@ +Rails.application.config.to_prepare do + VADotGovService = (ApplicationController.dependencies_faked? ? Fakes::VADotGovService : ExternalApi::VADotGovService) +end diff --git a/config/initializers/va_notify.rb b/config/initializers/va_notify.rb deleted file mode 100644 index 80d05092136..00000000000 --- a/config/initializers/va_notify.rb +++ /dev/null @@ -1,6 +0,0 @@ -case Rails.deploy_env -when :uat, :prod - VANotifyService = ExternalApi::VANotifyService -else - VANotifyService = Fakes::VANotifyService -end diff --git a/config/initializers/va_notify_service.rb b/config/initializers/va_notify_service.rb new file mode 100644 index 00000000000..b4f330a98a1 --- /dev/null +++ b/config/initializers/va_notify_service.rb @@ -0,0 +1,8 @@ +Rails.application.config.to_prepare do + case Rails.deploy_env + when :uat, :prod + VANotifyService = ExternalApi::VANotifyService + else + VANotifyService = Fakes::VANotifyService + end +end diff --git a/config/initializers/vacols_request_spy.rb b/config/initializers/vacols_request_spy.rb index d79b92df7d6..7cdcfce10dc 100644 --- a/config/initializers/vacols_request_spy.rb +++ b/config/initializers/vacols_request_spy.rb @@ -1,50 +1,52 @@ # frozen_string_literal: true -if DatabaseRequestCounter.valid_env? +Rails.application.config.after_initialize do + if DatabaseRequestCounter.valid_env? - EXCLUDED_PATTERNS = [ - # Ignore the following request to describe the database since they will only happen once in the lifetime of the - # Rails app and may happen at different times based on the order the tests run. - # - # Table columns: - # https://github.com/rsim/oracle-enhanced/blob/1272b3c58d082930514e625182a14a729e1e693e/lib/active_record/... - # connection_adapters/oracle_enhanced_adapter.rb#L559 - "FROM all_tab_cols cols", - # Table sequences: - # https://github.com/rsim/oracle-enhanced/blob/1272b3c58d082930514e625182a14a729e1e693e/lib/active_record/... - # connection_adapters/oracle_enhanced_adapter.rb#L591 - "from all_sequences", - # Table primary keys: - # https://github.com/rsim/oracle-enhanced/blob/1272b3c58d082930514e625182a14a729e1e693e/lib/active_record/... - # connection_adapters/oracle_enhanced_adapter.rb#L591 - "FROM all_constraints" - ].freeze + EXCLUDED_PATTERNS = [ + # Ignore the following request to describe the database since they will only happen once in the lifetime of the + # Rails app and may happen at different times based on the order the tests run. + # + # Table columns: + # https://github.com/rsim/oracle-enhanced/blob/1272b3c58d082930514e625182a14a729e1e693e/lib/active_record/... + # connection_adapters/oracle_enhanced_adapter.rb#L559 + "FROM all_tab_cols cols", + # Table sequences: + # https://github.com/rsim/oracle-enhanced/blob/1272b3c58d082930514e625182a14a729e1e693e/lib/active_record/... + # connection_adapters/oracle_enhanced_adapter.rb#L591 + "from all_sequences", + # Table primary keys: + # https://github.com/rsim/oracle-enhanced/blob/1272b3c58d082930514e625182a14a729e1e693e/lib/active_record/... + # connection_adapters/oracle_enhanced_adapter.rb#L591 + "FROM all_constraints" + ].freeze - def vacols_request_spy(statement) - unless statement.match?(Regexp.union(EXCLUDED_PATTERNS)) - simulate_vacols_latency - DatabaseRequestCounter.increment_counter(:vacols) + def vacols_request_spy(statement) + unless statement.match?(Regexp.union(EXCLUDED_PATTERNS)) + simulate_vacols_latency + DatabaseRequestCounter.increment_counter(:vacols) + end end - end - - def simulate_vacols_latency - # Simulate VACOLS latency by running something the Rails server by using something like the following: - # $> REACT_ON_RAILS_ENV=HOT SIMULATE_VACOLS_LATENCY=true bundle exec rails s -p 3000 - return unless ENV["SIMULATE_VACOLS_LATENCY"] - latency = ENV["VACOLS_DELAY_MS"] || 80 - sleep(latency / 1000.0) - end + def simulate_vacols_latency + # Simulate VACOLS latency by running something the Rails server by using something like the following: + # $> REACT_ON_RAILS_ENV=HOT SIMULATE_VACOLS_LATENCY=true bundle exec rails s -p 3000 + return unless ENV["SIMULATE_VACOLS_LATENCY"] - class ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter - def execute(*args) - vacols_request_spy(args.first) - super + latency = ENV["VACOLS_DELAY_MS"] || 80 + sleep(latency / 1000.0) end - def exec_query(*args) - vacols_request_spy(args.first) - super + class ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter + def execute(*args) + vacols_request_spy(args.first) + super + end + + def exec_query(*args) + vacols_request_spy(args.first) + super + end end end end diff --git a/config/initializers/vbms.rb b/config/initializers/vbms.rb deleted file mode 100644 index aa3cf63293d..00000000000 --- a/config/initializers/vbms.rb +++ /dev/null @@ -1,6 +0,0 @@ -VBMSService = (!ApplicationController.dependencies_faked? ? ExternalApi::VBMSService : Fakes::VBMSService) - -if ApplicationController.dependencies_faked? - VBMSService.manifest_vbms_fetched_at = Time.zone.now - VBMSService.manifest_vva_fetched_at = Time.zone.now -end \ No newline at end of file diff --git a/config/initializers/vbms_service.rb b/config/initializers/vbms_service.rb new file mode 100644 index 00000000000..9f012922865 --- /dev/null +++ b/config/initializers/vbms_service.rb @@ -0,0 +1,8 @@ +Rails.application.config.to_prepare do + VBMSService = (!ApplicationController.dependencies_faked? ? ExternalApi::VBMSService : Fakes::VBMSService) + + if ApplicationController.dependencies_faked? + VBMSService.manifest_vbms_fetched_at = Time.zone.now + VBMSService.manifest_vva_fetched_at = Time.zone.now + end +end diff --git a/config/initializers/warmup_vacols.rb b/config/initializers/warmup_vacols.rb deleted file mode 100644 index 053b49551f7..00000000000 --- a/config/initializers/warmup_vacols.rb +++ /dev/null @@ -1,65 +0,0 @@ -# VACOLS throttles the rate of new connections, create up front to prevent -# blocking as pool grows under load - -# configure timeouts, in seconds, for underlying socket in environments that use Oracle -if defined? OCI8 - OCI8.properties[:tcp_connect_timeout] = 10 - OCI8.properties[:connect_timeout] = 10 - OCI8.properties[:send_timeout] = 10 - OCI8.properties[:recv_timeout] = 20 -end - -WARMUP_TABLES = ["vacols.brieff", "vacols.corres", "vacols.folder"] - -ActiveSupport.on_load(:active_record_vacols) do - - # skip if accessing via 'rails c' - next if defined? Rails::Console - next if Rails.env.staging? || Rails.env.ssh_forwarding? - - db_config = Rails.application.config.database_configuration[Rails.env] - - # use specified initial pool size, default to half the maximum size - initial_pool_size = (ENV['DB_CONN_POOL_INITIAL_SIZE'] || db_config['primary']['pool'] / 2).to_i - Rails.logger.info("creating #{initial_pool_size} initial connections...") - - unless ApplicationController.dependencies_faked? - MetricsService.record("VACOLS: warmup_vacols #{initial_pool_size} connections", - service: :vacols, - name: "warmup_vacols") do - - warmup_pool(VACOLS::Record.connection_pool, initial_pool_size) - end - end -end - -def warmup_pool(pool, initial_pool_size) - threads = [] - latch = Concurrent::CountDownLatch.new(initial_pool_size) - - initial_pool_size.times do |i| - threads << Thread.new do - conn = pool.connection - Rails.logger.info("taking connection #{i}; db pool size: #{pool.connections.size}") - - latch.count_down - - # don't return the connection to the pool until all other threads have taken a connection; - # otherwise could take/putback the same connection initial_pool_size times - latch.wait() - Rails.logger.info("returning connection #{i}") - conn.close - end - end - - threads.each(&:join) - - # Warmup active record too, by querying for index & columns - conn = VACOLS::Record.connection - WARMUP_TABLES.each do |table_name| - Rails.logger.info("fetching indexes & columns for #{table_name}") - conn.indexes(table_name) - conn.columns(table_name) - end - conn.close -end diff --git a/config/initializers/webex.rb b/config/initializers/webex.rb index 561e795cc0f..de4509c4b23 100644 --- a/config/initializers/webex.rb +++ b/config/initializers/webex.rb @@ -1 +1,3 @@ -WebexService = (ApplicationController.dependencies_faked? ? Fakes::WebexService : ExternalApi::WebexService) +Rails.application.config.to_prepare do + WebexService = (ApplicationController.dependencies_faked? ? Fakes::WebexService : ExternalApi::WebexService) +end diff --git a/config/routes.rb b/config/routes.rb index 45431c98754..7fa833a51fc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -85,9 +85,7 @@ namespace :ama do get "find_by_veteran/:participant_id", to: "veterans#show" end - namespace :vacols do - get 'find_by_veteran', to: "veterans#show" # passing in ssn/vfn as a header - end + get 'vacols/find_by_veteran', to: "v_a_c_o_l_s/veterans#show" # passing in ssn/vfn as a header end end namespace :docs do diff --git a/db/etl_migrate/20241007132413_no_op_migration.rb b/db/etl_migrate/20241007132413_no_op_migration.rb new file mode 100644 index 00000000000..c11c5a2c32c --- /dev/null +++ b/db/etl_migrate/20241007132413_no_op_migration.rb @@ -0,0 +1,6 @@ +# @note This migration is for testing purposes only. +class NoOpMigration < ActiveRecord::Migration[6.1] + def change + # no-op + end +end diff --git a/db/etl_schema.rb b/db/etl_schema.rb index 29c81a2b524..e57bb929ba4 100644 --- a/db/etl_schema.rb +++ b/db/etl_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_06_17_205006) do +ActiveRecord::Schema.define(version: 2024_10_07_132413) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/db/migrate/20241007131619_no_op_migration.rb b/db/migrate/20241007131619_no_op_migration.rb new file mode 100644 index 00000000000..c11c5a2c32c --- /dev/null +++ b/db/migrate/20241007131619_no_op_migration.rb @@ -0,0 +1,6 @@ +# @note This migration is for testing purposes only. +class NoOpMigration < ActiveRecord::Migration[6.1] + def change + # no-op + end +end diff --git a/db/seeds/facols.rb b/db/seeds/facols.rb index a417c64bb35..8d53f9f19f6 100644 --- a/db/seeds/facols.rb +++ b/db/seeds/facols.rb @@ -3,8 +3,6 @@ # FACOLS (Fake VACOLS) seeds. # Called by rake task and as prereq for other Caseflow seeds. -require_relative "../../lib/helpers/vacols_csv_reader" - module Seeds class Facols < Base def seed! diff --git a/app/services/deprecation_warnings/production_handler.rb b/lib/deprecation_warnings.rb similarity index 74% rename from app/services/deprecation_warnings/production_handler.rb rename to lib/deprecation_warnings.rb index 7e4f70d0743..3322de8e958 100644 --- a/app/services/deprecation_warnings/production_handler.rb +++ b/lib/deprecation_warnings.rb @@ -1,7 +1,23 @@ # frozen_string_literal: true -# @note For use with `ActiveSupport::Deprecation.behavior=` or `Rails.application.config.active_support.deprecation=` module DeprecationWarnings + # Regular expressions for custom deprecation warnings that we have addressed in the codebase + CUSTOM_DEPRECATION_WARNING_REGEXES = [ + /Caseflow::Migration is deprecated/ + ].freeze + + # Regular expressions for Rails 7.0 deprecation warnings that we have addressed in the codebase + RAILS_7_0_FIXED_DEPRECATION_WARNING_REGEXES = [ + /Initialization autoloaded the constant/ + ].freeze + + # Regular expressions for deprecation warnings that should raise an exception on detection + DISALLOWED_DEPRECATION_WARNING_REGEXES = [ + *CUSTOM_DEPRECATION_WARNING_REGEXES, + *RAILS_7_0_FIXED_DEPRECATION_WARNING_REGEXES + ].freeze + + # @note For use with `ActiveSupport::Deprecation.behavior=` or `Rails.application.config.active_support.deprecation=` class ProductionHandler APP_NAME = "caseflow" SLACK_ALERT_TITLE = "Deprecation Warning - #{APP_NAME} (#{ENV['DEPLOY_ENV']})" diff --git a/lib/fakes/vbms_service.rb b/lib/fakes/vbms_service.rb index b62bc75dfe5..5152cd12bbb 100644 --- a/lib/fakes/vbms_service.rb +++ b/lib/fakes/vbms_service.rb @@ -3,23 +3,6 @@ require "ostruct" require "csv" -class VBMSCaseflowLogger - def self.log(event, data) - case event - when :request - status = data[:response_code] - name = data[:request].class.name - - if status != 200 - Rails.logger.error( - "VBMS HTTP Error #{status} " \ - "(#{name}) #{data[:response_body]}" - ) - end - end - end -end - class Fakes::VBMSService HOLD_REQUEST_TIMEOUT_SECONDS = 2 diff --git a/lib/generators/legacy_appeal_v2.rb b/lib/generators/legacy_appeal_v2.rb index 14cdd73b418..d144de2dac3 100644 --- a/lib/generators/legacy_appeal_v2.rb +++ b/lib/generators/legacy_appeal_v2.rb @@ -76,7 +76,7 @@ def add_inaccessible_appeal(vbms_id) end def setup_vacols_data(attrs) - Generators::Vacols::Case.create( + Generators::VACOLS::Case.create( attrs.merge( case_attrs: { bfkey: attrs[:vacols_id], bfcorlid: attrs[:vbms_id] diff --git a/lib/generators/vacols/case.rb b/lib/generators/vacols/case.rb index c87585a1ed6..845f49f8188 100644 --- a/lib/generators/vacols/case.rb +++ b/lib/generators/vacols/case.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::Case +class Generators::VACOLS::Case class << self def generate_pkseq SecureRandom.random_number(99_999_999) @@ -105,25 +105,25 @@ def create(attrs = {}) # Commit dependencies folder_attrs = attrs[:folder_attrs].nil? ? {} : attrs[:folder_attrs] folder_attrs[:ticknum] = custom_case_attrs[:bfkey] - Generators::Vacols::Folder.create(folder_attrs) + Generators::VACOLS::Folder.create(folder_attrs) representative_attrs = attrs[:representative_attrs].nil? ? {} : attrs[:representative_attrs] representative_attrs[:repkey] = custom_case_attrs[:bfkey] - Generators::Vacols::Representative.create(representative_attrs) + Generators::VACOLS::Representative.create(representative_attrs) unless attrs[:corres_exists] correspondent_attrs = attrs[:correspondent_attrs].nil? ? {} : attrs[:correspondent_attrs] correspondent_attrs[:stafkey] = custom_case_attrs[:bfcorkey] - Generators::Vacols::Correspondent.create(correspondent_attrs) + Generators::VACOLS::Correspondent.create(correspondent_attrs) end note_attrs = attrs[:note_attrs].nil? ? {} : attrs[:note_attrs] note_attrs[:tsktknm] = custom_case_attrs[:bfkey] - Generators::Vacols::Note.create(note_attrs) + Generators::VACOLS::Note.create(note_attrs) decass_attrs = attrs[:decass_attrs].nil? ? {} : attrs[:decass_attrs] decass_attrs[:defolder] = custom_case_attrs[:bfkey] - Generators::Vacols::Decass.create(decass_attrs) + Generators::VACOLS::Decass.create(decass_attrs) # One to many relationships @@ -133,16 +133,16 @@ def create(attrs = {}) issue[:isskey] = custom_case_attrs[:bfkey] issue[:issseq] = idx end - Generators::Vacols::CaseIssue.create(case_issue_attrs) + Generators::VACOLS::CaseIssue.create(case_issue_attrs) # Default to zero hearings case_hearing_attrs = attrs[:case_hearing_attrs].nil? ? [{}] : attrs[:case_hearing_attrs] case_hearing_attrs.each { |hearing| hearing[:folder_nr] = custom_case_attrs[:bfkey] } - Generators::Vacols::CaseHearing.create(case_hearing_attrs) + Generators::VACOLS::CaseHearing.create(case_hearing_attrs) staff_attrs = attrs[:staff_attrs].nil? ? {} : attrs[:staff_attrs] staff_attrs[:slogid] = custom_case_attrs[:bfcurloc] - Generators::Vacols::Staff.create(staff_attrs) + Generators::VACOLS::Staff.create(staff_attrs) VACOLS::Case.create(custom_case_attrs) end diff --git a/lib/generators/vacols/case_hearing.rb b/lib/generators/vacols/case_hearing.rb index 07c6273fa61..052073da29e 100644 --- a/lib/generators/vacols/case_hearing.rb +++ b/lib/generators/vacols/case_hearing.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::CaseHearing +class Generators::VACOLS::CaseHearing class << self # rubocop:disable Metrics/MethodLength def case_hearing_attrs diff --git a/lib/generators/vacols/case_issue.rb b/lib/generators/vacols/case_issue.rb index acef6acc659..01255fa7fc3 100644 --- a/lib/generators/vacols/case_issue.rb +++ b/lib/generators/vacols/case_issue.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::CaseIssue +class Generators::VACOLS::CaseIssue class << self def case_issue_attrs { diff --git a/lib/generators/vacols/correspondent.rb b/lib/generators/vacols/correspondent.rb index 2098fd9e824..52b81507d86 100644 --- a/lib/generators/vacols/correspondent.rb +++ b/lib/generators/vacols/correspondent.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::Correspondent +class Generators::VACOLS::Correspondent class << self def generate_pkseq SecureRandom.random_number(99_999_999) diff --git a/lib/generators/vacols/decass.rb b/lib/generators/vacols/decass.rb index d206b18a4d5..440b32eaaa3 100644 --- a/lib/generators/vacols/decass.rb +++ b/lib/generators/vacols/decass.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::Decass +class Generators::VACOLS::Decass class << self # rubocop:disable Metrics/MethodLength def decass_attrs diff --git a/lib/generators/vacols/folder.rb b/lib/generators/vacols/folder.rb index 04687e2f9c3..f507479897b 100644 --- a/lib/generators/vacols/folder.rb +++ b/lib/generators/vacols/folder.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::Folder +class Generators::VACOLS::Folder class << self # rubocop:disable Metrics/MethodLength def folder_attrs diff --git a/lib/generators/vacols/note.rb b/lib/generators/vacols/note.rb index 3b5d849a910..bda5726d6dd 100644 --- a/lib/generators/vacols/note.rb +++ b/lib/generators/vacols/note.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::Note +class Generators::VACOLS::Note class << self # rubocop:disable Metrics/MethodLength def note_attrs diff --git a/lib/generators/vacols/representative.rb b/lib/generators/vacols/representative.rb index ce7461b59b9..a42caca1b38 100644 --- a/lib/generators/vacols/representative.rb +++ b/lib/generators/vacols/representative.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::Representative +class Generators::VACOLS::Representative class << self # rubocop:disable Metrics/MethodLength def representative_attrs diff --git a/lib/generators/vacols/staff.rb b/lib/generators/vacols/staff.rb index 71a4e8c038d..631cd70063e 100644 --- a/lib/generators/vacols/staff.rb +++ b/lib/generators/vacols/staff.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::Staff +class Generators::VACOLS::Staff class << self # rubocop:disable Metrics/MethodLength def staff_attrs diff --git a/lib/generators/vacols/travel_board_schedule.rb b/lib/generators/vacols/travel_board_schedule.rb index 6dc5467cbf1..445fdabd57c 100644 --- a/lib/generators/vacols/travel_board_schedule.rb +++ b/lib/generators/vacols/travel_board_schedule.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Generators::Vacols::TravelBoardSchedule +class Generators::VACOLS::TravelBoardSchedule class << self # rubocop:disable Metrics/MethodLength def travel_board_sched_attrs diff --git a/lib/helpers/association_wrapper.rb b/lib/helpers/association_wrapper.rb index 71efe8f7a64..1c59552c4b6 100644 --- a/lib/helpers/association_wrapper.rb +++ b/lib/helpers/association_wrapper.rb @@ -5,7 +5,7 @@ # https://stackoverflow.com/questions/13355549/rails-activerecord-detect-if-a-column-is-an-association-or-not ## -class AssocationWrapper +class AssociationWrapper def initialize(klass) @associations = klass.reflect_on_all_associations @selects = [] diff --git a/lib/helpers/sanitation_transforms.rb b/lib/helpers/sanitization_transforms.rb similarity index 100% rename from lib/helpers/sanitation_transforms.rb rename to lib/helpers/sanitization_transforms.rb diff --git a/lib/helpers/sanitized_json_configuration.rb b/lib/helpers/sanitized_json_configuration.rb index f1852532e07..e9a2885d9f2 100644 --- a/lib/helpers/sanitized_json_configuration.rb +++ b/lib/helpers/sanitized_json_configuration.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "helpers/association_wrapper.rb" -require "helpers/sanitation_transforms.rb" +require "helpers/sanitization_transforms.rb" # Configuration for exporting/importing data from/to Caseflow's database. # Needed by SanitizedJsonExporter and SanitizedJsonImporter. @@ -229,7 +229,7 @@ def offset_id_fields reassociate_types.map do |klass| [ klass, - AssocationWrapper.new(klass).grouped_fieldnames_of_typed_associations_with(known_types.map(&:name)) + AssociationWrapper.new(klass).grouped_fieldnames_of_typed_associations_with(known_types.map(&:name)) .values.flatten.sort ] end.to_h.tap do |class_to_fieldnames_hash| @@ -361,7 +361,7 @@ def reassociate_fields # Typed polymorphic association fields will be associated based on the '_type' field type: reassociate_types.map do |klass| [klass, - AssocationWrapper.new(klass).fieldnames_of_typed_associations(excluding: offset_id_fields[klass]).presence] + AssociationWrapper.new(klass).fieldnames_of_typed_associations(excluding: offset_id_fields[klass]).presence] end.to_h.compact }.merge( # Untyped association fields (ie, without the matching '_type' field) will associate to their corresponding type @@ -370,7 +370,7 @@ def reassociate_fields assoc_class.name, reassociate_types.map do |klass| [klass, - AssocationWrapper.new(klass).fieldnames_of_untyped_associations_with(assoc_class).presence] + AssociationWrapper.new(klass).fieldnames_of_untyped_associations_with(assoc_class).presence] end.to_h.compact ] end.to_h @@ -397,7 +397,7 @@ def before_creation_hook(klass, obj_hash, obj_description: nil, importer: nil) "\n\tPossible fixes:" \ "\n\t- Check for a `belongs_to:` association in #{klass}" \ "\n\t- Check @configuration.reassociate_fields, specifically:" \ - "\n\t AssocationWrapper.new(#{klass}).fieldnames_of_untyped_associations_with(assoc_class)" + "\n\t AssociationWrapper.new(#{klass}).fieldnames_of_untyped_associations_with(assoc_class)" end end # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Lint/UnusedMethodArgument diff --git a/lib/helpers/sanitizers.rb b/lib/helpers/sanitizers.rb index fb73d48f807..562a7d40752 100644 --- a/lib/helpers/sanitizers.rb +++ b/lib/helpers/sanitizers.rb @@ -13,7 +13,7 @@ # You'll also need a method called sanitize_klassname which assigns_attributes to any fields you want # to fake out. The first line of this method should use a key from the table to seed the Faker randomization # so that our randomizations are deterministic for a given row. -class Helpers::Sanitizers +class Sanitizers def errors @errors ||= [] end diff --git a/lib/helpers/DtaDooDescriptionRemediationByReportLoad.rb b/lib/helpers/war_room/DtaDooDescriptionRemediationByReportLoad.rb similarity index 100% rename from lib/helpers/DtaDooDescriptionRemediationByReportLoad.rb rename to lib/helpers/war_room/DtaDooDescriptionRemediationByReportLoad.rb diff --git a/lib/helpers/claim_label_change.rb b/lib/helpers/war_room/claim_label_change.rb similarity index 100% rename from lib/helpers/claim_label_change.rb rename to lib/helpers/war_room/claim_label_change.rb diff --git a/lib/helpers/dupp_ep_claims_sync_status_update_can_clr.rb b/lib/helpers/war_room/dupp_ep_claims_sync_status_update_can_clr.rb similarity index 100% rename from lib/helpers/dupp_ep_claims_sync_status_update_can_clr.rb rename to lib/helpers/war_room/dupp_ep_claims_sync_status_update_can_clr.rb diff --git a/lib/helpers/hearings_info_migration.rb b/lib/helpers/war_room/hearings_info_migration.rb similarity index 100% rename from lib/helpers/hearings_info_migration.rb rename to lib/helpers/war_room/hearings_info_migration.rb diff --git a/lib/helpers/payee_code_update.rb b/lib/helpers/war_room/payee_code_update.rb similarity index 100% rename from lib/helpers/payee_code_update.rb rename to lib/helpers/war_room/payee_code_update.rb diff --git a/lib/helpers/poa_access.rb b/lib/helpers/war_room/poa_access.rb similarity index 100% rename from lib/helpers/poa_access.rb rename to lib/helpers/war_room/poa_access.rb diff --git a/lib/helpers/pre_docket_ihp_tasks.rb b/lib/helpers/war_room/pre_docket_ihp_tasks.rb similarity index 100% rename from lib/helpers/pre_docket_ihp_tasks.rb rename to lib/helpers/war_room/pre_docket_ihp_tasks.rb diff --git a/lib/helpers/remand_dta_or_doo_higher_level_review.rb b/lib/helpers/war_room/remand_dta_or_doo_higher_level_review.rb similarity index 100% rename from lib/helpers/remand_dta_or_doo_higher_level_review.rb rename to lib/helpers/war_room/remand_dta_or_doo_higher_level_review.rb diff --git a/lib/helpers/report_load_end_product_sync.rb b/lib/helpers/war_room/report_load_end_product_sync.rb similarity index 100% rename from lib/helpers/report_load_end_product_sync.rb rename to lib/helpers/war_room/report_load_end_product_sync.rb diff --git a/lib/helpers/unrecognized_appellant.rb b/lib/helpers/war_room/unrecognized_appellant.rb similarity index 100% rename from lib/helpers/unrecognized_appellant.rb rename to lib/helpers/war_room/unrecognized_appellant.rb diff --git a/lib/tasks/additional_legacy_remanded_appeals.rake b/lib/tasks/additional_legacy_remanded_appeals.rake index ed00c4237d6..04981b9f1f3 100644 --- a/lib/tasks/additional_legacy_remanded_appeals.rake +++ b/lib/tasks/additional_legacy_remanded_appeals.rake @@ -34,16 +34,16 @@ namespace :additional_legacy_remand_reasons do end staff = VACOLS::Staff.find_by(sdomainid: user.css_id) # user for local/demo || UAT - Generators::Vacols::Case.create( + Generators::VACOLS::Case.create( decass_creation: decass_creation, corres_exists: true, - folder_attrs: Generators::Vacols::Folder.folder_attrs.merge( + folder_attrs: Generators::VACOLS::Folder.folder_attrs.merge( custom_folder_attributes(vacols_veteran_record, docket_number.to_s) ), case_issue_attrs: [ - Generators::Vacols::CaseIssue.case_issue_attrs, - Generators::Vacols::CaseIssue.case_issue_attrs, - Generators::Vacols::CaseIssue.case_issue_attrs + Generators::VACOLS::CaseIssue.case_issue_attrs, + Generators::VACOLS::CaseIssue.case_issue_attrs, + Generators::VACOLS::CaseIssue.case_issue_attrs ], case_attrs: { bfcorkey: vacols_veteran_record.stafkey, @@ -149,7 +149,7 @@ namespace :additional_legacy_remand_reasons do end end - # Generators::Vacols::Case will create new correspondents, and I think it'll just be easier to + # Generators::VACOLS::Case will create new correspondents, and I think it'll just be easier to # update the cases created rather than mess with the generator's internals. def find_or_create_vacols_veteran(veteran) # Being naughty and calling a private method (it'd be cool to have this be public...) @@ -157,8 +157,8 @@ namespace :additional_legacy_remand_reasons do return vacols_veteran_record if vacols_veteran_record - Generators::Vacols::Correspondent.create( - Generators::Vacols::Correspondent.correspondent_attrs.merge( + Generators::VACOLS::Correspondent.create( + Generators::VACOLS::Correspondent.correspondent_attrs.merge( ssalut: veteran.name_suffix, snamef: veteran.first_name, snamemi: veteran.middle_name, diff --git a/lib/tasks/appeal_state_synchronizer.rake b/lib/tasks/appeal_state_synchronizer.rake index ca1094a7c04..bd62a57a759 100644 --- a/lib/tasks/appeal_state_synchronizer.rake +++ b/lib/tasks/appeal_state_synchronizer.rake @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "#{Rails.root}/app/helpers/sync_decided_appeals_helper.rb" - namespace :appeal_state_synchronizer do desc "Used to synchronize appeal_states table using data from other sources." task sync_appeal_states: :environment do diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index e56cb6d3404..a5d6f6a835b 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -65,7 +65,7 @@ end # To avoid accidents, we re-define these tasks here to no-op and output a helpful message to redirect developers toward # using their new database-specific counterparts instead. -# rubocop:disable Rails/RakeEnvironment, Layout/HeredocIndentation +# rubocop:disable Rails/RakeEnvironment, Layout/HeredocIndentation, Style/SignalException, Rails/Blank namespace :db do Rake::Task["db:create"].clear if Rake::Task.task_defined?("db:create") desc "[PROHIBITED] Use the appropriate database-specific tasks instead" @@ -124,6 +124,37 @@ namespace :db do HEREDOC end + # The original definition of the `db:migrate:down:{name}` task invokes `db:schema:dump`, which we have prohibited + # in favor of `db:schema:dump:{name}`. + # https://github.com/rails/rails/blob/ac87f58207cff18880593263be9d83456aa3a2ef/activerecord/lib/active_record/railties/databases.rake#L223 + # + # This re-definiton of `db:migrate:down:{name}` will instead call the DB-specific `db:schema:dump:{name}` + + namespace :down do + %w[primary etl].each do |name| + Rake::Task["db:migrate:down:#{name}"].clear if Rake::Task.task_defined?("db:migrate:down:#{name}") + task name => :load_config do + raise "VERSION is required" if !ENV["VERSION"] || ENV["VERSION"].empty? + + db_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: name) + + ActiveRecord::Base.establish_connection(db_config) + ActiveRecord::Tasks::DatabaseTasks.check_target_version + ActiveRecord::Base.connection.migration_context.run( + :down, + ActiveRecord::Tasks::DatabaseTasks.target_version + ) + + if ActiveRecord::Base.dump_schema_after_migration + db_namespace["schema:dump:#{name}"].invoke + end + # Allow this task to be called as many times as required. An example is the + # `migrate:redo` task, which calls `migrate:down` and `migrate:up` internally, which depend on this one. + db_namespace["schema:dump:#{name}"].reenable + end + end + end + Rake::Task["db:migrate:redo"].clear if Rake::Task.task_defined?("db:migrate:redo") desc "[PROHIBITED] Use the appropriate database-specific tasks instead" task :redo do @@ -165,6 +196,37 @@ namespace :db do db:migrate:up:etl # Runs the "up" for a given migration VERSION on the etl database HEREDOC end + + # The original definition of the `db:migrate:up:{name}` task invokes `db:schema:dump`, which we have prohibited + # in favor of `db:schema:dump:{name}`. + # https://github.com/rails/rails/blob/ac87f58207cff18880593263be9d83456aa3a2ef/activerecord/lib/active_record/railties/databases.rake#L189 + # + # This re-definiton of `db:migrate:up:{name}` will instead call the DB-specific `db:schema:dump:{name}` + + namespace :up do + %w[primary etl].each do |name| + Rake::Task["db:migrate:up:#{name}"].clear if Rake::Task.task_defined?("db:migrate:up:#{name}") + task name => :load_config do + raise "VERSION is required" if !ENV["VERSION"] || ENV["VERSION"].empty? + + db_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: name) + + ActiveRecord::Base.establish_connection(db_config) + ActiveRecord::Tasks::DatabaseTasks.check_target_version + ActiveRecord::Base.connection.migration_context.run( + :up, + ActiveRecord::Tasks::DatabaseTasks.target_version + ) + + if ActiveRecord::Base.dump_schema_after_migration + db_namespace["schema:dump:#{name}"].invoke + end + # Allow this task to be called as many times as required. An example is the + # `migrate:redo` task, which calls `migrate:down` and `migrate:up` internally, which depend on this one. + db_namespace["schema:dump:#{name}"].reenable + end + end + end end Rake::Task["db:reset"].clear if Rake::Task.task_defined?("db:reset") @@ -297,4 +359,4 @@ namespace :db do end end end -# rubocop:enable Rails/RakeEnvironment, Layout/HeredocIndentation +# rubocop:enable Rails/RakeEnvironment, Layout/HeredocIndentation, Style/SignalException, Rails/Blank diff --git a/lib/tasks/local/vacols.rake b/lib/tasks/local/vacols.rake index 7e271ec568a..dcaf093dfba 100644 --- a/lib/tasks/local/vacols.rake +++ b/lib/tasks/local/vacols.rake @@ -2,7 +2,6 @@ require "csv" require "rainbow" -require_relative "../../helpers/vacols_csv_reader" require_relative "../../../db/seeds/base" require_relative "../../../db/seeds/facols" @@ -63,7 +62,7 @@ namespace :local do :decass ).find(ids) - sanitizer = Helpers::Sanitizers.new + sanitizer = Sanitizers.new VACOLS::Staff.all.each_with_index do |staff, row_index| sanitizer.generate_staff_mapping(staff, row_index) @@ -72,7 +71,7 @@ namespace :local do write_csv(VACOLS::Staff, VACOLS::Staff.all, sanitizer) # In order to add a new table, you'll also need to add a sanitize and white_list method - # to the Helpers::Sanitizers class. + # to the Sanitizers class. write_csv(VACOLS::Case, cases, sanitizer) write_csv(VACOLS::Folder, cases.map(&:folder), sanitizer) write_csv(VACOLS::Representative, cases.map(&:vacols_representatives), sanitizer) diff --git a/lib/tasks/remediations/appellant_change.rake b/lib/tasks/remediations/appellant_change.rake index 78286dcb5e9..a4440bf461f 100644 --- a/lib/tasks/remediations/appellant_change.rake +++ b/lib/tasks/remediations/appellant_change.rake @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative "../../helpers/appellant_change.rb" - namespace :remediations do desc "Changes the Claimant on the appeal" task :appellant_change, diff --git a/lib/tasks/remediations/cancel_vrr_tasks_open_for_vre.rake b/lib/tasks/remediations/cancel_vrr_tasks_open_for_vre.rake index b76b86a6dd5..54e3dac2c1a 100644 --- a/lib/tasks/remediations/cancel_vrr_tasks_open_for_vre.rake +++ b/lib/tasks/remediations/cancel_vrr_tasks_open_for_vre.rake @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative "../../../lib/helpers/cancel_tasks_and_descendants" - namespace :remediations do desc "Cancel VeteranRecordRequest tasks that are both open and assigned to " \ "the 'Veterans Readiness and Employment' business line" diff --git a/lib/tasks/remediations/sync_attributes_with_bgs.rake b/lib/tasks/remediations/sync_attributes_with_bgs.rake index b0a8dbbca67..6d9cd6f8291 100644 --- a/lib/tasks/remediations/sync_attributes_with_bgs.rake +++ b/lib/tasks/remediations/sync_attributes_with_bgs.rake @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative "../../../lib/helpers/sync_attributes_with_bgs" - namespace :remediations do desc "Sync veteran cached attributes with bgs record" task :update_veteran_cached_attributes, [:file_number] => :environment do |_task, args| diff --git a/lib/tasks/seed_legacy_appeals.rake b/lib/tasks/seed_legacy_appeals.rake index d0d3510cbbd..a9c88fea07f 100644 --- a/lib/tasks/seed_legacy_appeals.rake +++ b/lib/tasks/seed_legacy_appeals.rake @@ -20,14 +20,14 @@ namespace :db do cases = Array.new(num_appeals_to_create).each_with_index.map do |_element, idx| key = VACOLS::Folder.maximum(:ticknum).next - Generators::Vacols::Case.create( + Generators::VACOLS::Case.create( corres_exists: true, case_issue_attrs: [ - Generators::Vacols::CaseIssue.case_issue_attrs.merge(ADD_SPECIAL_ISSUES ? special_issue_types(idx) : {}), - Generators::Vacols::CaseIssue.case_issue_attrs.merge(ADD_SPECIAL_ISSUES ? special_issue_types(idx) : {}), - Generators::Vacols::CaseIssue.case_issue_attrs.merge(ADD_SPECIAL_ISSUES ? special_issue_types(idx) : {}) + Generators::VACOLS::CaseIssue.case_issue_attrs.merge(ADD_SPECIAL_ISSUES ? special_issue_types(idx) : {}), + Generators::VACOLS::CaseIssue.case_issue_attrs.merge(ADD_SPECIAL_ISSUES ? special_issue_types(idx) : {}), + Generators::VACOLS::CaseIssue.case_issue_attrs.merge(ADD_SPECIAL_ISSUES ? special_issue_types(idx) : {}) ], - folder_attrs: Generators::Vacols::Folder.folder_attrs.merge( + folder_attrs: Generators::VACOLS::Folder.folder_attrs.merge( custom_folder_attributes(vacols_veteran_record, docket_number.to_s) ), case_attrs: { @@ -62,7 +62,7 @@ namespace :db do } end - # Generators::Vacols::Case will create new correspondents, and I think it'll just be easier to + # Generators::VACOLS::Case will create new correspondents, and I think it'll just be easier to # update the cases created rather than mess with the generator's internals. def find_or_create_vacols_veteran(veteran) # Being naughty and calling a private method (it'd be cool to have this be public...) @@ -70,8 +70,8 @@ namespace :db do return vacols_veteran_record if vacols_veteran_record - Generators::Vacols::Correspondent.create( - Generators::Vacols::Correspondent.correspondent_attrs.merge( + Generators::VACOLS::Correspondent.create( + Generators::VACOLS::Correspondent.correspondent_attrs.merge( ssalut: veteran.name_suffix, snamef: veteran.first_name, snamemi: veteran.middle_name, diff --git a/lib/tasks/seed_legacy_hearing.rake b/lib/tasks/seed_legacy_hearing.rake index 507f80b0795..144253e0aa1 100644 --- a/lib/tasks/seed_legacy_hearing.rake +++ b/lib/tasks/seed_legacy_hearing.rake @@ -32,8 +32,8 @@ namespace :db do return vacols_veteran_record if vacols_veteran_record - Generators::Vacols::Correspondent.create( - Generators::Vacols::Correspondent.correspondent_attrs.merge( + Generators::VACOLS::Correspondent.create( + Generators::VACOLS::Correspondent.correspondent_attrs.merge( ssalut: veteran.name_suffix, snamef: veteran.first_name, snamemi: veteran.middle_name, @@ -115,12 +115,12 @@ namespace :db do cases = Array.new(num_appeals_to_create).each_with_index.map do |_element| key = VACOLS::Case.pluck(:bfkey).map(&:to_i).max + 1 - Generators::Vacols::Case.create( + Generators::VACOLS::Case.create( corres_exists: true, - folder_attrs: Generators::Vacols::Folder.folder_attrs.merge( + folder_attrs: Generators::VACOLS::Folder.folder_attrs.merge( custom_folder_attributes(vacols_veteran_record, docket_number.to_s) ), - case_hearing_attrs: [Generators::Vacols::CaseHearing.case_hearing_attrs.merge( + case_hearing_attrs: [Generators::VACOLS::CaseHearing.case_hearing_attrs.merge( custom_hearing_attributes(type) )], case_attrs: other_params(vacols_veteran_record, key, type, regional_office) diff --git a/lib/tasks/spec.rake b/lib/tasks/spec.rake index 31dfc56f59a..3d3982d7445 100644 --- a/lib/tasks/spec.rake +++ b/lib/tasks/spec.rake @@ -76,8 +76,6 @@ namespace :spec do desc "Setup VACOLS VFTYPES and ISSREF tables" task setup_vacols: [:environment] do - require_relative "../helpers/vacols_csv_reader" - # We need the VFTYPES and ISSREF tables to do any queries for issues. This code is borrowed from the # local:vacols:seed rake task to load all of our dumped data for the VFTYPES and ISSREF tables. date_shift = Time.now.utc.beginning_of_day - Time.utc(2017, 11, 1) diff --git a/lib/tasks/support/jailer_polymorphic_associations.rb b/lib/tasks/support/jailer_polymorphic_associations.rb index 496bb9d4ecf..4d2eda5544a 100644 --- a/lib/tasks/support/jailer_polymorphic_associations.rb +++ b/lib/tasks/support/jailer_polymorphic_associations.rb @@ -46,7 +46,7 @@ def jailer_record_classes(base_class) def jailer_assocs_hash(base_class) jailer_assocs_hash = {} jailer_record_classes(base_class).each do |klass| - polymorphic_assocs = AssocationWrapper.new(klass).belongs_to.polymorphic.select_associations + polymorphic_assocs = AssociationWrapper.new(klass).belongs_to.polymorphic.select_associations # Skip if there are no polymorphic_associations or the table has already been processed next if polymorphic_assocs.blank? || jailer_assocs_hash.key?(klass.table_name) diff --git a/spec/config/sti_model_preloading_spec.rb b/spec/config/sti_model_preloading_spec.rb new file mode 100644 index 00000000000..adafba1f2e2 --- /dev/null +++ b/spec/config/sti_model_preloading_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# Ensure that all STI models are eager loaded, even when eager loading is disabled for the environment. +# Why? Single Table Inheritance doesn't play well with lazy loading: Active Record has to be aware of STI hierarchies +# to work correctly, but, when lazy loading, classes are only loaded only on demand. +# For example, the class method `.descendants` will only return subclasses that have already been loaded into +# mememory. So for STI classes leveraging this method, all subclasses will need to have been loaded already. +# +# See https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#single-table-inheritance +# +# This test should be skipped if eager loading is enabled. +describe "STI Models", unless: Rails.application.config.eager_load do + specify "are preloaded even when eager loading is disabled" do + # Find preloaded STI classes (before eager loading) + sti_class_names = find_sti_classes.map(&:name) + + # Find all expected STI classes (after eager loading) + Rails.application.eager_load! + expected_sti_class_names = find_sti_classes.map(&:name) + + # Assert that preloaded STI classes include all expected STI classes + expect(sti_class_names).to eq(expected_sti_class_names) + end + + def find_sti_classes + ApplicationRecord.descendants.each_with_object([]) do |model, memo| + next if model.abstract_class? + next unless model.column_names.include?(model.inheritance_column) + + memo << model + end + end +end diff --git a/spec/config/zeitwerk_spec.rb b/spec/config/zeitwerk_spec.rb new file mode 100644 index 00000000000..446214ef814 --- /dev/null +++ b/spec/config/zeitwerk_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +RSpec.describe "Zeitwerk" do + it "eager loads all files without errors" do + expect { Rails.application.eager_load! }.not_to raise_error + end +end diff --git a/spec/controllers/tasks/change_type_controller_spec.rb b/spec/controllers/tasks/change_type_controller_spec.rb index 4a3e21333e8..fc71ca74f87 100644 --- a/spec/controllers/tasks/change_type_controller_spec.rb +++ b/spec/controllers/tasks/change_type_controller_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "mail_task" - RSpec.describe Tasks::ChangeTypeController, :postgres, type: :controller do describe "POST tasks/change_type/:id" do let(:user) { create(:user) } diff --git a/spec/feature/asyncable_jobs/asyncable_jobs_index_spec.rb b/spec/feature/asyncable_jobs/asyncable_jobs_index_spec.rb index c089beb39bb..45216a8c581 100644 --- a/spec/feature/asyncable_jobs/asyncable_jobs_index_spec.rb +++ b/spec/feature/asyncable_jobs/asyncable_jobs_index_spec.rb @@ -135,12 +135,12 @@ it "allows user to page through jobs" do visit "/jobs" - expect(page).to have_content("Viewing 1-50 of 54 total") + expect(page).to have_content("Viewing 1-50 of 55 total") page.execute_script("document.querySelector('[name=page-button-1]').click()") expect(current_url).to match(/\?page=2/) - expect(page).to have_content("Viewing 51-54 of 54 total") + expect(page).to have_content("Viewing 51-55 of 55 total") end it "links to individual jobs" do diff --git a/spec/feature/reader/logs_controller_spec.rb b/spec/feature/reader/logs_controller_spec.rb index d5cfa415415..8de91c58571 100644 --- a/spec/feature/reader/logs_controller_spec.rb +++ b/spec/feature/reader/logs_controller_spec.rb @@ -6,7 +6,7 @@ Fakes::Initializer.load! RequestStore[:current_user] = User.find_or_create_by(css_id: "BVASCASPER1", station_id: 101) - Generators::Vacols::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") + Generators::VACOLS::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") User.authenticate!(roles: ["Reader"]) end diff --git a/spec/feature/reader/logs_spec.rb b/spec/feature/reader/logs_spec.rb index eb1814f7f74..0631ad42d0e 100644 --- a/spec/feature/reader/logs_spec.rb +++ b/spec/feature/reader/logs_spec.rb @@ -8,7 +8,7 @@ Fakes::Initializer.load! RequestStore[:current_user] = User.find_or_create_by(css_id: "BVASCASPER1", station_id: 101) - Generators::Vacols::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") + Generators::VACOLS::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") User.authenticate!(roles: ["Reader"]) end diff --git a/spec/feature/reader/reader_spec.rb b/spec/feature/reader/reader_spec.rb index bb386d02be8..af63f9a4586 100644 --- a/spec/feature/reader/reader_spec.rb +++ b/spec/feature/reader/reader_spec.rb @@ -60,7 +60,7 @@ def clear_filters Fakes::Initializer.load! RequestStore[:current_user] = User.find_or_create_by(css_id: "BVASCASPER1", station_id: 101) - Generators::Vacols::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") + Generators::VACOLS::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") FeatureToggle.disable!(:reader_prototype) User.authenticate!(roles: ["Reader"]) end diff --git a/spec/feature/test_seeds/test_docket_case_seeds/test_docket_case_seeds_spec.rb b/spec/feature/test_seeds/test_docket_case_seeds/test_docket_case_seeds_spec.rb index c5ae96e44d2..2855ab4ba45 100644 --- a/spec/feature/test_seeds/test_docket_case_seeds/test_docket_case_seeds_spec.rb +++ b/spec/feature/test_seeds/test_docket_case_seeds/test_docket_case_seeds_spec.rb @@ -175,7 +175,7 @@ end def login - visit "test/seeds" + Sniffybara::Driver.path_exclusions << /test\/seeds/ visit "test/seeds" end end diff --git a/spec/helpers/cancel_tasks_and_descendants_spec.rb b/spec/helpers/cancel_tasks_and_descendants_spec.rb index 3b1bc195617..2240fc45968 100644 --- a/spec/helpers/cancel_tasks_and_descendants_spec.rb +++ b/spec/helpers/cancel_tasks_and_descendants_spec.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "helpers/cancel_tasks_and_descendants" require "securerandom" describe CancelTasksAndDescendants do diff --git a/spec/helpers/sync_decided_appeals_helper_spec.rb b/spec/helpers/sync_decided_appeals_helper_spec.rb index b55dbe97ae7..6d552569a30 100644 --- a/spec/helpers/sync_decided_appeals_helper_spec.rb +++ b/spec/helpers/sync_decided_appeals_helper_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative "../../app/helpers/sync_decided_appeals_helper" - describe "SyncDecidedAppealsHelper" do self.use_transactional_tests = false diff --git a/spec/jobs/file_number_not_found_fix_job_spec.rb b/spec/jobs/file_number_not_found_fix_job_spec.rb index 3c0e04a23e0..8e58afc7500 100644 --- a/spec/jobs/file_number_not_found_fix_job_spec.rb +++ b/spec/jobs/file_number_not_found_fix_job_spec.rb @@ -226,7 +226,7 @@ allow(bgs_service).to receive(:fetch_file_number_by_ssn) .and_return(bgs_file_number) - allow(FixfileNumberCollections) + allow(described_class::FixfileNumberCollections) .to receive(:get_collections) .with(veteran_2) .and_return([FixFileNumberWizard::Collection.new(Form8, veteran_2.ssn)]) diff --git a/spec/jobs/nightly_syncs_job_spec.rb b/spec/jobs/nightly_syncs_job_spec.rb index 2af498ffbfb..3fc3d0e1dba 100644 --- a/spec/jobs/nightly_syncs_job_spec.rb +++ b/spec/jobs/nightly_syncs_job_spec.rb @@ -145,7 +145,7 @@ class FakeTask < Dispatch::Task end end - # our BgsService fake returns five records in the poas_list, this creates one of the records + # our BGSService fake returns five records in the poas_list, this creates one of the records # before the job and verifies that the job creates the remaining four records context "with BGS attorneys" do before { create(:bgs_attorney, participant_id: "12345678") } diff --git a/spec/lib/deprecation_warnings_spec.rb b/spec/lib/deprecation_warnings_spec.rb new file mode 100644 index 00000000000..d713bd7ffd1 --- /dev/null +++ b/spec/lib/deprecation_warnings_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +describe DeprecationWarnings::ProductionHandler do + context ".call" do + subject(:call) { described_class.call(message, callstack, deprecation_horizon, gem_name) } + + let(:message) { "dummy deprecation message" } + let(:callstack) { [] } + let(:deprecation_horizon) { "6.0" } + let(:gem_name) { "Rails" } + + let(:rails_logger) { Rails.logger } + let(:slack_service) { SlackService.new(url: "dummy-url") } + + before do + allow(Rails).to receive(:logger).and_return(rails_logger) + allow(rails_logger).to receive(:warn) + + allow(Raven).to receive(:capture_message) + allow(Raven).to receive(:capture_exception) + + allow(SlackService).to receive(:new).and_return(slack_service) + allow(slack_service).to receive(:send_notification) + end + + it "emits a warning to Sentry" do + call + + expect(Raven).to have_received(:capture_message).with( + message, + level: "warning", + extra: { + message: message, + gem_name: gem_name, + deprecation_horizon: deprecation_horizon, + callstack: callstack, + environment: Rails.env + } + ) + end + + it "emits a warning to Slack channel" do + slack_alert_title = "Deprecation Warning - caseflow (test)" + + call + + expect(slack_service).to have_received(:send_notification).with( + message, + slack_alert_title, + "#appeals-deprecation-alerts" + ) + end + + context "when an exception occurs" do + before { allow(slack_service).to receive(:send_notification).and_raise(StandardError) } + + it "logs error to Sentry" do + call + + expect(Raven).to have_received(:capture_exception).with(StandardError) + end + + it "does not raise error" do + expect { call }.not_to raise_error + end + end + end +end diff --git a/spec/lib/helpers/appellant_change_spec.rb b/spec/lib/helpers/appellant_change_spec.rb index babe67c4a04..3384939f963 100644 --- a/spec/lib/helpers/appellant_change_spec.rb +++ b/spec/lib/helpers/appellant_change_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "helpers/appellant_change" - describe AppellantChange do describe ".run_appellant_change" do subject(:run_appellant_change) { described_class.run_appellant_change(arguments) } diff --git a/spec/lib/helpers/association_wrapper_spec.rb b/spec/lib/helpers/association_wrapper_spec.rb index 4c8140a921a..c07bd714692 100644 --- a/spec/lib/helpers/association_wrapper_spec.rb +++ b/spec/lib/helpers/association_wrapper_spec.rb @@ -2,8 +2,8 @@ require "helpers/association_wrapper.rb" -describe "AssocationWrapper" do - subject { AssocationWrapper.new(target_class) } +describe "AssociationWrapper" do + subject { AssociationWrapper.new(target_class) } describe "#fieldnames and #select_associations}" do context "for Task class" do let(:target_class) { Task } @@ -101,7 +101,7 @@ end end describe "#polymorphic" do - subject { AssocationWrapper.new(target_class).belongs_to.polymorphic } + subject { AssociationWrapper.new(target_class).belongs_to.polymorphic } context "for DecisionDocument class" do let(:target_class) { DecisionDocument } it "returns those with polymorphic belongs_to associations" do @@ -128,8 +128,8 @@ end end end - describe "AssocationWrapper#fieldnames_of_untyped_associations_with User records" do - subject { AssocationWrapper.new(target_class).fieldnames_of_untyped_associations_with(User) } + describe "AssociationWrapper#fieldnames_of_untyped_associations_with User records" do + subject { AssociationWrapper.new(target_class).fieldnames_of_untyped_associations_with(User) } context "for Task class" do let(:target_class) { Task } it "returns fieldnames associated with User records" do diff --git a/spec/lib/helpers/dupp_ep_claims_sync_status_update_can_clr_spec.rb b/spec/lib/helpers/dupp_ep_claims_sync_status_update_can_clr_spec.rb index b5f5d434daa..b0a1ed76c7f 100644 --- a/spec/lib/helpers/dupp_ep_claims_sync_status_update_can_clr_spec.rb +++ b/spec/lib/helpers/dupp_ep_claims_sync_status_update_can_clr_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "helpers/dupp_ep_claims_sync_status_update_can_clr" - describe "DuppEpClaimsSyncStatusUpdateCanClr", :postgres do let(:script) { WarRoom::DuppEpClaimsSyncStatusUpdateCanClr.new } # create a test ep diff --git a/spec/lib/helpers/poa_access_spec.rb b/spec/lib/helpers/poa_access_spec.rb index 5b3f24113a1..36c8e38661a 100644 --- a/spec/lib/helpers/poa_access_spec.rb +++ b/spec/lib/helpers/poa_access_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "helpers/poa_access" - describe "WarRoom::PoaAccess" do let!(:legacy_appeal) { create(:legacy_appeal, vacols_case: create(:case), vbms_id: "000001234") } let!(:poa) { create(:bgs_power_of_attorney, file_number: "000001234") } diff --git a/spec/lib/helpers/sanitized_json_exporter_spec.rb b/spec/lib/helpers/sanitized_json_exporter_spec.rb index 95fb03f3ae1..77497eec1f9 100644 --- a/spec/lib/helpers/sanitized_json_exporter_spec.rb +++ b/spec/lib/helpers/sanitized_json_exporter_spec.rb @@ -166,7 +166,7 @@ end end - describe "SjConfiguration uses of AssocationWrapper" do + describe "SjConfiguration uses of AssociationWrapper" do let(:configuration) { SjConfiguration.new } it "causes SjConfiguration instances to return correct results" do expect(configuration.transform_methods).to include(:random_pin, :obfuscate_sentence, :similar_date) diff --git a/spec/lib/helpers/sync_attributes_with_bgs_spec.rb b/spec/lib/helpers/sync_attributes_with_bgs_spec.rb index f754af41fee..31c5a44a86b 100644 --- a/spec/lib/helpers/sync_attributes_with_bgs_spec.rb +++ b/spec/lib/helpers/sync_attributes_with_bgs_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "helpers/sync_attributes_with_bgs" - describe SyncAttributesWithBGS::VeteranCacheUpdater do describe "#run_by_file_number" do subject(:run_by_file_number) { described_class.new.run_by_file_number(file_number) } diff --git a/spec/models/hearing_day_spec.rb b/spec/models/hearing_day_spec.rb index 5ce3387c0d5..a6fc0f31847 100644 --- a/spec/models/hearing_day_spec.rb +++ b/spec/models/hearing_day_spec.rb @@ -530,7 +530,7 @@ def format_begins_at_from_db(time_string, scheduled_for) context "bulk persist" do let(:schedule_period) do RequestStore[:current_user] = User.create(css_id: "BVASCASPER1", station_id: 101) - Generators::Vacols::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") + Generators::VACOLS::Staff.create(stafkey: "SCASPER1", sdomainid: "BVASCASPER1", slogid: "SCASPER1") create(:ro_schedule_period) end diff --git a/spec/models/hearings/schedule_hearing_task_pager_spec.rb b/spec/models/hearings/schedule_hearing_task_pager_spec.rb index 10439866a79..839c29205e3 100644 --- a/spec/models/hearings/schedule_hearing_task_pager_spec.rb +++ b/spec/models/hearings/schedule_hearing_task_pager_spec.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -describe Hearings::ScheduleHearingTaskPager, :all_dbs do +describe ScheduleHearingTaskPager, :all_dbs do let(:assignee) { HearingsManagement.singleton } let(:regional_office_key) { "RO18" } - let(:legacy_task_pager) { Hearings::ScheduleHearingTaskPager.new(legacy_arguments) } - let(:ama_task_pager) { Hearings::ScheduleHearingTaskPager.new(ama_arguments) } + let(:legacy_task_pager) { ScheduleHearingTaskPager.new(legacy_arguments) } + let(:ama_task_pager) { ScheduleHearingTaskPager.new(ama_arguments) } let(:default_cases_per_page) { TaskPager::TASKS_PER_PAGE } let(:page_no) { 1 } let(:legacy_arguments) do diff --git a/spec/requests/api/v3/issues/vacols/veterans_controller_spec.rb b/spec/requests/api/v3/issues/vacols/veterans_controller_spec.rb index aa2978a66ce..b14bead73de 100644 --- a/spec/requests/api/v3/issues/vacols/veterans_controller_spec.rb +++ b/spec/requests/api/v3/issues/vacols/veterans_controller_spec.rb @@ -3,7 +3,7 @@ require "test_prof/recipes/rspec/let_it_be" # rubocop:disable Layout/LineLength -describe Api::V3::Issues::Vacols::VeteransController, :postgres, type: :request do +describe Api::V3::Issues::VACOLS::VeteransController, :postgres, type: :request do let_it_be(:api_key) do ApiKey.create!(consumer_name: "ApiV3 Test VBMS Consumer").key_string end @@ -81,8 +81,8 @@ end context "when a veteran is found - but an unexpected error has happened." do - before { Api::V3::Issues::Vacols::VeteransController::DEFAULT_UPPER_BOUND_PER_PAGE = "breaking_the_api" } - after { Api::V3::Issues::Vacols::VeteransController::DEFAULT_UPPER_BOUND_PER_PAGE = 50 } + before { Api::V3::Issues::VACOLS::VeteransController::DEFAULT_UPPER_BOUND_PER_PAGE = "breaking_the_api" } + after { Api::V3::Issues::VACOLS::VeteransController::DEFAULT_UPPER_BOUND_PER_PAGE = 50 } let(:vet) { create(:veteran) } it "should return 500 error" do headers = { "Authorization": authorization_token, "X-VA-File-Number": vet.file_number } diff --git a/spec/requests/hearing_day_spec.rb b/spec/requests/hearing_day_spec.rb index 77c00b9d507..7f12d3402c8 100644 --- a/spec/requests/hearing_day_spec.rb +++ b/spec/requests/hearing_day_spec.rb @@ -180,10 +180,10 @@ { request_type: HearingDay::REQUEST_TYPES[:travel], scheduled_for: "13-Jun-2019 08:30:00.000-4:00", regional_office: "RO27", room: "4" }] ) - Generators::Vacols::TravelBoardSchedule.create(tbyear: 2019, tbstdate: "2019-01-30 00:00:00", + Generators::VACOLS::TravelBoardSchedule.create(tbyear: 2019, tbstdate: "2019-01-30 00:00:00", tbenddate: "2019-02-03 00:00:00", tbmem1: "111") - Generators::Vacols::Staff.create(sattyid: "111") - Generators::Vacols::Staff.create(sattyid: "105", sdomainid: "BVARTONY", snamel: "Randall", snamef: "Tony") + Generators::VACOLS::Staff.create(sattyid: "111") + Generators::VACOLS::Staff.create(sattyid: "105", sdomainid: "BVARTONY", snamel: "Randall", snamef: "Tony") end it "Get hearings for specified date range" do @@ -212,9 +212,9 @@ { request_type: HearingDay::REQUEST_TYPES[:travel], scheduled_for: "8-Jun-2019 09:00:00.000-4:00", room: "3", regional_office: "RO27" }] ) - Generators::Vacols::TravelBoardSchedule.create(tbyear: 2019, tbstdate: "2019-01-30 00:00:00", + Generators::VACOLS::TravelBoardSchedule.create(tbyear: 2019, tbstdate: "2019-01-30 00:00:00", tbenddate: "2019-02-03 00:00:00", tbmem1: "111") - Generators::Vacols::Staff.create(sattyid: "111") + Generators::VACOLS::Staff.create(sattyid: "111") end it "Get hearings for RO" do @@ -233,7 +233,7 @@ let!(:staff) { create(:staff, stafkey: "RO04", stc2: 2, stc3: 3, stc4: 4) } let!(:hearings) do RequestStore[:current_user] = user - Generators::Vacols::Staff.create(sattyid: "111") + Generators::VACOLS::Staff.create(sattyid: "111") HearingDay.create( [{ request_type: HearingDay::REQUEST_TYPES[:video], scheduled_for: "7-Mar-2019 09:00:00.000-4:00", room: "1", regional_office: "RO04" }, diff --git a/spec/rubocop/custom_cop/top_level_constants_per_file_spec.rb b/spec/rubocop/custom_cop/top_level_constants_per_file_spec.rb new file mode 100644 index 00000000000..98d7543efd2 --- /dev/null +++ b/spec/rubocop/custom_cop/top_level_constants_per_file_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require "spec_helper" +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../../.rubocop/custom_cop/top_level_constants_per_file" + +describe RuboCop::CustomCop::TopLevelConstantsPerFile do + include RuboCop::RSpec::ExpectOffense + + subject(:cop) { described_class.new(config) } + let(:config) { RuboCop::Config.new } + + let(:message) do + "Multiple top-level constants detected in one file. The autoloader expects one top-level constant per file." + end + + context "when there is only one top-level class in file" do + it "does not register an offense" do + expect_no_offenses(<<~RUBY) + class SomeClass; end + RUBY + end + end + + context "when there is only one top-level module in file" do + it "does not register an offense" do + expect_no_offenses(<<~RUBY) + module SomeModule; end + RUBY + end + end + + context "when there is only one top-level class/module in file, having one or more nested classes/modules" do + it "does not register an offense" do + expect_no_offenses(<<~RUBY) + module SomeModule + class FirstNestedClass; end + class SecondNestedClass; end + end + RUBY + end + end + + context "when there are multiple top-level classes/modules in file" do + it "registers an offense on the second one" do + expect_offense(<<~RUBY) + class FirstClass; end + module SomeModule; end + ^^^^^^^^^^^^^^^^^^^^^^ #{message} + class SecondClass; end + RUBY + end + end +end diff --git a/spec/serializers/api/v3/issues/vacols/vacols_issue_serializer_spec.rb b/spec/serializers/api/v3/issues/vacols/vacols_issue_serializer_spec.rb index 59cba3b9142..c1a4acc9b34 100644 --- a/spec/serializers/api/v3/issues/vacols/vacols_issue_serializer_spec.rb +++ b/spec/serializers/api/v3/issues/vacols/vacols_issue_serializer_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe Api::V3::Issues::Vacols::VacolsIssueSerializer, :postgres do +describe Api::V3::Issues::VACOLS::VacolsIssueSerializer, :postgres do context "VACOLS issue object" do let(:vacols_id) { "12345678" } let(:disposition) { nil } @@ -21,7 +21,7 @@ let(:issue) { Issue.load_from_vacols(vacols_case_issue.attributes) } it "should show all the fields" do - serialized_vacols_issue = Api::V3::Issues::Vacols::VacolsIssueSerializer.new(issue) + serialized_vacols_issue = Api::V3::Issues::VACOLS::VacolsIssueSerializer.new(issue) .serializable_hash[:data][:attributes][:vacols_issue] expect(serialized_vacols_issue).not_to eq nil diff --git a/spec/services/claim_change_history/claim_history_event_spec.rb b/spec/services/claim_change_history/claim_history_event_spec.rb index 0dc5263585f..3affa43ac0e 100644 --- a/spec/services/claim_change_history/claim_history_event_spec.rb +++ b/spec/services/claim_change_history/claim_history_event_spec.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative "../../../app/services/claim_change_history/claim_history_event.rb" - describe ClaimHistoryEvent do let(:change_data) do { @@ -277,7 +275,7 @@ context "when the event type is invalid" do let(:event_type) { :invalid_event } it "should raise InvalidEventType error" do - expect { subject }.to raise_error(InvalidEventType) + expect { subject }.to raise_error(described_class::InvalidEventType) end end @@ -1072,7 +1070,7 @@ context "when the event type is invalid" do let(:event_type) { :invalid_event } it "should raise InvalidEventType error" do - expect { subject }.to raise_error(InvalidEventType) + expect { subject }.to raise_error(described_class::InvalidEventType) end end diff --git a/spec/services/deprecation_warnings/production_handler_spec.rb b/spec/services/deprecation_warnings/production_handler_spec.rb deleted file mode 100644 index a34c219d584..00000000000 --- a/spec/services/deprecation_warnings/production_handler_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -module DeprecationWarnings - describe ProductionHandler do - context ".call" do - subject(:call) { described_class.call(message, callstack, deprecation_horizon, gem_name) } - - let(:message) { "dummy deprecation message" } - let(:callstack) { [] } - let(:deprecation_horizon) { "6.0" } - let(:gem_name) { "Rails" } - - let(:rails_logger) { Rails.logger } - let(:slack_service) { SlackService.new(url: "dummy-url") } - let(:deploy_env) { ENV["DEPLOY_ENV"] } - - before do - allow(Rails).to receive(:logger).and_return(rails_logger) - allow(rails_logger).to receive(:warn) - - allow(Raven).to receive(:capture_message) - allow(Raven).to receive(:capture_exception) - - allow(SlackService).to receive(:new).and_return(slack_service) - allow(slack_service).to receive(:send_notification) - end - - it "emits a warning to Sentry" do - call - - expect(Raven).to have_received(:capture_message).with( - message, - level: "warning", - extra: { - message: message, - gem_name: gem_name, - deprecation_horizon: deprecation_horizon, - callstack: callstack, - environment: Rails.env - } - ) - end - - it "emits a warning to Slack channel" do - slack_alert_title = "Deprecation Warning - caseflow (#{deploy_env})" - - call - - expect(slack_service).to have_received(:send_notification).with( - message, - slack_alert_title, - "#appeals-deprecation-alerts" - ) - end - - context "when an exception occurs" do - before { allow(slack_service).to receive(:send_notification).and_raise(StandardError) } - - it "logs error to Sentry" do - call - - expect(Raven).to have_received(:capture_exception).with(StandardError) - end - - it "does not raise error" do - expect { call }.not_to raise_error - end - end - end - end -end