Sha256: 8a8a0499a9d3a8cb3bc9b1f31b3f3902080ad862bd7c76394c63726ef6694a22

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require File.dirname(__FILE__) + "/../spec_helper"

RSpec.describe "ActionMailer deliver 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(InfluxDB::Rails::Configuration).to receive(:ignored_environments).and_return(%w[development])
    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:            "deliver",
        mailer:          "MetricMailer",
        location:        "MetricsController#index",
        additional_tag:  :value,
        server:          Socket.gethostname,
        app_name:        :app_name,
        tags_middleware: :tags_middleware
      ),
      values: a_hash_including(
        additional_value: :value,
        request_id:       :request_id,
        value:            1
      )
    )
  end

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

    get "/metrics"

    expect_no_metric(
      tags: a_hash_including(
        hook:   "deliver",
        mailer: "MetricMailer"
      )
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
influxdb-rails-1.0.1.beta2 spec/requests/action_mailer_deliver_metrics_spec.rb