My app needs the user to upload a CSV and I need to test this functionality and it uses an import route and saves that data in an instance variable
but in the process of writing this test I am getting this error
undefined method `authenticate!' for nil:NilClass
many others have encountered this error in the past, but apparently the previous fix of adding
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
end
no longer works for Devise 3, and I have been unable to find another work around
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
Any help in this matter would be greatly appreciated.