Sha256: a122e04db371670e37f77c1ee34594a0cf644ea65bf3504cf55f48780519fcc1

Contents?: true

Size: 1.71 KB

Versions: 9

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'
require 'rack'

describe VersionCake::Rack::Middleware do
  let(:response_strategy) { nil }
  let(:config) do
    VersionCake::Configuration.new.tap do |config|
      config.extraction_strategy = [:http_header]
      config.response_strategy = response_strategy
      config.resources do |resource_config|
        resource_config.resource %r{.*}, [], [], (1..5)
      end
    end
  end
  let(:upstream_headers) { {} }
  let(:middleware) do
    VersionCake::Rack::Middleware.new(
      double(call: [nil, upstream_headers, nil] ),
      config
    )
  end

  context '#call' do
    let(:env) do
      {
        'SCRIPT_NAME' => '',
        'PATH_INFO' => '',
        'HTTP_API_VERSION' => '1'
      }
    end

    subject { middleware.call(env) }
    let(:response_headers) { subject[1] }

    context 'when response_strategy is http_header' do
      let(:response_strategy) { [:http_header] }

      it 'sets the version in the response header' do
        expect(response_headers['api-version']).to eq '1'
      end
    end

    context 'when response_strategy is http_content_type' do
      let(:response_strategy) { [:http_content_type] }
      let(:upstream_headers) { { 'Content-Type' => 'application/vnd.api+json; charset=utf-8;' } }

      it 'sets the version in the content type' do
        expect(response_headers['Content-Type']).to match 'application/vnd.api+json; charset=utf-8; api_version=1'
      end

      context 'with a simpler content type' do
        let(:upstream_headers) { { 'Content-Type' => 'application/json' } }

        it 'sets the version in the content type' do
          expect(response_headers['Content-Type']).to match 'application/json; api_version=1'
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
versioncake-4.1.1 spec/unit/middleware_spec.rb
versioncake-4.1.0 spec/unit/middleware_spec.rb
versioncake-4.0.2 spec/unit/middleware_spec.rb
versioncake-4.0.1 spec/unit/middleware_spec.rb
versioncake-4.0.0 spec/unit/middleware_spec.rb
versioncake-3.4.0 spec/unit/middleware_spec.rb
versioncake-3.3.0 spec/unit/middleware_spec.rb
versioncake-3.2.0 spec/unit/middleware_spec.rb
versioncake-3.1.0 spec/unit/middleware_spec.rb