orders_controller_test.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 OrdersControllerTest < ActionController::TestCase
  19. # ...
  20. setup do
  21. @order = orders(:one)
  22. end
  23. test "should get index" do
  24. get :index
  25. assert_response :success
  26. assert_not_nil assigns(:orders)
  27. end
  28. test "requires item in cart" do
  29. get :new
  30. assert_redirected_to store_path
  31. assert_equal flash[:notice], 'Your cart is empty'
  32. end
  33. test "should get new" do
  34. cart = Cart.create
  35. session[:cart_id] = cart.id
  36. LineItem.create(:cart => cart, :product => products(:ruby))
  37. get :new
  38. assert_response :success
  39. end
  40. test "should create order" do
  41. assert_difference('Order.count') do
  42. post :create, :order => @order.attributes
  43. end
  44. assert_redirected_to store_path
  45. end
  46. # ...
  47. test "should show order" do
  48. get :show, :id => @order.to_param
  49. assert_response :success
  50. end
  51. test "should get edit" do
  52. get :edit, :id => @order.to_param
  53. assert_response :success
  54. end
  55. test "should update order" do
  56. put :update, :id => @order.to_param, :order => @order.attributes
  57. assert_redirected_to order_path(assigns(:order))
  58. end
  59. test "should destroy order" do
  60. assert_difference('Order.count', -1) do
  61. delete :destroy, :id => @order.to_param
  62. end
  63. assert_redirected_to orders_path
  64. end
  65. end