Sha256: 7fb637bdc528c9f489f70916911855b342cd79aeda12f1d97a38845825b50648

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe AgraApi::Organisation do
  subject { AgraApi.new(host: 'test.com') }

  describe 'configuration' do
    it 'should propagate the host' do
      expect(subject.organisation.client.connection.configuration.host).to eq('test.com')
    end
  end

  describe 'find_by_host' do
    let(:body) { fixture('organisation.json') }
    let(:request_path) { '/api/organisations/?host=foo.com' }

    before(:each) do
      stub_get(request_path).to_return(:body => body, :status => status,
                                      :headers => { content_type: "application/json; charset=utf-8"})
    end

    describe 'success' do
      let(:status) { 200 }
      let(:organisation) { subject.organisation.find_by_host('foo.com') }

      it 'should find an organisation' do
        expect(organisation.settings.action_kit_host).to eq('foo.com')
      end
    end

    describe 'an error' do
      let(:status) { 500 }

      it 'should raise' do
        expect { subject.organisation.find_by_host('foo.com') }.to raise_exception(StandardError)
      end
    end
  end

  describe "basic authentication" do
    subject { AgraApi.new(host: 'test.com', username: 'username', password: 'password')}
    let(:request_path) { '/api/organisations/?host=foo.com' }
    let(:body) { "" }

    before(:each) do
      stub_request(:get, "https://username:password@test.com#{request_path}").to_return(:body => body, :status => status,
                                                                 :headers => { content_type: "application/json; charset=utf-8"})
    end


    describe "unauthorized" do
      let(:status) { 401 }

      it "should raise" do
        expect { subject.organisation.find_by_host('foo.com') }.to raise_exception(StandardError)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
agra_api-0.3.3 spec/organisation_spec.rb
agra_api-0.3.2 spec/organisation_spec.rb
agra_api-0.3.1 spec/organisation_spec.rb
agra_api-0.3.0 spec/organisation_spec.rb
agra_api-0.2.1 spec/organisation_spec.rb
agra_api-0.2.0 spec/organisation_spec.rb
agra_api-0.1.1 spec/organisation_spec.rb