spec/client_class_spec.rb in contentful-2.11.1 vs spec/client_class_spec.rb in contentful-2.12.0

- old
+ new

@@ -1,13 +1,14 @@ require 'spec_helper' describe Contentful::Client do describe '#get' do - let(:client) { create_client } + let(:client) { create_client() } let(:proxy_client) { create_client(proxy_host: '183.207.232.194', proxy_port: 8080, secure: false) } + let(:timeout_client) { create_client(timeout_connect: 1, timeout_read: 2, timeout_write: 3) } let(:request) { Contentful::Request.new(nil, client.environment_url('/content_types'), nil, 'cat') } it 'uses #base_url' do expect(client).to receive(:base_url).and_call_original @@ -30,18 +31,38 @@ expect(request).to receive(:query).twice.and_call_original vcr('content_type') { client.get(request) } end it 'calls #get_http' do - expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params) { raw_fixture('content_type') } + expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params, client.timeout_params) { raw_fixture('content_type') } client.get(request) end it 'calls #get_http via proxy' do - expect(proxy_client.class).to receive(:get_http).with(proxy_client.base_url + request.url, request.query, proxy_client.request_headers, proxy_client.proxy_params) { raw_fixture('content_type') } + expect(proxy_client.class).to receive(:get_http).with(proxy_client.base_url + request.url, request.query, proxy_client.request_headers, proxy_client.proxy_params, client.timeout_params) { raw_fixture('content_type') } proxy_client.get(request) expect(proxy_client.proxy_params[:host]).to eq '183.207.232.194' expect(proxy_client.proxy_params[:port]).to eq 8080 + end + + describe 'timeout params' do + context 'with timeouts configured' do + it 'calls #get_http with timeouts' do + expect(timeout_client.class).to receive(:get_http).with(timeout_client.base_url + request.url, request.query, timeout_client.request_headers, timeout_client.proxy_params, timeout_client.timeout_params) { raw_fixture('content_type') } + timeout_client.get(request) + expect(timeout_client.timeout_params[:connect]).to eq 1 + expect(timeout_client.timeout_params[:read]).to eq 2 + expect(timeout_client.timeout_params[:write]).to eq 3 + end + end + + context 'without timeouts' do + it 'calls #get_http with timeouts' do + expect(client.class).to receive(:get_http).with(client.base_url + request.url, request.query, client.request_headers, client.proxy_params, client.timeout_params) { raw_fixture('content_type') } + client.get(request) + expect(client.timeout_params).to eq({}) + end + end end describe 'build_resources parameter' do it 'returns Contentful::Resource object if second parameter is true [default]' do res = vcr('content_type') { client.get(request) }