3 class UserStoriesTest
< ActionController
::IntegrationTest
6 # Replace this with your real tests.
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.
16 test
"buying a product" do
19 ruby_book
= products(:ruby_book)
22 assert_response
:success
23 assert_template
"index"
25 xml_http_request
:put, "/store/add_to_cart" , :id => ruby_book
.id
26 assert_response
:success
29 assert_equal
1, cart
.items
.size
30 assert_equal ruby_book
, cart
.items
[0].product
32 post
"/store/checkout"
33 assert_response
:success
34 assert_template
"checkout"
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"
45 assert_equal
0, session
[:cart].items
.size
46 orders
= Order
.find(:all)
47 assert_equal
1, orders
.size
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
55 assert_equal
1, order
.line_items
.size
56 line_item
= order
.line_items
[0]
57 assert_equal ruby_book
, line_item
.product