schools_controller_test.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. require 'test_helper'
  2. class SchoolsControllerTest < ActionDispatch::IntegrationTest
  3. def setup
  4. @school = schools(:two)
  5. @student_user = users(:billy)
  6. @school_admin = users(:daniel)
  7. @global_admin = users(:admin)
  8. end
  9. test "should show school" do
  10. log_in_as @student_user
  11. get school_path @school
  12. assert_response :success
  13. end
  14. test "student should not edit school" do
  15. log_in_as @student_user
  16. get edit_school_path @school
  17. assert_redirected_to root_url
  18. end
  19. test "school admin should edit and update school" do
  20. log_in_as @school_admin
  21. get edit_school_path @school
  22. assert_response :success
  23. patch school_path(@school), params: { school: { name: "New Name" } }
  24. assert_redirected_to @school
  25. assert_equal "New Name", @school.reload.name
  26. end
  27. test "school admin should not create new school" do
  28. log_in_as @school_admin
  29. get new_school_path
  30. assert_redirected_to root_url
  31. end
  32. test "global admin should create new school" do
  33. log_in_as @global_admin
  34. get new_school_path
  35. assert_response :success
  36. assert_difference "School.count", 1 do
  37. post schools_path, params: { school: { name: "New School" } }
  38. end
  39. end
  40. end