Sha256: 68a6f03c05acd3dc42cbc1c876cb9c2853d4566388de0699c197a188fbfe8556

Contents?: true

Size: 1.06 KB

Versions: 115

Compression:

Stored size: 1.06 KB

Contents

require 'spec_helper'

describe Acfs::Middleware::MessagePackDecoder do
  let(:data)     { [{id: 1, name: "Anon"},{id: 2, name:"John", friends: [ 1 ]}] }
  let(:body)     { data.to_param }
  let(:headers)  { {} }
  let(:request)  { Acfs::Request.new "fubar" }
  let(:response) { Acfs::Response.new request, status: 200, headers: headers, body: body }
  let(:decoder)  { Acfs::Middleware::MessagePackDecoder.new lambda { |req| req } }

  before do
    decoder.call request
  end

  context 'with Message Pack response' do
    let(:headers) { { 'Content-Type' => 'application/x-msgpack' } }
    let(:body)    { MessagePack.pack data }

    it 'should decode body data' do
      request.complete! response

      expect(response.data).to be == data.map(&:stringify_keys)
    end
  end

  context 'without Message Pack response' do
    let(:headers) { { 'Content-Type' => 'application/text' } }
    let(:body)    { data.to_json }

    it 'should not decode non-MessagePack encoded responses' do
      request.complete! response

      expect(response.data).to be_nil
    end
  end
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
acfs-0.30.0 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.29.1.1.b259 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.29.1.1.b257 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.29.1 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.29.0.1.b256 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.29.0.1.b254 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.29.0 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.28.0.1.b253 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.28.0.1.b249 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.28.0 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.27.0.1.b248 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.27.0.1.b244 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.27.0 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.26.0.1.b243 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.26.0.1.b242 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.26.0 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b232 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b229 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b228 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b227 spec/acfs/middleware/msgpack_decoder_spec.rb