summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb
blob: 77f3e69d5234d5d6b8464474d8d82e82a860df80 (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
require 'spec_helper'

describe Gitlab::Metrics::Subscribers::ActionView do
  let(:transaction) { Gitlab::Metrics::Transaction.new }

  let(:subscriber) { described_class.new }

  let(:event) do
    root = Rails.root.to_s

    double(:event, duration: 2.1,
                   payload:  { identifier: "#{root}/app/views/x.html.haml" })
  end

  before do
    allow(subscriber).to receive(:current_transaction).and_return(transaction)

    allow(Gitlab::Metrics).to receive(:last_relative_application_frame).
      and_return(['app/views/x.html.haml', 4])
  end

  describe '#render_template' do
    it 'tracks rendering of a template' do
      values = { duration: 2.1, file: 'app/views/x.html.haml', line: 4 }

      expect(transaction).to receive(:add_metric).
        with(described_class::SERIES, values, path: 'app/views/x.html.haml')

      subscriber.render_template(event)
    end
  end
end