Sha256: 03da9a72bca3349baac5bd043b78a6979705e99a8d50f87736982eca3b88eab1

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

require "#{File.dirname(__FILE__)}/../spec_helper"

RSpec.describe "ActionView template metrics", type: :request do
  let(:tags_middleware) do
    lambda do |tags|
      tags.merge(tags_middleware: :tags_middleware)
    end
  end
  before do
    allow_any_instance_of(ActionDispatch::Request).to receive(:request_id).and_return(:request_id)
    allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:application_name).and_return(:app_name)
    allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:tags_middleware).and_return(tags_middleware)
  end

  it "writes metric" do
    get "/metrics"

    expect_metric(
      tags:   a_hash_including(
        hook:     "render_template",
        filename: include("spec/support/views/metrics/index.html.erb")
      ),
      values: a_hash_including(
        value: be_between(1, 500)
      )
    )
  end

  it "includes correct timestamps" do
    travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)

    get "/metrics"

    expect_metric(
      tags:      a_hash_including(
        hook: "render_template"
      ),
      timestamp: 1_514_797_200
    )
  end

  it "does not write metric when hook is ignored" do
    allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["render_template.action_view"])

    get "/metrics"

    expect_no_metric(
      tags: a_hash_including(
        hook: "render_template"
      )
    )
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
influxdb-rails-1.0.3 spec/requests/action_view_template_metrics_spec.rb
influxdb-rails-1.0.2 spec/requests/action_view_template_metrics_spec.rb