|
| 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