use 'adapter_name' instead of 'class.to_s' to determine database type - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit 4e9584baf0421883d41e415f62df65a741625acc
 (DIR) parent d48fcc5ad3dad4227a805cfe89c586958752e355
 (HTM) Author: Maximilian Schöfmann <max@pragmatic-it.de>
       Date:   Thu, 15 Jan 2009 22:23:54 +0800
       
       use 'adapter_name' instead of 'class.to_s' to determine database type
       
       Signed-off-by: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       Diffstat:
         M lib/kvlr/reports_as_sparkline/grou… |      12 ++++++------
         M spec/classes/grouping_spec.rb       |      16 ++++++----------
       
       2 files changed, 12 insertions(+), 16 deletions(-)
       ---
 (DIR) diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sparkline/grouping.rb
       @@ -18,7 +18,7 @@ module Kvlr #:nodoc:
              end
        
              def date_parts_from_db_string(db_string) #:nodoc:
       -        if ActiveRecord::Base.connection.class.to_s == 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
       +        if ActiveRecord::Base.connection.adapter_name =~ /postgres/i
                  case @identifier
                    when :hour
                      return (db_string[0..9].split('-') + [db_string[11..12]]).map(&:to_i)
       @@ -33,7 +33,7 @@ module Kvlr #:nodoc:
                  end
                else
                  parts = db_string.split('/').map(&:to_i)
       -          if ActiveRecord::Base.connection.class.to_s == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
       +          if ActiveRecord::Base.connection.adapter_name =~ /mysql/i
                    if @identifier == :week && parts[1] > 52
                      parts[0] += 1
                      parts[1] = 1
       @@ -46,12 +46,12 @@ module Kvlr #:nodoc:
              end
        
              def to_sql(date_column) #:nodoc:
       -        return case ActiveRecord::Base.connection.class.to_s
       -          when 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
       +        return case ActiveRecord::Base.connection.adapter_name
       +          when /mysql/i
                    mysql_format(date_column)
       -          when 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
       +          when /sqlite/i
                    sqlite_format(date_column)
       -          when 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter'
       +          when /postgres/i
                    postgresql_format(date_column)
                end
              end
 (DIR) diff --git a/spec/classes/grouping_spec.rb b/spec/classes/grouping_spec.rb
       @@ -15,7 +15,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
            describe 'for MySQL' do
        
              before do
       -        ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::ConnectionAdapters::MysqlAdapter)
       +        ActiveRecord::Base.connection.stub!(:adapter_name).and_return('MySQL')
              end
        
              it 'should use DATE_FORMAT with format string "%Y/%m/%d/%H" for grouping :hour' do
       @@ -39,7 +39,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
            describe 'for PostgreSQL' do
        
              before do
       -        ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
       +        ActiveRecord::Base.connection.stub!(:adapter_name).and_return('PostgreSQL')
              end
        
              for grouping in [:hour, :day, :week, :month] do
       @@ -55,7 +55,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
            describe 'for SQLite3' do
        
              before do
       -        ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
       +        ActiveRecord::Base.connection.stub!(:adapter_name).and_return('SQLite')
              end
        
              it 'should use strftime with format string "%Y/%m/%d/%H" for grouping :hour' do
       @@ -83,7 +83,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
            describe 'for SQLite3' do
        
              before do
       -        ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
       +        ActiveRecord::Base.connection.stub!(:adapter_name).and_return('SQLite')
              end
        
              for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month, '2008/12']] do
       @@ -106,7 +106,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
            describe 'for PostgreSQL' do
        
              before do
       -        ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
       +        ActiveRecord::Base.connection.stub!(:adapter_name).and_return('PostgreSQL')
              end
        
              it 'should split the date part of the string with "-" and read out the hour for grouping :hour' do
       @@ -130,7 +130,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do
            describe 'for MySQL' do
        
              before do
       -        ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::ConnectionAdapters::MysqlAdapter)
       +        ActiveRecord::Base.connection.stub!(:adapter_name).and_return('MySQL')
              end
        
              for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:week, '2008/40'], [:month, '2008/12']] do
       @@ -153,7 +153,3 @@ describe Kvlr::ReportsAsSparkline::Grouping do
          end
        
        end
       -
       -class ActiveRecord::ConnectionAdapters::MysqlAdapter; end
       -class ActiveRecord::ConnectionAdapters::SQLite3Adapter; end
       -class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter; end