Welcome to mirror list, hosted at ThFree Co, Russian Federation.

requests_profiles_controller_spec.rb « admin « controllers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10850cb4603f255ddbd026d4c269de994bcc5fc0 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

require 'spec_helper'

describe Admin::RequestsProfilesController do
  set(:admin) { create(:admin) }

  before do
    sign_in(admin)
  end

  describe '#show' do
    let(:basename) { "profile_#{Time.now.to_i}.html" }
    let(:tmpdir) { Dir.mktmpdir('profiler-test') }
    let(:test_file) { File.join(tmpdir, basename) }
    let(:profile) { Gitlab::RequestProfiler::Profile.new(basename) }
    let(:sample_data) do
      <<~HTML
        <!DOCTYPE html>
        <html>
        <body>
        <h1>My First Heading</h1>
        <p>My first paragraph.</p>
        </body>
        </html>
      HTML
    end

    before do
      stub_const('Gitlab::RequestProfiler::PROFILES_DIR', tmpdir)
      output = File.open(test_file, 'w')
      output.write(sample_data)
      output.close
    end

    after do
      File.unlink(test_file)
    end

    it 'loads an HTML profile' do
      get :show, params: { name: basename }

      expect(response).to have_gitlab_http_status(200)
      expect(response.body).to eq(sample_data)
    end
  end
end