<br><br><div><span class="gmail_quote">On 13/10/06, <b class="gmail_sendername">Tim Case</b> <<a href="mailto:gk@karmacrash.com">gk@karmacrash.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
James, just figured it out and everything works! Here's what was going on:<br><br>class Order < ActiveRecord::Base<br> def successful?<br> end<br>end<br><br>class CcOrder < Order<br>end<br><br>def test_post_checkout
<br> Order.any_instance.stubs(:successful?).returns(true)<br> post :checkout<br> assert_response :redirect<br> assert_equal "Checkout was successful.", flash[:notice]<br>end<br><br>CcOrder is the concrete class that was actually getting called in the
<br>process_order method inside the store controller code. In the test, I<br>was stubbing out the method from CcOrder's parent class Order, by<br>changing the stub to operate on CcOrder the test worked as expected.<br><br>
def process_order<br> if @order.process and @order.successful? /*<--@order is a CcOrder<br>not Order*/<br> @cart.empty!<br> if customer_logged_in?<br> flash[:notice] = "Checkout was successful."
<br> else<br> flash[:notice] = "Checkout was successful, and your account was<br>created."<br> end<br> redirect_to_order_confirmation @<a href="http://order.id">order.id</a><br> return
<br> else<br> render_errors_in_order_summary<br> end<br> end<br><br>def test_post_checkout<br> CcOrder.any_instance.stubs(:successful?).returns(true)<br> post :checkout<br> assert_response :redirect<br>
assert_equal "Checkout was successful.", flash[:notice]<br>end</blockquote><div><br>Great - I'm glad you worked it out - it all makes sense now. <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
It seems to me that the original call to stub Order should have<br>propagated down to Order's child classes as well. Is this by design or<br>something for the future? (Maybe I can help)</blockquote><div><br>It's not by design - more by accident. We don't tend to use the any_instance() functionality much, so I guess we just haven't come across a case like this. Maybe it is something we should support.
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">A new mocha fan! Nice work James!!!</blockquote><div><br>Thanks - I'm glad you're finding it useful.
<br></div>-- <br></div>James.<br><a href="http://blog.floehopper.org">http://blog.floehopper.org</a>