我在控制器中有这个动作:
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"]>
知道为什么吗?
答案 0 :(得分:1)
您的测试正在调用patch :create
,而不是patch :update
,因此它的操作完全错误。