Skip to content

Commit 9931a11

Browse files
committed
Fix tags middleware parsing
Don't include key-value hash elements which: - are only a sequence of empty strings - are nil Reintroduce tags spec.
1 parent 281ee2b commit 9931a11

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/influxdb/rails/configuration.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ class Configuration
6767
set_defaults(
6868
measurement_name: "rails".freeze,
6969
ignored_hooks: [].freeze,
70-
tags_middleware: ->(tags) { tags },
70+
tags_middleware: lambda { |tags|
71+
tags.reject do |_key, value|
72+
value.nil? || (value.is_a?(String) && value.match?(/^\s*$/))
73+
end
74+
},
7175
rails_app_name: nil,
7276
ignored_environments: %w[test cucumber selenium].freeze,
7377
environment: ::Rails.env,

spec/unit/tags.rb renamed to spec/unit/influx_db/rails/tags_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
it "removes empty strings" do
2828
subject = described_class.new(config: config, tags: { hans: "", franz: " " })
29-
expect(subject.to_h).not_to a_hash_including(hans: "", franz: " ")
29+
expect(subject.to_h).not_to a_hash_including(:hans, :franz)
3030
end
3131

3232
it "returns symbols" do
@@ -36,7 +36,7 @@
3636

3737
it "removes nil" do
3838
subject = described_class.new(config: config, tags: { hans: nil })
39-
expect(subject.to_h).not_to a_hash_including(hans: nil)
39+
expect(subject.to_h).not_to a_hash_including(:hans)
4040
end
4141

4242
it "leaves arrays alone" do

0 commit comments

Comments
 (0)