users_controller_test.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. @input_attributes = {
  21. :name => "sam",
  22. :password => "private",
  23. :password_confirmation => "private"
  24. }
  25. @user = users(:one)
  26. end
  27. test "should get index" do
  28. get :index
  29. assert_response :success
  30. assert_not_nil assigns(:users)
  31. end
  32. test "should get new" do
  33. get :new
  34. assert_response :success
  35. end
  36. #...
  37. test "should create user" do
  38. assert_difference('User.count') do
  39. post :create, :user => @input_attributes
  40. end
  41. assert_redirected_to users_path
  42. end
  43. test "should show user" do
  44. get :show, :id => @user.to_param
  45. assert_response :success
  46. end
  47. test "should get edit" do
  48. get :edit, :id => @user.to_param
  49. assert_response :success
  50. end
  51. #...
  52. test "should update user" do
  53. put :update, :id => @user.to_param, :user => @input_attributes
  54. assert_redirected_to users_path
  55. end
  56. test "should destroy user" do
  57. assert_difference('User.count', -1) do
  58. delete :destroy, :id => @user.to_param
  59. end
  60. assert_redirected_to users_path
  61. end
  62. end