spec/unit/middleware/render_subscriber_spec.rb in influxdb-rails-1.0.0.beta2 vs spec/unit/middleware/render_subscriber_spec.rb in influxdb-rails-1.0.0.beta3
- old
+ new
@@ -1,6 +1,7 @@
require "spec_helper"
+require "shared_examples/tags"
RSpec.describe InfluxDB::Rails::Middleware::RenderSubscriber do
let(:config) { InfluxDB::Rails::Configuration.new }
let(:logger) { double(:logger) }
@@ -9,69 +10,70 @@
allow(config).to receive(:ignored_environments).and_return([])
allow(config).to receive(:time_precision).and_return("ms")
end
describe ".call" do
- let(:start_time) { Time.at(1_517_567_368) }
- let(:finish_time) { Time.at(1_517_567_370) }
+ let(:start) { Time.at(1_517_567_368) }
+ let(:finish) { Time.at(1_517_567_370) }
let(:series_name) { "series_name" }
let(:payload) { { identifier: "index.html", count: 43, cache_hits: 42 } }
- let(:result) do
+ let(:data) do
{
values: {
- value: 2000
- },
- tags: {
- filename: "index.html",
- location: "Foo#bar",
+ value: 2000,
count: 43,
cache_hits: 42
},
+ tags: {
+ filename: "index.html",
+ location: "Foo#bar",
+ },
timestamp: 1_517_567_370_000
}
end
subject { described_class.new(config, series_name) }
before do
- Thread.current[:_influxdb_rails_controller] = "Foo"
- Thread.current[:_influxdb_rails_action] = "bar"
+ InfluxDB::Rails.current.controller = "Foo"
+ InfluxDB::Rails.current.action = "bar"
end
after do
- Thread.current[:_influxdb_rails_action] = nil
- Thread.current[:_influxdb_rails_controller] = nil
+ InfluxDB::Rails.current.reset
end
context "successfully" do
it "writes to InfluxDB" do
expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
- series_name, result
+ series_name, data
)
- subject.call("name", start_time, finish_time, "id", payload)
+ subject.call("name", start, finish, "id", payload)
end
- context "with empty tags" do
+ it_behaves_like "with additional tags", ["series_name"]
+
+ context "with an empty value" do
before do
payload[:count] = nil
- result[:tags].delete(:count)
+ data[:values].delete(:count)
end
- it "does not write empty tags" do
+ it "does not write empty value" do
expect_any_instance_of(InfluxDB::Client).to receive(:write_point).with(
- series_name, result
+ series_name, data
)
- subject.call("name", start_time, finish_time, "id", payload)
+ subject.call("name", start, finish, "id", payload)
end
end
context "disabled" do
subject { described_class.new(config, nil) }
it "does not write a data point" do
expect_any_instance_of(InfluxDB::Client).not_to receive(:write_point)
- subject.call("name", start_time, finish_time, "id", payload)
+ subject.call("name", start, finish, "id", payload)
end
end
end
context "unsuccessfully" do
@@ -81,10 +83,10 @@
end
it "does log exceptions" do
allow_any_instance_of(InfluxDB::Client).to receive(:write_point).and_raise("boom")
expect(logger).to receive(:error).with(/boom/)
- subject.call("name", start_time, finish_time, "id", payload)
+ subject.call("name", start, finish, "id", payload)
end
end
end
end