Commit 7a2a9aff authored by Zac Wood's avatar Zac Wood

rubo 馃懏

parent 43791089
Pipeline #3850 passed with stage
in 2 minutes and 45 seconds
...@@ -11,10 +11,10 @@ class API::CourseSectionsController < ApplicationController ...@@ -11,10 +11,10 @@ class API::CourseSectionsController < ApplicationController
param :instructor, String, desc: "Get course sections being taught by this instructor" param :instructor, String, desc: "Get course sections being taught by this instructor"
def index def index
@sections = CourseSection @sections = CourseSection
.where(semester: @semester) .where(semester: @semester)
.joins(:course) .joins(:course)
.joins(:instructor) .joins(:instructor)
.select('course_sections.*, instructors.name AS instructor_name') .select('course_sections.*, instructors.name AS instructor_name')
if params.key?(:course_id) if params.key?(:course_id)
@sections = @sections.where(course_id: params[:course_id]) @sections = @sections.where(course_id: params[:course_id])
......
...@@ -7,7 +7,7 @@ class API::SemestersController < ApplicationController ...@@ -7,7 +7,7 @@ class API::SemestersController < ApplicationController
year: s.year year: s.year
} }
end end
render json: result render json: result
end end
end end
...@@ -3,8 +3,8 @@ class CourseSection < ApplicationRecord ...@@ -3,8 +3,8 @@ class CourseSection < ApplicationRecord
# Each +CourseSection+ belongs to a +Course+ and an +Instructor+. # Each +CourseSection+ belongs to a +Course+ and an +Instructor+.
belongs_to :course belongs_to :course
belongs_to :instructor belongs_to :instructor
# Each course belongs to a +Semester+ # Each course belongs to a +Semester+
belongs_to :semester belongs_to :semester
# Ensure all necessary fields are present. # Ensure all necessary fields are present.
......
...@@ -119,7 +119,6 @@ def main ...@@ -119,7 +119,6 @@ def main
parser.parse_semesters[0..6] parser.parse_semesters[0..6]
end end
puts "\tParsing subjects..." puts "\tParsing subjects..."
subjects = parser.parse_subjects(semesters.first[:value]) subjects = parser.parse_subjects(semesters.first[:value])
...@@ -128,7 +127,7 @@ def main ...@@ -128,7 +127,7 @@ def main
puts "\tLoading courses..." puts "\tLoading courses..."
load_courses(courses) load_courses(courses)
semesters.each do |semester| semesters.each do |semester|
puts "#{semester[:season]} #{semester[:year]}" puts "#{semester[:season]} #{semester[:year]}"
db_semester = Semester.find_or_create_by!(season: semester[:season], year: semester[:year]) db_semester = Semester.find_or_create_by!(season: semester[:season], year: semester[:year])
......
...@@ -4,13 +4,13 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest ...@@ -4,13 +4,13 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
test 'should get index' do test 'should get index' do
get api_course_sections_url(course_id: courses(:cs112).id, get api_course_sections_url(course_id: courses(:cs112).id,
semester_id: semesters(:fall2018).id) semester_id: semesters(:fall2018).id)
assert_response :success assert_response :success
sections_returned = JSON.parse @response.body sections_returned = JSON.parse @response.body
num_sections = CourseSection num_sections = CourseSection
.where(course_id: courses(:cs112).id) .where(course_id: courses(:cs112).id)
.where(semester: semesters(:fall2018)).count .where(semester: semesters(:fall2018)).count
assert_equal num_sections, sections_returned.count assert_equal num_sections, sections_returned.count
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