test/hyperclient/entry_point_test.rb in hyperclient-0.6.1 vs test/hyperclient/entry_point_test.rb in hyperclient-0.7.0

- old
+ new

@@ -12,12 +12,12 @@ it 'creates a Faraday connection with the entry point url' do entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/' end it 'creates a Faraday connection with the default headers' do - entry_point.headers['Content-Type'].must_equal 'application/json' - entry_point.headers['Accept'].must_equal 'application/json' + entry_point.headers['Content-Type'].must_equal 'application/hal+json' + entry_point.headers['Accept'].must_equal 'application/hal+json,application/json' end it 'can update headers after a connection has been constructed' do entry_point.connection.must_be_kind_of Faraday::Connection entry_point.headers.update('Content-Type' => 'application/foobar') @@ -33,12 +33,12 @@ it 'creates a Faraday connection with the default block' do handlers = entry_point.connection.builder.handlers handlers.must_include Faraday::Response::RaiseError handlers.must_include FaradayMiddleware::FollowRedirects - handlers.must_include FaradayMiddleware::EncodeJson - handlers.must_include FaradayMiddleware::ParseJson + handlers.must_include FaradayMiddleware::EncodeHalJson + handlers.must_include FaradayMiddleware::ParseHalJson handlers.must_include Faraday::Adapter::NetHttp end it 'raises a ConnectionAlreadyInitializedError if attempting to modify headers' do entry_point.connection.must_be_kind_of Faraday::Connection @@ -55,77 +55,125 @@ it 'sets a Link with the entry point url' do entry_point._url.must_equal 'http://my.api.org' end end end - end - describe 'custom' do - let(:entry_point) do - EntryPoint.new 'http://my.api.org' do |entry_point| - entry_point.connection(default: false) do |conn| - conn.request :json - conn.response :json, content_type: /\bjson$/ - conn.adapter :net_http + describe 'faraday_options' do + let(:entry_point) do + EntryPoint.new 'http://my.api.org' do |entry_point| + entry_point.faraday_options = { proxy: 'http://my.proxy:8080' } end + end - entry_point.headers = { - 'Content-Type' => 'application/foobar', - 'Accept' => 'application/foobar' - } + describe 'connection' do + it 'creates a Faraday connection with the entry point url' do + entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/' + end + + it 'creates a Faraday connection with the default headers' do + entry_point.headers['Content-Type'].must_equal 'application/hal+json' + entry_point.headers['Accept'].must_equal 'application/hal+json,application/json' + end + + it 'creates a Faraday connection with options' do + entry_point.connection.proxy.must_be_kind_of Faraday::ProxyOptions + entry_point.connection.proxy.uri.to_s.must_equal 'http://my.proxy:8080' + end end end - describe 'connection' do - it 'creates a Faraday connection with the entry point url' do - entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/' + describe 'options' do + let(:entry_point) do + EntryPoint.new 'http://my.api.org' do |entry_point| + entry_point.connection(proxy: 'http://my.proxy:8080') + end end - it 'creates a Faraday connection with non-default headers' do - entry_point.headers['Content-Type'].must_equal 'application/foobar' - entry_point.headers['Accept'].must_equal 'application/foobar' - end + describe 'connection' do + it 'creates a Faraday connection with the entry point url' do + entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/' + end - it 'creates a Faraday connection with the default block' do - handlers = entry_point.connection.builder.handlers - handlers.wont_include Faraday::Response::RaiseError - handlers.wont_include FaradayMiddleware::FollowRedirects - handlers.must_include FaradayMiddleware::EncodeJson - handlers.must_include FaradayMiddleware::ParseJson - handlers.must_include Faraday::Adapter::NetHttp + it 'creates a Faraday connection with the default headers' do + entry_point.headers['Content-Type'].must_equal 'application/hal+json' + entry_point.headers['Accept'].must_equal 'application/hal+json,application/json' + end + + it 'creates a Faraday connection with options' do + entry_point.connection.proxy.must_be_kind_of Faraday::ProxyOptions + entry_point.connection.proxy.uri.to_s.must_equal 'http://my.proxy:8080' + end end end - end - describe 'inherited' do - let(:entry_point) do - EntryPoint.new 'http://my.api.org' do |entry_point| - entry_point.connection(default: true) do |conn| - conn.use Faraday::Request::OAuth + describe 'custom' do + let(:entry_point) do + EntryPoint.new 'http://my.api.org' do |entry_point| + entry_point.connection(default: false) do |conn| + conn.request :json + conn.response :json, content_type: /\bjson$/ + conn.adapter :net_http + end + + entry_point.headers = { + 'Content-Type' => 'application/foobar', + 'Accept' => 'application/foobar' + } end - entry_point.headers['Access-Token'] = 'token' end - end - describe 'connection' do - it 'creates a Faraday connection with the default and additional headers' do - entry_point.headers['Content-Type'].must_equal 'application/json' - entry_point.headers['Accept'].must_equal 'application/json' - entry_point.headers['Access-Token'].must_equal 'token' + describe 'connection' do + it 'creates a Faraday connection with the entry point url' do + entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/' + end + + it 'creates a Faraday connection with non-default headers' do + entry_point.headers['Content-Type'].must_equal 'application/foobar' + entry_point.headers['Accept'].must_equal 'application/foobar' + end + + it 'creates a Faraday connection with the default block' do + handlers = entry_point.connection.builder.handlers + handlers.wont_include Faraday::Response::RaiseError + handlers.wont_include FaradayMiddleware::FollowRedirects + handlers.must_include FaradayMiddleware::EncodeJson + handlers.must_include FaradayMiddleware::ParseJson + handlers.must_include Faraday::Adapter::NetHttp + end end + end - it 'creates a Faraday connection with the entry point url' do - entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/' + describe 'inherited' do + let(:entry_point) do + EntryPoint.new 'http://my.api.org' do |entry_point| + entry_point.connection do |conn| + conn.use Faraday::Request::OAuth + end + entry_point.headers['Access-Token'] = 'token' + end end - it 'creates a Faraday connection with the default block plus any additional handlers' do - handlers = entry_point.connection.builder.handlers - handlers.must_include Faraday::Request::OAuth - handlers.must_include Faraday::Response::RaiseError - handlers.must_include FaradayMiddleware::FollowRedirects - handlers.must_include FaradayMiddleware::EncodeJson - handlers.must_include FaradayMiddleware::ParseJson - handlers.must_include Faraday::Adapter::NetHttp + describe 'connection' do + it 'creates a Faraday connection with the default and additional headers' do + entry_point.headers['Content-Type'].must_equal 'application/hal+json' + entry_point.headers['Accept'].must_equal 'application/hal+json,application/json' + entry_point.headers['Access-Token'].must_equal 'token' + end + + it 'creates a Faraday connection with the entry point url' do + entry_point.connection.url_prefix.to_s.must_equal 'http://my.api.org/' + end + + it 'creates a Faraday connection with the default block plus any additional handlers' do + handlers = entry_point.connection.builder.handlers + handlers.must_include Faraday::Request::OAuth + handlers.must_include Faraday::Response::RaiseError + handlers.must_include FaradayMiddleware::FollowRedirects + handlers.must_include FaradayMiddleware::EncodeHalJson + handlers.must_include FaradayMiddleware::ParseHalJson + handlers.must_include Faraday::Adapter::NetHttp + end end end end end