0

我在控制器中有这个动作:

  def update
    @board = Board.find(params[:board_id])
    @category = Category.find(params[:id])

    if @category.update_attributes(category_params)
      flash[:notice] = "You sucessfully changed category name."
      redirect_to settings_board_path(@board)
    else
      render :edit
    end
  end

这个测试用例的问题:

context "with invalid attributes" do
  let(:updated_category) { FactoryGirl.attributes_for(:category, name: "") }

  it "re-renders :edit template" do
    patch :create, board_id: board, id: category, category: updated_category
    expect(response).to render_template :edit 
  end
end

我收到此错误:

expecting <"edit"> but rendering with <["categories/new", "layouts/application"]>

知道为什么吗?

4

1 回答 1

1

您的测试正在调用patch :create,而不是patch :update,因此它完全运行了错误的操作。

于 2013-10-18T14:23:26.297 回答