Skip to content

Commit 383f436

Browse files
committed
Do not reject FalseClass from tags/values
false is blank Loading production environment (Rails 6.0.3.6) [1] pry(main)> false.blank? => true Also spec out how Values should behave.
1 parent 0287553 commit 383f436

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

lib/influxdb/rails/tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def initialize(config:, tags: {}, additional_tags: InfluxDB::Rails.current.tags)
99

1010
def to_h
1111
expanded_tags.reject do |_, value|
12-
value.blank?
12+
value.to_s.blank?
1313
end
1414
end
1515

lib/influxdb/rails/values.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(values: {}, additional_values: InfluxDB::Rails.current.values)
88

99
def to_h
1010
expanded_values.reject do |_, value|
11-
value.blank?
11+
value.to_s.blank?
1212
end
1313
end
1414

spec/unit/tags.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require "spec_helper"
2+
3+
RSpec.describe InfluxDB::Rails::Tags do
4+
let(:config) { InfluxDB::Rails::Configuration.new }
5+
6+
describe ".to_h" do
7+
it "returns TrueClass" do
8+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: true })
9+
expect(subject.to_h).to a_hash_including(hans: true)
10+
end
11+
12+
it "returns FalseClass" do
13+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: false })
14+
expect(subject.to_h).to a_hash_including(hans: false)
15+
end
16+
17+
it "returns strings" do
18+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: "franz" })
19+
expect(subject.to_h).to a_hash_including(hans: "franz")
20+
end
21+
22+
it "returns strings containing blank" do
23+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: "franz hans" })
24+
expect(subject.to_h).to a_hash_including(hans: "franz hans")
25+
end
26+
27+
it "removes empty strings" do
28+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: "", franz: " " })
29+
expect(subject.to_h).not_to a_hash_including(hans: "", franz: " ")
30+
end
31+
32+
it "returns symbols" do
33+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: :franz })
34+
expect(subject.to_h).to a_hash_including(hans: :franz)
35+
end
36+
37+
it "removes nil" do
38+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: nil })
39+
expect(subject.to_h).not_to a_hash_including(hans: nil)
40+
end
41+
42+
it "leaves arrays alone" do
43+
subject = InfluxDB::Rails::Tags.new(config: config, tags: { hans: [], franz: %w[a b] })
44+
expect(subject.to_h).to a_hash_including(hans: [], franz: %w[a b])
45+
end
46+
end
47+
end

0 commit comments

Comments
 (0)