demarches-normaliennes/spec/support/controller_helpers.rb

17 lines
579 B
Ruby
Raw Normal View History

2015-08-10 11:05:06 +02:00
module ControllerHelpers
def sign_in(user = double('test@localhost.com'))
if user.nil?
2015-08-20 17:30:17 +02:00
allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, scope: :user)
2015-08-10 11:05:06 +02:00
allow(controller).to receive(:current_user).and_return(nil)
else
allow(request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(create(:user))
2015-08-10 11:05:06 +02:00
end
end
end
RSpec.configure do |config|
2015-08-20 17:30:17 +02:00
config.include Devise::TestHelpers, type: :controller
config.include ControllerHelpers, type: :controller
end