diff --git a/spec/model_spec.rb b/spec/model_spec.rb index f0000bf..19755bd 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -5,6 +5,7 @@ describe Redistat::Model do include Redistat::Database before(:each) do + @time = Time.utc(2010, 8, 28, 12, 0, 0) ModelHelper1.redis.flushdb ModelHelper2.redis.flushdb ModelHelper3.redis.flushdb @@ -43,28 +44,28 @@ describe Redistat::Model do end it "should store and fetch stats" do - ModelHelper1.store("sheep.black", {:count => 6, :weight => 461}, 4.hours.ago) - ModelHelper1.store("sheep.black", {:count => 2, :weight => 156}) + ModelHelper1.store("sheep.black", {:count => 6, :weight => 461}, @time.hours_ago(4)) + ModelHelper1.store("sheep.black", {:count => 2, :weight => 156}, @time) - stats = ModelHelper1.fetch("sheep.black", 2.hours.ago, 1.hour.from_now) + stats = ModelHelper1.fetch("sheep.black", @time.hours_ago(2), @time.hours_since(1)) stats.total["count"].should == 2 stats.total["weight"].should == 156 stats.first.should == stats.total - stats = ModelHelper1.fetch("sheep.black", 5.hours.ago, 1.hour.from_now) + stats = ModelHelper1.fetch("sheep.black", @time.hours_ago(5), @time.hours_since(1)) stats.total[:count].should == 8 stats.total[:weight].should == 617 stats.first.should == stats.total - ModelHelper1.store("sheep.white", {:count => 5, :weight => 393}, 4.hours.ago) - ModelHelper1.store("sheep.white", {:count => 4, :weight => 316}) + ModelHelper1.store("sheep.white", {:count => 5, :weight => 393}, @time.hours_ago(4)) + ModelHelper1.store("sheep.white", {:count => 4, :weight => 316}, @time) - stats = ModelHelper1.fetch("sheep.white", 2.hours.ago, 1.hour.from_now) + stats = ModelHelper1.fetch("sheep.white", @time.hours_ago(2), @time.hours_since(1)) stats.total[:count].should == 4 stats.total[:weight].should == 316 stats.first.should == stats.total - stats = ModelHelper1.fetch("sheep.white", 5.hours.ago, 1.hour.from_now) + stats = ModelHelper1.fetch("sheep.white", @time.hours_ago(5), @time.hours_since(1)) stats.total[:count].should == 9 stats.total[:weight].should == 709 stats.first.should == stats.total @@ -73,31 +74,31 @@ describe Redistat::Model do it "should connect to different Redis servers on a per-model basis" do ModelHelper3.redis.client.db.should == 14 - ModelHelper3.store("sheep.black", {:count => 6, :weight => 461}, 4.hours.ago) - ModelHelper3.store("sheep.black", {:count => 2, :weight => 156}) + ModelHelper3.store("sheep.black", {:count => 6, :weight => 461}, @time.hours_ago(4)) + ModelHelper3.store("sheep.black", {:count => 2, :weight => 156}, @time) db.keys("*").should be_empty ModelHelper1.redis.keys("*").should be_empty db("ModelHelper3").keys("*").should have(5).items ModelHelper3.redis.keys("*").should have(5).items - stats = ModelHelper3.fetch("sheep.black", 2.hours.ago, 1.hour.from_now) + stats = ModelHelper3.fetch("sheep.black", @time.hours_ago(2), @time.hours_since(1)) stats.total["count"].should == 2 stats.total["weight"].should == 156 - stats = ModelHelper3.fetch("sheep.black", 5.hours.ago, 1.hour.from_now) + stats = ModelHelper3.fetch("sheep.black", @time.hours_ago(5), @time.hours_since(1)) stats.total[:count].should == 8 stats.total[:weight].should == 617 ModelHelper3.connect_to(:port => 8379, :db => 13) ModelHelper3.redis.client.db.should == 13 - stats = ModelHelper3.fetch("sheep.black", 5.hours.ago, 1.hour.from_now) + stats = ModelHelper3.fetch("sheep.black", @time.hours_ago(5), @time.hours_since(1)) stats.total.should == {} ModelHelper3.connect_to(:port => 8379, :db => 14) ModelHelper3.redis.client.db.should == 14 - stats = ModelHelper3.fetch("sheep.black", 5.hours.ago, 1.hour.from_now) + stats = ModelHelper3.fetch("sheep.black", @time.hours_ago(5), @time.hours_since(1)) stats.total[:count].should == 8 stats.total[:weight].should == 617 end