Codebase list ruby-gitlab / debian/4.17.0-2 spec / gitlab / file_response_spec.rb
debian/4.17.0-2

Tree @debian/4.17.0-2 (Download .tar.gz)

file_response_spec.rb @debian/4.17.0-2raw · history · blame

# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::FileResponse do
  before do
    @file_response = described_class.new StringIO.new(+'', 'rb+')
  end

  describe '.empty?' do
    it 'returns false' do
      expect(@file_response.empty?).to be false
    end
  end

  describe '.to_hash' do
    it 'has `filename` key and `data` key' do
      h = @file_response.to_hash
      expect(h).to be_key(:filename)
      expect(h).to be_key(:data)
    end
  end

  describe '.parse_headers!' do
    it 'parses headers' do
      @file_response.parse_headers!('Content-Disposition' => 'attachment; filename=artifacts.zip')
      expect(@file_response.filename).to eq 'artifacts.zip'
    end

    it 'handles quoted filenames' do
      @file_response.parse_headers!('Content-Disposition' => 'attachment; filename="artifacts.zip"')
      expect(@file_response.filename).to eq 'artifacts.zip'
    end
  end
end