Introduction
Introduction Statistics Contact Development Disclaimer Help
use 'adapter_name' instead of 'class.to_s' to determine database type - reporta…
Log
Files
Refs
README
---
commit 4e9584baf0421883d41e415f62df65a741625acc
parent d48fcc5ad3dad4227a805cfe89c586958752e355
Author: Maximilian Schöfmann <[email protected]>
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 <[email protected]>
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
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.