| added updating of last cached reporting period if new data has been read - repo… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 415849fbf6a05c044df8465162a4218165f1d773 | |
| parent ca91ca842c410fa1afea209b550ac8ed2d812e35 | |
| Author: marcoow <[email protected]> | |
| Date: Fri, 12 Dec 2008 00:48:11 +0800 | |
| added updating of last cached reporting period if new data has been read | |
| Signed-off-by: Marco Otte-Witte <[email protected]> | |
| Diffstat: | |
| M lib/kvlr/reports_as_sparkline/repo… | 6 ++++-- | |
| M spec/boot.rb | 2 +- | |
| M spec/other/report_cache_spec.rb | 14 +++++++++++++- | |
| 3 files changed, 18 insertions(+), 4 deletions(-) | |
| --- | |
| diff --git a/lib/kvlr/reports_as_sparkline/report_cache.rb b/lib/kvlr/reports_a… | |
| @@ -50,8 +50,10 @@ module Kvlr #:nodoc: | |
| result << [cached.reporting_period.date_time, cached.value] | |
| reporting_period = reporting_period.previous | |
| end while reporting_period != last_reporting_period_to_read | |
| - if !no_cache && cached = cached_data.detect { |cached| cached.report… | |
| - cached.update_attributes!(:value => data[1]) | |
| + unless no_cache | |
| + cached = cached_data.last || nil | |
| + data = (new_data.first && new_data.first[0] == last_reporting_peri… | |
| + cached.update_attributes!(:value => data[1]) unless cached.nil? ||… | |
| end | |
| result | |
| end | |
| diff --git a/spec/boot.rb b/spec/boot.rb | |
| @@ -19,5 +19,5 @@ FileUtils.mkdir_p File.join(File.dirname(__FILE__), 'log') | |
| ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), 'log'… | |
| databases = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'db', 'databa… | |
| -ActiveRecord::Base.establish_connection(databases['sqlite3']) | |
| +ActiveRecord::Base.establish_connection(databases['postgresql']) | |
| load(File.join(File.dirname(__FILE__), 'db', 'schema.rb')) | |
| diff --git a/spec/other/report_cache_spec.rb b/spec/other/report_cache_spec.rb | |
| @@ -168,7 +168,19 @@ describe Kvlr::ReportsAsSparkline::ReportCache do | |
| result.length.should == 10 | |
| end | |
| - #TODO: add specs for update of record in cache fpr last_reporting_period_t… | |
| + it 'should update the last cached record if new data has been read for the… | |
| + Kvlr::ReportsAsSparkline::ReportingPeriod.stub!(:from_db_string).and_ret… | |
| + @cached.should_receive(:update_attributes!).once.with(:value => 1.0) | |
| + | |
| + Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, [… | |
| + end | |
| + | |
| + it 'should not update the last cached record if new data has been read for… | |
| + Kvlr::ReportsAsSparkline::ReportingPeriod.stub!(:from_db_string).and_ret… | |
| + @cached.should_not_receive(:update_attributes!) | |
| + | |
| + Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, [… | |
| + end | |
| end | |