Added :include option to allow conditions with joint tables - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit ad7246944c072bd3fe1632a62eecacb4be1abbe0
 (DIR) parent 980da245617fbf79d79ad4e6fff71c4a131e083b
 (HTM) Author: Pedro Freitas <pelf@webreakstuff.com>
       Date:   Tue, 19 Mar 2013 13:47:44 +0000
       
       Added :include option to allow conditions with joint tables
       
       Diffstat:
         M lib/saulabs/reportable.rb           |       1 +
         M lib/saulabs/reportable/report.rb    |       6 ++++--
         M spec/classes/report_spec.rb         |       6 +++---
       
       3 files changed, 8 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/lib/saulabs/reportable.rb b/lib/saulabs/reportable.rb
       @@ -38,6 +38,7 @@ module Saulabs
                #   the number of reporting periods to get (see +:grouping+)
                # @option options [Hash] :conditions ({})
                #   conditions like in +ActiveRecord::Base#find+; only records that match these conditions are reported;
       +        
                # @option options [Boolean] :live_data (false)
                #   specifies whether data for the current reporting period is to be read; <b>if +:live_data+ is +true+, you will experience a performance hit since the request cannot be satisfied from the cache alone</b>
                # @option options [DateTime, Boolean] :end_date (false)
 (DIR) diff --git a/lib/saulabs/reportable/report.rb b/lib/saulabs/reportable/report.rb
       @@ -69,6 +69,7 @@ module Saulabs
                @options = {
                  :limit      => options[:limit] || 100,
                  :distinct   => options[:distinct] || false,
       +          :include    => options[:include] || [],
                  :conditions => options[:conditions] || [],
                  :grouping   => Grouping.new(options[:grouping] || :day),
                  :live_data  => options[:live_data] || false,
       @@ -119,6 +120,7 @@ module Saulabs
                  @klass.send(@aggregation,
                    @value_column,
                    :conditions => conditions,
       +            :include    => options[:include],
                    :distinct   => options[:distinct],
                    :group      => options[:grouping].to_sql(@date_column),
                    :order      => "#{options[:grouping].to_sql(@date_column)} ASC",
       @@ -147,13 +149,13 @@ module Saulabs
                  case context
                    when :initialize
                      options.each_key do |k|
       -                raise ArgumentError.new("Invalid option #{k}!") unless [:limit, :aggregation, :grouping, :distinct, :date_column, :value_column, :conditions, :live_data, :end_date].include?(k)
       +                raise ArgumentError.new("Invalid option #{k}!") unless [:limit, :aggregation, :grouping, :distinct, :include, :date_column, :value_column, :conditions, :live_data, :end_date].include?(k)
                      end
                      raise ArgumentError.new("Invalid aggregation #{options[:aggregation]}!") if options[:aggregation] && ![:count, :sum, :maximum, :minimum, :average].include?(options[:aggregation])
                      raise ArgumentError.new('The name of the column holding the value to sum has to be specified for aggregation :sum!') if [:sum, :maximum, :minimum, :average].include?(options[:aggregation]) && !options.key?(:value_column)
                    when :run
                      options.each_key do |k|
       -                raise ArgumentError.new("Invalid option #{k}!") unless [:limit, :conditions, :grouping, :live_data, :end_date].include?(k)
       +                raise ArgumentError.new("Invalid option #{k}!") unless [:limit, :conditions, :include, :grouping, :live_data, :end_date].include?(k)
                      end
                  end
                  raise ArgumentError.new('Options :live_data and :end_date may not both be specified!') if options[:live_data] && options[:end_date]
 (DIR) diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb
       @@ -21,7 +21,7 @@ describe Saulabs::Reportable::Report do
            it 'should process the data with the report cache' do
              Saulabs::Reportable::ReportCache.should_receive(:process).once.with(
                @report,
       -        { :limit => 100, :grouping => @report.options[:grouping], :conditions => [], :live_data => false, :end_date => false, :distinct => false }
       +        { :limit => 100, :grouping => @report.options[:grouping], :conditions => [], :include => [], :live_data => false, :end_date => false, :distinct => false }
              )
        
              @report.run
       @@ -30,7 +30,7 @@ describe Saulabs::Reportable::Report do
            it 'should process the data with the report cache when custom conditions are given' do
              Saulabs::Reportable::ReportCache.should_receive(:process).once.with(
                @report,
       -        { :limit => 100, :grouping => @report.options[:grouping], :conditions => { :some => :condition }, :live_data => false, :end_date => false, :distinct => false }
       +        { :limit => 100, :grouping => @report.options[:grouping], :conditions => { :some => :condition }, :include => [], :live_data => false, :end_date => false, :distinct => false }
              )
        
              @report.run(:conditions => { :some => :condition })
       @@ -47,7 +47,7 @@ describe Saulabs::Reportable::Report do
              Saulabs::Reportable::Grouping.should_receive(:new).once.with(:month).and_return(grouping)
              Saulabs::Reportable::ReportCache.should_receive(:process).once.with(
                @report,
       -        { :limit => 100, :grouping => grouping, :conditions => [], :live_data => false, :end_date => false, :distinct => false }
       +        { :limit => 100, :grouping => grouping, :conditions => [], :live_data => false, :end_date => false, :distinct => false, :include => [] }
              )
        
              @report.run(:grouping => :month)