submissions_controller_test.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. require 'test_helper'
  2. class SubmissionsControllerTest < ActionDispatch::IntegrationTest
  3. setup do
  4. @teacher = users(:daniel)
  5. @student = users(:billy)
  6. @assignment = assignments(:one)
  7. @submission = submissions(:one)
  8. log_in_as @teacher
  9. end
  10. test "should get index" do
  11. get assignment_submissions_url(@assignment)
  12. assert_response :success
  13. end
  14. test "should get new" do
  15. get new_assignment_submission_url(@assignment)
  16. assert_response :success
  17. end
  18. test "student should create submission" do
  19. log_in_as @student
  20. assert_difference('Submission.count') do
  21. post assignment_submissions_url(@assignment), params: { submission: { description: @submission.description, title: @submission.title } }
  22. end
  23. assert_redirected_to submission_url(Submission.last)
  24. end
  25. test "should show submission" do
  26. get submission_url(@submission)
  27. assert_response :success
  28. end
  29. test "student should get edit" do
  30. log_in_as @student
  31. get edit_submission_url(@submission)
  32. assert_response :success
  33. end
  34. test "student should update submission" do
  35. log_in_as @student
  36. patch submission_url(@submission), params: { submission: { description: @submission.description, title: @submission.title } }
  37. assert_redirected_to submission_url(@submission)
  38. end
  39. test "should destroy submission" do
  40. assert_difference('Submission.count', -1) do
  41. delete submission_url(@submission)
  42. end
  43. assert_redirected_to assignment_submissions_url(@assignment)
  44. end
  45. end