Skip to content

Commit

Permalink
Vfep 1264 - Zeitwerk changes (#1093)
Browse files Browse the repository at this point in the history
* Zeitwerk fixes commit 01

* refactor specs & fix rubocop issues flagged with latest gem release

* fix namespace issue in lint.rake

* fix namespace issue in security.rake

---------

Co-authored-by: nfstern02 <[email protected]>
  • Loading branch information
GcioGregg and nfstern02 authored Apr 10, 2024
1 parent c44d9a6 commit 3d741c6
Show file tree
Hide file tree
Showing 175 changed files with 1,834 additions and 1,751 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Style/SingleArgumentDig:
Enabled: false

Layout/LineLength:
Max: 120
Max: 135
Exclude:
- "app/controllers/v0/institutions_controller.rb"
- "app/controllers/v1/institutions_controller.rb"
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def resolve_version
v = params[:version]
@version = (v.present? && Version.find_by(uuid: v)) || Version.current_production

raise Common::Exceptions::InvalidFieldValue, "Version #{v} not found" unless @version.try(:number)
raise Common::Exceptions::Internal::InvalidFieldValue, "Version #{v} not found" unless @version.try(:number)
end

def self_link
Expand All @@ -42,14 +42,14 @@ def self_link
va_exception =
case exception
when ActionController::ParameterMissing
Common::Exceptions::ParameterMissing.new(exception.param)
Common::Exceptions::Internal::ParameterMissing.new(exception.param)
when Common::Exceptions::BaseError
exception
else
Common::Exceptions::InternalServerError.new(exception)
Common::Exceptions::Internal::InternalServerError.new(exception)
end

headers['WWW-Authenticate'] = 'Token realm="Application"' if va_exception.is_a?(Common::Exceptions::Unauthorized)
headers['WWW-Authenticate'] = 'Token realm="Application"' if va_exception.is_a?(Common::Exceptions::Internal::Unauthorized)
render json: { errors: va_exception.errors }, status: va_exception.status_code
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/archives_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def export
filename: "#{params[:csv_type]}_version_#{params[:number]}.csv"
end
end
rescue ArgumentError, Common::Exceptions::RecordNotFound, ActionController::UnknownFormat, MissingAttributeError => e
rescue ArgumentError, Common::Exceptions::Internal::RecordNotFound, ActionController::UnknownFormat, MissingAttributeError => e
Rails.logger.error e.message
redirect_to archives_path, alert: e.message
end
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def export_version
filename: "institutions_version_#{params[:number]}.csv"
end
end
rescue ArgumentError, Common::Exceptions::RecordNotFound, ActionController::UnknownFormat => e
rescue ArgumentError, Common::Exceptions::Internal::RecordNotFound, ActionController::UnknownFormat => e
log_error(e)
end

Expand All @@ -55,7 +55,7 @@ def export_ungeocodables
), type: 'text/csv', filename: 'ungeocodables.csv'
end
end
rescue ArgumentError, Common::Exceptions::RecordNotFound, ActionController::UnknownFormat => e
rescue ArgumentError, Common::Exceptions::Internal::RecordNotFound, ActionController::UnknownFormat => e
log_error(e)
end

Expand All @@ -67,7 +67,7 @@ def export_unaccrediteds
), type: 'text/csv', filename: 'unaccrediteds.csv'
end
end
rescue ArgumentError, Common::Exceptions::RecordNotFound, ActionController::UnknownFormat => e
rescue ArgumentError, Common::Exceptions::Internal::RecordNotFound, ActionController::UnknownFormat => e
log_error(e)
end

Expand All @@ -78,7 +78,7 @@ def export_partials
type: 'text/csv', filename: 'partials.csv'
end
end
rescue ArgumentError, Common::Exceptions::RecordNotFound, ActionController::UnknownFormat => e
rescue ArgumentError, Common::Exceptions::Internal::RecordNotFound, ActionController::UnknownFormat => e
log_error(e)
end

Expand All @@ -89,7 +89,7 @@ def export_orphans
type: 'text/csv', filename: 'orphans.csv'
end
end
rescue ArgumentError, Common::Exceptions::RecordNotFound, ActionController::UnknownFormat => e
rescue ArgumentError, Common::Exceptions::Internal::RecordNotFound, ActionController::UnknownFormat => e
log_error(e)
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def requirements

def upload_requirements(type)
{ type: type.name,
requirements: UploadRequirements.requirements_messages(type),
requirements: UploadTypes::UploadRequirements.requirements_messages(type),
custom_batch_validator: "#{type.name}Validator::REQUIREMENT_DESCRIPTIONS".safe_constantize,
inclusion: UploadRequirements.validation_messages_inclusion(type) }
inclusion: UploadTypes::UploadRequirements.validation_messages_inclusion(type) }
end

def alert_messages(loaded_data)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def show
private

def csv_requirements
@requirements = [RooHelper.valid_col_seps] + UploadRequirements.requirements_messages(klass)
@requirements = [RooHelper::Shared.valid_col_seps] + UploadTypes::UploadRequirements.requirements_messages(klass)
@custom_batch_validator = "#{klass.name}Validator::REQUIREMENT_DESCRIPTIONS".safe_constantize
@inclusion = UploadRequirements.validation_messages_inclusion(klass)
@inclusion = UploadTypes::UploadRequirements.validation_messages_inclusion(klass)
end

def alert_messages(data)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v0/institution_programs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module V0
class InstitutionProgramsController < ApiController
include Facets
include Search::Facets

# GET /v0/institution_programs/autocomplete?term=harv
def autocomplete
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/v0/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module V0
class InstitutionsController < ApiController
include Facets
include Search::Facets

# GET /v0/institutions/autocomplete?term=harv
def autocomplete
Expand Down Expand Up @@ -48,7 +48,7 @@ def index
def show
resource = Institution.approved_institutions(@version).find_by(facility_code: params[:id])

raise Common::Exceptions::RecordNotFound, params[:id] unless resource
raise Common::Exceptions::Internal::RecordNotFound, params[:id] unless resource

@links = { self: self_link }
render json: resource, serializer: InstitutionProfileSerializer,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v0/yellow_ribbon_programs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module V0
class YellowRibbonProgramsController < ApiController
include Facets
include Search::Facets

# GET /v0/yellow_ribbon_programs
# ?page=1
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v0/zipcode_rates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ZipcodeRatesController < ApiController
def show
resource = ZipcodeRate.joins(:version)
.where(zip_code: params[:id], version: @version).order(:mha_rate).first
raise Common::Exceptions::RecordNotFound, params[:id] unless resource
raise Common::Exceptions::Internal::RecordNotFound, params[:id] unless resource

render json: resource, serializer: ZipcodeRateSerializer
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/v1/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module V1
class InstitutionsController < ApiController
include Facets
include Search::Facets

# GET /v1/institutions/autocomplete?term=harv
def autocomplete
Expand Down Expand Up @@ -88,7 +88,7 @@ def facility_codes
def show
resource = Institution.approved_institutions(@version).find_by(facility_code: params[:id])

raise Common::Exceptions::RecordNotFound, params[:id] unless resource
raise Common::Exceptions::Internal::RecordNotFound, params[:id] unless resource

@links = { self: self_link }
render json: resource, serializer: InstitutionProfileSerializer,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v1/zipcode_rates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ZipcodeRatesController < ApiController
def show
resource = ZipcodeRate.joins(:version)
.where(zip_code: params[:id], version: @version).order(:mha_rate).first
raise Common::Exceptions::RecordNotFound, params[:id] unless resource
raise Common::Exceptions::Internal::RecordNotFound, params[:id] unless resource

render json: resource, serializer: ZipcodeRateSerializer
end
Expand Down
22 changes: 11 additions & 11 deletions app/models/accreditation_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class AccreditationAction < ImportableRecord
inverse_of: :accreditation_actions)

CSV_CONVERTER_INFO = {
'dapipid' => { column: :dapip_id, converter: NumberConverter },
'agencyid' => { column: :agency_id, converter: NumberConverter },
'agencyname' => { column: :agency_name, converter: InstitutionConverter },
'programid' => { column: :program_id, converter: NumberConverter },
'programname' => { column: :program_name, converter: BaseConverter },
'sequentialid' => { column: :sequential_id, converter: NumberConverter },
'actiondescription' => { column: :action_description, converter: BaseConverter },
'actiondate' => { column: :action_date, converter: AccreditationDateTimeConverter },
'justificationdescription' => { column: :justification_description, converter: BaseConverter },
'justificationother' => { column: :justification_other, converter: BaseConverter },
'enddate' => { column: :end_date, converter: BaseConverter }
'dapipid' => { column: :dapip_id, converter: Converters::NumberConverter },
'agencyid' => { column: :agency_id, converter: Converters::NumberConverter },
'agencyname' => { column: :agency_name, converter: Converters::InstitutionConverter },
'programid' => { column: :program_id, converter: Converters::NumberConverter },
'programname' => { column: :program_name, converter: Converters::BaseConverter },
'sequentialid' => { column: :sequential_id, converter: Converters::NumberConverter },
'actiondescription' => { column: :action_description, converter: Converters::BaseConverter },
'actiondate' => { column: :action_date, converter: Converters::AccreditationDateTimeConverter },
'justificationdescription' => { column: :justification_description, converter: Converters::BaseConverter },
'justificationother' => { column: :justification_other, converter: Converters::BaseConverter },
'enddate' => { column: :end_date, converter: Converters::BaseConverter }
}.freeze

PROBATIONARY_STATUSES = [
Expand Down
28 changes: 14 additions & 14 deletions app/models/accreditation_institute_campus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class AccreditationInstituteCampus < ImportableRecord
dependent: :nullify)

CSV_CONVERTER_INFO = {
'dapipid' => { column: :dapip_id, converter: NumberConverter },
'opeid' => { column: :ope, converter: OpeConverter },
'locationname' => { column: :location_name, converter: InstitutionConverter },
'parentname' => { column: :parent_name, converter: InstitutionConverter },
'parentdapipid' => { column: :parent_dapip_id, converter: NumberConverter },
'locationtype' => { column: :location_type, converter: BaseConverter },
'address' => { column: :address, converter: BaseConverter },
'generalphone' => { column: :general_phone, converter: BaseConverter },
'adminname' => { column: :admin_name, converter: BaseConverter },
'adminphone' => { column: :admin_phone, converter: BaseConverter },
'adminemail' => { column: :admin_email, converter: BaseConverter },
'fax' => { column: :fax, converter: BaseConverter },
'updatedate' => { column: :update_date, converter: DateConverter }
'dapipid' => { column: :dapip_id, converter: Converters::NumberConverter },
'opeid' => { column: :ope, converter: Converters::OpeConverter },
'locationname' => { column: :location_name, converter: Converters::InstitutionConverter },
'parentname' => { column: :parent_name, converter: Converters::InstitutionConverter },
'parentdapipid' => { column: :parent_dapip_id, converter: Converters::NumberConverter },
'locationtype' => { column: :location_type, converter: Converters::BaseConverter },
'address' => { column: :address, converter: Converters::BaseConverter },
'generalphone' => { column: :general_phone, converter: Converters::BaseConverter },
'adminname' => { column: :admin_name, converter: Converters::BaseConverter },
'adminphone' => { column: :admin_phone, converter: Converters::BaseConverter },
'adminemail' => { column: :admin_email, converter: Converters::BaseConverter },
'fax' => { column: :fax, converter: Converters::BaseConverter },
'updatedate' => { column: :update_date, converter: Converters::DateConverter }
}.freeze

validates :dapip_id, presence: true
Expand All @@ -33,6 +33,6 @@ class AccreditationInstituteCampus < ImportableRecord
private

def set_ope6
self.ope6 = Ope6Converter.convert(ope)
self.ope6 = Converters::Ope6Converter.convert(ope)
end
end
29 changes: 15 additions & 14 deletions app/models/accreditation_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ class AccreditationRecord < ImportableRecord
belongs_to(:accreditation_institute_campus, foreign_key: 'dapip_id', primary_key: :dapip_id,
inverse_of: :accreditation_records)

belongs_to(:accreditation_type_keyword, inverse_of: :accreditation_records)
# records may not have an accreditation_type_keyword
belongs_to(:accreditation_type_keyword, inverse_of: :accreditation_records, optional: true)

CSV_CONVERTER_INFO = {
'dapipid' => { column: :dapip_id, converter: NumberConverter },
'agencyid' => { column: :agency_id, converter: NumberConverter },
'agencyname' => { column: :agency_name, converter: InstitutionConverter },
'programid' => { column: :program_id, converter: NumberConverter },
'programname' => { column: :program_name, converter: BaseConverter },
'sequentialid' => { column: :sequential_id, converter: NumberConverter },
'initialdateflag' => { column: :initial_date_flag, converter: BaseConverter },
'accreditationdate' => { column: :accreditation_date, converter: DateConverter },
'accreditationstatus' => { column: :accreditation_status, converter: BaseConverter },
'reviewdate' => { column: :review_date, converter: DateConverter },
'departmentdescription' => { column: :department_description, converter: BaseConverter },
'accreditationenddate' => { column: :accreditation_end_date, converter: DateConverter },
'endingactionid' => { column: :ending_action_id, converter: NumberConverter }
'dapipid' => { column: :dapip_id, converter: Converters::NumberConverter },
'agencyid' => { column: :agency_id, converter: Converters::NumberConverter },
'agencyname' => { column: :agency_name, converter: Converters::InstitutionConverter },
'programid' => { column: :program_id, converter: Converters::NumberConverter },
'programname' => { column: :program_name, converter: Converters::BaseConverter },
'sequentialid' => { column: :sequential_id, converter: Converters::NumberConverter },
'initialdateflag' => { column: :initial_date_flag, converter: Converters::BaseConverter },
'accreditationdate' => { column: :accreditation_date, converter: Converters::DateConverter },
'accreditationstatus' => { column: :accreditation_status, converter: Converters::BaseConverter },
'reviewdate' => { column: :review_date, converter: Converters::DateConverter },
'departmentdescription' => { column: :department_description, converter: Converters::BaseConverter },
'accreditationenddate' => { column: :accreditation_end_date, converter: Converters::DateConverter },
'endingactionid' => { column: :ending_action_id, converter: Converters::NumberConverter }
}.freeze

validates :dapip_id, presence: true
Expand Down
14 changes: 7 additions & 7 deletions app/models/arf_gi_bill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

class ArfGiBill < ImportableRecord
CSV_CONVERTER_INFO = {
'facility_no.' => { column: :facility_code, converter: FacilityCodeConverter },
'school_name' => { column: :institution, converter: InstitutionConverter },
'station' => { column: :station, converter: BaseConverter },
'count_of_adv_pay_students' => { column: :count_of_adv_pay_students, converter: NumberConverter },
'count_of_reg_students' => { column: :count_of_reg_students, converter: NumberConverter },
'total_count_of_students' => { column: :gibill, converter: NumberConverter },
'total_paid' => { column: :station, converter: NumberConverter }
'facility_no.' => { column: :facility_code, converter: Converters::FacilityCodeConverter },
'school_name' => { column: :institution, converter: Converters::InstitutionConverter },
'station' => { column: :station, converter: Converters::BaseConverter },
'count_of_adv_pay_students' => { column: :count_of_adv_pay_students, converter: Converters::NumberConverter },
'count_of_reg_students' => { column: :count_of_reg_students, converter: Converters::NumberConverter },
'total_count_of_students' => { column: :gibill, converter: Converters::NumberConverter },
'total_paid' => { column: :station, converter: Converters::NumberConverter }
}.freeze

validates :facility_code, presence: true
Expand Down
6 changes: 3 additions & 3 deletions app/models/calculator_constant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class CalculatorConstant < ImportableRecord
CSV_CONVERTER_INFO = {
'name' => { column: :name, converter: UpcaseConverter },
'value' => { column: :float_value, converter: NumberConverter },
'description' => { column: :description, converter: BaseConverter }
'name' => { column: :name, converter: Converters::UpcaseConverter },
'value' => { column: :float_value, converter: Converters::NumberConverter },
'description' => { column: :description, converter: Converters::BaseConverter }
}.freeze

default_scope { order('name') }
Expand Down
16 changes: 8 additions & 8 deletions app/models/census_lat_long.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

class CensusLatLong < ImportableRecord
CSV_CONVERTER_INFO = {
'facility_code' => { column: :facility_code, converter: BaseConverter },
'input_address' => { column: :input_address, converter: BaseConverter },
'tiger_address_range_match_indicator' => { column: :tiger_address_range_match_indicator, converter: BaseConverter },
'tiger_match_type' => { column: :tiger_match_type, converter: BaseConverter },
'tiger_output_address' => { column: :tiger_output_address, converter: BaseConverter },
'interpolated_longitude_latitude' => { column: :interpolated_longitude_latitude, converter: BaseConverter },
'tiger_line_id' => { column: :tiger_line_id, converter: BaseConverter },
'tiger_line_id_side' => { column: :tiger_line_id_side, converter: BaseConverter }
'facility_code' => { column: :facility_code, converter: Converters::BaseConverter },
'input_address' => { column: :input_address, converter: Converters::BaseConverter },
'tiger_address_range_match_indicator' => { column: :tiger_address_range_match_indicator, converter: Converters::BaseConverter },
'tiger_match_type' => { column: :tiger_match_type, converter: Converters::BaseConverter },
'tiger_output_address' => { column: :tiger_output_address, converter: Converters::BaseConverter },
'interpolated_longitude_latitude' => { column: :interpolated_longitude_latitude, converter: Converters::BaseConverter },
'tiger_line_id' => { column: :tiger_line_id, converter: Converters::BaseConverter },
'tiger_line_id_side' => { column: :tiger_line_id_side, converter: Converters::BaseConverter }
}.freeze
end
16 changes: 8 additions & 8 deletions app/models/cip_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

class CipCode < ImportableRecord
CSV_CONVERTER_INFO = {
'cipfamily' => { column: :cip_family, converter: BaseConverter },
'cipcode' => { column: :cip_code, converter: BaseConverter },
'action' => { column: :action, converter: BaseConverter },
'textchange' => { column: :text_change, converter: BooleanConverter },
'ciptitle' => { column: :cip_title, converter: BaseConverter },
'cipdefinition' => { column: :cip_definition, converter: BaseConverter },
'crossreferences' => { column: :cross_references, converter: BaseConverter },
'examples' => { column: :examples, converter: BaseConverter }
'cipfamily' => { column: :cip_family, converter: Converters::BaseConverter },
'cipcode' => { column: :cip_code, converter: Converters::BaseConverter },
'action' => { column: :action, converter: Converters::BaseConverter },
'textchange' => { column: :text_change, converter: Converters::BooleanConverter },
'ciptitle' => { column: :cip_title, converter: Converters::BaseConverter },
'cipdefinition' => { column: :cip_definition, converter: Converters::BaseConverter },
'crossreferences' => { column: :cross_references, converter: Converters::BaseConverter },
'examples' => { column: :examples, converter: Converters::BaseConverter }
}.freeze
end
Loading

0 comments on commit 3d741c6

Please sign in to comment.