diff --git a/lib/redistat/finder.rb b/lib/redistat/finder.rb index fbd8578..83752e5 100644 --- a/lib/redistat/finder.rb +++ b/lib/redistat/finder.rb @@ -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 diff --git a/lib/redistat/result.rb b/lib/redistat/result.rb new file mode 100644 index 0000000..1f658d7 --- /dev/null +++ b/lib/redistat/result.rb @@ -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 \ No newline at end of file diff --git a/spec/finder_spec.rb b/spec/finder_spec.rb index 76642e5..6f2a90f 100644 --- a/spec/finder_spec.rb +++ b/spec/finder_spec.rb @@ -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 \ No newline at end of file + it "should fetch data per unit when interval option is specified" do + + end + +end + + + + + + + + + diff --git a/spec/result_spec.rb b/spec/result_spec.rb new file mode 100644 index 0000000..e26bb19 --- /dev/null +++ b/spec/result_spec.rb @@ -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 \ No newline at end of file