summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/devise_failure_spec.rb
blob: a452de59795123ae95640bed448752d09d13ec98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::DeviseFailure do
  let(:env) do
    {
      'REQUEST_URI' => 'http://test.host/',
      'HTTP_HOST' => 'test.host',
      'REQUEST_METHOD' => 'GET',
      'warden.options' => { scope: :user },
      'rack.session' => {},
      'rack.session.options' => {},
      'rack.input' => "",
      'warden' => OpenStruct.new(message: nil)
    }
  end

  let(:response) { described_class.call(env).to_a }
  let(:request) { ActionDispatch::Request.new(env) }

  context 'When redirecting' do
    it 'sets the expire_after key' do
      response

      expect(env['rack.session.options']).to have_key(:expire_after)
    end

    it 'returns to the default redirect location' do
      expect(response.first).to eq(302)
      expect(request.flash[:alert]).to eq('You need to sign in or sign up before continuing.')
      expect(response.second['Location']).to eq('http://test.host/users/sign_in')
    end
  end
end