Sha256: cf4cd50b4a079acf7b85e3e45b5b9068a364e42d5d547ff5260163bedfe0162e

Contents?: true

Size: 905 Bytes

Versions: 3

Compression:

Stored size: 905 Bytes

Contents

require 'ostruct'

require 'spec_helper'

describe AuthenticatedController, type: :controller do
  describe 'not authenticated' do
    it 'redirects to the identity_provider' do
      get :index

      expect(response.location).to match('/auth/gaggleamp')
    end

    it 'sets origin to the location an unauthenticated user was trying to access' do
      get :index

      response.location.split('?').last.tap do |query_string|
        expect(query_string.split('=').first).to eq('origin')
        expect(query_string.split('=').last).to eq(CGI.escape('/authenticated'))
      end
    end
  end

  describe 'after authenticating' do
    let(:user) { OpenStruct.new.tap { |i| i.id = rand(10_000) } }
    before do
      sign_in user
      Foyer.user_finder = ->(_) { user }
    end

    it 'allows user to access the action' do
      get :index

      expect(response.status).to eq 200
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foyer-0.5.0 spec/controllers/authenticated_controller_spec.rb
foyer-0.4.0 spec/controllers/authenticated_controller_spec.rb
foyer-0.3.1 spec/controllers/authenticated_controller_spec.rb