fixed Grouping#date_parts_from_db_string - reportable - Fork of reportable required by WarVox, from hdm/reportable.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 3766a5046d1c774ed50b4471c88f261839536c27
(DIR) parent bea3592f63f6bd00be2b31f57f56ffe4103e55df
(HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
Date: Thu, 15 Jan 2009 04:29:48 +0800
fixed Grouping#date_parts_from_db_string
Signed-off-by: Marco Otte-Witte <marco.otte-witte@simplabs.com>
Diffstat:
M lib/kvlr/reports_as_sparkline/grou… | 11 +++++++----
M spec/classes/grouping_spec.rb | 17 ++++++++++++-----
2 files changed, 19 insertions(+), 9 deletions(-)
---
(DIR) diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sparkline/grouping.rb
@@ -33,11 +33,14 @@ module Kvlr #:nodoc:
end
else
parts = db_string.split('/').map(&:to_i)
- return parts if ActiveRecord::Base.connection.class.to_s == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
- if @identifier == :week && parts[1] > 52
- parts[0] += 1
- parts[1] = 1
+ if ActiveRecord::Base.connection.class.to_s == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
+ if @identifier == :week && parts[1] > 52
+ parts[0] += 1
+ parts[1] = 1
+ end
+ return parts
end
+ parts[1] += 1 if @identifier == :week
parts
end
end
(DIR) diff --git a/spec/classes/grouping_spec.rb b/spec/classes/grouping_spec.rb
@@ -86,7 +86,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
end
- for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month, '2008/12'], [:week, '2008/2']] do
+ for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month, '2008/12']] do
it "should split the string with '/' for grouping :#{grouping[0].to_s}" do
Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_db_string(grouping[1]).should == grouping[1].split('/').map(&:to_i)
@@ -94,9 +94,9 @@ describe Kvlr::ReportsAsSparkline::Grouping do
end
- it 'should split the string with "/", set the week to 1 and increment the year by 1 if the week is above 52' do
- db_string = '2008/53'
- expected = [2009, 1]
+ it 'should split the string with "/" and increment the week by 1 for grouping :week' do
+ db_string = '2008/2'
+ expected = [2008, 3]
Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_string(db_string).should == expected
end
@@ -117,7 +117,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
Kvlr::ReportsAsSparkline::Grouping.new(:day).date_parts_from_db_string('2008-12-03 00:00:00').should == [2008, 12, 03]
end
- it 'should split the date part of the string with "-" for grouping :week' do
+ it 'should split the date part of the string with "-" and calculate the calendar week for grouping :week' do
Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_string('2008-12-01 00:00:00').should == [2008, 49]
end
@@ -141,6 +141,13 @@ describe Kvlr::ReportsAsSparkline::Grouping do
end
+ it 'should split the string with "/", set the week to 1 and increment the year by 1 if the week is greater than 52 for grouping :week' do
+ db_string = '2008/53'
+ expected = [2009, 1]
+
+ Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_string(db_string).should == expected
+ end
+
end
end