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.25.0.1.b226 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b225 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b223 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b221 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0.1.b217 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.25.0 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.24.0.1.b216 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.24.0.1.b214 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.24.0.1.b212 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.24.0.b210 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.24.0 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b209 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b208 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b206 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b205 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b204 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b203 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b200 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2.b199 spec/acfs/middleware/msgpack_decoder_spec.rb
acfs-0.23.2 spec/acfs/middleware/msgpack_decoder_spec.rb