Sha256: af38e28ada0b9a3acab5b1ebad1a938518a65e52b2340c0c810165ce68cba360

Contents?: true

Size: 1.66 KB

Versions: 38

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

RSpec.describe RestfulResource::Request do
  let(:method) { 'get' }
  let(:url) { 'https://www.carwow.co.uk/api/v2/models' }

  describe '.headers' do
    context 'given no headers' do
      subject { described_class.new(method, url).headers }

      its(['Accept']) { is_expected.to eq 'application/json' }
    end

    context 'given an explicit accept header' do
      subject { described_class.new(method, url, headers: { accept: 'application/xml' }).headers }

      its(['Accept']) { is_expected.to eq 'application/xml' }
    end

    context 'given symbolized header' do
      subject { described_class.new(method, url, headers: { authorization: 'Bearer: xyz' }).headers }

      its(['Authorization']) { is_expected.to eq 'Bearer: xyz' }
      its(['Accept']) { is_expected.to eq 'application/json' }
    end

    context 'given multi word symbolized header' do
      subject { described_class.new(method, url, headers: { cache_control: 'no-cache' }).headers }

      its(['Cache-Control']) { is_expected.to eq 'no-cache' }
      its(['Accept']) { is_expected.to eq 'application/json' }
    end

    context 'given string header' do
      subject { described_class.new(method, url, headers: { 'authorization' => 'Bearer: xyz' }).headers }

      its(['Authorization']) { is_expected.to eq 'Bearer: xyz' }
      its(['Accept']) { is_expected.to eq 'application/json' }
    end

    context 'given multi word string header' do
      subject { described_class.new(method, url, headers: { 'cache control' => 'no-cache' }).headers }

      its(['Cache-Control']) { is_expected.to eq 'no-cache' }
      its(['Accept']) { is_expected.to eq 'application/json' }
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
restful_resource-2.18.1 spec/restful_resource/request_spec.rb
restful_resource-2.18.0 spec/restful_resource/request_spec.rb
restful_resource-2.17.0 spec/restful_resource/request_spec.rb
restful_resource-2.16.0 spec/restful_resource/request_spec.rb
restful_resource-2.15.0 spec/restful_resource/request_spec.rb
restful_resource-2.14.0 spec/restful_resource/request_spec.rb
restful_resource-2.13.4 spec/restful_resource/request_spec.rb
restful_resource-2.13.3 spec/restful_resource/request_spec.rb
restful_resource-2.13.2 spec/restful_resource/request_spec.rb
restful_resource-2.13.1 spec/restful_resource/request_spec.rb
restful_resource-2.13.0 spec/restful_resource/request_spec.rb
restful_resource-2.12.1 spec/restful_resource/request_spec.rb
restful_resource-2.12.0 spec/restful_resource/request_spec.rb
restful_resource-2.11.0 spec/restful_resource/request_spec.rb
restful_resource-2.10.3 spec/restful_resource/request_spec.rb
restful_resource-2.10.1 spec/restful_resource/request_spec.rb
restful_resource-2.10.0 spec/restful_resource/request_spec.rb
restful_resource-2.9.1 spec/restful_resource/request_spec.rb
restful_resource-2.8.0 spec/restful_resource/request_spec.rb
restful_resource-2.7.0 spec/restful_resource/request_spec.rb