1

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.

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
tallgirltaadaa
  • 1,804
  • 18
  • 26
  • Have you tried adding `sign_in(@preset_user)` to the `before`, and `sign_out(@preset_user)` to the `after`? That uses the Devise helpers. I'm using Devise 3, with those helpers mixed in in a Rails 4.x project right now, works great. – Nick Veys May 15 '14 at 02:27
  • yes i have tried to sign_in, but in capybara Devise helpers cannot be used. http://stackoverflow.com/questions/7141763/undefined-method-sign-in-for-rspeccoreexamplegroupnested-1nested-10... i tried to use the suggestion in that last question to manually sign in, but then I am left with the same original error – tallgirltaadaa May 15 '14 at 13:41

0 Answers0