line_items_controller_test.rb 2.2 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 LineItemsControllerTest < ActionController::TestCase
  19. setup do
  20. @line_item = line_items(:one)
  21. end
  22. test "should get index" do
  23. get :index
  24. assert_response :success
  25. assert_not_nil assigns(:line_items)
  26. end
  27. test "should get new" do
  28. get :new
  29. assert_response :success
  30. end
  31. test "should create line_item" do
  32. assert_difference('LineItem.count') do
  33. post :create, :product_id => products(:ruby).id
  34. end
  35. assert_redirected_to store_path
  36. end
  37. test "should show line_item" do
  38. get :show, :id => @line_item.to_param
  39. assert_response :success
  40. end
  41. test "should get edit" do
  42. get :edit, :id => @line_item.to_param
  43. assert_response :success
  44. end
  45. test "should update line_item" do
  46. put :update, :id => @line_item.to_param, :line_item => @line_item.attributes
  47. assert_redirected_to line_item_path(assigns(:line_item))
  48. end
  49. test "should destroy line_item" do
  50. assert_difference('LineItem.count', -1) do
  51. delete :destroy, :id => @line_item.to_param
  52. end
  53. assert_redirected_to line_items_path
  54. end
  55. test "should create line_item via ajax" do
  56. assert_difference('LineItem.count') do
  57. xhr :post, :create, :product_id => products(:ruby).id
  58. end
  59. assert_response :success
  60. assert_select_rjs :replace_html, 'cart' do
  61. assert_select 'tr#current_item td', /Programming Ruby 1.9/
  62. end
  63. end
  64. end