Merge pull request #28 from pelf/master - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 89f342b0eebca0d7331a8a652aa453de97715785
 (DIR) parent e84698645f207ecd889c79b76af56188b3456f24
 (HTM) Author: Martin Kvlr <mk@katercalling.com>
       Date:   Thu, 28 Mar 2013 04:34:04 -0700
       
       Merge pull request #28 from pelf/master
       
       Supports :include option for more elaborate report needs
       Diffstat:
         M generators/reportable_jquery_flot_… |       2 ++
         M generators/reportable_raphael_asse… |       2 ++
         M lib/saulabs/reportable.rb           |       2 ++
         M lib/saulabs/reportable/report.rb    |      12 ++++++++----
         M spec/classes/report_spec.rb         |       6 +++---
       
       5 files changed, 17 insertions(+), 7 deletions(-)
       ---
 (DIR) diff --git a/generators/reportable_jquery_flot_assets/reportable_jquery_flot_assets_generator.rb b/generators/reportable_jquery_flot_assets/reportable_jquery_flot_assets_generator.rb
       @@ -2,6 +2,8 @@ class ReportableJqueryFlotAssetsGenerator < Rails::Generators::Base
        
          include Rails::Generators::Actions
        
       +  source_root File.expand_path('../templates/', __FILE__)
       +
          def create_jquery_flot_file
            empty_directory('public/javascripts')
            copy_file(
 (DIR) diff --git a/generators/reportable_raphael_assets/reportable_raphael_assets_generator.rb b/generators/reportable_raphael_assets/reportable_raphael_assets_generator.rb
       @@ -2,6 +2,8 @@ class ReportableRaphaelAssetsGenerator < Rails::Generators::Base
        
          include Rails::Generators::Actions
        
       +  source_root File.expand_path('../templates/', __FILE__)
       +
          def create_raphael_file
            empty_directory('public/javascripts')
            copy_file(
 (DIR) diff --git a/lib/saulabs/reportable.rb b/lib/saulabs/reportable.rb
       @@ -38,6 +38,8 @@ 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 [Hash] :include ({})
       +        #   include like in +ActiveRecord::Base#find+; names associations that should be loaded alongside; the symbols named refer to already defined associations
                # @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
       @@ -54,6 +54,8 @@ 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 [Hash] :include ({})
       +      #   include like in +ActiveRecord::Base#find+; names associations that should be loaded alongside; the symbols named refer to already defined associations
              # @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)
       @@ -69,6 +71,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,9 +122,10 @@ 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",
       +            :group      => options[:grouping].to_sql("#{ActiveRecord::Base.connection.quote_table_name(@klass.table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@date_column.to_s)}"),
       +            :order      => "#{options[:grouping].to_sql("#{ActiveRecord::Base.connection.quote_table_name(@klass.table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@date_column.to_s)}")} ASC",
                    :limit      => options[:limit]
                  )
                end
       @@ -147,13 +151,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)