Skip to content

Commit

Permalink
Fix tags middleware parsing
Browse files Browse the repository at this point in the history
Don't include key-value hash elements which:
- are only a sequence of empty strings
- are nil

Reintroduce tags spec.
  • Loading branch information
eduardoj committed May 28, 2024
1 parent 281ee2b commit 9931a11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/influxdb/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ class Configuration
set_defaults(
measurement_name: "rails".freeze,
ignored_hooks: [].freeze,
tags_middleware: ->(tags) { tags },
tags_middleware: lambda { |tags|
tags.reject do |_key, value|
value.nil? || (value.is_a?(String) && value.match?(/^\s*$/))
end
},
rails_app_name: nil,
ignored_environments: %w[test cucumber selenium].freeze,
environment: ::Rails.env,
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/tags.rb → spec/unit/influx_db/rails/tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

it "removes empty strings" do
subject = described_class.new(config: config, tags: { hans: "", franz: " " })
expect(subject.to_h).not_to a_hash_including(hans: "", franz: " ")
expect(subject.to_h).not_to a_hash_including(:hans, :franz)
end

it "returns symbols" do
Expand All @@ -36,7 +36,7 @@

it "removes nil" do
subject = described_class.new(config: config, tags: { hans: nil })
expect(subject.to_h).not_to a_hash_including(hans: nil)
expect(subject.to_h).not_to a_hash_including(:hans)
end

it "leaves arrays alone" do
Expand Down

0 comments on commit 9931a11

Please sign in to comment.