| fixed Grouping#date_parts_from_db_string - reportable - Fork of reportable requ… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 3766a5046d1c774ed50b4471c88f261839536c27 | |
| parent bea3592f63f6bd00be2b31f57f56ffe4103e55df | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Thu, 15 Jan 2009 04:29:48 +0800 | |
| fixed Grouping#date_parts_from_db_string | |
| Signed-off-by: Marco Otte-Witte <[email protected]> | |
| Diffstat: | |
| M lib/kvlr/reports_as_sparkline/grou… | 11 +++++++---- | |
| M spec/classes/grouping_spec.rb | 17 ++++++++++++----- | |
| 2 files changed, 19 insertions(+), 9 deletions(-) | |
| --- | |
| diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sp… | |
| @@ -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 == 'ActiveR… | |
| - if @identifier == :week && parts[1] > 52 | |
| - parts[0] += 1 | |
| - parts[1] = 1 | |
| + if ActiveRecord::Base.connection.class.to_s == 'ActiveRecord::Connec… | |
| + 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 | |
| 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::C… | |
| end | |
| - for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month… | |
| + for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month… | |
| it "should split the string with '/' for grouping :#{grouping[0].to_s}… | |
| Kvlr::ReportsAsSparkline::Grouping.new(grouping[0]).date_parts_from_… | |
| @@ -94,9 +94,9 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| end | |
| - it 'should split the string with "/", set the week to 1 and increment th… | |
| - db_string = '2008/53' | |
| - expected = [2009, 1] | |
| + it 'should split the string with "/" and increment the week by 1 for gro… | |
| + db_string = '2008/2' | |
| + expected = [2008, 3] | |
| Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin… | |
| end | |
| @@ -117,7 +117,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| Kvlr::ReportsAsSparkline::Grouping.new(:day).date_parts_from_db_string… | |
| end | |
| - it 'should split the date part of the string with "-" for grouping :week… | |
| + it 'should split the date part of the string with "-" and calculate the … | |
| Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin… | |
| end | |
| @@ -141,6 +141,13 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| end | |
| + it 'should split the string with "/", set the week to 1 and increment th… | |
| + db_string = '2008/53' | |
| + expected = [2009, 1] | |
| + | |
| + Kvlr::ReportsAsSparkline::Grouping.new(:week).date_parts_from_db_strin… | |
| + end | |
| + | |
| end | |
| end |