carts_controller_test.rb 1.4 KB

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