small medium large xlarge

11 May 2012, 11:50
JVP (1 post)


I’m having problems in Ch. 13 integration test test_buying_a_product.

When the test does post_via_redirect the test Fails.

post_via_redirect "/orders",
    order: { name:     "Dave Thomas",
             address:  "123 The Street",
             email:    "",
             pay_type: "Check" }

Test output

test_buying_a_product                                               ERROR
        You have a nil object when you didn't expect it!
        You might have expected an instance of Array.
        The error occurred while evaluating
        Exception `ActionView::Template::Error' at app/views/orders/_form.html.erb:28:in `block in _app_vie\

Test.log shows

Started POST "/orders" for at 2012-05-11 14:17:10 +0300
  Processing by OrdersController#create as HTML
  Parameters: {"order"=>{"name"=>"Dave Thomas", "address"=>"123 The Street", "email"=>"", "pay_type"=>"Check"}}
  Cart Load (0.2ms)  SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1  [["id", 980190963]]
  LineItem Load (0.3ms)  SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = 980190963
   (0.1ms)  SAVEPOINT active_record_1
   (0.1ms)  RELEASE SAVEPOINT active_record_1
   (0.1ms)  SAVEPOINT active_record_1
   (0.1ms)  ROLLBACK TO SAVEPOINT active_record_1
  CACHE (0.0ms)  SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1
Rendered orders/_form.html.erb (10.8ms)
Rendered orders/new.html.erb within layouts/application (11.7ms)
Completed 500 Internal Server Error in 93ms

When I do the same steps in the browser I get no errors, and all is well.

You must be logged in to comment