Introduction
Introduction Statistics Contact Development Disclaimer Help
refactored ReportCache.prepare_result - reportable - Fork of reportable require…
Log
Files
Refs
README
---
commit ef0e7538ed36be1760669e5dad94482ef4789418
parent b3c5f1a04b24429fe96a1b2eeb1dadc63214574d
Author: Marco Otte-Witte <[email protected]>
Date: Mon, 19 Jan 2009 13:21:56 +0100
refactored ReportCache.prepare_result
Diffstat:
M lib/kvlr/reports_as_sparkline/repo… | 10 +++++-----
M spec/classes/report_cache_spec.rb | 36 ++++++++++++++++-------------…
2 files changed, 23 insertions(+), 23 deletions(-)
---
diff --git a/lib/kvlr/reports_as_sparkline/report_cache.rb b/lib/kvlr/reports_a…
@@ -14,19 +14,19 @@ module Kvlr #:nodoc:
last_reporting_period_to_read = ReportingPeriod.new(options[:group…
end
new_data = yield(last_reporting_period_to_read.date_time)
- prepare_result(new_data, cached_data, last_reporting_period_to_read,…
+ prepare_result(new_data, cached_data, last_reporting_period_to_read,…
end
end
private
- def self.prepare_result(new_data, cached_data, last_reporting_period_t…
- new_data.map! { |data| [ReportingPeriod.from_db_string(grouping, dat…
+ def self.prepare_result(new_data, cached_data, last_reporting_period_t…
+ new_data.map! { |data| [ReportingPeriod.from_db_string(options[:grou…
result = cached_data.map { |cached| [cached.reporting_period, cached…
- current_reporting_period = ReportingPeriod.new(grouping)
+ current_reporting_period = ReportingPeriod.new(options[:grouping])
reporting_period = last_reporting_period_to_read
while reporting_period < current_reporting_period
- cached = build_cached_data(report, grouping, reporting_period, fin…
+ cached = build_cached_data(report, options[:grouping], reporting_p…
cached.save! if cache
result << [reporting_period.date_time, cached.value]
reporting_period = reporting_period.next
diff --git a/spec/classes/report_cache_spec.rb b/spec/classes/report_cache_spec…
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe Kvlr::ReportsAsSparkline::ReportCache do
before do
- @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations)
+ @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations, :limi…
end
describe '.process' do
@@ -15,19 +15,19 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
it 'should raise an ArgumentError if no block is given' do
lambda do
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10,…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options)
end.should raise_error(ArgumentError)
end
it 'sould start a transaction' do
Kvlr::ReportsAsSparkline::ReportCache.should_receive(:transaction)
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10, :…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) …
end
it 'should yield to the given block' do
lambda {
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10,…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options…
}.should raise_error(YieldMatchException)
end
@@ -46,7 +46,7 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
:order => 'reporting_period ASC'
)
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10, :…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) …
end
it "should read existing data from the cache for the correct grouping if o…
@@ -73,13 +73,13 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
cached_data = []
Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return(cached_dat…
last_reporting_period_to_read = Kvlr::ReportsAsSparkline::ReportingPerio…
- Kvlr::ReportsAsSparkline::ReportCache.should_receive(:prepare_result).on…
+ Kvlr::ReportsAsSparkline::ReportCache.should_receive(:prepare_result).on…
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10, :…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) …
end
it 'should yield the first reporting period if the cache is empty' do
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10, :…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) …
begin_at.should == Kvlr::ReportsAsSparkline::ReportingPeriod.first(@re…
[]
end
@@ -97,7 +97,7 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
})
Kvlr::ReportsAsSparkline::ReportCache.stub!(:find).and_return([cached])
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10, :…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options) …
begin_at.should == reporting_period.next.date_time
[]
end
@@ -108,11 +108,11 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
it 'should not read any data from cache' do
Kvlr::ReportsAsSparkline::ReportCache.should_not_receive(:find)
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10,…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options…
end
it 'should yield the first reporting period' do
- Kvlr::ReportsAsSparkline::ReportCache.process(@report, { :limit => 10,…
+ Kvlr::ReportsAsSparkline::ReportCache.process(@report, @report.options…
begin_at.should == Kvlr::ReportsAsSparkline::ReportingPeriod.first(@…
[]
end
@@ -136,7 +136,7 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
it 'should convert the date strings from the newly read data to reporting …
Kvlr::ReportsAsSparkline::ReportingPeriod.should_receive(:from_db_string…
- Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, […
+ Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, […
end
it 'should create (:limit - 1) instances of Kvlr::ReportsAsSparkline::Repo…
@@ -147,7 +147,7 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
0.0
).and_return(@cached)
- Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [], [], @las…
+ Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, [], [], @las…
end
it 'should create a new Kvlr::ReportsAsSparkline::ReportCache with the cor…
@@ -164,17 +164,17 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
1.0
).and_return(@cached)
- Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, […
+ Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, […
end
it 'should save the created Kvlr::ReportsAsSparkline::ReportCache if no_ca…
@cached.should_receive(:save!).once
- Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, […
+ Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data, […
end
it 'should return an array of arrays of Dates and Floats' do
- result = Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @ne…
+ result = Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @ne…
result.should be_kind_of(Array)
result[0].should be_kind_of(Array)
@@ -187,14 +187,14 @@ describe Kvlr::ReportsAsSparkline::ReportCache do
it 'should not save the created Kvlr::ReportsAsSparkline::ReportCache' do
@cached.should_not_receive(:save!)
- Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data,…
+ Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data,…
end
it 'should not update the last cached record if new data has been read f…
Kvlr::ReportsAsSparkline::ReportingPeriod.stub!(:from_db_string).and_r…
@cached.should_not_receive(:update_attributes!)
- Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data,…
+ Kvlr::ReportsAsSparkline::ReportCache.send(:prepare_result, @new_data,…
end
end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.