Sha256: 91611728cd4e9e80bdf63a1da322e7b5d6dfadfc98a1152cbf8fd5d1e811d3e8

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

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

  describe '#initialize' do
    it 'sets the core_host instance attribute' do
      session = AuthSession.new core_host: 'some_core_host'
      expect(session.core_host).to eq('some_core_host')
    end

    it 'defaults the core_host to the CORE_HOST env variable' do
      orginal_env_core_host = ENV['CORE_HOST']
      ENV['CORE_HOST'] = 'some_env_core_host'
      session = AuthSession.new
      ENV['CORE_HOST'] = orginal_env_core_host
      expect(session.core_host).to eq('some_env_core_host')
    end
  end

  describe '#get' do
    it 'performs a get request' do
      allow(session).to receive(:basic_auth).and_return(username: 'some_username', password: 'some_password')
      allow(session).to receive(:headers).and_return(some: 'header')
      expect(HTTParty).to receive(:get).with('http://core.dev/api/v1/some_path.json',
                                             query: {some: 'param'},
                                             headers: {some: 'header'},
                                             basic_auth: {username: 'some_username', password: 'some_password'})
                                       .and_return(response)
      session.get '/some_path', some: 'param'
    end

    it 'throws an error if the reponse is not within the 200 range' do
      allow(response).to receive(:code).and_return(500)
      allow(HTTParty).to receive(:get).and_return(response)
      expect { session.get '/some_path' }.to raise_error(RuntimeError, 'some_response')
    end

    it 'returns the response' do
      allow(HTTParty).to receive(:get).and_return(response)
      expect(session.get '/some_path').to eq(response)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roqua-core-api-0.0.12 spec/lib/roqua/core_api/sessions/auth_session_spec.rb