File: file_response_spec.rb

package info (click to toggle)
ruby-gitlab 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,660 kB
  • sloc: ruby: 12,582; makefile: 7; sh: 4
file content (35 lines) | stat: -rw-r--r-- 923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

require 'spec_helper'

RSpec.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