I am using rails 3.2.13 and ruby 1.9.3p0, and I also encountered the same problem.
I then tried to add and destroy carts manually by web interface, but it behaved strange. For create action, when there is no cart, it creates two. For destroy action, when there is only one cart left, it destroys it but creates a new one at the same time.
The test above led me to the cause of the problem: the line in the controller @depot/app/controllers/carts_controller.rb@
before_filter :set_cart, only: [:show, :edit, :update, :destroy]
The function @before_filter@ is renamed as @before_action@ in rails 4.
The @set_cart@ function will create a new cart automatically if there is none corresponds to current session. That’s why test “@should destroy cart@” didn’t decrease the number of carts.
I simply comment out the line shown above and the problem is gone.
My solution seems contradicting to author’s intention to protect one’s cart from others, but I don’t have any better alternative for now.
Anyone could share his/her experience or opinion would be appreciated.
Later in chapter 10, the author modified the test “@should destroy cart@” and it solves the problem. However, there are still some strange behaviors in web interfaces.