嗨,我尝试将测试添加到控制器中,我有一种下载Excel文件的方法
在我的方法控制器中,我有此代码。
def download_syllabus_evaluation_system
@syllabus_programs = SyllabusProgram.match_course_coordinator.actives.order(:id)
name_file = "Syllabus_evalution_system"
setHeaderExportExcel(name_file)
respond_to do |format|
format.excel { render template: '/syllabuses/excel/syllabus_evaluation_system', layout: 'report/excel/template', status: :ok}
end
end
设置标题的方法
def setHeaderExportExcel(name_file)
headers['Content-Type'] = "application/vnd.ms-excel; charset=UTF-8; charset=ISO-8859-1; header=present"
headers['Content-Disposition'] = 'attachment; filename="' + name_file +'.xls"'
headers['Cache-Control'] = ''
end
在我的Rspec控制器中,我有此代码
require 'rails_helper'
#TODO: add test controller
RSpec.describe SyllabusesController, type: :controller do
describe "syllabus_program#update " do
context "as an authorized " do
before do
#@user = FactoryBot.create(:user)
end
end
end
describe "GET#download_syllabus_excel" do
it "return succes response" do
get download_syllabus_evaluation_system_path(format: "excel")
expect(response).to be_successful
end
end
end
我的路线是
get 'download_syllabus_evaluation_system' => 'syllabuses#download_syllabus_evaluation_system', as: "download_syllabus_evaluation_system"
但是当我运行测试时,出现此错误
Failure/Error: get download_syllabus_evaluation_system_path(format: "excel")
ActionController::UrlGenerationError:
No route matches {:action=>"/download_syllabus_evaluation_system.excel", :controller=>"syllabuses"}
出什么问题了?