courses_controller_test.rb 1.3 KB
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2 3
require 'test_helper'

class CoursesControllerTest < ActionDispatch::IntegrationTest
4 5
  test '#index should return all courses' do
    get courses_url
Zac Wood's avatar
Zac Wood committed
6
    assert_response :success
7 8 9 10
    
    courses_returned = JSON.parse @response.body
    courses_count = Course.all.count
    assert_equal courses_count, courses_returned.count
Zac Wood's avatar
Zac Wood committed
11
  end
12

13 14
  test '#index should return filtered by subject case insensitive' do
    get courses_url subject: "Cs"
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    assert_response :success

    courses_returned = JSON.parse @response.body
    courses_count = Course.where(subject: "CS").count

    assert_equal courses_count, courses_returned.count
  end

  test '#index should return filtered by subject and course number' do
    get courses_url subject: "CS", course_number: "112"
    assert_response :success

    courses_returned = JSON.parse @response.body
    courses_count = Course.where(subject: "CS", course_number: "112").count

    assert_equal courses_count, courses_returned.count
  end

  test '#show should return course_sections for course' do
    cs_112_id = courses(:cs112).id
    
    get course_url id: cs_112_id
    assert_response :success

    sections_returned = JSON.parse @response.body
    cs_112_sections = CourseSection.where(course_id: cs_112_id)

    assert_equal cs_112_sections.count, sections_returned.count
  end
    
Zac Wood's avatar
Zac Wood committed
45
end