Permalink
Browse files

Merge pull request #32 from reinh/fix-postfix=-with-blank-value

Fix bug in #postfix= with a blank value
  • Loading branch information...
2 parents 24fc9d0 + f68e77c commit 4989ea49a81e82489096e2897e2e0e9950a70e8d @raggi raggi committed Dec 21, 2012
Showing with 19 additions and 1 deletion.
  1. +7 −1 lib/statsd.rb
  2. +12 −0 spec/statsd_spec.rb
View
8 lib/statsd.rb
@@ -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
12 spec/statsd_spec.rb
@@ -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 4989ea4

Please sign in to comment.