Commit cdadfe65 authored by Zac Wood's avatar Zac Wood

Added search by CRN for course sections

parent b5bd4381
......@@ -3,7 +3,11 @@
class CourseSectionsController < ApplicationController
# Render JSON of all Sections belonging to a given Course.
def index
@sections = CourseSection.where(course_id: params[:course_id])
@sections = CourseSection.all
@sections = @sections.where(course_id: params[:course_id]) if params.key?(:course_id)
@sections = @sections.where(crn: params[:crn]) if params.key?(:crn)
render json: @sections
end
end
......@@ -10,4 +10,12 @@ class CourseSectionsControllerTest < ActionDispatch::IntegrationTest
assert_equal num_sections, sections_returned.count
end
test 'should filter by crn' do
get course_sections_url crn: course_sections(:cs112001).crn
assert_response :success
sections_returned = JSON.parse @response.body
assert_equal course_sections(:cs112001).name, sections_returned[0]["name"]
end
end
......@@ -37,7 +37,7 @@ cs112002:
course: cs112
cs211001:
name: MyString
name: MyString3
crn: MyString3
section_type: MyString
title: MyString
......
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