validate required attributes in ReportCache - reportable - Unnamed repository; edit this file 'description' to name the repository. (DIR) Log (DIR) Files (DIR) Refs (DIR) README --- (DIR) commit 9a0e5ad1403a13890c482901cfbf6dc9c8ee1e09 (DIR) parent b026d0c5c59126e57f28e5405c04c9505671a955 (HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com> Date: Wed, 24 Mar 2010 21:58:17 +0100 validate required attributes in ReportCache Diffstat: M lib/saulabs/reportable/report_cach… | 7 +++++++ M spec/classes/report_cache_spec.rb | 85 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 0 deletions(-) --- (DIR) diff --git a/lib/saulabs/reportable/report_cache.rb b/lib/saulabs/reportable/report_cache.rb @@ -9,6 +9,13 @@ module Saulabs set_table_name :reportable_cache + validates_presence_of :model_name + validates_presence_of :report_name + validates_presence_of :grouping + validates_presence_of :aggregation + validates_presence_of :value + validates_presence_of :reporting_period + self.skip_time_zone_conversion_for_attributes = [:reporting_period] # Clears the cache for the specified +klass+ and +report+ (DIR) diff --git a/spec/classes/report_cache_spec.rb b/spec/classes/report_cache_spec.rb @@ -6,6 +6,91 @@ describe Saulabs::Reportable::ReportCache do @report = Saulabs::Reportable::Report.new(User, :registrations, :limit => 10) end + describe 'validations' do + + before do + @report_cache = Saulabs::Reportable::ReportCache.new( + :model_name => User.name, + :report_name => 'registrations', + :grouping => 'date', + :aggregation => 'count', + :value => 1.0, + :reporting_period => '2070/03/23' + ) + end + + it 'should succeed when all required attributes are set' do + @report_cache.should be_valid + end + + it 'should not succeed when no model_name is set' do + @report_cache.model_name = nil + + @report_cache.should_not be_valid + end + + it 'should not succeed when a blank model_name is set' do + @report_cache.model_name = '' + + @report_cache.should_not be_valid + end + + it 'should not succeed when no report_name is set' do + @report_cache.report_name = nil + + @report_cache.should_not be_valid + end + + it 'should not succeed when a blank report_name is set' do + @report_cache.report_name = '' + + @report_cache.should_not be_valid + end + + it 'should not succeed when no grouping is set' do + @report_cache.grouping = nil + + @report_cache.should_not be_valid + end + + it 'should not succeed when a blank grouping is set' do + @report_cache.grouping = '' + + @report_cache.should_not be_valid + end + + it 'should not succeed when no aggregation is set' do + @report_cache.aggregation = nil + + @report_cache.should_not be_valid + end + + it 'should not succeed when a blank aggregation is set' do + @report_cache.aggregation = '' + + @report_cache.should_not be_valid + end + + it 'should not succeed when no value is set' do + @report_cache.value = nil + + @report_cache.should_not be_valid + end + + it 'should not succeed when no reporting_period is set' do + @report_cache.reporting_period = nil + + @report_cache.should_not be_valid + end + + it 'should not succeed when a blank reporting_period is set' do + @report_cache.reporting_period = '' + + @report_cache.should_not be_valid + end + + end + describe '.clear_for' do it 'should delete all entries in the cache for the klass and report name' do