courses_controller_test.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'test_helper'
  2. class CoursesControllerTest < ActionDispatch::IntegrationTest
  3. def setup
  4. @course = courses(:two)
  5. @school = schools(:two)
  6. @student_user = users(:billy)
  7. @school_admin = users(:daniel)
  8. @global_admin = users(:admin)
  9. end
  10. test "should show course" do
  11. log_in_as @student_user
  12. get course_path @course
  13. assert_response :success
  14. end
  15. test "student should not edit course" do
  16. log_in_as @student_user
  17. get edit_course_path @course
  18. assert_redirected_to root_url
  19. end
  20. test "school admin should edit and update course" do
  21. log_in_as @school_admin
  22. get edit_course_path @course
  23. assert_response :success
  24. patch course_path(@course), params: { course: { name: "New Name" } }
  25. assert_redirected_to @course
  26. assert_equal "New Name", @course.reload.name
  27. end
  28. test "school admin should create new course" do
  29. log_in_as @school_admin
  30. get new_course_path
  31. assert_response :success
  32. assert_difference "Course.count", 1 do
  33. post courses_path, params: { course: { name: "New Course",
  34. school_id: @school.id,
  35. starts_on: 2.days.ago,
  36. ends_on: 2.days.since } }
  37. end
  38. end
  39. test "global admin should create new course" do
  40. log_in_as @global_admin
  41. get new_course_path
  42. assert_response :success
  43. assert_difference "Course.count", 1 do
  44. post courses_path, params: { course: { name: "New Course",
  45. school_id: @school.id,
  46. starts_on: 2.days.ago,
  47. ends_on: 2.days.since } }
  48. end
  49. end
  50. end