small medium large xlarge

Generic-user-small
02 Nov 2011, 14:37
Steven Finnegan (19 posts)

I have implemented one of the ‘Playtime’ exercises that adds a button to the line_items in the cart, to decrement the item’s count when clicked. (and remove the line item when decremented to zero)

After completing chapter 14, and with all tests passing, I discovered that the decrement button no longer functioned. Pressing the button (which should have decremented the count, then used JavaScript to re-display the line_item) had NO obvious effect. Not even a page reload.

Examining the logs informed me that when the button was pushed, I was being redirected to “login” (with a GET) as JS. It “rendered” the logon screen, but since it was JS, the page did not change. The solution here is that the LineItemController should have “:destroy” added to the skip_before_filter.

But, why didn’t the functional tests detect this? The line_item_controller_test does a should_destroy_line_item test, but since the test setup function logs in for ALL controllers, the test succeeded in deleting the line item, and passed.

So, I can fix the functional issue by adding :destroy to the before filter, but how do I manage the tests such that it would discover this problem? It would seem I’d need to have the tests perform the setup/login only for the appropriate tests, not for a blanket “if defined: session” conditional.

You must be logged in to comment