Sha256: bbe306cf38deee0ba76246588819da6867ade356e1fae4dcc4fd9d406c62b92e

Contents?: true

Size: 1.55 KB

Versions: 24

Compression:

Stored size: 1.55 KB

Contents

require_relative '../spec_helper'

describe RestfulResource::Base, 'authorization' do
  before :each do
    class FirstClient < RestfulResource::Base
    end

    class SecondClient < RestfulResource::Base
    end

    class NotConfiguredClient < RestfulResource::Base; end

    class FirstTest < FirstClient
      resource_path 'test'
    end

    class SecondTest < SecondClient
      resource_path 'test'
    end

    FirstClient.configure(base_url: 'http://api.carwow.co.uk/api/first')
    SecondClient.configure(base_url: 'http://api.carwow.co.uk/api/second',
                           username: 'test_user',
                           password: 'test_pass')
  end

  it "should use two different http instances" do
    expect(FirstTest.send(:http)).not_to equal(SecondTest.send(:http))
  end

  it 'should have http auth on SecondClient when initialised first' do
    SecondTest.send(:http)
    FirstTest.send(:http)

    authorization = SecondTest.send(:http).instance_variable_get :@authorization
    expect(authorization).to be_truthy
  end

  it 'should have http auth on SecondTest when initialised second' do
    FirstTest.send(:http)
    SecondTest.send(:http)

    authorization = SecondTest.send(:http).instance_variable_get :@authorization
    expect(authorization).to be_truthy
  end

  it 'should have same http auth on superclass' do
    expect(SecondTest.send(:http)).to equal(SecondClient.send(:http))
  end

  it 'should raise exception if base_url is not set' do
    expect { NotConfiguredClient.send(:base_url) }.to raise_error 'Base url missing'
  end

end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
restful_resource-0.8.34 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.33 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.32 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.30 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.29 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.28 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.27 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.26 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.25 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.24 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.23 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.22 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.21 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.20 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.19 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.18 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.17 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.16 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.15 spec/restful_resource/base_authorization_spec.rb
restful_resource-0.8.14 spec/restful_resource/base_authorization_spec.rb