Sha256: e8505d4d45265b47c7f3496b0719bc86dff1ae086a2d95dfa5de9964db3716dc

Contents?: true

Size: 936 Bytes

Versions: 14

Compression:

Stored size: 936 Bytes

Contents

require 'sitehub/middleware/transaction_id'

class SiteHub
  module Middleware
    describe TransactionId do
      let(:transaction_id) { Constants::HttpHeaderKeys::TRANSACTION_ID }
      subject do
        described_class.new(proc {})
      end

      let(:request) { Request.new(env: {}) }
      let(:env) { { REQUEST => request } }

      it 'adds a unique identifier to the request' do
        uuid = UUID.generate(:compact)
        expect(UUID).to receive(:generate).with(:compact).and_return(uuid)
        subject.call(env)

        expect(request.headers[transaction_id]).to eq(uuid)
      end

      context 'transaction id header already exists' do
        it 'leaves it intact' do
          expect(UUID).to_not receive(:generate)
          request.headers[transaction_id] = :existing_id
          subject.call(env)

          expect(request.headers[transaction_id]).to eq(:existing_id)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha12 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.4.10 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha11 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha10 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha8 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha7 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha6 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha5 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha4 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha3 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.5.0.alpha2 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.4.9 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.4.8 spec/sitehub/middleware/transaction_id_spec.rb
sitehub-0.4.7 spec/sitehub/middleware/transaction_id_spec.rb