Commit 8b0cf18d authored by Zac Wood's avatar Zac Wood
Browse files

Renamed Section to CourseSection

parent 89b77445
...@@ -6,7 +6,7 @@ class CalendarGeneratorController < ApplicationController ...@@ -6,7 +6,7 @@ class CalendarGeneratorController < ApplicationController
cal = Icalendar::Calendar.new cal = Icalendar::Calendar.new
params[:_json].each do |crn| # for each CRN sent by the post request params[:_json].each do |crn| # for each CRN sent by the post request
section = Section.find_by_crn(crn) section = CourseSection.find_by_crn(crn)
event = generate_event_from_section(section) event = generate_event_from_section(section)
cal.add_event(event) cal.add_event(event)
end end
...@@ -17,7 +17,7 @@ class CalendarGeneratorController < ApplicationController ...@@ -17,7 +17,7 @@ class CalendarGeneratorController < ApplicationController
private private
# Configures a calendar event from a given section # Configures a calendar event from a given section
# @param section [Section] # @param section [CourseSection]
def generate_event_from_section(section) def generate_event_from_section(section)
event = Icalendar::Event.new event = Icalendar::Event.new
...@@ -56,7 +56,7 @@ class CalendarGeneratorController < ApplicationController ...@@ -56,7 +56,7 @@ class CalendarGeneratorController < ApplicationController
# Generates a recurrence rule string descripting which day the class event # Generates a recurrence rule string descripting which day the class event
# should take place on # should take place on
# @param section [Section] # @param section [CourseSection]
# @return [String] # @return [String]
def recurrence_rule_str(section) def recurrence_rule_str(section)
days = section.days.split("").map do |day| days = section.days.split("").map do |day|
...@@ -67,7 +67,7 @@ class CalendarGeneratorController < ApplicationController ...@@ -67,7 +67,7 @@ class CalendarGeneratorController < ApplicationController
end end
# Get all dates that should excluded from the schedule # Get all dates that should excluded from the schedule
# @param section [Section] # @param section [CourseSection]
# @return [Array] # @return [Array]
def exdates_for_section(section) def exdates_for_section(section)
# Generate exdates for all closures in a semester # Generate exdates for all closures in a semester
......
# Contains all actions having to do with Sections. # Contains all actions having to do with CourseSections.
# This is a nested controller -- see +config/routes.rb+ for details # This is a nested controller -- see +config/routes.rb+ for details
class SectionsController < ApplicationController class CourseSectionsController < ApplicationController
# Render JSON of all Sections belonging to a given Course. # Render JSON of all Sections belonging to a given Course.
def index def index
@course = Course.find(params[:course_id]) @course = Course.find(params[:course_id])
@sections = @course.sections @sections = @course.course_sections
render json: @sections render json: @sections
end end
end end
...@@ -2,7 +2,7 @@ class SearchController < ApplicationController ...@@ -2,7 +2,7 @@ class SearchController < ApplicationController
def index def index
if params.key?(:crn) if params.key?(:crn)
crn = params[:crn] crn = params[:crn]
@sections = Section.find_by_crn(crn) @sections = CourseSection.find_by_crn(crn)
render json: @sections render json: @sections
else else
render status: 404 render status: 404
......
...@@ -10,9 +10,9 @@ class Course < ApplicationRecord ...@@ -10,9 +10,9 @@ class Course < ApplicationRecord
validates :subject, presence: true validates :subject, presence: true
validates :semester_id, presence: true validates :semester_id, presence: true
# Returns all +Section+ objects that belong to this course. # Returns all +CourseSection+ objects that belong to this course.
# @return [Array] # @return [Array]
def sections def course_sections
Section.where course_id: id CourseSection.where course_id: id
end end
end end
# Contains logic belonging to the +Section+ model. # Contains logic belonging to the +CourseSection+ model.
# #
# TODO: Add more docs # TODO: Add more docs
class Section < ApplicationRecord class CourseSection < ApplicationRecord
# Each +Section+ belongs to a +Course+. # Each +CourseSection+ belongs to a +Course+.
belongs_to :course belongs_to :course
# Ensure all necessary fields are present. # Ensure all necessary fields are present.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Rails.application.routes.draw do Rails.application.routes.draw do
scope :api do # Register /api routes scope :api do # Register /api routes
resources :courses, only: [:index] do # GET /api/courses resources :courses, only: [:index] do # GET /api/courses
resources :sections, only: [:index] # GET /api/courses/:course_id/sections resources :course_sections, only: [:index] # GET /api/courses/:course_id/sections
end end
get 'search', controller: 'search', action: 'index' get 'search', controller: 'search', action: 'index'
......
...@@ -38,7 +38,7 @@ class ExcelLoader ...@@ -38,7 +38,7 @@ class ExcelLoader
def delete_all_records def delete_all_records
Semester.delete_all Semester.delete_all
Course.delete_all Course.delete_all
Section.delete_all CourseSection.delete_all
end end
# Tries to create a course from a given row. # Tries to create a course from a given row.
...@@ -70,7 +70,7 @@ class ExcelLoader ...@@ -70,7 +70,7 @@ class ExcelLoader
# So, split the times string by the - character # So, split the times string by the - character
times = row.cells[23]&.value times = row.cells[23]&.value
time_strs = times.split('-') time_strs = times.split('-')
section = Section.create name: section_name, section = CourseSection.create name: section_name,
course: @current_course, course: @current_course,
crn: row.cells[6]&.value, crn: row.cells[6]&.value,
section_type: row.cells[8]&.value, section_type: row.cells[8]&.value,
......
class ChangeSectionToCourseSection < ActiveRecord::Migration[5.1]
def change
rename_table :sections, :course_sections
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180505195736) do ActiveRecord::Schema.define(version: 20180619011649) do
create_table "closures", force: :cascade do |t| create_table "closures", force: :cascade do |t|
t.date "date" t.date "date"
...@@ -20,16 +20,7 @@ ActiveRecord::Schema.define(version: 20180505195736) do ...@@ -20,16 +20,7 @@ ActiveRecord::Schema.define(version: 20180505195736) do
t.index ["semester_id"], name: "index_closures_on_semester_id" t.index ["semester_id"], name: "index_closures_on_semester_id"
end end
create_table "courses", force: :cascade do |t| create_table "course_sections", force: :cascade do |t|
t.string "subject"
t.string "course_number"
t.integer "semester_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["semester_id"], name: "index_courses_on_semester_id"
end
create_table "sections", force: :cascade do |t|
t.string "name" t.string "name"
t.string "crn" t.string "crn"
t.string "section_type" t.string "section_type"
...@@ -48,7 +39,16 @@ ActiveRecord::Schema.define(version: 20180505195736) do ...@@ -48,7 +39,16 @@ ActiveRecord::Schema.define(version: 20180505195736) do
t.integer "course_id" t.integer "course_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["course_id"], name: "index_sections_on_course_id" t.index ["course_id"], name: "index_course_sections_on_course_id"
end
create_table "courses", force: :cascade do |t|
t.string "subject"
t.string "course_number"
t.integer "semester_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["semester_id"], name: "index_courses_on_semester_id"
end end
create_table "semesters", force: :cascade do |t| create_table "semesters", force: :cascade do |t|
......
...@@ -33,7 +33,7 @@ ThreadsWait.all_waits(*threads) ...@@ -33,7 +33,7 @@ ThreadsWait.all_waits(*threads)
# delete everything in the current database # delete everything in the current database
Closure.delete_all Closure.delete_all
Section.delete_all CourseSection.delete_all
Course.delete_all Course.delete_all
Semester.delete_all Semester.delete_all
...@@ -59,7 +59,7 @@ total.each do |subject, sections| ...@@ -59,7 +59,7 @@ total.each do |subject, sections|
puts "Adding #{section_name}..." puts "Adding #{section_name}..."
Section.create!(name: section_name, CourseSection.create!(name: section_name,
crn: section[:crn], crn: section[:crn],
section_type: section[:type], section_type: section[:type],
title: section[:title], title: section[:title],
......
require 'test_helper'
class CourseSectionsControllerTest < ActionDispatch::IntegrationTest
test 'should get index' do
# get url_for controller: 'course_sections', action: 'index', course_id: 1
get url_for controller: 'course_sections', action: 'index', course_id: 1
assert_response :success
end
end
require 'test_helper'
class SectionsControllerTest < ActionDispatch::IntegrationTest
test 'should get index' do
get url_for controller: 'sections', action: 'index', course_id: 1
assert_response :success
end
end
require 'test_helper' require 'test_helper'
class SectionTest < ActiveSupport::TestCase class CourseSectionTest < ActiveSupport::TestCase
test 'fails with improper data' do test 'fails with improper data' do
assert_raise do assert_raise do
Section.create! name: nil, CourseSection.create! name: nil,
crn: nil, crn: nil,
title: nil, title: nil,
start_date: nil, start_date: nil,
...@@ -13,7 +13,7 @@ class SectionTest < ActiveSupport::TestCase ...@@ -13,7 +13,7 @@ class SectionTest < ActiveSupport::TestCase
end end
test 'succeeds with proper data' do test 'succeeds with proper data' do
Section.create! name: 'Test section', CourseSection.create! name: 'Test section',
crn: '12345', crn: '12345',
title: 'Test title', title: 'Test title',
start_date: Time.zone.today, start_date: Time.zone.today,
......
...@@ -9,6 +9,6 @@ class ExcelLoaderTest < ActiveSupport::TestCase ...@@ -9,6 +9,6 @@ class ExcelLoaderTest < ActiveSupport::TestCase
assert(Semester.count > NUMBER_ADDED_BY_FIXTURES, 'No semester loaded') assert(Semester.count > NUMBER_ADDED_BY_FIXTURES, 'No semester loaded')
assert(Course.count > NUMBER_ADDED_BY_FIXTURES, 'No courses loaded') assert(Course.count > NUMBER_ADDED_BY_FIXTURES, 'No courses loaded')
assert(Section.count > NUMBER_ADDED_BY_FIXTURES, 'No sections loaded') assert(CourseSection.count > NUMBER_ADDED_BY_FIXTURES, 'No sections loaded')
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment