added proper support for hashed_label option, and

disabled it by default
This commit is contained in:
2010-11-22 13:28:19 +00:00
parent 8e3e54a027
commit 8a0e1a47a2
7 changed files with 50 additions and 28 deletions

View File

@@ -19,24 +19,24 @@ describe Redistat::Key do
end
it "should convert to string properly" do
@key.to_s.should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(:hour)}"
@key.to_s.should == "#{@scope}/#{@label}:#{@key.date.to_s(:hour)}"
props = [:year, :month, :day, :hour, :min, :sec]
props.each do
@key.to_s(props.last).should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(props.last)}"
@key.to_s(props.last).should == "#{@scope}/#{@label}:#{@key.date.to_s(props.last)}"
props.pop
end
end
it "should abide to hash_label option" do
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :label_hash => true})
it "should abide to hashed_label option" do
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :hashed_label => true})
@key.to_s.should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(:hour)}"
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :label_hash => false})
@key = Redistat::Key.new(@scope, @label, @date, {:depth => :hour, :hashed_label => false})
@key.to_s.should == "#{@scope}/#{@label}:#{@key.date.to_s(:hour)}"
end
it "should have default depth option" do
@key = Redistat::Key.new(@scope, @label, @date)
@key.depth.should == :day
@key.depth.should == :hour
end
it "should allow changing attributes" do

View File

@@ -15,14 +15,14 @@ describe Redistat::Label do
end
it "should store a label hash lookup key" do
@label.save
@label.saved?.should be_true
db.get("#{Redistat::KEY_LEBELS}#{@label.hash}").should == @name
label = Redistat::Label.new(@name, {:hashed_label => true}).save
label.saved?.should be_true
db.get("#{Redistat::KEY_LEBELS}#{label.hash}").should == @name
@name = "contact_us"
@label = Redistat::Label.create(@name)
@label.saved?.should be_true
db.get("#{Redistat::KEY_LEBELS}#{@label.hash}").should == @name
name = "contact_us"
label = Redistat::Label.create(name, {:hashed_label => true})
label.saved?.should be_true
db.get("#{Redistat::KEY_LEBELS}#{label.hash}").should == name
end
end

View File

@@ -11,5 +11,6 @@ class ModelHelper2
depth :day
store_event true
hashed_label true
end

View File

@@ -16,17 +16,23 @@ describe Redistat::Model do
it "should listen to model-defined options" do
ModelHelper2.depth.should == :day
ModelHelper2.store_event.should == true
ModelHelper2.hashed_label.should == true
ModelHelper.depth.should == nil
ModelHelper.store_event.should == nil
ModelHelper.hashed_label.should == nil
ModelHelper.depth(:hour)
ModelHelper.depth.should == :hour
ModelHelper.store_event(true)
ModelHelper.store_event.should == true
ModelHelper.hashed_label(true)
ModelHelper.hashed_label.should == true
ModelHelper.options[:depth] = nil
ModelHelper.options[:store_event] = nil
ModelHelper.options[:hashed_label] = nil
ModelHelper.depth.should == nil
ModelHelper.store_event.should == nil
ModelHelper.hashed_label.should == nil
end
it "should store and fetch stats" do