Sha256: f9dfbd4a731a9b8bf80d342f9cd7399ade5700b681c1718dd653f8b76cc87d8f

Contents?: true

Size: 1.37 KB

Versions: 49

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe Ridley::Middleware::Gzip do
  let(:env) do
    Hashie::Mash.new(
      'response_headers' => {
        'content-encoding' => nil
      },
      'body' => nil
    )
  end

  subject { described_class.new }

  describe "#on_complete" do
    let(:run) { subject.on_complete(env) }

    context "when content-encoding is set to 'gzip'" do
      let(:secret) { "this is a secret zipped message" }

      before do
        env['response_headers']['content-encoding'] = 'gzip'
        io = StringIO.new
        writer = Zlib::GzipWriter.new(io)
        writer.write(secret)
        writer.close
        env['body'] = io.string
      end

      it "unzips the commpressed body" do
        run
        expect(env['body']).to eq(secret)
      end
    end

    context "when content-encoding is set to 'deflate'" do
      let(:secret) { "this is a secret deflated message" }

      before do
        env['response_headers']['content-encoding'] = 'deflate'
        env['body'] = Zlib::Deflate.deflate(secret)
      end

      it "inflates the compressed body" do
        run
        expect(env['body']).to eq(secret)
      end
    end

    context "when content-encoding is set to nothing" do
      before { env['body'] = 'not changed' }

      it "does not manipulate the body of the request" do
        run
        expect(env['body']).to eq('not changed')
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
ridley-4.2.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-4.1.2 spec/unit/ridley/middleware/gzip_spec.rb
ridley-4.1.1 spec/unit/ridley/middleware/gzip_spec.rb
ridley-4.1.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-4.0.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-3.1.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-3.0.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-3.0.0.rc1 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.5.1 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.5.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.4.4 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.4.3 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.4.2 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.4.1 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.4.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.3.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.2.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.1.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-2.0.0 spec/unit/ridley/middleware/gzip_spec.rb
ridley-1.7.1 spec/unit/ridley/middleware/gzip_spec.rb