2013-10-18 45 views
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"]> 

任何想法为什么?

回答

1

您的测试呼叫patch :create而不是patch :update,因此它完全运行错误的操作。

+0

Blah,谢谢:) –

相关问题