line_items_controller_test.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 store_path
  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. test "should create line_item via ajax" do
  48. assert_difference('LineItem.count') do
  49. xhr :post, :create, product_id: products(:ruby).id
  50. end
  51. assert_response :success
  52. assert_select_jquery :html, '#cart' do
  53. assert_select 'tr#current_item td', /Programming Ruby 1.9/
  54. end
  55. end
  56. end