您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

64 行
1.5 KiB

  1. require 'test_helper'
  2. class LineItemsControllerTest < ActionDispatch::IntegrationTest
  3. setup do
  4. @line_item = line_items(:one)
  5. end
  6. test "should get index" do
  7. get line_items_url
  8. assert_response :success
  9. end
  10. test "should get new" do
  11. get new_line_item_url
  12. assert_response :success
  13. end
  14. test "should create line_item" do
  15. assert_difference('LineItem.count') do
  16. post line_items_url, params: { product_id: products(:ruby).id }
  17. end
  18. follow_redirect!
  19. assert_select 'h2', 'Your Cart'
  20. assert_select 'td', 'Programming Ruby 1.9'
  21. end
  22. test "should create line_item via ajax" do
  23. assert_difference('LineItem.count') do
  24. post line_items_url, params: { product_id: products(:ruby).id }, xhr: true
  25. end
  26. assert_response :success
  27. assert_select_jquery :html, '#cart' do
  28. assert_select 'tr#current_item td', /Programming Ruby 1.9/
  29. end
  30. end
  31. test "should show line_item" do
  32. get line_item_url(@line_item)
  33. assert_response :success
  34. end
  35. test "should get edit" do
  36. get edit_line_item_url(@line_item)
  37. assert_response :success
  38. end
  39. test "should update line_item" do
  40. patch line_item_url(@line_item),
  41. params: { line_item: { product_id: @line_item.product_id } }
  42. assert_redirected_to line_item_url(@line_item)
  43. end
  44. test "should destroy line_item" do
  45. assert_difference('LineItem.count', -1) do
  46. delete line_item_url(@line_item)
  47. end
  48. assert_redirected_to line_items_url
  49. end
  50. end