Merge branch 'michael-groble_master'

This commit is contained in:
Zach Dennis 2012-12-14 10:29:46 -05:00
commit 1c675d7c31
14 changed files with 75 additions and 23 deletions

View file

@ -36,7 +36,7 @@ namespace :display do
end
task :default => ["display:notice"]
ADAPTERS = %w(mysql mysql2 jdbcmysql postgresql sqlite3 seamless_database_pool)
ADAPTERS = %w(mysql mysql2 jdbcmysql postgresql sqlite3 seamless_database_pool mysqlspatial mysql2spatial spatialite postgis)
ADAPTERS.each do |adapter|
namespace :test do
desc "Runs #{adapter} database tests."

View file

@ -1,6 +1,6 @@
require "active_record/connection_adapters/mysql2_adapter"
require "activerecord-import/adapters/mysql_adapter"
require "activerecord-import/adapters/mysql2_adapter"
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
include ActiveRecord::Import::MysqlAdapter
include ActiveRecord::Import::Mysql2Adapter
end

View file

@ -0,0 +1,5 @@
require File.dirname(__FILE__) + "/mysql_adapter"
module ActiveRecord::Import::Mysql2Adapter
include ActiveRecord::Import::MysqlAdapter
end

View file

@ -5,10 +5,20 @@ require "active_record/version"
module ActiveRecord::Import
AdapterPath = File.join File.expand_path(File.dirname(__FILE__)), "/active_record/adapters"
def self.base_adapter(adapter)
case adapter
when 'mysqlspatial' then 'mysql'
when 'mysql2spatial' then 'mysql2'
when 'spatialite' then 'sqlite3'
when 'postgis' then 'postgresql'
else adapter
end
end
# Loads the import functionality for a specific database adapter
def self.require_adapter(adapter)
require File.join(AdapterPath,"/abstract_adapter")
require File.join(AdapterPath,"/#{adapter}_adapter")
require File.join(AdapterPath,"/#{base_adapter(adapter)}_adapter")
end
# Loads the import functionality for the passed in ActiveRecord connection

View file

@ -0,0 +1 @@
ENV["ARE_DB"] = "mysql2spatial"

View file

@ -0,0 +1 @@
ENV["ARE_DB"] = "mysqlspatial"

1
test/adapters/postgis.rb Normal file
View file

@ -0,0 +1 @@
ENV["ARE_DB"] = "postgis"

View file

@ -0,0 +1 @@
ENV["ARE_DB"] = "spatialite"

View file

@ -13,6 +13,12 @@ mysql2:
<<: *common
adapter: mysql2
mysqlspatial:
<<: *mysql
mysqlspatial2:
<<: *mysql2
seamless_database_pool:
<<: *common
adapter: seamless_database_pool
@ -26,6 +32,9 @@ postgresql:
adapter: postgresql
min_messages: warning
postgis:
<<: *postgresql
oracle:
<<: *common
adapter: oracle
@ -38,3 +47,6 @@ sqlite:
sqlite3:
adapter: sqlite3
database: test.db
spatialite:
<<: *sqlite3

View file

@ -0,0 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
should_support_mysql_import_functionality

View file

@ -0,0 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/assertions')
require File.expand_path(File.dirname(__FILE__) + '/../support/mysql/import_examples')
should_support_mysql_import_functionality

View file

@ -0,0 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/import_examples')
should_support_postgresql_import_functionality

View file

@ -1,20 +1,4 @@
require File.expand_path('../../test_helper', __FILE__)
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require File.expand_path(File.dirname(__FILE__) + '/../support/postgresql/import_examples')
describe "#supports_imports?" do
it "should support import" do
assert ActiveRecord::Base.supports_import?
end
end
describe "#import" do
it "should import with a single insert" do
# see ActiveRecord::ConnectionAdapters::AbstractAdapter test for more specifics
assert_difference "Topic.count", +10 do
result = Topic.import Build(3, :topics)
assert_equal 1, result.num_inserts
result = Topic.import Build(7, :topics)
assert_equal 1, result.num_inserts
end
end
end
should_support_postgresql_import_functionality

View file

@ -0,0 +1,21 @@
# encoding: UTF-8
def should_support_postgresql_import_functionality
describe "#supports_imports?" do
it "should support import" do
assert ActiveRecord::Base.supports_import?
end
end
describe "#import" do
it "should import with a single insert" do
# see ActiveRecord::ConnectionAdapters::AbstractAdapter test for more specifics
assert_difference "Topic.count", +10 do
result = Topic.import Build(3, :topics)
assert_equal 1, result.num_inserts
result = Topic.import Build(7, :topics)
assert_equal 1, result.num_inserts
end
end
end
end