Skip to content

Commit

Permalink
(hopefully ;) fixed bug in ReportCache
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoow committed Jan 20, 2009
1 parent baf5e26 commit c7ad0fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/kvlr/reports_as_sparkline/report_cache.rb
Expand Up @@ -11,7 +11,7 @@ def self.process(report, options, cache = true, &block)
first_reporting_period = ReportingPeriod.first(options[:grouping], options[:limit])
if cache
cached_data = find_cached_data(report, options, first_reporting_period)
last_cached_reporting_period = (ReportingPeriod.new(options[:grouping], cached_data.last.reporting_period.date_time) rescue nil)
last_cached_reporting_period = cached_data.empty? ? nil : ReportingPeriod.new(options[:grouping], cached_data.last.reporting_period)
end
new_data = if !options[:live_data] && last_cached_reporting_period == ReportingPeriod.new(options[:grouping]).previous
[]
Expand All @@ -28,7 +28,7 @@ def self.prepare_result(new_data, cached_data, report, options, cache = true)
new_data.map! { |data| [ReportingPeriod.from_db_string(options[:grouping], data[0]), data[1]] }
result = cached_data.map { |cached| [cached.reporting_period, cached.value] }
current_reporting_period = ReportingPeriod.new(options[:grouping])
reporting_period = (cached_data.last.reporting_period.next rescue ReportingPeriod.first(options[:grouping], options[:limit]))
reporting_period = cached_data.empty? ? ReportingPeriod.first(options[:grouping], options[:limit]) : ReportingPeriod.new(options[:grouping], cached_data.last.reporting_period).next
while reporting_period < current_reporting_period
cached = build_cached_data(report, options[:grouping], reporting_period, find_value(new_data, reporting_period))
cached.save! if cache
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/report_cache_spec.rb
Expand Up @@ -43,7 +43,7 @@
Time.now - 3.send(@report.options[:grouping].identifier)
)
cached = Kvlr::ReportsAsSparkline::ReportCache.new
cached.stub!(:reporting_period).and_return(reporting_period)
cached.stub!(:reporting_period).and_return(reporting_period.date_time)
Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cached])

Kvlr::ReportsAsSparkline::ReportCache.process(@report, @options) do |begin_at|
Expand Down Expand Up @@ -77,7 +77,7 @@
Time.now - 3.send(@report.options[:grouping].identifier)
)
cached = Kvlr::ReportsAsSparkline::ReportCache.new
cached.stub!(:reporting_period).and_return(reporting_period)
cached.stub!(:reporting_period).and_return(reporting_period.date_time)
Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cached])

Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) do |begin_at|
Expand Down

0 comments on commit c7ad0fb

Please sign in to comment.