mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
Created Redistat::Result and started using it
Finder. All specs pass.
This commit is contained in:
@@ -27,6 +27,8 @@ module Redistat
|
||||
total_sum.set_or_incr(k, v.to_i)
|
||||
end
|
||||
end
|
||||
total_sum.date = Date.new(@options[:from], @options[:depth])
|
||||
total_sum.till = Date.new(@options[:till], @options[:depth])
|
||||
total_sum
|
||||
end
|
||||
|
||||
|
||||
14
lib/redistat/result.rb
Normal file
14
lib/redistat/result.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
module Redistat
|
||||
class Result < ::Hash
|
||||
|
||||
attr_accessor :date
|
||||
attr_accessor :till
|
||||
|
||||
def set_or_incr(key, value)
|
||||
self[key] = 0 if !self.has_key?(key)
|
||||
self[key] += value
|
||||
self
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -44,8 +44,6 @@ describe Redistat::Finder do
|
||||
end
|
||||
|
||||
it "should fetch stats properly" do
|
||||
# pending "needs reimplementation"
|
||||
|
||||
key = Redistat::Key.new(@scope, @label, 2.hours.ago)
|
||||
Redistat::Summary.update(key, @stats, :hour)
|
||||
key = Redistat::Key.new(@scope, @label, 1.hours.ago)
|
||||
@@ -53,9 +51,14 @@ describe Redistat::Finder do
|
||||
key = Redistat::Key.new(@scope, @label, 24.minutes.ago)
|
||||
Redistat::Summary.update(key, @stats, :hour)
|
||||
|
||||
stats = Redistat::Finder.find({:from => 3.hours.ago, :till => 2.hours.from_now, :scope => @scope, :label => @label, :depth => :hour})
|
||||
stats.should == { "views" => 9, "visitors" => 6 }
|
||||
three_hours_ago = 3.hours.ago
|
||||
two_hours_from_now = 2.hours.from_now
|
||||
depth = :hour
|
||||
|
||||
stats = Redistat::Finder.find({:from => three_hours_ago, :till => two_hours_from_now, :scope => @scope, :label => @label, :depth => depth})
|
||||
stats.should == { "views" => 9, "visitors" => 6 }
|
||||
stats.date.to_s.should == three_hours_ago.to_rs.to_s(depth)
|
||||
stats.till.to_s.should == two_hours_from_now.to_rs.to_s(depth)
|
||||
end
|
||||
|
||||
it "should return empty hash when attempting to fetch non-existent results" do
|
||||
@@ -63,4 +66,17 @@ describe Redistat::Finder do
|
||||
stats.should == {}
|
||||
end
|
||||
|
||||
end
|
||||
it "should fetch data per unit when interval option is specified" do
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
19
spec/result_spec.rb
Normal file
19
spec/result_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require "spec_helper"
|
||||
|
||||
describe Redistat::Result do
|
||||
|
||||
before(:each) do
|
||||
@name = "PageViews"
|
||||
@scope = Redistat::Scope.new(@name)
|
||||
end
|
||||
|
||||
it "should have set_or_incr method" do
|
||||
result = Redistat::Result.new
|
||||
result[:world].should be_nil
|
||||
result.set_or_incr(:world, 3)
|
||||
result[:world].should == 3
|
||||
result.set_or_incr(:world, 8)
|
||||
result[:world].should == 11
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user