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

Renamed Section to CourseSection

parent 89b77445
......@@ -6,7 +6,7 @@ class CalendarGeneratorController < ApplicationController
cal = Icalendar::Calendar.new
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)
cal.add_event(event)
end
......@@ -17,7 +17,7 @@ class CalendarGeneratorController < ApplicationController
private
# Configures a calendar event from a given section
# @param section [Section]
# @param section [CourseSection]
def generate_event_from_section(section)
event = Icalendar::Event.new
......@@ -56,7 +56,7 @@ class CalendarGeneratorController < ApplicationController
# Generates a recurrence rule string descripting which day the class event
# should take place on
# @param section [Section]
# @param section [CourseSection]
# @return [String]
def recurrence_rule_str(section)
days = section.days.split("").map do |day|
......@@ -67,7 +67,7 @@ class CalendarGeneratorController < ApplicationController
end
# Get all dates that should excluded from the schedule
# @param section [Section]
# @param section [CourseSection]
# @return [Array]
def exdates_for_section(section)
# 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
class SectionsController < ApplicationController
class CourseSectionsController < ApplicationController
# Render JSON of all Sections belonging to a given Course.
def index
@course = Course.find(params[:course_id])
@sections = @course.sections
@sections = @course.course_sections
render json: @sections
end
end
......@@ -2,7 +2,7 @@ class SearchController < ApplicationController
def index
if params.key?(:crn)
crn = params[:crn]
@sections = Section.find_by_crn(crn)
@sections = CourseSection.find_by_crn(crn)
render json: @sections
else
render status: 404
......
......@@ -10,9 +10,9 @@ class Course < ApplicationRecord
validates :subject, 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]
def sections
Section.where course_id: id
def course_sections
CourseSection.where course_id: id
end
end
# Contains logic belonging to the +Section+ model.
# Contains logic belonging to the +CourseSection+ model.
#
# TODO: Add more docs
class Section < ApplicationRecord
# Each +Section+ belongs to a +Course+.
class CourseSection < ApplicationRecord
# Each +CourseSection+ belongs to a +Course+.
belongs_to :course
# Ensure all necessary fields are present.
......
......@@ -2,7 +2,7 @@
Rails.application.routes.draw do
scope :api do # Register /api routes
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
get 'search', controller: 'search', action: 'index'
......
......@@ -38,7 +38,7 @@ class ExcelLoader
def delete_all_records
Semester.delete_all
Course.delete_all
Section.delete_all
CourseSection.delete_all
end
# Tries to create a course from a given row.
......@@ -70,7 +70,7 @@ class ExcelLoader
# So, split the times string by the - character
times = row.cells[23]&.value
time_strs = times.split('-')
section = Section.create name: section_name,
section = CourseSection.create name: section_name,
course: @current_course,
crn: row.cells[6]&.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 @@
#
# 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|
t.date "date"
......@@ -20,16 +20,7 @@ ActiveRecord::Schema.define(version: 20180505195736) do
t.index ["semester_id"], name: "index_closures_on_semester_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
create_table "sections", force: :cascade do |t|
create_table "course_sections", force: :cascade do |t|
t.string "name"
t.string "crn"
t.string "section_type"
......@@ -48,7 +39,16 @@ ActiveRecord::Schema.define(version: 20180505195736) do
t.integer "course_id"
t.datetime "created_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
create_table "semesters", force: :cascade do |t|
......
......@@ -33,7 +33,7 @@ ThreadsWait.all_waits(*threads)
# delete everything in the current database
Closure.delete_all
Section.delete_all
CourseSection.delete_all
Course.delete_all
Semester.delete_all
......@@ -59,7 +59,7 @@ total.each do |subject, sections|
puts "Adding #{section_name}..."
Section.create!(name: section_name,
CourseSection.create!(name: section_name,
crn: section[:crn],
section_type: section[:type],
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'
class SectionTest < ActiveSupport::TestCase
class CourseSectionTest < ActiveSupport::TestCase
test 'fails with improper data' do
assert_raise do
Section.create! name: nil,
CourseSection.create! name: nil,
crn: nil,
title: nil,
start_date: nil,
......@@ -13,7 +13,7 @@ class SectionTest < ActiveSupport::TestCase
end
test 'succeeds with proper data' do
Section.create! name: 'Test section',
CourseSection.create! name: 'Test section',
crn: '12345',
title: 'Test title',
start_date: Time.zone.today,
......
......@@ -9,6 +9,6 @@ class ExcelLoaderTest < ActiveSupport::TestCase
assert(Semester.count > NUMBER_ADDED_BY_FIXTURES, 'No semester 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
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