line_items_controller_test.rb 1.5 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 LineItemsControllerTest < ActionController::TestCase
  11. setup do
  12. @line_item = line_items(:one)
  13. end
  14. test "should get index" do
  15. get :index
  16. assert_response :success
  17. assert_not_nil assigns(:line_items)
  18. end
  19. test "should get new" do
  20. get :new
  21. assert_response :success
  22. end
  23. test "should create line_item" do
  24. assert_difference('LineItem.count') do
  25. post :create, product_id: products(:ruby).id
  26. end
  27. assert_redirected_to cart_path(assigns(:line_item).cart)
  28. end
  29. test "should show line_item" do
  30. get :show, id: @line_item.to_param
  31. assert_response :success
  32. end
  33. test "should get edit" do
  34. get :edit, id: @line_item.to_param
  35. assert_response :success
  36. end
  37. test "should update line_item" do
  38. put :update, id: @line_item.to_param, line_item: @line_item.attributes
  39. assert_redirected_to line_item_path(assigns(:line_item))
  40. end
  41. test "should destroy line_item" do
  42. assert_difference('LineItem.count', -1) do
  43. delete :destroy, id: @line_item.to_param
  44. end
  45. assert_redirected_to line_items_path
  46. end
  47. end