Done testing
[depot.git] / test / integration / user_stories_test.rb
1 require 'test_helper'
2
3 class UserStoriesTest < ActionController::IntegrationTest
4 fixtures :products
5
6 # Replace this with your real tests.
7 test "the truth" do
8 assert true
9 end
10
11 # A user goes to the index page. They select a product, adding it to their
12 # cart, and check out, filling in their details on the checkout form. When
13 # they submit, an order is created containing their information, along with a
14 # single line item corresponding to the product they added to their cart.
15
16 test "buying a product" do
17 LineItem.delete_all
18 Order.delete_all
19 ruby_book = products(:ruby_book)
20
21 get "/store/index"
22 assert_response :success
23 assert_template "index"
24
25 xml_http_request :put, "/store/add_to_cart" , :id => ruby_book.id
26 assert_response :success
27
28 cart = session[:cart]
29 assert_equal 1, cart.items.size
30 assert_equal ruby_book, cart.items[0].product
31
32 post "/store/checkout"
33 assert_response :success
34 assert_template "checkout"
35
36 post_via_redirect "/store/save_order" ,
37 :order => { :name => "Dave Thomas" ,
38 :address => "123 The Street" ,
39 :email => "dave@pragprog.com" ,
40 :pay_type => "cheque" }
41 assert_response :success
42 assert_template "index"
43 # assert_template "store/checkout"
44
45 assert_equal 0, session[:cart].items.size
46 orders = Order.find(:all)
47 assert_equal 1, orders.size
48
49 order = orders[0]
50 assert_equal "Dave Thomas", order.name
51 assert_equal "123 The Street", order.address
52 assert_equal "dave@pragprog.com", order.email
53 assert_equal "cheque", order.pay_type
54
55 assert_equal 1, order.line_items.size
56 line_item = order.line_items[0]
57 assert_equal ruby_book, line_item.product
58 end
59 end