Introduction
Introduction Statistics Contact Development Disclaimer Help
fixed specs for CumulatedReport; removed some unneccessary specs; fixed quoting…
Log
Files
Refs
README
---
commit f757bffbf6e3107a81753511f9f7dbe25b7baca1
parent bbec0de4cda48704427b6978a4d8080edf5d3a2d
Author: Marco Otte-Witte <[email protected]>
Date: Wed, 29 Apr 2009 11:11:20 +0200
fixed specs for CumulatedReport; removed some unneccessary specs; fixed quoting…
Diffstat:
M lib/simplabs/reports_as_sparkline/… | 2 +-
M lib/simplabs/reports_as_sparkline/… | 2 +-
M spec/classes/cumulated_report_spec… | 51 ++++++++++++++++-----------…
M spec/classes/report_spec.rb | 31 ++++++++++-------------------…
4 files changed, 38 insertions(+), 48 deletions(-)
---
diff --git a/lib/simplabs/reports_as_sparkline/cumulated_report.rb b/lib/simpla…
@@ -22,7 +22,7 @@ module Simplabs #:nodoc:
protected
- def cumulate(data, options) #:nodoc:
+ def cumulate(data, options)
first_reporting_period = ReportingPeriod.first(options[:grouping], o…
acc = initial_cumulative_value(first_reporting_period.date_time, opt…
result = []
diff --git a/lib/simplabs/reports_as_sparkline/report.rb b/lib/simplabs/reports…
@@ -77,7 +77,7 @@ module Simplabs #:nodoc:
def setup_conditions(begin_at, end_at, custom_conditions = [])
conditions = [@klass.send(:sanitize_sql_for_conditions, custom_condi…
- conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ')}\"#{@klass…
+ conditions[0] += "#{(conditions[0].blank? ? '' : ' AND ')}#{ActiveRe…
conditions[0] += if begin_at && end_at
'BETWEEN ? AND ?'
elsif begin_at
diff --git a/spec/classes/cumulated_report_spec.rb b/spec/classes/cumulated_rep…
@@ -36,9 +36,10 @@ describe Simplabs::ReportsAsSparkline::CumulatedReport do
before(:all) do
User.delete_all
- User.create!(:login => 'test 1', :created_at => Time.now - 1.sen…
- User.create!(:login => 'test 2', :created_at => Time.now - 3.sen…
- User.create!(:login => 'test 3', :created_at => Time.now - 3.sen…
+ User.create!(:login => 'test 1', :created_at => Time.now - 1.sen…
+ User.create!(:login => 'test 2', :created_at => Time.now - 3.sen…
+ User.create!(:login => 'test 3', :created_at => Time.now - 3.sen…
+ User.create!(:login => 'test 4', :created_at => Time.now - 20.se…
end
describe 'the returned result' do
@@ -78,11 +79,11 @@ describe Simplabs::ReportsAsSparkline::CumulatedReport do
)
result = @report.run
- result[10][1].should == 3.0 if live_data
- result[9][1].should == 3.0
- result[8][1].should == 2.0
- result[7][1].should == 2.0
- result[6][1].should == 0.0
+ result[10][1].should == 4.0 if live_data
+ result[9][1].should == 4.0
+ result[8][1].should == 3.0
+ result[7][1].should == 3.0
+ result[6][1].should == 1.0
end
it 'should return correct data for aggregation :sum' do
@@ -95,11 +96,11 @@ describe Simplabs::ReportsAsSparkline::CumulatedReport do
)
result = @report.run()
- result[10][1].should == 6.0 if live_data
- result[9][1].should == 6.0
- result[8][1].should == 5.0
- result[7][1].should == 5.0
- result[6][1].should == 0.0
+ result[10][1].should == 7.0 if live_data
+ result[9][1].should == 7.0
+ result[8][1].should == 6.0
+ result[7][1].should == 6.0
+ result[6][1].should == 1.0
end
it 'should return correct data for aggregation :count when custom …
@@ -109,13 +110,13 @@ describe Simplabs::ReportsAsSparkline::CumulatedReport do
:limit => 10,
:live_data => live_data
)
- result = @report.run(:conditions => ['login IN (?)', ['test 1', …
+ result = @report.run(:conditions => ['login IN (?)', ['test 1', …
- result[10][1].should == 2.0 if live_data
- result[9][1].should == 2.0
- result[8][1].should == 1.0
- result[7][1].should == 1.0
- result[6][1].should == 0.0
+ result[10][1].should == 3.0 if live_data
+ result[9][1].should == 3.0
+ result[8][1].should == 2.0
+ result[7][1].should == 2.0
+ result[6][1].should == 1.0
end
it 'should return correct data for aggregation :sum when custom co…
@@ -126,13 +127,13 @@ describe Simplabs::ReportsAsSparkline::CumulatedReport do
:limit => 10,
:live_data => live_data
)
- result = @report.run(:conditions => ['login IN (?)', ['test 1', …
+ result = @report.run(:conditions => ['login IN (?)', ['test 1', …
- result[10][1].should == 3.0 if live_data
- result[9][1].should == 3.0
- result[8][1].should == 2.0
- result[7][1].should == 2.0
- result[6][1].should == 0.0
+ result[10][1].should == 4.0 if live_data
+ result[9][1].should == 4.0
+ result[8][1].should == 3.0
+ result[7][1].should == 3.0
+ result[6][1].should == 1.0
end
end
diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb
@@ -334,18 +334,19 @@ describe Simplabs::ReportsAsSparkline::Report do
before do
@begin_at = Time.now
@end_at = 5.days.from_now
+ @created_at_column_clause = "#{ActiveRecord::Base.connection.quote_table…
end
it 'should return conditions for date_column BETWEEN begin_at and end_at o…
- @report.send(:setup_conditions, @begin_at, @end_at).should == ['"users".…
+ @report.send(:setup_conditions, @begin_at, @end_at).should == ["#{@creat…
end
it 'should return conditions for date_column >= begin_at when no custom co…
- @report.send(:setup_conditions, @begin_at, nil).should == ['"users"."cre…
+ @report.send(:setup_conditions, @begin_at, nil).should == ["#{@created_a…
end
it 'should return conditions for date_column <= end_at when no custom cond…
- @report.send(:setup_conditions, nil, @end_at).should == ['"users"."creat…
+ @report.send(:setup_conditions, nil, @end_at).should == ["#{@created_at_…
end
it 'should raise an argument error when neither begin_at or end_at are spe…
@@ -353,11 +354,11 @@ describe Simplabs::ReportsAsSparkline::Report do
end
it 'should return conditions for date_column BETWEEN begin_at and end_date…
- @report.send(:setup_conditions, @begin_at, @end_at, {}).should == ['"use…
+ @report.send(:setup_conditions, @begin_at, @end_at, {}).should == ["#{@c…
end
it 'should return conditions for date_column BETWEEN begin_at and end_date…
- @report.send(:setup_conditions, @begin_at, @end_at, []).should == ['"use…
+ @report.send(:setup_conditions, @begin_at, @end_at, []).should == ["#{@c…
end
it 'should correctly include custom conditions if they are specified as a …
@@ -365,29 +366,17 @@ describe Simplabs::ReportsAsSparkline::Report do
conditions = @report.send(:setup_conditions, @begin_at, @end_at, custom_…
# cannot directly check for string equqlity here since hashes are not or…
- conditions[0].should =~ (/"users"."first_name" = \'first name\'/)
- conditions[0].should =~ (/"users"."last_name" = \'last name\'/)
- conditions[0].should =~ (/"users"."created_at" BETWEEN \? AND \?/)
+ conditions[0].should =~ (/#{ActiveRecord::Base.connection.quote_table_na…
+ conditions[0].should =~ (/#{ActiveRecord::Base.connection.quote_table_na…
+ conditions[0].should =~ (/#{@created_at_column_clause} BETWEEN \? AND \?…
conditions[1].should == @begin_at
conditions[2].should == @end_at
end
- it 'should correctly translate { :column => nil }' do
- @report.send(:setup_conditions, @begin_at, @end_at, { :column => nil }).…
- end
-
- it 'should correctly translate { :column => [1, 2] }' do
- @report.send(:setup_conditions, @begin_at, @end_at, { :column => [1, 2] …
- end
-
- it 'should correctly translate { :column => (1..3) }' do
- @report.send(:setup_conditions, @begin_at, @end_at, { :column => (1..3) …
- end
-
it 'should correctly include custom conditions if they are specified as an…
custom_conditions = ['first_name = ? AND last_name = ?', 'first name', '…
- @report.send(:setup_conditions, @begin_at, @end_at, custom_conditions).s…
+ @report.send(:setup_conditions, @begin_at, @end_at, custom_conditions).s…
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.