Post_via_redirect - testing problem

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 T.",
              :address => "123 The Street",
              :email => "[email protected]",
              :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

Just to give more info, it gets even more puzzling when i debug it:
stepping through the controller code, at the point where it gets to the
if statement that tests the request type:

if request.post?

At this point, i’ve sent a post_via_redirect request, and according to
the debugger, self.request.request_method = “post”. BUT, the if test
returns false, and sends me into the else section (which is why the
integration test is failing).

Can anyone explain this to me? It seems crazy.