assignments_controller_test.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. require 'test_helper'
  2. class AssignmentsControllerTest < ActionDispatch::IntegrationTest
  3. setup do
  4. @assignment = assignments(:one)
  5. @course = courses(:one)
  6. @global_admin = users(:admin)
  7. log_in_as @global_admin
  8. end
  9. test "should get index" do
  10. get assignments_url
  11. assert_response :success
  12. end
  13. test "should get new" do
  14. get new_assignment_url
  15. assert_response :success
  16. end
  17. test "should create assignment" do
  18. assert_difference('Assignment.count') do
  19. post assignments_url, params: { assignment: { course_id: @course.id, name: "Lorem Ipsum", due_at: 2.days.since } }
  20. end
  21. assert_redirected_to assignment_url(Assignment.last)
  22. end
  23. test "should not create invalid assignment" do
  24. assert_no_difference('Assignment.count') do
  25. post assignments_url, params: { assignment: { course_id: @course.id, name: "Lorem Ipsum" } }
  26. end
  27. end
  28. test "should show assignment" do
  29. get assignment_url(@assignment)
  30. assert_response :success
  31. end
  32. test "should get edit" do
  33. get edit_assignment_url(@assignment)
  34. assert_response :success
  35. end
  36. test "should update assignment" do
  37. patch assignment_url(@assignment), params: { assignment: { name: "New Name" } }
  38. assert_redirected_to assignment_url(@assignment)
  39. assert_equal @assignment.reload.name, "New Name"
  40. end
  41. test "should destroy assignment" do
  42. assert_difference('Assignment.count', -1) do
  43. delete assignment_url(@assignment)
  44. end
  45. assert_redirected_to assignments_url
  46. end
  47. end