small medium large xlarge

Generic-user-small
20 Apr 2009, 18:59
Nicholas Lewis (2 posts)

I’ve been banging my head on this for about 2 days now… absolutely LOVE rails. But need better direction when it comes to debugging tests..

I’m working through implementing the “test_buying_a_product” Integration Test (test_user_stories.rb)

However.. every time I run it. It fails and says: test_buying_a_product(UserStoriesTest) [/test/integration/user_stories_test.rb:51]: <1> expected but was <0>.

line 51: assert_equal 1, orders.size

So its going through everything fine. Adds an item to the cart, proceeds to checkout, checks out, empties the cart, but the order itself doesn’t save to the test database? (sqlite3)

Here’s the store#checkout action which saves the checkout form from the store controller. *Note: I merged the checkout & save order actions into one:

def checkout if @cart.items.empty? redirect_to_index else @order = Order.new(params[:order]) if request.post? and params[:order] @order.add_line_items( @cart.get_cart_items) @order.save session[:cart] = nil redirect_to_index(“Thanks for your order!!”) else render :action => ‘checkout’ end end end

As if this isn’t odd enough… it works fine via the live app. Is there some issue with the test database maybe? I queried test.sqlite3 from the command line and selected * from orders to SEE if they were any orders in the database and this is what it returned:

953125641|MyString|MyText|MyString|2009-04-20 18:12:40|2009-04-20 18:12:40|MyString 996332877|MyString|MyText|MyString|2009-04-20 18:12:40|2009-04-20 18:12:40|MyString

Odd. It has to Orders, yet the columns are filled with “Mystring” “MyText” is this common in the test database?

Any ideas? Help! -=D

Generic-user-small
20 Apr 2009, 19:16
Nicholas Lewis (2 posts)

Hmm ok drilling into this further, I noticed that I grouped @order.save into the same if statement as the request.post? Therefore if the order WASN’T saved (in this case), I would have never known.

So changed the checkout action to this:

def checkout if @cart.items.empty? redirect_to_index else @order = Order.new(params[:order]) if request.post? and params[:order] @order.add_line_items( @cart.get_cart_items) if @order.save session[:cart] = nil redirect_to_index(“Thanks for your order!!”) else render :action => ‘checkout’ end end end end

Testing this now returns the following:

1) Failure: test_buying_a_product(UserStoriesTest) [/test/integration/user_stories_test.rb:47]: expecting <”index”> but rendering with <”store/checkout.html.erb”>

Soo… the order isn’t being saved for some reason. It works fine via the web though. Very Very odd. Any ideas on wow it isn’t saved via testing?

You must be logged in to comment