users_controller_test.rb 1.8 KB

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