我的应用需要用户上传CSV,我需要测试此功能 它使用导入路由并将该数据保存在实例变量
中但在编写此测试的过程中,我收到此错误
未定义的方法`authenticate!'为零:NilClass
过去很多其他人都遇到过此错误,但显然是先前添加
的修复程序RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
end
不再适用于Devise 3,我无法找到另外的工作
shotlist_presets_controller.rb
def import
if @spreadsheet = ShotlistPreset.open_spreadsheet(params[:file])
render :index
flash[:notice] = "Import Successful!"
else
flash[:notice] = "Import Failed!"
render :index
end
end
shotlist_presets_controller_spec.rb
describe ShotlistPresetsController do
include ActionDispatch::TestProcess
include RSpec::Rails::ControllerExampleGroup
before :each do
@preset_client = FactoryGirl.create(:client, :display_name => 'Nike')
@preset_user = FactoryGirl.create(:user, :first_name => "Stay", :last_name => "Lurkn", :client_id => @preset_client.id)
@preset_user.add_role(:manager)
visit shotlist_presets_path
end
before :each do
login_as(@preset_user)
visit shotlist_presets_path
end
it 'should upload a file' do
@file = fixture_file_upload("example.csv", 'text/csv')
post :import, :file => fixture_file_upload("example.csv", 'text/csv')
end
end
非常感谢任何有关此事的帮助。