Sha256: 77849ed5364736efda18f46e85a7ba952f84571be6dca9e520669324c6bc7c2b

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

require 'spec_helper'

describe OAuthSession do
  let(:session) { Fabricate :oauth_session }
  let(:response) { double('response', code: 201, parsed_response: 'some_response') }

  describe '#initialize' do
    it 'sets the access_token instance variable' do
      session = Roqua::CoreApi.oauth_session access_token: 'some_access_token'
      expect(session.access_token).to eq('some_access_token')
    end

    it 'allows to override the core_site variable' do
      session = Roqua::CoreApi.oauth_session access_token: 'some_access_token', core_site: 'some_core_site'
      expect(session.core_site).to eq('some_core_site')
    end

    it 'defaults the AuthSession core_site CORE_SITE env variable default value' do
      original_env_core_site = ENV['CORE_SITE']
      ENV['CORE_SITE'] = 'some_env_core_site'
      session = Roqua::CoreApi.oauth_session access_token: 'some_access_token'
      ENV['CORE_SITE'] = original_env_core_site
      expect(session.core_site).to eq('some_env_core_site')
    end
  end

  describe '#logout_url' do
    it 'returns the oauth session destroy url with an escaped redirect_to parameter' do
      expect(session.logout_url return_to: 'some redirect to')
        .to eq('http://core.dev/session/destroy?token=some_access_token&redirect_to=some+redirect+to')
    end
  end

  describe 'headers' do
    it 'sets the Authorization header' do
      expect(HTTParty).to receive(:get).with(an_instance_of(String),
                                             headers: {"Authorization" => "Bearer some_access_token"},
                                             query: {},
                                             basic_auth: nil,
                                             timeout: nil).and_return(response)
      session.get 'some_path'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
roqua-core-api-0.0.19 spec/lib/roqua/core_api/sessions/oauth_session_spec.rb
roqua-core-api-0.0.18 spec/lib/roqua/core_api/sessions/oauth_session_spec.rb
roqua-core-api-0.0.17 spec/lib/roqua/core_api/sessions/oauth_session_spec.rb