mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
31 lines
988 B
Ruby
31 lines
988 B
Ruby
require "spec_helper"
|
|
|
|
describe Redistat::Key do
|
|
|
|
before(:each) do
|
|
@scope = "PageViews"
|
|
@label = "/about/us"
|
|
@label_hash = Digest::SHA1.hexdigest(@label)
|
|
@now = Time.now
|
|
@key = Redistat::Key.new(@scope, @label, @now, {:depth => :day})
|
|
end
|
|
|
|
it "should initialize properly" do
|
|
@key.scope.should == @scope
|
|
@key.label.should be_instance_of(Redistat::Label)
|
|
@key.label.name.should == @label
|
|
@key.label.hash.should == @label_hash
|
|
@key.date.should be_instance_of(Redistat::Date)
|
|
@key.date.to_time.to_s.should == @now.to_s
|
|
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
|
|
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
|
|
props.pop
|
|
end
|
|
end
|
|
|
|
end |