| Merge branch 'master' of [email protected]:mk/reports_as_sparkline - reportable - … | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 683b03c8ae82c2ad348e5a6490aeafa5365c9cdb | |
| parent 9577b0d728079889d178694076d0bbcc6861eb3c | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Thu, 15 Jan 2009 15:32:06 +0100 | |
| Merge branch 'master' of [email protected]:mk/reports_as_sparkline | |
| Diffstat: | |
| M lib/kvlr/reports_as_sparkline/grou… | 12 ++++++------ | |
| M spec/classes/grouping_spec.rb | 16 ++++++---------- | |
| 2 files changed, 12 insertions(+), 16 deletions(-) | |
| --- | |
| diff --git a/lib/kvlr/reports_as_sparkline/grouping.rb b/lib/kvlr/reports_as_sp… | |
| @@ -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::Connecti… | |
| + if ActiveRecord::Base.connection.adapter_name =~ /postgres/i | |
| case @identifier | |
| when :hour | |
| return (db_string[0..9].split('-') + [db_string[11..12]]).map(&:… | |
| @@ -33,7 +33,7 @@ module Kvlr #:nodoc: | |
| end | |
| else | |
| parts = db_string.split('/').map(&:to_i) | |
| - if ActiveRecord::Base.connection.class.to_s == 'ActiveRecord::Connec… | |
| + 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 | |
| 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::C… | |
| + ActiveRecord::Base.connection.stub!(:adapter_name).and_return('MySQL') | |
| end | |
| it 'should use DATE_FORMAT with format string "%Y/%m/%d/%H" for grouping… | |
| @@ -39,7 +39,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| describe 'for PostgreSQL' do | |
| before do | |
| - ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C… | |
| + ActiveRecord::Base.connection.stub!(:adapter_name).and_return('Postgre… | |
| 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::C… | |
| + ActiveRecord::Base.connection.stub!(:adapter_name).and_return('SQLite') | |
| end | |
| it 'should use strftime with format string "%Y/%m/%d/%H" for grouping :h… | |
| @@ -83,7 +83,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| describe 'for SQLite3' do | |
| before do | |
| - ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C… | |
| + ActiveRecord::Base.connection.stub!(:adapter_name).and_return('SQLite') | |
| end | |
| for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:month… | |
| @@ -106,7 +106,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| describe 'for PostgreSQL' do | |
| before do | |
| - ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C… | |
| + ActiveRecord::Base.connection.stub!(:adapter_name).and_return('Postgre… | |
| end | |
| it 'should split the date part of the string with "-" and read out the h… | |
| @@ -130,7 +130,7 @@ describe Kvlr::ReportsAsSparkline::Grouping do | |
| describe 'for MySQL' do | |
| before do | |
| - ActiveRecord::Base.connection.stub!(:class).and_return(ActiveRecord::C… | |
| + ActiveRecord::Base.connection.stub!(:adapter_name).and_return('MySQL') | |
| end | |
| for grouping in [[:hour, '2008/12/31/12'], [:day, '2008/12/31'], [:week,… | |
| @@ -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 |