Sha256: 6cd93afa206e4307064c83620e8d9fa89298fdde3cd0c5785bad2845a76442b8

Contents?: true

Size: 1.31 KB

Versions: 18

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

# Normally, we'd do this as a feature spec, but there's
# currently no easy way to get capybara to play along nicely
# with mocks for external redirects (the capybara-mechanize driver
# comes closest, but not quite)
RSpec.describe 'Signing out' do
  let(:auth_sign_out_url) do
    "#{ENV['G5_AUTH_ENDPOINT']}/users/sign_out" \
      '?redirect_url=http%3A%2F%2Fwww.example.com%2F'
  end

  describe 'GET /g5_auth/users/sign_out' do
    subject(:sign_out) { safe_get '/g5_auth/users/sign_out' }

    context 'when user is logged in', :auth_request do
      it 'should redirect to the auth server' do
        expect(sign_out).to redirect_to(auth_sign_out_url)
      end

      it 'should not allow the user to access protected pages' do
        sign_out
        expect(safe_get('/protected_page'))
          .to redirect_to('/g5_auth/users/sign_in')
      end
    end

    context 'when user is not logged in' do
      it 'should redirect to the auth server' do
        expect(sign_out).to redirect_to(auth_sign_out_url)
      end
    end
  end

  describe 'DELETE /g5_auth/users/sign_out', :auth_request do
    subject(:sign_out) { safe_delete '/g5_auth/users/sign_out' }

    it 'should redirect to GET' do
      expect(sign_out).to redirect_to('/g5_auth/users/sign_out')
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
g5_authenticatable-1.1.4 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.4.rc.3 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.4.rc.2 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.4.rc.1 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.2 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.2.pre.1 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.2.rc.5 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.2.rc.4 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.2.rc.3 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.2.rc.2 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.2.rc.1 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.1 spec/requests/sign_out_spec.rb
g5_authenticatable-1.1.0 spec/requests/sign_out_spec.rb
g5_authenticatable-1.0.0 spec/requests/sign_out_spec.rb
g5_authenticatable-1.0.0.pre.4 spec/requests/sign_out_spec.rb
g5_authenticatable-1.0.0.pre.3 spec/requests/sign_out_spec.rb
g5_authenticatable-1.0.0.pre.2 spec/requests/sign_out_spec.rb
g5_authenticatable-1.0.0.pre.1 spec/requests/sign_out_spec.rb