From dd10aa6f9297a82736482a9a8a7d80d5c31a0133 Mon Sep 17 00:00:00 2001 From: colbyendres Date: Mon, 21 Oct 2024 18:55:49 -0500 Subject: [PATCH] Change class name to satisfy autoloader --- app/controllers/schedules_controller.rb | 6 +++--- app/services/csv_handler.rb | 2 +- app/views/rooms/_room.html.erb | 22 ---------------------- config/application.rb | 3 --- spec/services/csv_handler_spec.rb | 16 ++++++++-------- 5 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 app/views/rooms/_room.html.erb diff --git a/app/controllers/schedules_controller.rb b/app/controllers/schedules_controller.rb index 9349860..c6cf630 100644 --- a/app/controllers/schedules_controller.rb +++ b/app/controllers/schedules_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../services/csv_handler' +# require_relative '../services/csv_handler' # app/controllers/schedules_controller.rb class SchedulesController < ApplicationController @@ -50,7 +50,7 @@ def upload_rooms # We've erased our past data with no way to restore it # We probably need to create a back up and restore if parsing gives an alert @schedule.rooms.destroy_all - csv_handler = CSVHandler.new + csv_handler = CsvHandler.new csv_handler.upload(params[:room_file]) flash_result = csv_handler.parse_room_csv(@schedule.id) flash[flash_result.keys.first] = flash_result.values.first @@ -64,7 +64,7 @@ def upload_instructors if params[:instructor_file].present? # FIXME: See concern in upload_rooms @schedule.instructors.destroy_all - csv_handler = CSVHandler.new + csv_handler = CsvHandler.new csv_handler.upload(params[:instructor_file]) flash_result = csv_handler.parse_instructor_csv(@schedule.id) flash[flash_result.keys.first] = flash_result.values.first diff --git a/app/services/csv_handler.rb b/app/services/csv_handler.rb index 1050cbc..a1f1cd2 100644 --- a/app/services/csv_handler.rb +++ b/app/services/csv_handler.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CSVHandler +class CsvHandler require 'csv' def upload(file) diff --git a/app/views/rooms/_room.html.erb b/app/views/rooms/_room.html.erb deleted file mode 100644 index d5b4328..0000000 --- a/app/views/rooms/_room.html.erb +++ /dev/null @@ -1,22 +0,0 @@ - - <%= room.campus %> - <%= room.building_code %> - <%= room.room_number %> - <%= room.capacity %> - - - - <%= usage_type_message(room.is_lecture_hall, room.is_active) %> - - - - - <%= usage_type_message(room.is_learning_studio, room.is_active) %> - - - - - <%= usage_type_message(room.is_lab, room.is_active) %> - - <%= room.comments %> - \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 0e4384d..346dd68 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,8 +26,5 @@ class Application < Rails::Application # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") - - # Ensure that the CSV handler services is autoloaded - config.autoload_paths += %W(#{config.root}/app/services) end end diff --git a/spec/services/csv_handler_spec.rb b/spec/services/csv_handler_spec.rb index aa0dfc3..1a1b1fd 100644 --- a/spec/services/csv_handler_spec.rb +++ b/spec/services/csv_handler_spec.rb @@ -1,7 +1,7 @@ # spec/services/csv_handler_spec.rb require 'rails_helper' -RSpec.describe CSVHandler do +RSpec.describe CsvHandler do let(:schedule) { create(:schedule) } let(:valid_room_csv) { File.read(Rails.root.join('spec', 'fixtures', 'rooms', 'rooms_valid.csv')) } let(:invalid_room_csv) { File.read(Rails.root.join('spec', 'fixtures', 'rooms', 'rooms_invalid.csv')) } @@ -10,7 +10,7 @@ describe '#initialize' do it 'initializes with a file' do - handler = CSVHandler.new + handler = CsvHandler.new handler.upload(valid_room_csv) expect(handler.instance_variable_get(:@file)).to eq(valid_room_csv) end @@ -19,14 +19,14 @@ describe '#parse_room_csv' do context 'with valid data' do it 'creates room records' do - handler = CSVHandler.new + handler = CsvHandler.new handler.upload(StringIO.new(valid_room_csv)) handler.parse_room_csv(schedule.id) expect(Room.count).to eq(10) end it 'returns a success message' do - handler = CSVHandler.new + handler = CsvHandler.new handler.upload(StringIO.new(valid_room_csv)) result = handler.parse_room_csv(schedule.id) expect(result[:notice]).to eq('Rooms successfully uploaded.') @@ -35,7 +35,7 @@ context 'with invalid data' do it 'prints an alert' do - handler = CSVHandler.new + handler = CsvHandler.new handler.upload(StringIO.new(invalid_room_csv)) result = handler.parse_room_csv(schedule.id) expect(result[:alert]).to include('There was an error uploading the CSV file') @@ -46,14 +46,14 @@ describe '#parse_instructor_csv' do context 'with valid data' do it 'creates instructor records' do - handler = CSVHandler.new + handler = CsvHandler.new handler.upload(StringIO.new(valid_instructor_csv)) handler.parse_instructor_csv(schedule.id) expect(Instructor.count).to eq(4) end it 'returns a success message' do - handler = CSVHandler.new + handler = CsvHandler.new handler.upload(StringIO.new(valid_instructor_csv)) result = handler.parse_instructor_csv(schedule.id) expect(result[:notice]).to eq('Instructors successfully uploaded.') @@ -62,7 +62,7 @@ context 'with missing header data' do it 'prints an alert' do - handler = CSVHandler.new + handler = CsvHandler.new handler.upload(StringIO.new(invalid_instructor_csv)) result = handler.parse_instructor_csv(schedule.id) expect(result[:alert]).to include('Missing required headers')