Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Khalid Ali
schedules
Commits
cdadfe65
Commit
cdadfe65
authored
Aug 01, 2018
by
Zac Wood
Browse files
Added search by CRN for course sections
parent
b5bd4381
Changes
3
Hide whitespace changes
Inline
Side-by-side
schedules_api/app/controllers/course_sections_controller.rb
View file @
cdadfe65
...
...
@@ -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
schedules_api/test/controllers/course_sections_controller_test.rb
View file @
cdadfe65
...
...
@@ -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
schedules_api/test/fixtures/course_sections.yml
View file @
cdadfe65
...
...
@@ -37,7 +37,7 @@ cs112002:
course
:
cs112
cs211001
:
name
:
MyString
name
:
MyString
3
crn
:
MyString3
section_type
:
MyString
title
:
MyString
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment