I''ve got an integration test that''s failing but i
can''t work out why:
Here''s the action being tested - in case anyone recognises it,
it''s
based on the Depot app in Agile Web Dev with Rails.
def checkout
@in_checkout = true
#don''t let user checkout with an empty cart
if @cart.items.empty?
redirect_to_index("Your cart is empty")
else
#see if the form is being submitted, ie if it''s a POST request
if request.post?
#make a new object with the form data
@order = Order.create(:name => params[:name],
:address => params[:address],
:email => params[:email],
:pay_type => params[:pay_type])
@order.add_line_items_from_cart(@cart)
#if we saved the order, empty the cart and go back to index page
if @order.save
session[:cart] = nil
redirect_to_index("Thank you for your order")
else
#if it didn''t save, show the order form again
render :action => :checkout
end
else#not a POST request, ie a GET request detected. Should be
case for
#when an empty form is displayed.
#make a new order object for the form to work with
@order = Order.new
end#if request.post?
end
end
So, the checkout action can be called with a get (to create the empty
form) or a post (to send the details to make a new Order object)
request. In my testing, the get request works fine but the post request
seems to not create the order object correctly: here''s the problem
part
of the test:
post_via_redirect "/store/checkout",
{ :name => "Dave Thomas",
:address => "123 The Street",
:email =>
"dave-kbbdpT5sCmpWk0Htik3J/w@public.gmane.org",
:pay_type => "check"
}
assert_response :success
assert_template "index"
assert_equal nil, session[:cart]
So, i''m passing the relevant details to checkout as part of a post
request - as far as i can tell this is what happens when i hit the
"place order" button, using the app normally. But it looks like the
action''s going wrong somewhere when i use the test.
Can anyone see what i''m doing wrong?
thanks
max
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---