Pt-H-3
Add integration tests for both of the above.
Suresh attempted:
Note: I cheat a bit since I update the ship date in the order controller as soon as the order is taken. Let us assume we are selling only ebooks :).
For testing whether the shipment notification mail works properly, modify UserStoriesTest.”buying a product”:
test "buying a product" do
# existing code here...
ship_date_expected = Time.now.to_date ### new line
post_via_redirect "/orders", ### existing line
# existing code here...
assert_equal "Check", order.pay_type ### existing line
assert_equal ship_date_expected, order.ship_date.to_date ### new line
# existing code here...
end
For testing whether error notification mail works properly, add a new test:
test "should mail the admin when error occurs" do
get "/carts/wibble"
assert_response :redirect # should redirect to...
assert_template "/" # ...store index
mail = ActionMailer::Base.deliveries.last
assert_equal ["abc@xmail.com"], mail.to ## replace mail id
assert_equal "some one <depot@example.com>", mail[:from].value ## replace contact name/mail id
assert_equal "Depot App Error Incident", mail.subject
end

