made ReportingPeriod#from_db_string work with rails 3 (ActiveRecord returns Date objects instead of Strings for the grouping query) - reportable - Fork of reportable required by WarVox, from hdm/reportable.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit de7922a1a0fd55d0c699c8bfa4e3acc37e9d35b7
(DIR) parent 9e9cff42fe0979687a6ee47bc7bfb7642a3fda3e
(HTM) Author: Lars Kuhnt <lars.kuhnt@gmail.com>
Date: Wed, 15 Sep 2010 14:52:39 +0200
made ReportingPeriod#from_db_string work with rails 3 (ActiveRecord returns Date objects instead of Strings for the grouping query)
Diffstat:
M lib/saulabs/reportable/reporting_p… | 1 +
M spec/classes/reporting_period_spec… | 10 ++++++++++
2 files changed, 11 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/lib/saulabs/reportable/reporting_period.rb b/lib/saulabs/reportable/reporting_period.rb
@@ -70,6 +70,7 @@ module Saulabs
# the reporting period for the {Saulabs::Reportable::Grouping} as parsed from the db string
#
def self.from_db_string(grouping, db_string)
+ return self.new(grouping, db_string) if db_string.is_a?(Date)
parts = grouping.date_parts_from_db_string(db_string)
case grouping.identifier
when :hour
(DIR) diff --git a/spec/classes/reporting_period_spec.rb b/spec/classes/reporting_period_spec.rb
@@ -138,6 +138,16 @@ describe Saulabs::Reportable::ReportingPeriod do
Saulabs::Reportable::ReportingPeriod.from_db_string(grouping, '').date_time.should == Date.new(2008, 1, 1)
end
+
+ it "should return a reporting period with the correct date when a Date object is passed" do
+ grouping = Saulabs::Reportable::Grouping.new(:day)
+ Saulabs::Reportable::ReportingPeriod.from_db_string(grouping, Date.new(2008, 1, 1)).date_time.should == Date.new(2008, 1, 1)
+ end
+
+ it "should return a reporting period with the correct date when a DateTime object is passed" do
+ grouping = Saulabs::Reportable::Grouping.new(:hour)
+ Saulabs::Reportable::ReportingPeriod.from_db_string(grouping, DateTime.new(2008, 1, 1, 12, 0, 0)).date_time.should == DateTime.new(2008, 1, 1, 12, 0, 0)
+ end
end