report execution can now handle conditions like :column => [1,2,3] or :column => nil; introduced new aggregation :maximum, :minimum and :average - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit c3fb5b3acc00333cfe3b2b5d61963a15e7859760
 (DIR) parent 4456641ee6fc1c363ab38ccac57eea159b1e2a56
 (HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       Date:   Mon, 23 Feb 2009 15:57:42 +0100
       
       report execution can now handle conditions like :column => [1,2,3] or :column => nil; introduced new aggregation :maximum, :minimum and :average
       
       Diffstat:
         M README.rdoc                         |       4 ++--
         M generators/reports_as_sparkline_mi… |       4 ++--
         M lib/kvlr/reports_as_sparkline.rb    |       2 +-
         M lib/kvlr/reports_as_sparkline/repo… |      18 +++++++++++++-----
         M rdoc/classes/Kvlr/ReportsAsSparkli… |       6 ++++--
         M rdoc/classes/Kvlr/ReportsAsSparkli… |      10 ++++++----
         M rdoc/classes/Kvlr/ReportsAsSparkli… |      52 ++++++++++++++++----------------
         M rdoc/created.rid                    |       2 +-
         M rdoc/files/lib/kvlr/reports_as_spa… |       2 +-
         M rdoc/files/lib/kvlr/reports_as_spa… |       2 +-
         M rdoc/files/lib/kvlr/reports_as_spa… |       2 +-
         M spec/classes/report_spec.rb         |      89 +++++++++++++++++++++++++------
       
       12 files changed, 132 insertions(+), 61 deletions(-)
       ---
 (DIR) diff --git a/README.rdoc b/README.rdoc
       @@ -9,7 +9,7 @@ to it with the following options:
        
        * :date_column - The name of the date column on that the records are aggregated
        * :value_column - The name of the column that holds the value to sum for aggregation :sum
       -* :aggregation - The aggregation to use (either :count or :sum); when using :sum, :value_column must also be specified
       +* :aggregation - The aggregation to use (one of :count, :sum, :minimum, :maximum or :average); when using anything other than :count, :value_column must also be specified (<b>If you really want to e.g. sumon the 'id' column, you have to explicitely say so.</b>)
        * :grouping - The period records are grouped on (:hour, :day, :week, :month); <b>Beware that reports_as_sparkline treats weeks as starting on monday!</b>
        * :limit - The number of periods to get (see :grouping)
        * :conditions - Conditions like in ActiveRecord::Base#find; only records that match there conditions are reported on
       @@ -101,4 +101,4 @@ If you are on PostgreSQL, you should add functional indices:
        
        If you want ot suggest any new features or report bugs, do so at http://simplabs.lighthouseapp.com/projects/21060-reportsassparkline/overview.
        
       -© 2008-2009 Martin Kavalar, Marco Otte-Witte (http://simplabs.com/#open-source), released under the MIT license
       +© 2008-2009 Martin Kavalar, Marco Otte-Witte (http://simplabs.com/#projects), released under the MIT license
 (DIR) diff --git a/generators/reports_as_sparkline_migration/templates/migration.erb b/generators/reports_as_sparkline_migration/templates/migration.erb
       @@ -28,8 +28,8 @@ class <%= class_name %> < ActiveRecord::Migration
          end
        
          def self.down
       -    remove_index :name_model_grouping_agregation
       -    remove_index :name_model_grouping_aggregation_period
       +    remove_index :report_caches, :name => :name_model_grouping_agregation
       +    remove_index :report_caches, :name => :name_model_grouping_aggregation_period
        
            drop_table :report_caches
          end
 (DIR) diff --git a/lib/kvlr/reports_as_sparkline.rb b/lib/kvlr/reports_as_sparkline.rb
       @@ -18,7 +18,7 @@ module Kvlr #:nodoc:
              #
              # * <tt>:date_column</tt> - The name of the date column on that the records are aggregated
              # * <tt>:value_column</tt> - The name of the column that holds the value to sum for aggregation :sum
       -      # * <tt>:aggregation</tt> - The aggregation to use (either :count or :sum); when using :sum, :value_column must also be specified
       +      # * <tt>:aggregation</tt> - The aggregation to use (one of :count, :sum, :minimum, :maximum or :average); when using anything other than :count, :value_column must also be specified (<b>If you really want to e.g. sumon the 'id' column, you have to explicitely say so.</b>)
              # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day, :week, :month); <b>Beware that reports_as_sparkline treats weeks as starting on monday!</b>
              # * <tt>:limit</tt> - The number of periods to get (see :grouping)
              # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; only records that match there conditions are reported on
 (DIR) diff --git a/lib/kvlr/reports_as_sparkline/report.rb b/lib/kvlr/reports_as_sparkline/report.rb
       @@ -15,7 +15,7 @@ module Kvlr #:nodoc:
              #
              # * <tt>:date_column</tt> - The name of the date column on that the records are aggregated
              # * <tt>:value_column</tt> - The name of the column that holds the value to sum for aggregation :sum
       -      # * <tt>:aggregation</tt> - The aggregation to use (either :count or :sum); when using :sum, :value_column must also be specified
       +      # * <tt>:aggregation</tt> - The aggregation to use (one of :count, :sum, :minimum, :maximum or :average); when using anything other than :count, :value_column must also be specified (<b>If you really want to e.g. sumon the 'id' column, you have to explicitely say so.</b>)
              # * <tt>:grouping</tt> - The period records are grouped on (:hour, :day, :week, :month); <b>Beware that reports_as_sparkline treats weeks as starting on monday!</b>
              # * <tt>:limit</tt> - The number of periods to get (see :grouping)
              # * <tt>:conditions</tt> - Conditions like in ActiveRecord::Base#find; only records that match there conditions are reported on
       @@ -25,8 +25,8 @@ module Kvlr #:nodoc:
                @klass        = klass
                @name         = name
                @date_column  = (options[:date_column] || 'created_at').to_s
       -        @value_column = (options[:value_column] || (options[:aggregation] != :sum ? 'id' : name)).to_s
                @aggregation  = options[:aggregation] || :count
       +        @value_column = (options[:value_column] || (@aggregation == :count ? 'id' : name)).to_s
                @options = {
                  :limit      => options[:limit] || 100,
                  :conditions => options[:conditions] || [],
       @@ -69,7 +69,15 @@ module Kvlr #:nodoc:
                def setup_conditions(begin_at, custom_conditions = [])
                  conditions = ['']
                  if custom_conditions.is_a?(Hash)
       -            conditions = [custom_conditions.map{ |k, v| "#{k.to_s} = ?" }.join(' AND '), *custom_conditions.map{ |k, v| v }]
       +            conditions = [custom_conditions.map do |k, v|
       +              if v.nil?
       +                "#{k.to_s} IS NULL"
       +              elsif v.is_a?(Array) || v.is_a?(Range)
       +                "#{k.to_s} IN (?)"
       +              else
       +                "#{k.to_s} = ?"
       +              end
       +            end.join(' AND '), *custom_conditions.map { |k, v| v }.compact]
                  elsif custom_conditions.size > 0
                    conditions = [(custom_conditions[0] || ''), *custom_conditions[1..-1]]
                  end
       @@ -83,8 +91,8 @@ module Kvlr #:nodoc:
                      options.each_key do |k|
                        raise ArgumentError.new("Invalid option #{k}") unless [:limit, :aggregation, :grouping, :date_column, :value_column, :conditions, :live_data].include?(k)
                      end
       -              raise ArgumentError.new("Invalid aggregation #{options[:aggregation]}") if options[:aggregation] && ![:count, :sum].include?(options[:aggregation])
       -              raise ArgumentError.new('The name of the column holding the value to sum has to be specified for aggregation :sum') if options[:aggregation] == :sum && !options.key?(:value_column)
       +              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].include?(k)
 (DIR) diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/ClassMethods.html b/rdoc/classes/Kvlr/ReportsAsSparkline/ClassMethods.html
       @@ -134,8 +134,10 @@ aggregated
        for aggregation :sum
        
        </li>
       -<li><tt>:aggregation</tt> - The aggregation to use (either :count or :sum);
       -when using :sum, :value_column must also be specified
       +<li><tt>:aggregation</tt> - The aggregation to use (one of :count, :sum,
       +:minimum, :maximum or :average); when using anything other than :count,
       +:value_column must also be specified (<b>If you really want to e.g. sumon
       +the &#8216;id&#8217; column, you have to explicitely say so.</b>)
        
        </li>
        <li><tt>:grouping</tt> - The period records are grouped on (:hour, :day, :week,
 (DIR) diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/Report.html b/rdoc/classes/Kvlr/ReportsAsSparkline/Report.html
       @@ -187,8 +187,10 @@ aggregated
        for aggregation :sum
        
        </li>
       -<li><tt>:aggregation</tt> - The aggregation to use (either :count or :sum);
       -when using :sum, :value_column must also be specified
       +<li><tt>:aggregation</tt> - The aggregation to use (one of :count, :sum,
       +:minimum, :maximum or :average); when using anything other than :count,
       +:value_column must also be specified (<b>If you really want to e.g. sumon
       +the &#8216;id&#8217; column, you have to explicitely say so.</b>)
        
        </li>
        <li><tt>:grouping</tt> - The period records are grouped on (:hour, :day, :week,
       @@ -220,8 +222,8 @@ false)
        25:         <span class="ruby-ivar">@klass</span>        = <span class="ruby-identifier">klass</span>
        26:         <span class="ruby-ivar">@name</span>         = <span class="ruby-identifier">name</span>
        27:         <span class="ruby-ivar">@date_column</span>  = (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:date_column</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'created_at'</span>).<span class="ruby-identifier">to_s</span>
       -28:         <span class="ruby-ivar">@value_column</span> = (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:value_column</span>] <span class="ruby-operator">||</span> (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:aggregation</span>] <span class="ruby-operator">!=</span> <span class="ruby-identifier">:sum</span> <span class="ruby-operator">?</span> <span class="ruby-value str">'id'</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">name</span>)).<span class="ruby-identifier">to_s</span>
       -29:         <span class="ruby-ivar">@aggregation</span>  = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:aggregation</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">:count</span>
       +28:         <span class="ruby-ivar">@aggregation</span>  = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:aggregation</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">:count</span>
       +29:         <span class="ruby-ivar">@value_column</span> = (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:value_column</span>] <span class="ruby-operator">||</span> (<span class="ruby-ivar">@aggregation</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:count</span> <span class="ruby-operator">?</span> <span class="ruby-value str">'id'</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">name</span>)).<span class="ruby-identifier">to_s</span>
        30:         <span class="ruby-ivar">@options</span> = {
        31:           <span class="ruby-identifier">:limit</span>      =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:limit</span>] <span class="ruby-operator">||</span> <span class="ruby-value">100</span>,
        32:           <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:conditions</span>] <span class="ruby-operator">||</span> [],
 (DIR) diff --git a/rdoc/classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html b/rdoc/classes/Kvlr/ReportsAsSparkline/ReportingPeriod.html
       @@ -246,19 +246,19 @@ hour/day/month/year)
                    onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
                  <div class="method-source-code" id="M000008-source">
        <pre>
       -    <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/reporting_period.rb, line 54</span>
       -54:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
       -55:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@grouping</span>.<span class="ruby-identifier">identifier</span>
       -56:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:hour</span>
       -57:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">hour</span>)
       -58:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:day</span>
       -59:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">day</span>)
       -60:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:week</span>
       -61:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">week</span>)
       -62:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:month</span>
       -63:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">month</span>)
       -64:         <span class="ruby-keyword kw">end</span>
       -65:       <span class="ruby-keyword kw">end</span>
       +    <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/reporting_period.rb, line 53</span>
       +53:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
       +54:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@grouping</span>.<span class="ruby-identifier">identifier</span>
       +55:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:hour</span>
       +56:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">hour</span>)
       +57:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:day</span>
       +58:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">day</span>)
       +59:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:week</span>
       +60:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">week</span>)
       +61:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:month</span>
       +62:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">month</span>)
       +63:         <span class="ruby-keyword kw">end</span>
       +64:       <span class="ruby-keyword kw">end</span>
        </pre>
                  </div>
                </div>
       @@ -283,19 +283,19 @@ hour/day/month/year)
                    onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
                  <div class="method-source-code" id="M000009-source">
        <pre>
       -    <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/reporting_period.rb, line 68</span>
       -68:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">previous</span>
       -69:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@grouping</span>.<span class="ruby-identifier">identifier</span>
       -70:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:hour</span>
       -71:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">hour</span>)
       -72:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:day</span>
       -73:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">day</span>)
       -74:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:week</span>
       -75:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">week</span>)
       -76:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:month</span>
       -77:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">month</span>)
       -78:         <span class="ruby-keyword kw">end</span>
       -79:       <span class="ruby-keyword kw">end</span>
       +    <span class="ruby-comment cmt"># File lib/kvlr/reports_as_sparkline/reporting_period.rb, line 67</span>
       +67:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">previous</span>
       +68:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@grouping</span>.<span class="ruby-identifier">identifier</span>
       +69:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:hour</span>
       +70:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">hour</span>)
       +71:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:day</span>
       +72:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">day</span>)
       +73:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:week</span>
       +74:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">week</span>)
       +75:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:month</span>
       +76:             <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@grouping</span>, <span class="ruby-ivar">@date_time</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">month</span>)
       +77:         <span class="ruby-keyword kw">end</span>
       +78:       <span class="ruby-keyword kw">end</span>
        </pre>
                  </div>
                </div>
 (DIR) diff --git a/rdoc/created.rid b/rdoc/created.rid
       @@ -1 +1 @@
       -Mon, 02 Feb 2009 14:31:59 +0100
       +Mon, 23 Feb 2009 15:46:25 +0100
 (DIR) diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/report_rb.html b/rdoc/files/lib/kvlr/reports_as_sparkline/report_rb.html
       @@ -56,7 +56,7 @@
            </tr>
            <tr class="top-aligned-row">
              <td><strong>Last Update:</strong></td>
       -      <td>Mon Feb 02 11:52:42 +0100 2009</td>
       +      <td>Mon Feb 23 15:45:50 +0100 2009</td>
            </tr>
            </table>
          </div>
 (DIR) diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline/reporting_period_rb.html b/rdoc/files/lib/kvlr/reports_as_sparkline/reporting_period_rb.html
       @@ -56,7 +56,7 @@
            </tr>
            <tr class="top-aligned-row">
              <td><strong>Last Update:</strong></td>
       -      <td>Mon Feb 02 14:00:53 +0100 2009</td>
       +      <td>Mon Feb 02 14:32:12 +0100 2009</td>
            </tr>
            </table>
          </div>
 (DIR) diff --git a/rdoc/files/lib/kvlr/reports_as_sparkline_rb.html b/rdoc/files/lib/kvlr/reports_as_sparkline_rb.html
       @@ -56,7 +56,7 @@
            </tr>
            <tr class="top-aligned-row">
              <td><strong>Last Update:</strong></td>
       -      <td>Mon Feb 02 11:52:04 +0100 2009</td>
       +      <td>Mon Feb 23 15:46:05 +0100 2009</td>
            </tr>
            </table>
          </div>
 (DIR) diff --git a/spec/classes/report_spec.rb b/spec/classes/report_spec.rb
       @@ -142,6 +142,57 @@ describe Kvlr::ReportsAsSparkline::Report do
                      result[6][1].should  == 0.0
                    end
        
       +            it 'should return correct data for aggregation :maximum' do
       +              @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,
       +                :aggregation  => :maximum,
       +                :grouping     => grouping,
       +                :value_column => :profile_visits,
       +                :limit        => 10,
       +                :live_data    => live_data
       +              )
       +              result = @report.run().to_a
       +
       +              result[10][1].should == 2.0 if live_data
       +              result[9][1].should  == 1.0
       +              result[8][1].should  == 0.0
       +              result[7][1].should  == 3.0
       +              result[6][1].should  == 0.0
       +            end
       +
       +            it 'should return correct data for aggregation :minimum' do
       +              @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,
       +                :aggregation  => :minimum,
       +                :grouping     => grouping,
       +                :value_column => :profile_visits,
       +                :limit        => 10,
       +                :live_data    => live_data
       +              )
       +              result = @report.run().to_a
       +
       +              result[10][1].should == 2.0 if live_data
       +              result[9][1].should  == 1.0
       +              result[8][1].should  == 0.0
       +              result[7][1].should  == 2.0
       +              result[6][1].should  == 0.0
       +            end
       +
       +            it 'should return correct data for aggregation :average' do
       +              @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,
       +                :aggregation  => :average,
       +                :grouping     => grouping,
       +                :value_column => :profile_visits,
       +                :limit        => 10,
       +                :live_data    => live_data
       +              )
       +              result = @report.run().to_a
       +
       +              result[10][1].should == 2.0 if live_data
       +              result[9][1].should  == 1.0
       +              result[8][1].should  == 0.0
       +              result[7][1].should  == 2.5
       +              result[6][1].should  == 0.0
       +            end
       +
                    it 'should return correct data for aggregation :count when custom conditions are specified' do
                      @report = Kvlr::ReportsAsSparkline::Report.new(User, :registrations,
                        :aggregation => :count,
       @@ -278,47 +329,55 @@ describe Kvlr::ReportsAsSparkline::Report do
        
          describe '#setup_conditions' do
        
       -    it 'should return conditions for date_column >= begin_at only when no custom conditions are specified' do
       -      begin_at = Time.now
       +    before do
       +      @begin_at = Time.now
       +    end
        
       -      @report.send(:setup_conditions, begin_at).should == ['created_at >= ?', begin_at]
       +    it 'should return conditions for date_column >= begin_at only when no custom conditions are specified' do
       +      @report.send(:setup_conditions, @begin_at).should == ['created_at >= ?', @begin_at]
            end
        
            it 'should return conditions for date_column >= begin_at only when an empty Hash of custom conditions is specified' do
       -      begin_at = Time.now
       -
       -      @report.send(:setup_conditions, begin_at, {}).should == ['created_at >= ?', begin_at]
       +      @report.send(:setup_conditions, @begin_at, {}).should == ['created_at >= ?', @begin_at]
            end
        
            it 'should return conditions for date_column >= begin_at only when an empty Array of custom conditions is specified' do
       -      begin_at = Time.now
       -
       -      @report.send(:setup_conditions, begin_at, []).should == ['created_at >= ?', begin_at]
       +      @report.send(:setup_conditions, @begin_at, []).should == ['created_at >= ?', @begin_at]
            end
        
            it 'should correctly include custom conditions if they are specified as a Hash' do
       -      begin_at = Time.now
              custom_conditions = { :first_name => 'first name', :last_name => 'last name' }
        
       -      conditions = @report.send(:setup_conditions, begin_at, custom_conditions)
       +      conditions = @report.send(:setup_conditions, @begin_at, custom_conditions)
              #cannot check for equality of complete conditions array since hashes are not ordered (thus it is unknown whether first_name or last_name comes first)
              conditions[0].should include('first_name = ?')
              conditions[0].should include('last_name = ?')
              conditions[0].should include('created_at >= ?')
              conditions.should include('first name')
              conditions.should include('last name')
       -      conditions.should include(begin_at)
       +      conditions.should include(@begin_at)
       +    end
       +
       +    it 'should correctly translate { :column => nil }' do
       +      @report.send(:setup_conditions, @begin_at, { :column => nil }).should == ['column IS NULL AND created_at >= ?', @begin_at]
       +    end
       +
       +    it 'should correctly translate { :column => [1, 2] }' do
       +      @report.send(:setup_conditions, @begin_at, { :column => [1, 2] }).should == ['column IN (?) AND created_at >= ?', [1, 2], @begin_at]
       +    end
       +
       +    it 'should correctly translate { :column => (1..3) }' do
       +      @report.send(:setup_conditions, @begin_at, { :column => (1..3) }).should == ['column IN (?) AND created_at >= ?', (1..3), @begin_at]
            end
        
            it 'should correctly include custom conditions if they are specified as an Array' do
       -      begin_at = Time.now
              custom_conditions = ['first_name = ? AND last_name = ?', 'first name', 'last name']
        
       -      @report.send(:setup_conditions, begin_at, custom_conditions).should == [
       +      @report.send(:setup_conditions, @begin_at, custom_conditions).should == [
                'first_name = ? AND last_name = ? AND created_at >= ?',
                'first name',
                'last name',
       -        begin_at
       +        @begin_at
              ]
            end