activerecord-jdbc-adapter 1.0.3-java → 50.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +33 -0
  3. data/.travis.yml +79 -0
  4. data/.yardopts +4 -0
  5. data/CONTRIBUTING.md +50 -0
  6. data/Gemfile +91 -0
  7. data/History.md +1191 -0
  8. data/LICENSE.txt +22 -17
  9. data/README.md +169 -0
  10. data/RUNNING_TESTS.md +127 -0
  11. data/Rakefile +294 -5
  12. data/Rakefile.jdbc +20 -0
  13. data/activerecord-jdbc-adapter.gemspec +55 -0
  14. data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
  15. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  16. data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
  17. data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
  18. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
  19. data/lib/activerecord-jdbc-adapter.rb +0 -5
  20. data/lib/arel/visitors/compat.rb +60 -0
  21. data/lib/arel/visitors/db2.rb +128 -6
  22. data/lib/arel/visitors/derby.rb +103 -10
  23. data/lib/arel/visitors/firebird.rb +79 -0
  24. data/lib/arel/visitors/h2.rb +25 -0
  25. data/lib/arel/visitors/hsqldb.rb +18 -10
  26. data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
  27. data/lib/arel/visitors/sql_server.rb +225 -0
  28. data/lib/arel/visitors/sql_server/ng42.rb +293 -0
  29. data/lib/arjdbc.rb +11 -21
  30. data/lib/arjdbc/abstract/connection_management.rb +35 -0
  31. data/lib/arjdbc/abstract/core.rb +64 -0
  32. data/lib/arjdbc/abstract/database_statements.rb +64 -0
  33. data/lib/arjdbc/abstract/statement_cache.rb +58 -0
  34. data/lib/arjdbc/abstract/transaction_support.rb +86 -0
  35. data/lib/arjdbc/db2.rb +3 -1
  36. data/lib/arjdbc/db2/adapter.rb +630 -250
  37. data/lib/arjdbc/db2/as400.rb +130 -0
  38. data/lib/arjdbc/db2/column.rb +167 -0
  39. data/lib/arjdbc/db2/connection_methods.rb +44 -0
  40. data/lib/arjdbc/derby.rb +1 -5
  41. data/lib/arjdbc/derby/active_record_patch.rb +13 -0
  42. data/lib/arjdbc/derby/adapter.rb +409 -217
  43. data/lib/arjdbc/derby/connection_methods.rb +16 -14
  44. data/lib/arjdbc/derby/schema_creation.rb +15 -0
  45. data/lib/arjdbc/discover.rb +62 -50
  46. data/lib/arjdbc/firebird.rb +3 -1
  47. data/lib/arjdbc/firebird/adapter.rb +365 -62
  48. data/lib/arjdbc/firebird/connection_methods.rb +23 -0
  49. data/lib/arjdbc/h2.rb +2 -3
  50. data/lib/arjdbc/h2/adapter.rb +273 -6
  51. data/lib/arjdbc/h2/connection_methods.rb +23 -8
  52. data/lib/arjdbc/hsqldb.rb +2 -3
  53. data/lib/arjdbc/hsqldb/adapter.rb +204 -77
  54. data/lib/arjdbc/hsqldb/connection_methods.rb +24 -10
  55. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  56. data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
  57. data/lib/arjdbc/informix.rb +4 -2
  58. data/lib/arjdbc/informix/adapter.rb +78 -54
  59. data/lib/arjdbc/informix/connection_methods.rb +8 -9
  60. data/lib/arjdbc/jdbc.rb +59 -2
  61. data/lib/arjdbc/jdbc/adapter.rb +356 -166
  62. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  63. data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
  64. data/lib/arjdbc/jdbc/base_ext.rb +15 -0
  65. data/lib/arjdbc/jdbc/callbacks.rb +27 -18
  66. data/lib/arjdbc/jdbc/column.rb +79 -20
  67. data/lib/arjdbc/jdbc/connection.rb +5 -119
  68. data/lib/arjdbc/jdbc/connection_methods.rb +32 -4
  69. data/lib/arjdbc/jdbc/error.rb +65 -0
  70. data/lib/arjdbc/jdbc/extension.rb +41 -29
  71. data/lib/arjdbc/jdbc/java.rb +5 -6
  72. data/lib/arjdbc/jdbc/jdbc.rake +3 -126
  73. data/lib/arjdbc/jdbc/railtie.rb +2 -9
  74. data/lib/arjdbc/jdbc/rake_tasks.rb +3 -10
  75. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -0
  76. data/lib/arjdbc/jdbc/type_cast.rb +166 -0
  77. data/lib/arjdbc/jdbc/type_converter.rb +35 -19
  78. data/lib/arjdbc/mssql.rb +6 -3
  79. data/lib/arjdbc/mssql/adapter.rb +630 -298
  80. data/lib/arjdbc/mssql/column.rb +200 -0
  81. data/lib/arjdbc/mssql/connection_methods.rb +66 -17
  82. data/lib/arjdbc/mssql/explain_support.rb +99 -0
  83. data/lib/arjdbc/mssql/limit_helpers.rb +189 -50
  84. data/lib/arjdbc/mssql/lock_methods.rb +77 -0
  85. data/lib/arjdbc/mssql/types.rb +343 -0
  86. data/lib/arjdbc/mssql/utils.rb +82 -0
  87. data/lib/arjdbc/mysql.rb +2 -3
  88. data/lib/arjdbc/mysql/adapter.rb +86 -356
  89. data/lib/arjdbc/mysql/connection_methods.rb +159 -23
  90. data/lib/arjdbc/oracle/adapter.rb +714 -263
  91. data/lib/arjdbc/postgresql.rb +2 -3
  92. data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +24 -0
  93. data/lib/arjdbc/postgresql/adapter.rb +570 -400
  94. data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
  95. data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
  96. data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
  97. data/lib/arjdbc/postgresql/base/pgconn.rb +11 -0
  98. data/lib/arjdbc/postgresql/column.rb +51 -0
  99. data/lib/arjdbc/postgresql/connection_methods.rb +57 -18
  100. data/lib/arjdbc/postgresql/name.rb +24 -0
  101. data/lib/arjdbc/postgresql/oid_types.rb +192 -0
  102. data/lib/arjdbc/railtie.rb +11 -0
  103. data/lib/arjdbc/sqlite3.rb +2 -3
  104. data/lib/arjdbc/sqlite3/adapter.rb +518 -198
  105. data/lib/arjdbc/sqlite3/connection_methods.rb +49 -24
  106. data/lib/arjdbc/sybase.rb +2 -2
  107. data/lib/arjdbc/sybase/adapter.rb +7 -6
  108. data/lib/arjdbc/tasks.rb +13 -0
  109. data/lib/arjdbc/tasks/database_tasks.rb +52 -0
  110. data/lib/arjdbc/tasks/databases.rake +91 -0
  111. data/lib/arjdbc/tasks/databases3.rake +215 -0
  112. data/lib/arjdbc/tasks/databases4.rake +39 -0
  113. data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
  114. data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
  115. data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
  116. data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
  117. data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
  118. data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
  119. data/lib/arjdbc/util/quoted_cache.rb +60 -0
  120. data/lib/arjdbc/util/serialized_attributes.rb +98 -0
  121. data/lib/arjdbc/util/table_copier.rb +110 -0
  122. data/lib/arjdbc/version.rb +1 -6
  123. data/lib/generators/jdbc/USAGE +9 -0
  124. data/lib/generators/jdbc/jdbc_generator.rb +8 -0
  125. data/lib/jdbc_adapter.rb +1 -1
  126. data/lib/jdbc_adapter/rake_tasks.rb +3 -2
  127. data/lib/jdbc_adapter/version.rb +2 -1
  128. data/pom.xml +114 -0
  129. data/rails_generators/jdbc_generator.rb +1 -1
  130. data/rails_generators/templates/config/initializers/jdbc.rb +8 -5
  131. data/rails_generators/templates/lib/tasks/jdbc.rake +7 -4
  132. data/rakelib/01-tomcat.rake +51 -0
  133. data/rakelib/02-test.rake +132 -0
  134. data/rakelib/bundler_ext.rb +11 -0
  135. data/rakelib/compile.rake +67 -22
  136. data/rakelib/db.rake +61 -0
  137. data/rakelib/rails.rake +204 -29
  138. data/src/java/arjdbc/ArJdbcModule.java +286 -0
  139. data/src/java/arjdbc/db2/DB2Module.java +76 -0
  140. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +126 -0
  141. data/src/java/arjdbc/derby/DerbyModule.java +99 -243
  142. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +152 -0
  143. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +174 -0
  144. data/src/java/arjdbc/{jdbc/JdbcConnectionFactory.java → h2/H2Module.java} +20 -6
  145. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +27 -12
  146. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +73 -0
  147. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
  148. data/src/java/arjdbc/jdbc/AdapterJavaService.java +7 -29
  149. data/src/java/arjdbc/jdbc/Callable.java +44 -0
  150. data/src/java/arjdbc/jdbc/ConnectionFactory.java +132 -0
  151. data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +157 -0
  152. data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
  153. data/src/java/arjdbc/jdbc/DriverWrapper.java +119 -0
  154. data/src/java/arjdbc/jdbc/JdbcResult.java +130 -0
  155. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +3622 -948
  156. data/src/java/arjdbc/mssql/MSSQLModule.java +90 -0
  157. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +181 -0
  158. data/src/java/arjdbc/mysql/MySQLModule.java +99 -81
  159. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +294 -0
  160. data/src/java/arjdbc/oracle/OracleModule.java +80 -0
  161. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +387 -17
  162. data/src/java/arjdbc/postgresql/ByteaUtils.java +157 -0
  163. data/src/java/arjdbc/postgresql/PgResultSetMetaDataWrapper.java +23 -0
  164. data/src/java/arjdbc/postgresql/PostgreSQLModule.java +77 -0
  165. data/src/java/arjdbc/postgresql/PostgreSQLResult.java +184 -0
  166. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +952 -0
  167. data/src/java/arjdbc/sqlite3/SQLite3Module.java +73 -0
  168. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +525 -0
  169. data/src/java/arjdbc/util/CallResultSet.java +826 -0
  170. data/src/java/arjdbc/util/DateTimeUtils.java +580 -0
  171. data/src/java/arjdbc/util/ObjectSupport.java +65 -0
  172. data/src/java/arjdbc/util/QuotingUtils.java +138 -0
  173. data/src/java/arjdbc/util/StringCache.java +63 -0
  174. data/src/java/arjdbc/util/StringHelper.java +159 -0
  175. metadata +245 -268
  176. data/History.txt +0 -369
  177. data/Manifest.txt +0 -180
  178. data/README.txt +0 -181
  179. data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
  180. data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
  181. data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
  182. data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
  183. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
  184. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
  185. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
  186. data/lib/arel/visitors/mssql.rb +0 -44
  187. data/lib/arjdbc/jdbc/compatibility.rb +0 -51
  188. data/lib/arjdbc/jdbc/core_ext.rb +0 -24
  189. data/lib/arjdbc/jdbc/discover.rb +0 -18
  190. data/lib/arjdbc/jdbc/driver.rb +0 -44
  191. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -87
  192. data/lib/arjdbc/jdbc/quoted_primary_key.rb +0 -28
  193. data/lib/arjdbc/jdbc/require_driver.rb +0 -16
  194. data/lib/arjdbc/mimer.rb +0 -2
  195. data/lib/arjdbc/mimer/adapter.rb +0 -142
  196. data/lib/arjdbc/mssql/tsql_helper.rb +0 -61
  197. data/lib/arjdbc/oracle.rb +0 -3
  198. data/lib/arjdbc/oracle/connection_methods.rb +0 -11
  199. data/lib/pg.rb +0 -4
  200. data/rakelib/package.rake +0 -92
  201. data/rakelib/test.rake +0 -81
  202. data/src/java/arjdbc/jdbc/SQLBlock.java +0 -48
  203. data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +0 -127
  204. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +0 -57
  205. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +0 -64
  206. data/test/abstract_db_create.rb +0 -117
  207. data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -31
  208. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
  209. data/test/db/db2.rb +0 -11
  210. data/test/db/derby.rb +0 -12
  211. data/test/db/h2.rb +0 -11
  212. data/test/db/hsqldb.rb +0 -13
  213. data/test/db/informix.rb +0 -11
  214. data/test/db/jdbc.rb +0 -11
  215. data/test/db/jndi_config.rb +0 -40
  216. data/test/db/logger.rb +0 -3
  217. data/test/db/mssql.rb +0 -9
  218. data/test/db/mysql.rb +0 -10
  219. data/test/db/oracle.rb +0 -34
  220. data/test/db/postgres.rb +0 -9
  221. data/test/db/sqlite3.rb +0 -11
  222. data/test/db2_simple_test.rb +0 -66
  223. data/test/derby_migration_test.rb +0 -68
  224. data/test/derby_multibyte_test.rb +0 -12
  225. data/test/derby_simple_test.rb +0 -99
  226. data/test/generic_jdbc_connection_test.rb +0 -29
  227. data/test/h2_simple_test.rb +0 -41
  228. data/test/has_many_through.rb +0 -79
  229. data/test/helper.rb +0 -5
  230. data/test/hsqldb_simple_test.rb +0 -6
  231. data/test/informix_simple_test.rb +0 -48
  232. data/test/jdbc_common.rb +0 -25
  233. data/test/jndi_callbacks_test.rb +0 -40
  234. data/test/jndi_test.rb +0 -25
  235. data/test/manualTestDatabase.rb +0 -191
  236. data/test/models/add_not_null_column_to_table.rb +0 -12
  237. data/test/models/auto_id.rb +0 -18
  238. data/test/models/data_types.rb +0 -28
  239. data/test/models/entry.rb +0 -43
  240. data/test/models/mixed_case.rb +0 -25
  241. data/test/models/reserved_word.rb +0 -18
  242. data/test/models/string_id.rb +0 -18
  243. data/test/models/validates_uniqueness_of_string.rb +0 -19
  244. data/test/mssql_db_create_test.rb +0 -26
  245. data/test/mssql_identity_insert_test.rb +0 -19
  246. data/test/mssql_legacy_types_test.rb +0 -58
  247. data/test/mssql_limit_offset_test.rb +0 -136
  248. data/test/mssql_multibyte_test.rb +0 -18
  249. data/test/mssql_simple_test.rb +0 -55
  250. data/test/mysql_db_create_test.rb +0 -27
  251. data/test/mysql_info_test.rb +0 -113
  252. data/test/mysql_multibyte_test.rb +0 -10
  253. data/test/mysql_nonstandard_primary_key_test.rb +0 -42
  254. data/test/mysql_simple_test.rb +0 -49
  255. data/test/oracle_simple_test.rb +0 -18
  256. data/test/oracle_specific_test.rb +0 -83
  257. data/test/pick_rails_version.rb +0 -3
  258. data/test/postgres_db_create_test.rb +0 -32
  259. data/test/postgres_drop_db_test.rb +0 -16
  260. data/test/postgres_mixed_case_test.rb +0 -29
  261. data/test/postgres_nonseq_pkey_test.rb +0 -38
  262. data/test/postgres_reserved_test.rb +0 -22
  263. data/test/postgres_schema_search_path_test.rb +0 -44
  264. data/test/postgres_simple_test.rb +0 -51
  265. data/test/postgres_table_alias_length_test.rb +0 -15
  266. data/test/simple.rb +0 -546
  267. data/test/sqlite3_simple_test.rb +0 -233
  268. data/test/sybase_jtds_simple_test.rb +0 -28
@@ -10,6 +10,6 @@ class JdbcGenerator < Rails::Generator::Base
10
10
 
11
11
  protected
12
12
  def banner
13
- "Usage: #{$0} jdbc\nGenerate JDBC bootstrapping files for your Rails application."
13
+ "Usage: #{$0} jdbc\nGenerate JDBC bootstrapping files for your Rails (2.x) application."
14
14
  end
15
15
  end
@@ -1,7 +1,10 @@
1
- # This file was generated by the "jdbc" generator, which is provided
2
- # by the activerecord-jdbc-adapter gem.
1
+ # This file was generated by the "jdbc" generator, which is provided by the
2
+ # activerecord-jdbc-adapter gem.
3
3
  #
4
- # This file allows the JDBC drivers to be hooked into ActiveRecord
5
- # such that you don't have to change anything else in your Rails
6
- # application.
4
+ # This file allows the JDBC adapters to be hooked into ActiveRecord such that
5
+ # you don't have to change anything else in your Rails application.
6
+ #
7
+ # NOTE: This is only needed on Rails 2.x - without Bundler since when you're
8
+ # using Bundler than `gem 'activerecord-jdbc-adapter'` will automatically
9
+ # `require 'arjdbc'` by default (unless you set it to `require: false`).
7
10
  require 'arjdbc' if defined?(JRUBY_VERSION)
@@ -1,8 +1,11 @@
1
- # This file was generated by the "jdbc" generator, which is provided
2
- # by the activerecord-jdbc-adapter gem.
1
+ # This file was generated by the "jdbc" generator, which is provided by the
2
+ # activerecord-jdbc-adapter gem.
3
3
  #
4
- # This file allows you to use Rails' various db:* tasks with JDBC.
4
+ # This file allows you to use Rails' various db:* tasks with the JDBC adapters.
5
+ #
6
+ # NOTE: Only needed on Rails 2.x and it's fine to delete this file otherwise,
7
+ # since on Rails 3.x AR-JDBC provides a Railtie that loads the Rake tasks.
5
8
  if defined?(JRUBY_VERSION)
6
9
  require 'arjdbc'
7
- require 'arjdbc/jdbc/rake_tasks'
10
+ require 'arjdbc/tasks'
8
11
  end
@@ -0,0 +1,51 @@
1
+ namespace :'tomcat-jndi' do # contains a FS JNDI impl (for tests)
2
+
3
+ TOMCAT_MAVEN_REPO = 'http://repo2.maven.org/maven2/org/apache/tomcat'
4
+ TOMCAT_VERSION = '7.0.54'
5
+
6
+ DOWNLOAD_DIR = File.expand_path('../test/jars', File.dirname(__FILE__))
7
+
8
+ #tomcat_jar = "tomcat-embed-core.jar"
9
+ #tomcat_uri = "#{TOMCAT_MAVEN_REPO}/embed/tomcat-embed-core/#{TOMCAT_VERSION}/tomcat-embed-core-#{TOMCAT_VERSION}.jar"
10
+
11
+ catalina_jar = "tomcat-catalina.jar"
12
+ catalina_uri = "#{TOMCAT_MAVEN_REPO}/tomcat-catalina/#{TOMCAT_VERSION}/tomcat-catalina-#{TOMCAT_VERSION}.jar"
13
+
14
+ juli_jar = "tomcat-juli.jar"
15
+ juli_uri = "#{TOMCAT_MAVEN_REPO}/tomcat-juli/#{TOMCAT_VERSION}/tomcat-juli-#{TOMCAT_VERSION}.jar"
16
+
17
+ task :download do
18
+ require 'open-uri'; require 'tmpdir'
19
+
20
+ temp_dir = File.join(Dir.tmpdir, (Time.now.to_f * 1000).to_i.to_s)
21
+ FileUtils.mkdir temp_dir
22
+
23
+ downloads = Hash.new
24
+ downloads[juli_jar] = juli_uri
25
+ downloads[catalina_jar] = catalina_uri
26
+
27
+ Dir.chdir(temp_dir) do
28
+ FileUtils.mkdir DOWNLOAD_DIR unless File.exist?(DOWNLOAD_DIR)
29
+ downloads.each do |jar, uri|
30
+ puts "downloading #{uri}"
31
+ file = open(uri)
32
+ FileUtils.cp file.path, File.join(DOWNLOAD_DIR, jar)
33
+ end
34
+ end
35
+
36
+ FileUtils.rm_r temp_dir
37
+ end
38
+
39
+ task :check do
40
+ jar_path = File.join(DOWNLOAD_DIR, catalina_jar)
41
+ unless File.exist?(jar_path)
42
+ Rake::Task['tomcat-jndi:download'].invoke
43
+ end
44
+ end
45
+
46
+ task :clear do
47
+ jar_path = File.join(DOWNLOAD_DIR, catalina_jar)
48
+ rm jar_path if File.exist?(jar_path)
49
+ end
50
+
51
+ end
@@ -0,0 +1,132 @@
1
+
2
+ test_tasks = [ 'test_mysql', 'test_sqlite3', 'test_postgresql_with_hint' ]
3
+ if defined?(JRUBY_VERSION)
4
+ test_tasks.push :test_derby, :test_hsqldb, :test_h2
5
+ test_tasks.push :test_jndi, :test_jdbc
6
+ end
7
+
8
+ desc "Run \"most\" available test_xxx tasks"
9
+ task :test => test_tasks
10
+
11
+ task 'test_postgresql_with_hint' do
12
+ require File.expand_path('../../test/shared_helper', __FILE__)
13
+ if PostgresHelper.have_postgres?(false)
14
+ Rake::Task['test_postgresql'].invoke
15
+ else
16
+ puts "NOTE: won't run test_postgresql"
17
+ end
18
+ end
19
+
20
+ Rake::TestTask.class_eval { attr_reader :test_files }
21
+
22
+ def test_task_for(adapter, options = {})
23
+ desc = options[:desc] || options[:comment] || "Run tests against #{options[:database_name] || adapter}"
24
+ adapter = adapter.to_s.downcase
25
+ driver = adapter if ( driver = options[:driver] ).nil?
26
+ prereqs = options[:prereqs] || []
27
+ unless prereqs.frozen?
28
+ prereqs = [ prereqs ].flatten; # prereqs << 'test_appraisal_hint'
29
+ end
30
+ name = options[:name] || "test_#{adapter}"
31
+ test_task = Rake::TestTask.new(name => prereqs) do |test_task|
32
+ files = options[:files] || begin
33
+ FileList["test/#{adapter}*_test.rb"] + FileList["test/db/#{adapter}/**/*_test.rb"]
34
+ end
35
+ test_task.test_files = files
36
+ test_task.libs = []
37
+ if defined?(JRUBY_VERSION)
38
+ test_task.libs << 'lib'
39
+ test_task.libs << "jdbc-#{driver}/lib" if driver && File.exists?("jdbc-#{driver}/lib")
40
+ test_task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
41
+ end
42
+ test_task.libs << 'test'
43
+ test_task.options = '--use-color=t'
44
+ test_task.verbose = true if $VERBOSE
45
+ yield(test_task) if block_given?
46
+ end
47
+ task = Rake::Task[name]
48
+ # reset the description set-up by Rake::TestTask :
49
+ if task.instance_variable_defined? :@full_comment
50
+ task.instance_variable_set(:@full_comment, nil)
51
+ else
52
+ task.instance_variable_get(:@comments).clear
53
+ end
54
+ task.add_description(desc)
55
+ test_task
56
+ end
57
+
58
+ test_task_for :Derby, :desc => 'Run tests against (embedded) DerbyDB'
59
+ test_task_for :H2, :desc => 'Run tests against H2 database engine'
60
+ test_task_for :HSQLDB, :desc => 'Run tests against HyperSQL (Java) database'
61
+ test_task_for :MSSQL, :driver => :jtds, :database_name => 'MS-SQL (SQLServer)'
62
+ test_task_for :MySQL #, :prereqs => 'db:mysql'
63
+ task :test_mysql2 => :test_mysql
64
+ test_task_for :PostgreSQL, :driver => ENV['JDBC_POSTGRES_VERSION'] || 'postgres' #, :prereqs => 'db:postgresql'
65
+ task :test_postgres => :test_postgresql # alias
66
+ test_task_for :SQLite3, :driver => ENV['JDBC_SQLITE_VERSION']
67
+ task :test_sqlite => :test_sqlite3 # alias
68
+ test_task_for :Firebird
69
+
70
+ test_task_for :MariaDB, :files => FileList["test/db/mysql/*_test.rb"] do |test_task| #, :prereqs => 'db:mysql'
71
+ test_task.ruby_opts << '-rdb/mariadb_config'
72
+ end
73
+
74
+ # ensure driver for these DBs is on your class-path
75
+ [ :Oracle, :DB2, :Informix, :CacheDB ].each do |adapter|
76
+ test_task_for adapter, :desc => "Run tests against #{adapter} (ensure driver is on class-path)"
77
+ end
78
+
79
+ #test_task_for :MSSQL, :name => 'test_sqlserver', :driver => nil, :database_name => 'MS-SQL using SQLJDBC'
80
+
81
+ test_task_for :AS400, :desc => "Run tests against AS400 (DB2) (ensure driver is on class-path)",
82
+ :files => FileList["test/db2*_test.rb"] + FileList["test/db/db2/*_test.rb"]
83
+
84
+ #task :test_jdbc => [ :test_jdbc_mysql, :test_jdbc_derby ] if defined?(JRUBY_VERSION)
85
+
86
+ test_task_for 'JDBC', :desc => 'Run tests against plain JDBC adapter (uses MySQL and Derby)',
87
+ :prereqs => [ 'db:mysql' ], :files => FileList['test/*jdbc_*test.rb'] do |test_task|
88
+ test_task.libs << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
89
+ end
90
+
91
+ # TODO since Derby AR 5.x support is not implemented we only run JNDI with MySQL :
92
+ #task :test_jndi => [ :test_jndi_mysql, :test_jndi_derby ] if defined?(JRUBY_VERSION)
93
+ task :test_jndi => [ :test_jndi_mysql ] if defined?(JRUBY_VERSION)
94
+
95
+ jndi_classpath = [ 'test/jars/tomcat-juli.jar', 'test/jars/tomcat-catalina.jar' ]
96
+
97
+ jndi_classpath.each do |jar_path|
98
+ file(jar_path) { Rake::Task['tomcat-jndi:download'].invoke }
99
+ end
100
+
101
+ get_jndi_classpath_opt = lambda do
102
+ cp = jndi_classpath.map { |jar_path| File.expand_path("../#{jar_path}", File.dirname(__FILE__)) }
103
+ "-J-cp \"#{cp.join(File::PATH_SEPARATOR)}\""
104
+ end
105
+
106
+ test_task_for 'JNDI_Derby', :desc => 'Run tests against a Derby JNDI connection',
107
+ :prereqs => jndi_classpath, :files => FileList['test/*jndi_derby*test.rb'] do |test_task|
108
+ test_task.libs << 'jdbc-derby/lib'
109
+ test_task.ruby_opts << get_jndi_classpath_opt.call
110
+ #test_task.verbose = true
111
+ end
112
+
113
+ test_task_for 'JNDI_MySQL', :desc => 'Run tests against a MySQL JNDI connection',
114
+ :prereqs => [ 'db:mysql' ] + jndi_classpath, :files => FileList['test/*jndi_mysql*test.rb'] do |test_task|
115
+ test_task.libs << 'jdbc-mysql/lib'
116
+ test_task.ruby_opts << get_jndi_classpath_opt.call
117
+ end
118
+
119
+ test_task_for :MySQL, :name => 'test_jdbc_mysql',
120
+ :prereqs => 'db:mysql', :database_name => 'MySQL (using adapter: jdbc)' do |test_task|
121
+ test_task.ruby_opts << '-rdb/jdbc_mysql' # replaces require 'db/mysql'
122
+ end
123
+ test_task_for :PostgreSQL, :name => 'test_jdbc_postgresql', :driver => 'postgres',
124
+ :prereqs => 'db:postgresql', :database_name => 'PostgreSQL (using adapter: jdbc)' do |test_task|
125
+ test_task.ruby_opts << '-rdb/jdbc_postgres' # replaces require 'db/postgres'
126
+ end
127
+
128
+ # NOTE: Sybase testing is currently broken, please fix it if you're on Sybase :
129
+ #test_task_for :Sybase, :desc => "Run tests against Sybase (using jTDS driver)"
130
+ #task :test_sybase_jtds => :test_sybase # alias
131
+ #test_task_for :Sybase, :name => 'sybase_jconnect',
132
+ # :desc => "Run tests against Sybase (ensure jConnect driver is on class-path)"
@@ -0,0 +1,11 @@
1
+ module Bundler
2
+ class GemHelper
3
+ def guard_already_tagged
4
+ # parent project performs the tag
5
+ end
6
+ def tag_version
7
+ Bundler.ui.confirm "Parent project tagged #{version_tag}"
8
+ yield if block_given?
9
+ end
10
+ end
11
+ end
@@ -1,25 +1,70 @@
1
- def java_classpath_arg # myriad of ways to discover JRuby classpath
2
- begin
3
- cpath = Java::java.lang.System.getProperty('java.class.path').split(File::PATH_SEPARATOR)
4
- cpath += Java::java.lang.System.getProperty('sun.boot.class.path').split(File::PATH_SEPARATOR)
5
- jruby_cpath = cpath.compact.join(File::PATH_SEPARATOR)
6
- rescue => e
7
- end
8
- unless jruby_cpath
9
- jruby_cpath = ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] &&
10
- FileList["#{ENV['JRUBY_HOME']}/lib/*.jar"].join(File::PATH_SEPARATOR)
11
- end
12
- jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
13
- end
1
+ jar_file = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
2
+ begin
3
+ require 'ant'
4
+ directory classes = "pkg/classes"
5
+ CLEAN << classes
6
+
7
+ driver_jars = []
8
+ # PostgreSQL driver :
9
+ driver_jars << Dir.glob("jdbc-postgres/lib/*.jar").sort.last
10
+
11
+ file jar_file => FileList['src/java/**/*.java', 'pkg/classes'] do
12
+ rm_rf FileList["#{classes}/**/*"]
13
+ ant.javac :srcdir => "src/java", :destdir => "pkg/classes",
14
+ :source => "7", :target => "7", :debug => true, :deprecation => true,
15
+ :classpath => "${java.class.path}:${sun.boot.class.path}:#{driver_jars.join(':')}",
16
+ :includeantRuntime => false
17
+
18
+ ant.tstamp do |ts|
19
+ ts.format(:property => 'TODAY', :pattern => 'yyyy-MM-dd HH:mm:ss')
20
+ end
14
21
 
15
- jar_name = File.join(*%w(lib arjdbc jdbc adapter_java.jar))
22
+ begin
23
+ require 'arjdbc/version'
24
+ rescue LoadError
25
+ path = File.expand_path('../lib', File.dirname(__FILE__))
26
+ unless $LOAD_PATH.include?(path)
27
+ $LOAD_PATH << path; retry
28
+ end
29
+ end
16
30
 
17
- desc "Compile the native Java code."
18
- task :java_compile do
19
- debug = ENV['DEBUG'] ? '-g' : ''
20
- pkg_classes = File.join(*%w(pkg classes))
21
- mkdir_p pkg_classes
22
- sh "javac -target 1.5 -source 1.5 #{debug} -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
23
- sh "jar cf #{jar_name} -C #{pkg_classes} ."
31
+ gem_version = Gem::Version.create(ArJdbc::VERSION)
32
+ if gem_version.segments.last == 'DEV'
33
+ version = gem_version.segments[0...-1] # 1.3.0.DEV -> 1.3.0
34
+ else
35
+ version = gem_version.segments.dup
36
+ end
37
+ version = version.join('.')
38
+
39
+ ant.manifest :file => 'MANIFEST.MF' do |mf|
40
+ mf.attribute :name => 'Built-By', :value => '${user.name}'
41
+ mf.attribute :name => 'Built-Time', :value => '${TODAY}'
42
+ mf.attribute :name => 'Built-Jdk', :value => '${java.version}'
43
+ mf.attribute :name => 'Built-JRuby', :value => JRUBY_VERSION
44
+
45
+ mf.attribute :name => 'Specification-Title', :value => 'ActiveRecord-JDBC'
46
+ mf.attribute :name => 'Specification-Version', :value => '1.3'
47
+ mf.attribute :name => 'Specification-Vendor', :value => 'JRuby'
48
+ mf.attribute :name => 'Implementation-Version', :value => version
49
+ mf.attribute :name => 'Implementation-Vendor', :value => 'The JRuby Team'
50
+ end
51
+
52
+ ant.jar :basedir => "pkg/classes", :includes => "**/*.class",
53
+ :destfile => jar_file, :manifest => 'MANIFEST.MF'
54
+ end
55
+
56
+ desc "Compile the native Java code."
57
+ task :jar => jar_file
58
+
59
+ namespace :jar do
60
+ task :force do
61
+ rm jar_file if File.exist?(jar_file)
62
+ Rake::Task['jar'].invoke
63
+ end
64
+ end
65
+
66
+ rescue LoadError
67
+ task :jar do
68
+ puts "Run 'jar' with JRuby to re-compile the agent extension class"
69
+ end
24
70
  end
25
- file jar_name => :java_compile
@@ -0,0 +1,61 @@
1
+ namespace :db do
2
+
3
+ desc "Creates the test database for MySQL"
4
+ task :mysql do
5
+ require File.expand_path('../../test/shared_helper', __FILE__)
6
+ fail "could not create test database: mysql executable not found" unless mysql = which('mysql')
7
+ load 'test/db/mysql_config.rb' # rescue nil
8
+ enc = MYSQL_CONFIG[:encoding] || 'utf8' # 'utf8mb4'
9
+ puts MYSQL_CONFIG.inspect if $VERBOSE
10
+ # DROP USER arjdbc@localhost; __ERROR 1396 (HY000): Operation CREATE USER failed__
11
+ script = sql_script <<-SQL, 'mysql'
12
+ DROP DATABASE IF EXISTS `#{MYSQL_CONFIG[:database]}`;
13
+ CREATE DATABASE `#{MYSQL_CONFIG[:database]}` DEFAULT CHARACTER SET `#{enc}` COLLATE `#{enc}_general_ci`;
14
+ GRANT ALL PRIVILEGES ON `#{MYSQL_CONFIG[:database]}`.* TO #{MYSQL_CONFIG[:username]}@localhost;
15
+ GRANT ALL PRIVILEGES ON `test\_%`.* TO #{MYSQL_CONFIG[:username]}@localhost;
16
+ SET PASSWORD FOR #{MYSQL_CONFIG[:username]}@localhost = PASSWORD('#{MYSQL_CONFIG[:password]}');
17
+ SQL
18
+ params = { '-u' => 'root' }
19
+ if ENV['DATABASE_YML']; require 'yaml'
20
+ params['-p'] = YAML.load(File.new(ENV['DATABASE_YML']))["production"]["password"]
21
+ end
22
+ params['-u'] = ENV['MY_USER'] if ENV['MY_USER']
23
+ params['-p'] = ENV['MY_PASSWORD'] if ENV['MY_PASSWORD']
24
+ puts "Creating MySQL (test) database: #{MYSQL_CONFIG[:database]}"
25
+ sh "cat #{script.path} | #{mysql} -f #{params.map {|k, v| "#{k}#{v}"}.join(' ')}", :verbose => $VERBOSE # so password is not echoed
26
+ end
27
+
28
+ desc "Creates the test database for PostgreSQL"
29
+ task :postgresql do
30
+ require File.expand_path('../../test/shared_helper', __FILE__)
31
+ fail 'could not create test database: psql executable not found' unless psql = which('psql')
32
+ fail 'could not create test database: missing "postgres" role' unless PostgresHelper.postgres_role?
33
+ load 'test/db/postgres_config.rb' # rescue nil
34
+ puts POSTGRES_CONFIG.inspect if $VERBOSE
35
+ script = sql_script <<-SQL, 'psql'
36
+ DROP DATABASE IF EXISTS #{POSTGRES_CONFIG[:database]};
37
+ DROP USER IF EXISTS #{POSTGRES_CONFIG[:username]};
38
+ CREATE USER #{POSTGRES_CONFIG[:username]} CREATEDB SUPERUSER LOGIN PASSWORD '#{POSTGRES_CONFIG[:password]}';
39
+ CREATE DATABASE #{POSTGRES_CONFIG[:database]} OWNER #{POSTGRES_CONFIG[:username]}
40
+ TEMPLATE template0
41
+ ENCODING '#{POSTGRES_CONFIG[:encoding]}' LC_COLLATE '#{POSTGRES_CONFIG[:collate]}' LC_CTYPE '#{POSTGRES_CONFIG[:collate]}';
42
+ SQL
43
+ params = { '-U' => ENV['PSQL_USER'] || 'postgres' }
44
+ params['-q'] = nil unless $VERBOSE
45
+ puts "Creating PostgreSQL (test) database: #{POSTGRES_CONFIG[:database]}"
46
+ sh "cat #{script.path} | #{psql} #{params.to_a.join(' ')}", :verbose => $VERBOSE
47
+ end
48
+ task :postgres => :postgresql
49
+
50
+ private
51
+
52
+ def sql_script(sql_content, name = 'sql_script')
53
+ require 'tempfile'; script = Tempfile.new(name)
54
+ script.puts sql_content
55
+ yield(script) if block_given?
56
+ script.close
57
+ at_exit { script.unlink }
58
+ script
59
+ end
60
+
61
+ end
@@ -1,41 +1,216 @@
1
1
  namespace :rails do
2
- def _adapter(n)
3
- case n
4
- when /postgres/
5
- 'postgresql'
6
- else
7
- n
2
+
3
+ %w(MySQL SQLite3 PostgreSQL).each do |adapter|
4
+
5
+ desc "Run Rails ActiveRecord tests with #{adapter} (JDBC)"
6
+ task "test_#{adapter = adapter.downcase}" do
7
+ puts "Use TESTOPTS=\"--verbose\" to pass --verbose to runners." if ARGV.include? '--verbose'
8
+
9
+ if ENV['RAILS']
10
+ ar_path = File.join(ENV['RAILS'], 'activerecord')
11
+ end
12
+
13
+ unless ar_path && File.exist?(ar_path)
14
+ ar_path = `bundle info --path activerecord`.chomp
15
+ end
16
+
17
+ unless File.exist? ar_test_dir = File.join(ar_path, 'test')
18
+ raise "can not directly load Rails tests;" +
19
+ " try setting a local repository path e.g. export RAILS=`pwd`/../rails"
20
+ end
21
+
22
+ driver = "jdbc-#{ENV['DRIVER'] ? ENV['DRIVER'].downcase : (adapter =~ /postgres/i ? 'postgres' : adapter)}"
23
+ adapter = 'mysql2' if adapter.eql?('mysql')
24
+
25
+ root_dir = File.expand_path('..', File.dirname(__FILE__))
26
+ env = {}
27
+ env['ARCONFIG'] = ENV['ARCONFIG'] || File.join(root_dir, 'test/rails', 'config.yml')
28
+ env['ARCONN'] = adapter
29
+ env['BUNDLE_GEMFILE'] = ENV['BUNDLE_GEMFILE'] || File.join(root_dir, 'Gemfile') # use AR-JDBC's with Rails tests
30
+ env['EXCLUDE_DIR'] = File.join(root_dir, 'test/rails/excludes', adapter) # minitest-excludes
31
+
32
+ libs = [
33
+ File.join(root_dir, 'lib'),
34
+ File.join(root_dir, driver, 'lib'),
35
+ File.join(root_dir, 'test/rails'),
36
+ ar_test_dir
37
+ ]
38
+
39
+ test_files_finder = lambda do
40
+ Dir.chdir(ar_path) do # taken from Rails' *activerecord/Rakefile* :
41
+ ( Dir.glob("test/cases/**/*_test.rb").reject { |x| x =~ /\/adapters\// } +
42
+ Dir.glob("test/cases/adapters/#{adapter}/**/*_test.rb") )
43
+ end
44
+ end
45
+
46
+ task_stub = Class.new(Rake::TestTask) { def define; end }.new # no-op define
47
+ test_loader_code = task_stub.run_code # :rake test-loader
48
+
49
+ ruby_opts_string = "-I\"#{libs.join(File::PATH_SEPARATOR)}\""
50
+ ruby_opts_string += " -C \"#{ar_path}\""
51
+ ruby_opts_string += " -rbundler/setup"
52
+ ruby_opts_string += " -rminitest -rminitest/excludes" unless ENV['NO_EXCLUDES'].eql?('true')
53
+ file_list = ENV["TEST"] ? FileList[ ENV["TEST"] ] : test_files_finder.call
54
+ file_list_string = file_list.map { |fn| "\"#{fn}\"" }.join(' ')
55
+ # test_loader_code = "-e \"ARGV.each{|f| require f}\"" # :direct
56
+ option_list = ( ENV["TESTOPTS"] || ENV["TESTOPT"] || ENV["TEST_OPTS"] || '' )
57
+
58
+ args = "#{ruby_opts_string} #{test_loader_code} #{file_list_string} #{option_list}"
59
+ env_sh env, "#{FileUtils::RUBY} #{args}" do |ok, status|
60
+ if !ok && status.respond_to?(:signaled?) && status.signaled?
61
+ raise SignalException.new(status.termsig)
62
+ elsif !ok
63
+ fail "Command failed with status (#{status.exitstatus})"
64
+ end
65
+ end
8
66
  end
9
- end
67
+ task :test_mysql2 => :test_mysql
68
+
69
+ FileUtils.module_eval do
70
+
71
+ def env_sh(env, *cmd, &block)
72
+ options = (Hash === cmd.last) ? cmd.pop : {}
73
+ shell_runner = block_given? ? block : create_shell_runner(cmd)
74
+ set_verbose_option(options)
75
+ options[:noop] ||= Rake::FileUtilsExt.nowrite_flag
76
+ Rake.rake_check_options options, :noop, :verbose
77
+
78
+ cmd = env.map { |k,v| "#{k}=\"#{v}\"" }.join(' ') + ' ' + cmd.join(' ')
79
+ Rake.rake_output_message cmd if options[:verbose]
80
+
81
+ unless options[:noop]
82
+ res = Kernel.system(cmd)
83
+ status = $?
84
+ status = Rake::PseudoStatus.new(1) if !res && status.nil?
85
+ shell_runner.call(res, status)
86
+ end
87
+ end
88
+
89
+ def env_system(env, cmd)
90
+ Kernel.system(env.map { |k,v| "#{k}=\"#{v}\"" }.join(' ') + ' ' + cmd)
91
+ end
10
92
 
11
- def _driver(n)
12
- case n
13
- when /postgres/
14
- 'postgres'
15
- else
16
- n
17
93
  end
94
+
18
95
  end
19
96
 
20
- def _target(n)
21
- case n
22
- when /postgres/
23
- 'test_jdbcpostgresql'
24
- else
25
- "test_jdbc#{n}"
97
+ namespace :db do
98
+ namespace :mysql do
99
+ desc 'Build the MySQL test databases'
100
+ task :build do
101
+ config = ARTest.config['connections']['mysql2']
102
+ %x( mysql --user=#{config['arunit']['username']} --password=#{config['arunit']['password']} -e "create DATABASE #{config['arunit']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
103
+ %x( mysql --user=#{config['arunit2']['username']} --password=#{config['arunit2']['password']} -e "create DATABASE #{config['arunit2']['database']} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci ")
104
+ end
105
+
106
+ desc 'Drop the MySQL test databases'
107
+ task :drop do
108
+ config = ARTest.config['connections']['mysql2']
109
+ %x( mysqladmin --user=#{config['arunit']['username']} --password=#{config['arunit']['password']} -f drop #{config['arunit']['database']} )
110
+ %x( mysqladmin --user=#{config['arunit2']['username']} --password=#{config['arunit2']['password']} -f drop #{config['arunit2']['database']} )
111
+ end
112
+
113
+ desc 'Rebuild the MySQL test databases'
114
+ task :rebuild => [:drop, :build]
115
+ end
116
+
117
+ namespace :postgresql do
118
+ desc 'Build the PostgreSQL test databases'
119
+ task :build do
120
+ config = ARTest.config['connections']['postgresql']
121
+ %x( createdb -E UTF8 -T template0 #{config['arunit']['database']} )
122
+ %x( createdb -E UTF8 -T template0 #{config['arunit2']['database']} )
123
+
124
+ # prepare hstore
125
+ if %x( createdb --version ).strip.gsub(/(.*)(\d\.\d\.\d)$/, "\\2") < "9.1.0"
126
+ puts "Please prepare hstore data type. See http://www.postgresql.org/docs/current/static/hstore.html"
127
+ end
128
+ end
129
+
130
+ desc 'Drop the PostgreSQL test databases'
131
+ task :drop do
132
+ config = ARTest.config['connections']['postgresql']
133
+ %x( dropdb #{config['arunit']['database']} )
134
+ %x( dropdb #{config['arunit2']['database']} )
135
+ end
136
+
137
+ desc 'Rebuild the PostgreSQL test databases'
138
+ task :rebuild => [:drop, :build]
26
139
  end
27
140
  end
28
141
 
29
- task :test => "java_compile" do
30
- driver = ENV['DRIVER']
31
- raise "need a DRIVER" unless driver
32
- activerecord = ENV['RAILS']
33
- raise "need location of RAILS source code" unless activerecord
34
- activerecord = File.join(activerecord, 'activerecord') unless activerecord =~ /activerecord$/
35
- ar_jdbc = File.expand_path(File.dirname(__FILE__) + '/..')
36
- rubylib = "#{ar_jdbc}/lib:#{ar_jdbc}/drivers/#{_driver(driver)}/lib:#{ar_jdbc}/adapters/#{_adapter(driver)}/lib"
37
- Dir.chdir(activerecord) do
38
- rake "RUBYLIB=#{rubylib}", "#{_target(driver)}"
142
+ # NOTE: we expect to, hopefully, not be using these anymore - delete at WILL!
143
+ namespace :test do
144
+ task :all do
145
+ driver = ENV['DRIVER'] || ENV['ADAPTER']
146
+ raise "need a DRIVER (DRIVER=mysql)" unless driver
147
+ rails_dir = _rails_dir
148
+ ENV['ARCONFIG'] = File.join(_ar_jdbc_dir, 'test', 'rails', 'config.yml')
149
+
150
+ Dir.chdir(File.join(rails_dir, 'activerecord')) do
151
+ sh FileUtils::RUBY, '-S', 'rake',
152
+ "RUBYLIB=#{_ruby_lib(rails_dir, driver)}",
153
+ _target(driver)
154
+ end
155
+ end
156
+
157
+ %w(MySQL SQLite3 Postgres).each do |adapter|
158
+ task adapter.downcase do
159
+ ENV['ADAPTER'] = adapter
160
+ Rake::Task['rails:test:all'].invoke
161
+ end
162
+
163
+ namespace adapter.downcase do
164
+ task "base_test" do
165
+ ENV['TEST'] ||= 'test/cases/base_test.rb'
166
+ ENV['ADAPTER'] = adapter
167
+ Rake::Task['rails:test:all'].invoke
168
+ end
169
+ end
170
+ end
171
+
172
+ private
173
+
174
+ def _ar_jdbc_dir
175
+ @ar_jdbc_dir ||= File.expand_path('..', File.dirname(__FILE__))
176
+ end
177
+
178
+ def _rails_dir
179
+ rails_dir = ENV['RAILS'] || File.join('..', 'rails')
180
+ unless File.directory? rails_dir
181
+ raise "can't find RAILS source at '#{rails_dir}' (maybe set ENV['RAILS'])"
182
+ end
183
+ rails_dir = File.join(rails_dir, '..') if rails_dir =~ /activerecord$/
184
+ File.expand_path(rails_dir)
185
+ end
186
+
187
+ def _ruby_lib(rails_dir, driver)
188
+ ar_jdbc_dir = _ar_jdbc_dir
189
+
190
+ if driver =~ /postgres/i
191
+ adapter, driver = 'postgresql', 'postgres'
192
+ else
193
+ adapter, driver = driver.downcase, adapter
194
+ end
195
+
196
+ [File.join(ar_jdbc_dir, 'lib'),
197
+ File.join(ar_jdbc_dir, 'test', 'rails'),
198
+ File.join(ar_jdbc_dir, "jdbc-#{driver}", 'lib'),
199
+ File.join(ar_jdbc_dir, "activerecord-jdbc#{adapter}-adapter", 'lib'),
200
+ File.expand_path('activesupport/lib', rails_dir),
201
+ File.expand_path('activemodel/lib', rails_dir),
202
+ File.expand_path('activerecord/lib', rails_dir)
203
+ ].join(':')
39
204
  end
205
+
206
+ def _target(name)
207
+ case name
208
+ when /postgres/i
209
+ 'test_postgresql'
210
+ else
211
+ "test_jdbc#{name.downcase}"
212
+ end
213
+ end
214
+
40
215
  end
41
216
  end