make Redistat::Key abide by the hash_label option

This commit is contained in:
2010-07-19 12:03:55 +03:00
parent 8a22b2134b
commit 9403aacd96
2 changed files with 9 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ module Redistat
def to_s(depth = nil)
depth ||= @options[:depth] if !@options[:depth].nil?
key = "#{@scope}"
key << "/#{@label.hash}" if !label.nil?
key << "/" + ((@options[:hash_label].nil? || @options[:hash_label] == true) ? @label.hash : @label.name) if !label.nil?
key << ":#{@date.to_s(depth)}"
end

View File

@@ -20,12 +20,18 @@ describe Redistat::Key do
end
it "should convert to string properly" do
@key.to_s.should == "#{@scope}/#{@label_hash}:" + [:year, :month, :day].map { |k| @now.send(k).to_s.rjust(2, '0') }.join
@key.to_s.should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(:day)}"
props = [:year, :month, :day, :hour, :min, :sec]
props.each do
@key.to_s(props.last).should == "#{@scope}/#{@label_hash}:" + props.map { |k| @now.send(k).to_s.rjust(2, '0') if !k.nil? }.join
@key.to_s(props.last).should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(props.last)}"
props.pop
end
end
it "should abide to hash_label option" do
@label = "about_us"
@key = Redistat::Key.new(@scope, @label, @now, {:depth => :day, :hash_label => false})
@key.to_s.should == "#{@scope}/#{@label}:#{@key.date.to_s(:day)}"
end
end