users_controller_test.rb 1.5 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. require 'test_helper'
  10. class UsersControllerTest < ActionController::TestCase
  11. setup do
  12. @input_attributes = {
  13. name: "sam",
  14. password: "private",
  15. password_confirmation: "private"
  16. }
  17. @user = users(:one)
  18. end
  19. test "should get index" do
  20. get :index
  21. assert_response :success
  22. assert_not_nil assigns(:users)
  23. end
  24. test "should get new" do
  25. get :new
  26. assert_response :success
  27. end
  28. #...
  29. test "should create user" do
  30. assert_difference('User.count') do
  31. post :create, user: @input_attributes
  32. end
  33. assert_redirected_to users_path
  34. end
  35. test "should show user" do
  36. get :show, id: @user
  37. assert_response :success
  38. end
  39. test "should get edit" do
  40. get :edit, id: @user
  41. assert_response :success
  42. end
  43. #...
  44. test "should update user" do
  45. put :update, id: @user, user: @input_attributes
  46. assert_redirected_to users_path
  47. end
  48. test "should destroy user" do
  49. assert_difference('User.count', -1) do
  50. delete :destroy, id: @user
  51. end
  52. assert_redirected_to users_path
  53. end
  54. end