Skip to content

Commit

Permalink
Change class name to satisfy autoloader
Browse files Browse the repository at this point in the history
  • Loading branch information
colbyendres committed Oct 22, 2024
1 parent 3c1a9a3 commit dd10aa6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 37 deletions.
6 changes: 3 additions & 3 deletions app/controllers/schedules_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/services/csv_handler.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class CSVHandler
class CsvHandler
require 'csv'

def upload(file)
Expand Down
22 changes: 0 additions & 22 deletions app/views/rooms/_room.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions spec/services/csv_handler_spec.rb
Original file line number Diff line number Diff line change
@@ -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')) }
Expand All @@ -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
Expand All @@ -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.')
Expand All @@ -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')
Expand All @@ -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.')
Expand All @@ -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')
Expand Down

0 comments on commit dd10aa6

Please sign in to comment.