users_controller_test.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #---
  2. # Excerpted from "Agile Web Development with Rails",
  3. # published by The Pragmatic Bookshelf.
  4. # Copyrights apply to this code. It may not be used to create training material,
  5. # courses, books, articles, and the like. Contact us if you are in doubt.
  6. # We make no guarantees that this code is fit for any purpose.
  7. # Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
  8. #---
  9. require 'test_helper'
  10. class UsersControllerTest < ActionController::TestCase
  11. setup do
  12. @user = users(:one)
  13. end
  14. test "should get index" do
  15. get :index
  16. assert_response :success
  17. assert_not_nil assigns(:users)
  18. end
  19. test "should get new" do
  20. get :new
  21. assert_response :success
  22. end
  23. test "should create user" do
  24. assert_difference('User.count') do
  25. post :create, user: { name: 'sam', password: 'secret',
  26. password_confirmation: 'secret' }
  27. end
  28. assert_redirected_to users_path
  29. end
  30. test "should show user" do
  31. get :show, id: @user
  32. assert_response :success
  33. end
  34. test "should get edit" do
  35. get :edit, id: @user
  36. assert_response :success
  37. end
  38. test "should update user" do
  39. patch :update, id: @user, user: { name: @user.name, password: 'secret',
  40. password_confirmation: 'secret' }
  41. assert_redirected_to users_path
  42. end
  43. test "should destroy user" do
  44. assert_difference('User.count', -1) do
  45. delete :destroy, id: @user
  46. end
  47. assert_redirected_to users_path
  48. end
  49. end