删除购物车中的商品后,Ruby on Rails会多次重定向

时间:2014-04-08 19:46:20

标签: ruby-on-rails redirect testing cart destroy

我的代码

def destroy
    @line_item = LineItem.find(params[:id])
    @line_item.destroy

    respond_to do |format|
    if current_cart.line_items.empty?
      format.html {redirect_to store_path, notice: 'Your cart is empty'}
    else
      format.html { redirect_to current_cart, notice:'Product removed.' }
    end
      format.xml  { head :ok }
    end
  end

我的考试

test "should destroy line_item" do
    assert_difference('LineItem.count', -1) do
      delete :destroy, id: @line_item
    end

    assert_redirected_to Cart.find(session[:cart_id])
end

如果我的购物车是空的,我怎样才能测试我的多次重定向?

0 个答案:

没有答案