Sha256: eb7e54665c5b18e5cae516c79312d3259973976dac2a360547b6e96b6084ec2c

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe Dune::Api::ApiConstraint do
  let(:request) { double :request }

  describe '#matches?' do
    let(:revision) { 1 }

    def header_for_revision(revision)
      "revision=#{revision}"
    end

    context 'when default is false' do
      subject(:constraint) { described_class.new(revision: revision) }


      it 'matches requests including the versioned vendor mime type' do
        headers = { accept: header_for_revision(revision) }
        allow(request).to receive(:headers).and_return(headers)

        expect(constraint.matches?(request)).to eq true
      end

      it 'does not match requests for other revisions' do
        headers = { accept: header_for_revision(revision + 1) }
        allow(request).to receive(:headers).and_return(headers)

        expect(constraint.matches?(request)).to eq false
      end
    end

    context 'when default is true' do
      subject(:constraint) { described_class.new(revision: revision, default: true) }

      it 'matches requests including the versioned vendor mime type' do
        headers = { accept: header_for_revision(revision) }
        allow(request).to receive(:headers).and_return(headers)

        expect(constraint.matches?(request)).to eq true
      end

      it 'matches requests when default is true' do
        headers = { accept: header_for_revision(revision + 1) }
        allow(request).to receive(:headers).and_return(headers)

        expect(constraint.matches?(request)).to eq true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dune-api-1.1.0 spec/constraints/dune/api/api_constraint_spec.rb
dune-api-1.0.2 spec/constraints/dune/api/api_constraint_spec.rb
dune-api-1.0.1 spec/constraints/neighborly/api/api_constraint_spec.rb