Permalink
Browse files

Fix bug in #postfix= with a blank value

@postfix was being set to `'.'` for `nil` or `''` or `'.false'` for
`false`. This ensures that the value will be correctly reset to `nil`
for `nil`, `false`, or `''` values.
  • Loading branch information...
1 parent 24fc9d0 commit f68e77cc404badb68bdcbb1b22859c31035a82fc @reinh committed Dec 12, 2012
Showing with 19 additions and 1 deletion.
  1. +7 −1 lib/statsd.rb
  2. +12 −0 spec/statsd_spec.rb
View
@@ -123,8 +123,14 @@ def namespace=(namespace)
@prefix = "#{namespace}."
end
+ # @attribute [w] postfix
+ # A value to be appended to the stat name after a '.'. If the value is
+ # blank then the postfix will be reset to nil (rather than to '.').
def postfix=(pf)
- @postfix = ".#{pf}"
+ case pf
+ when nil, false, '' then @postfix = nil
+ else @postfix = ".#{pf}"
+ end
end
# @attribute [w] host
View
@@ -228,6 +228,18 @@ class Statsd
end
end
+ describe '#postfix=' do
+ describe "when nil, false, or empty" do
+ it "should set postfix to nil" do
+ [nil, false, ''].each do |value|
+ @statsd.postfix = 'a postfix'
+ @statsd.postfix = value
+ @statsd.postfix.must_equal nil
+ end
+ end
+ end
+ end
+
describe "with logging" do
require 'stringio'
before { Statsd.logger = Logger.new(@log = StringIO.new)}

0 comments on commit f68e77c

Please sign in to comment.