Sha256: 3a04f911cc28db94516590dea8ed551ab942c145cf900d7f2e0bdac3888b8c90
Contents?: true
Size: 1.47 KB
Versions: 7
Compression:
Stored size: 1.47 KB
Contents
require 'spec_helper' require 'lookout/rack/utils/request' require 'zlib' class TestHelper attr_accessor :request include Lookout::Rack::Utils::Request def initialize end end describe Lookout::Rack::Utils::Request do let(:helper) { TestHelper.new } let(:sample_data) {'i am groot'} let(:zipped_sample_data){Zlib::Deflate.deflate(sample_data)} let(:log_instance) { double('Lookout::Rack::Utils::Log') } describe '#gunzipped_body' do before :each do helper.request = Object.new helper.request.stub(:env).and_return({'HTTP_CONTENT_ENCODING' => 'gzip'}) helper.request.stub(:body).and_return(double) helper.request.body.stub(:rewind).and_return(double) end it 'should unzip data zipped data properly' do helper.request.body.stub(:read).and_return(zipped_sample_data) expect(helper.gunzipped_body).to eq(sample_data) end it 'should do nothing if encoding is not set' do helper.request.stub(:env).and_return({}) helper.request.body.stub(:read).and_return(zipped_sample_data) expect(helper.gunzipped_body).to eq(zipped_sample_data) end it 'should halt and throw and 400 when we have badly encoded data' do allow(Lookout::Rack::Utils::Log).to receive(:instance).and_return(log_instance) expect(log_instance).to receive(:warn) helper.request.body.stub(:read).and_return(sample_data) expect(helper).to receive(:halt).with(400, "{}") helper.gunzipped_body end end end
Version data entries
7 entries across 7 versions & 1 rubygems