| made ReportingPeriod#from_db_string work with rails 3 (ActiveRecord returns Dat… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit de7922a1a0fd55d0c699c8bfa4e3acc37e9d35b7 | |
| parent 9e9cff42fe0979687a6ee47bc7bfb7642a3fda3e | |
| Author: Lars Kuhnt <[email protected]> | |
| Date: Wed, 15 Sep 2010 14:52:39 +0200 | |
| made ReportingPeriod#from_db_string work with rails 3 (ActiveRecord returns Dat… | |
| Diffstat: | |
| M lib/saulabs/reportable/reporting_p… | 1 + | |
| M spec/classes/reporting_period_spec… | 10 ++++++++++ | |
| 2 files changed, 11 insertions(+), 0 deletions(-) | |
| --- | |
| diff --git a/lib/saulabs/reportable/reporting_period.rb b/lib/saulabs/reportabl… | |
| @@ -70,6 +70,7 @@ module Saulabs | |
| # the reporting period for the {Saulabs::Reportable::Grouping} as pars… | |
| # | |
| 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 | |
| diff --git a/spec/classes/reporting_period_spec.rb b/spec/classes/reporting_per… | |
| @@ -138,6 +138,16 @@ describe Saulabs::Reportable::ReportingPeriod do | |
| Saulabs::Reportable::ReportingPeriod.from_db_string(grouping, '').date_t… | |
| end | |
| + | |
| + it "should return a reporting period with the correct date when a Date obj… | |
| + grouping = Saulabs::Reportable::Grouping.new(:day) | |
| + Saulabs::Reportable::ReportingPeriod.from_db_string(grouping, Date.new(2… | |
| + end | |
| + | |
| + it "should return a reporting period with the correct date when a DateTime… | |
| + grouping = Saulabs::Reportable::Grouping.new(:hour) | |
| + Saulabs::Reportable::ReportingPeriod.from_db_string(grouping, DateTime.n… | |
| + end | |
| end | |