action_view_spec.rb 846 字节
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::Metrics::Subscribers::ActionView do
4
  let(:transaction) { Gitlab::Metrics::Transaction.new }
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

  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)
  end

  describe '#render_template' do
    it 'tracks rendering of a template' do
21
      values = { duration: 2.1 }
22
      tags   = { view: 'app/views/x.html.haml' }
23

24
      expect(transaction).to receive(:increment).
25
        with(:view_duration, 2.1)
26

27
      expect(transaction).to receive(:add_metric).
28
        with(described_class::SERIES, values, tags)
29 30 31 32 33

      subscriber.render_template(event)
    end
  end
end