Sha256: 018e00b787183553edc426d79e8271c12a4282705d37168a905f0ed8c9d00dae

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require "spec_helper"

RSpec.shared_examples_for "with additional data" do |series_names|
  context "values" do
    let(:additional_values) do
      { another: :value }
    end

    after do
      InfluxDB::Rails.current.reset
    end

    it "does include the tags" do
      InfluxDB::Rails.current.values = additional_values

      series_names.each do |series_name|
        expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(series_name, hash_including(values: hash_including(another: :value)))
      end

      subject.call("unused", start, finish, "unused", payload)
    end
  end

  context "tags" do
    context "when tags_middleware is overwritten" do
      before do
        allow(config).to receive(:tags_middleware).and_return(tags_middleware)
      end

      let(:tags_middleware) { ->(tags) { tags.merge(static: "value", nil: nil, empty: "") } }

      it "processes tags throught the middleware" do
        tags = data[:tags].merge(static: "value")

        series_names.each do |series_name|
          expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(series_name, include(tags: tags))
        end

        subject.call("unused", start, finish, "unused", payload)
      end
    end

    context "when tags are set in the current context" do
      let(:input) do
        { another: :value, nil: nil, empty: "" }
      end
      let(:output) do
        { another: :value }
      end

      after do
        InfluxDB::Rails.current.reset
      end

      it "does include the tags" do
        InfluxDB::Rails.current.tags = input
        tags = data[:tags].merge(output)

        series_names.each do |series_name|
          expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(series_name, include(tags: tags))
        end

        subject.call("unused", start, finish, "unused", payload)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
experimental-influxdb-rails-1.0.0.beta5 spec/shared_examples/data.rb