| always serialize report cache conditions in the same way - reportable - Fork of… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit c66cd7bdff8d7050c328a668559809b942cd3507 | |
| parent cb4ffc9ae26e50d844a3bd21be0d0530e7a59fa4 | |
| Author: Lars Kuhnt <[email protected]> | |
| Date: Mon, 25 Oct 2010 15:55:57 +0200 | |
| always serialize report cache conditions in the same way | |
| Diffstat: | |
| M lib/saulabs/reportable/report_cach… | 14 ++++++++++++-- | |
| M spec/classes/report_cache_spec.rb | 14 ++++++++++++++ | |
| 2 files changed, 26 insertions(+), 2 deletions(-) | |
| --- | |
| diff --git a/lib/saulabs/reportable/report_cache.rb b/lib/saulabs/reportable/re… | |
| @@ -110,11 +110,21 @@ module Saulabs | |
| :report_name => report.name.to_s, | |
| :grouping => grouping.identifier.to_s, | |
| :aggregation => report.aggregation.to_s, | |
| - :conditions => conditions.join(''), | |
| + :conditions => serialize_conditions(conditions), | |
| :reporting_period => reporting_period.date_time, | |
| :value => value | |
| ) | |
| end | |
| + | |
| + def self.serialize_conditions(conditions) | |
| + if conditions.is_a?(Array) | |
| + conditions.join | |
| + elsif conditions.is_a?(Hash) | |
| + conditions.map.sort{|x,y|x.to_s<=>y.to_s}.flatten.join | |
| + else | |
| + conditions.to_s | |
| + end | |
| + end | |
| def self.read_cached_data(report, options) | |
| options[:conditions] ||= [] | |
| @@ -126,7 +136,7 @@ module Saulabs | |
| report.name.to_s, | |
| options[:grouping].identifier.to_s, | |
| report.aggregation.to_s, | |
| - options[:conditions].join('') | |
| + serialize_conditions(options[:conditions]) | |
| ] | |
| first_reporting_period = get_first_reporting_period(options) | |
| last_reporting_period = get_last_reporting_period(options) | |
| diff --git a/spec/classes/report_cache_spec.rb b/spec/classes/report_cache_spec… | |
| @@ -276,6 +276,20 @@ describe Saulabs::Reportable::ReportCache do | |
| end | |
| end | |
| end | |
| + | |
| + describe '.serialize_conditions' do | |
| + | |
| + it 'should serialize a conditions array correctly' do | |
| + result = Saulabs::Reportable::ReportCache.send(:serialize_conditions, ['… | |
| + result.should eql('active = ? AND gender = ?truemale') | |
| + end | |
| + | |
| + it 'should serialize a conditions hash correctly' do | |
| + result = Saulabs::Reportable::ReportCache.send(:serialize_conditions, { … | |
| + result.should eql('activetruegendermale') | |
| + end | |
| + | |
| + end | |
| describe '.prepare_result' do | |