carts_controller_test.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 CartsControllerTest < ActionController::TestCase
  19. setup do
  20. @cart = carts(:one)
  21. end
  22. test "should get index" do
  23. get :index
  24. assert_response :success
  25. assert_not_nil assigns(:carts)
  26. end
  27. test "should get new" do
  28. get :new
  29. assert_response :success
  30. end
  31. test "should create cart" do
  32. assert_difference('Cart.count') do
  33. post :create, :cart => @cart.attributes
  34. end
  35. assert_redirected_to cart_path(assigns(:cart))
  36. end
  37. test "should show cart" do
  38. get :show, :id => @cart.to_param
  39. assert_response :success
  40. end
  41. test "should get edit" do
  42. get :edit, :id => @cart.to_param
  43. assert_response :success
  44. end
  45. test "should update cart" do
  46. put :update, :id => @cart.to_param, :cart => @cart.attributes
  47. assert_redirected_to cart_path(assigns(:cart))
  48. end
  49. test "should destroy cart" do
  50. assert_difference('Cart.count', -1) do
  51. session[:cart_id] = @cart.id
  52. delete :destroy, :id => @cart.to_param
  53. end
  54. assert_redirected_to store_path
  55. end
  56. end