diff --git a/Rakefile b/Rakefile index ff42901..1a50839 100644 --- a/Rakefile +++ b/Rakefile @@ -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." diff --git a/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb b/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb index 7f34e2f..74828b7 100644 --- a/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb +++ b/lib/activerecord-import/active_record/adapters/mysql2_adapter.rb @@ -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 diff --git a/lib/activerecord-import/adapters/mysql2_adapter.rb b/lib/activerecord-import/adapters/mysql2_adapter.rb new file mode 100644 index 0000000..71e6a64 --- /dev/null +++ b/lib/activerecord-import/adapters/mysql2_adapter.rb @@ -0,0 +1,5 @@ +require File.dirname(__FILE__) + "/mysql_adapter" + +module ActiveRecord::Import::Mysql2Adapter + include ActiveRecord::Import::MysqlAdapter +end \ No newline at end of file diff --git a/lib/activerecord-import/base.rb b/lib/activerecord-import/base.rb index a9ee246..8498357 100644 --- a/lib/activerecord-import/base.rb +++ b/lib/activerecord-import/base.rb @@ -8,6 +8,7 @@ module ActiveRecord::Import 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 diff --git a/test/adapters/mysql2spatial.rb b/test/adapters/mysql2spatial.rb new file mode 100644 index 0000000..3bc9f6c --- /dev/null +++ b/test/adapters/mysql2spatial.rb @@ -0,0 +1 @@ +ENV["ARE_DB"] = "mysql2spatial" \ No newline at end of file diff --git a/test/adapters/mysqlspatial.rb b/test/adapters/mysqlspatial.rb new file mode 100644 index 0000000..03316d1 --- /dev/null +++ b/test/adapters/mysqlspatial.rb @@ -0,0 +1 @@ +ENV["ARE_DB"] = "mysqlspatial" \ No newline at end of file diff --git a/test/adapters/postgis.rb b/test/adapters/postgis.rb new file mode 100644 index 0000000..0902039 --- /dev/null +++ b/test/adapters/postgis.rb @@ -0,0 +1 @@ +ENV["ARE_DB"] = "postgis" \ No newline at end of file diff --git a/test/adapters/spatialite.rb b/test/adapters/spatialite.rb new file mode 100644 index 0000000..1ff27f2 --- /dev/null +++ b/test/adapters/spatialite.rb @@ -0,0 +1 @@ +ENV["ARE_DB"] = "spatialite" \ No newline at end of file diff --git a/test/database.yml.sample b/test/database.yml.sample index 6a9a364..9bd8221 100644 --- a/test/database.yml.sample +++ b/test/database.yml.sample @@ -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 diff --git a/test/mysqlspatial/import_test.rb b/test/mysqlspatial/import_test.rb new file mode 100644 index 0000000..feaff67 --- /dev/null +++ b/test/mysqlspatial/import_test.rb @@ -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 \ No newline at end of file diff --git a/test/mysqlspatial2/import_test.rb b/test/mysqlspatial2/import_test.rb new file mode 100644 index 0000000..feaff67 --- /dev/null +++ b/test/mysqlspatial2/import_test.rb @@ -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 \ No newline at end of file diff --git a/test/postgis/import_test.rb b/test/postgis/import_test.rb new file mode 100644 index 0000000..436fc83 --- /dev/null +++ b/test/postgis/import_test.rb @@ -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 \ No newline at end of file diff --git a/test/postgresql/import_test.rb b/test/postgresql/import_test.rb index 45e97ef..436fc83 100644 --- a/test/postgresql/import_test.rb +++ b/test/postgresql/import_test.rb @@ -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 \ No newline at end of file diff --git a/test/support/postgresql/import_examples.rb b/test/support/postgresql/import_examples.rb new file mode 100644 index 0000000..fe7b61f --- /dev/null +++ b/test/support/postgresql/import_examples.rb @@ -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