activerecord-jdbc-adapter 1.2.2.1 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. data/.gitignore +1 -2
  2. data/.travis.yml +18 -3
  3. data/Appraisals +16 -0
  4. data/Gemfile +10 -10
  5. data/Gemfile.lock +27 -17
  6. data/LICENSE.txt +20 -17
  7. data/README.rdoc +29 -14
  8. data/Rakefile +4 -4
  9. data/activerecord-jdbc-adapter.gemspec +2 -1
  10. data/gemfiles/rails23.gemfile +12 -0
  11. data/gemfiles/rails23.gemfile.lock +44 -0
  12. data/gemfiles/rails30.gemfile +11 -0
  13. data/gemfiles/rails30.gemfile.lock +39 -0
  14. data/gemfiles/rails31.gemfile +11 -0
  15. data/gemfiles/rails31.gemfile.lock +41 -0
  16. data/gemfiles/rails32.gemfile +11 -0
  17. data/gemfiles/rails32.gemfile.lock +41 -0
  18. data/lib/arel/visitors/sql_server.rb +7 -0
  19. data/lib/arjdbc/db2/adapter.rb +82 -32
  20. data/lib/arjdbc/derby.rb +0 -4
  21. data/lib/arjdbc/derby/adapter.rb +1 -1
  22. data/lib/arjdbc/derby/connection_methods.rb +3 -2
  23. data/lib/arjdbc/discover.rb +16 -1
  24. data/lib/arjdbc/firebird/adapter.rb +5 -1
  25. data/lib/arjdbc/h2.rb +0 -1
  26. data/lib/arjdbc/h2/connection_methods.rb +3 -1
  27. data/lib/arjdbc/hsqldb.rb +0 -1
  28. data/lib/arjdbc/hsqldb/adapter.rb +4 -3
  29. data/lib/arjdbc/hsqldb/connection_methods.rb +3 -3
  30. data/lib/arjdbc/informix/adapter.rb +5 -1
  31. data/lib/arjdbc/jdbc/adapter.rb +22 -24
  32. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  33. data/lib/arjdbc/jdbc/base_ext.rb +1 -1
  34. data/lib/arjdbc/jdbc/connection.rb +23 -29
  35. data/lib/arjdbc/jdbc/core_ext.rb +1 -1
  36. data/lib/arjdbc/jdbc/discover.rb +1 -1
  37. data/lib/arjdbc/jdbc/driver.rb +1 -1
  38. data/lib/arjdbc/jdbc/extension.rb +3 -3
  39. data/lib/arjdbc/jdbc/jdbc.rake +15 -5
  40. data/lib/arjdbc/mssql.rb +0 -1
  41. data/lib/arjdbc/mssql/adapter.rb +10 -4
  42. data/lib/arjdbc/mssql/connection_methods.rb +15 -15
  43. data/lib/arjdbc/mssql/limit_helpers.rb +24 -2
  44. data/lib/arjdbc/mssql/tsql_helper.rb +0 -8
  45. data/lib/arjdbc/mysql.rb +0 -1
  46. data/lib/arjdbc/mysql/adapter.rb +82 -0
  47. data/lib/arjdbc/mysql/connection_methods.rb +3 -4
  48. data/lib/arjdbc/oracle/adapter.rb +12 -2
  49. data/lib/arjdbc/postgresql.rb +0 -1
  50. data/lib/arjdbc/postgresql/adapter.rb +127 -27
  51. data/lib/arjdbc/postgresql/connection_methods.rb +3 -4
  52. data/lib/arjdbc/sqlite3.rb +0 -1
  53. data/lib/arjdbc/sqlite3/adapter.rb +13 -14
  54. data/lib/arjdbc/sqlite3/connection_methods.rb +3 -4
  55. data/lib/arjdbc/version.rb +1 -1
  56. data/rakelib/01-tomcat.rake +52 -0
  57. data/rakelib/02-test.rake +111 -0
  58. data/rakelib/db.rake +4 -3
  59. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +7 -0
  60. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +8 -3
  61. data/test/abstract_db_create.rb +5 -1
  62. data/test/activerecord/connection_adapters/type_conversion_test.rb +0 -1
  63. data/test/activerecord/jall.sh +0 -0
  64. data/test/activerecord/jtest.sh +0 -0
  65. data/test/db/db2.rb +2 -0
  66. data/test/db/derby.rb +3 -5
  67. data/test/db/h2.rb +3 -1
  68. data/test/db/hsqldb.rb +2 -0
  69. data/test/db/informix.rb +2 -0
  70. data/test/db/jdbc.rb +11 -10
  71. data/test/db/jdbc_derby.rb +14 -0
  72. data/test/db/jdbc_h2.rb +17 -0
  73. data/test/db/jdbc_mysql.rb +13 -0
  74. data/test/db/jdbc_postgres.rb +23 -0
  75. data/test/db/jndi_config.rb +28 -33
  76. data/test/db/jndi_pooled_config.rb +35 -0
  77. data/test/db/logger.rb +1 -1
  78. data/test/db/mssql.rb +2 -0
  79. data/test/db/mysql.rb +2 -7
  80. data/test/db/mysql_config.rb +7 -0
  81. data/test/db/oracle.rb +2 -0
  82. data/test/db/postgres.rb +9 -7
  83. data/test/db/postgres_config.rb +10 -0
  84. data/test/db/sqlite3.rb +2 -0
  85. data/test/db2_reset_column_information_test.rb +0 -2
  86. data/test/derby_migration_test.rb +0 -1
  87. data/test/derby_multibyte_test.rb +0 -1
  88. data/test/derby_reset_column_information_test.rb +0 -3
  89. data/test/derby_row_locking_test.rb +0 -3
  90. data/test/derby_simple_test.rb +0 -1
  91. data/test/generic_jdbc_connection_test.rb +72 -17
  92. data/test/h2_change_column_test.rb +0 -1
  93. data/test/h2_simple_test.rb +0 -1
  94. data/test/helper.rb +22 -91
  95. data/test/jdbc_common.rb +98 -3
  96. data/test/jndi_callbacks_test.rb +6 -5
  97. data/test/jndi_test.rb +40 -15
  98. data/test/models/custom_pk_name.rb +14 -0
  99. data/test/mssql_ignore_system_views_test.rb +7 -4
  100. data/test/mssql_limit_offset_test.rb +30 -0
  101. data/test/mssql_multibyte_test.rb +1 -2
  102. data/test/mssql_reset_column_information_test.rb +0 -2
  103. data/test/mssql_row_locking_sql_test.rb +0 -2
  104. data/test/mssql_row_locking_test.rb +0 -2
  105. data/test/mysql_reset_column_information_test.rb +0 -2
  106. data/test/mysql_simple_test.rb +3 -18
  107. data/test/oracle_limit_test.rb +23 -0
  108. data/test/oracle_reset_column_information_test.rb +0 -2
  109. data/test/postgres_db_create_test.rb +0 -1
  110. data/test/postgres_drop_db_test.rb +0 -1
  111. data/test/postgres_information_schema_leak_test.rb +0 -1
  112. data/test/postgres_native_type_mapping_test.rb +17 -14
  113. data/test/postgres_nonseq_pkey_test.rb +0 -1
  114. data/test/postgres_reserved_test.rb +1 -2
  115. data/test/postgres_reset_column_information_test.rb +0 -3
  116. data/test/postgres_schema_search_path_test.rb +0 -1
  117. data/test/postgres_simple_test.rb +40 -1
  118. data/test/postgres_table_alias_length_test.rb +0 -1
  119. data/test/postgres_type_conversion_test.rb +0 -1
  120. data/test/row_locking.rb +6 -2
  121. data/test/simple.rb +57 -20
  122. data/test/sqlite3_reset_column_information_test.rb +0 -2
  123. data/test/sqlite3_simple_test.rb +1 -16
  124. data/test/sybase_reset_column_information_test.rb +0 -2
  125. metadata +366 -343
  126. data/lib/arjdbc/jdbc/require_driver.rb +0 -16
@@ -0,0 +1,14 @@
1
+ require 'jdbc_common'
2
+
3
+ config = {
4
+ :adapter => 'jdbc',
5
+ :url => 'jdbc:derby:memory:derby-testdb;create=true',
6
+ :driver => 'org.apache.derby.jdbc.EmbeddedDriver',
7
+ :username => 'arjdbc',
8
+ :password => 'arjdbc'
9
+ }
10
+
11
+ require 'jdbc/derby' # driver not loaded for plain JDBC
12
+ Jdbc::Derby.load_driver(:require)
13
+
14
+ ActiveRecord::Base.establish_connection(config)
@@ -0,0 +1,17 @@
1
+ require 'jdbc_common'
2
+
3
+ config = {
4
+ :adapter => 'jdbc',
5
+ :driver => 'org.h2.Driver',
6
+ :url => 'jdbc:h2:test.db'
7
+ }
8
+
9
+ require 'jdbc/h2' # driver not loaded for plain JDBC
10
+ Jdbc::H2.load_driver(:require)
11
+
12
+ ActiveRecord::Base.establish_connection(config)
13
+
14
+ at_exit {
15
+ # Clean up hsqldb when done
16
+ Dir['test.db*'].each { |f| FileUtils.rm_rf(f) }
17
+ }
@@ -0,0 +1,13 @@
1
+ require 'jdbc_common'
2
+ require 'db/mysql_config'
3
+
4
+ require 'jdbc/mysql' # driver not loaded for plain JDBC
5
+ Jdbc::MySQL.load_driver
6
+
7
+ ActiveRecord::Base.establish_connection({
8
+ :adapter => 'jdbc',
9
+ :driver => 'com.mysql.jdbc.Driver',
10
+ :url => "jdbc:mysql://#{MYSQL_CONFIG[:host]}/#{MYSQL_CONFIG[:database]}",
11
+ :username => MYSQL_CONFIG[:username],
12
+ :password => MYSQL_CONFIG[:password],
13
+ })
@@ -0,0 +1,23 @@
1
+ require 'jdbc_common'
2
+ require 'db/postgres_config'
3
+
4
+ require 'jdbc/postgres' # driver not loaded for plain JDBC
5
+ Jdbc::Postgres::load_driver
6
+
7
+ url = POSTGRES_CONFIG[:host].dup
8
+ url << ":#{POSTGRES_CONFIG[:port]}" if POSTGRES_CONFIG[:port]
9
+
10
+ ActiveRecord::Base.establish_connection({
11
+ :adapter => 'jdbc',
12
+ :driver => 'org.postgresql.Driver',
13
+ :url => "jdbc:postgresql://#{url}/#{POSTGRES_CONFIG[:database]}",
14
+ :username => POSTGRES_CONFIG[:username],
15
+ :password => POSTGRES_CONFIG[:password],
16
+ })
17
+
18
+ begin
19
+ result = ActiveRecord::Base.connection.execute("SHOW server_version_num")
20
+ PG_VERSION = result.first.first[1].to_i
21
+ rescue
22
+ PG_VERSION = 0
23
+ end
@@ -1,40 +1,35 @@
1
- require 'fileutils'
2
1
  require 'arjdbc'
2
+ require 'jdbc_common'
3
3
 
4
4
  JNDI_CONFIG = {
5
- :adapter => "jdbc",
6
- :jndi => 'jdbc/derbydb'
5
+ :adapter => 'jdbc', :jndi => 'jdbc/DerbyDB'
7
6
  }
8
7
 
9
- # To test JNDI, grab fscontext-1_2-beta3.zip from
10
- # http://java.sun.com/products/jndi/downloads/index.html
11
- # and put fscontext.jar and providerutil.jar in test/
12
- require 'test/fscontext.jar'
13
- require 'test/providerutil.jar'
14
- require 'jdbc/derby'
15
-
16
- System = java.lang.System
17
- Context = javax.naming.Context
18
- InitialContext = javax.naming.InitialContext
19
- Reference = javax.naming.Reference
20
- StringRefAddr = javax.naming.StringRefAddr
21
-
22
- System.set_property(Context::INITIAL_CONTEXT_FACTORY,
23
- 'com.sun.jndi.fscontext.RefFSContextFactory')
24
- project_path = File.expand_path(File.dirname(__FILE__) + '/../..')
25
- jndi_dir = project_path + '/jndi_test'
26
- jdbc_dir = jndi_dir + '/jdbc'
27
- FileUtils.mkdir_p jdbc_dir unless File.exist?(jdbc_dir)
8
+ # FS based JNDI impl borrowed from tomcat :
9
+ load 'test/jars/tomcat-juli.jar'
10
+ load 'test/jars/tomcat-catalina.jar'
28
11
 
29
- System.set_property(Context::PROVIDER_URL, "file://#{jndi_dir}")
12
+ java.lang.System.set_property(
13
+ javax.naming.Context::INITIAL_CONTEXT_FACTORY,
14
+ 'org.apache.naming.java.javaURLContextFactory'
15
+ )
16
+ java.lang.System.set_property(
17
+ javax.naming.Context::URL_PKG_PREFIXES,
18
+ 'org.apache.naming'
19
+ )
30
20
 
31
- ic = InitialContext.new
32
- ic.rebind(JNDI_CONFIG[:jndi],
33
- org.apache.derby.jdbc.EmbeddedDataSource.new.tap {|ds|
34
- ds.database_name = "derby-testdb-jndi"
35
- ds.create_database = "create"
36
- ds.user = "sa"
37
- ds.password = ""})
38
-
39
-
40
- ActiveRecord::Base.establish_connection(JNDI_CONFIG)
21
+ require 'jdbc/derby'
22
+ Jdbc::Derby.load_driver
23
+
24
+ data_source = org.apache.derby.jdbc.EmbeddedDataSource.new
25
+ data_source.database_name = "memory:DerbyDB-JNDI"
26
+ data_source.create_database = "create"
27
+ data_source.user = "sa"
28
+ data_source.password = ""
29
+
30
+ init_context = javax.naming.InitialContext.new
31
+ begin
32
+ init_context.create_subcontext 'jdbc'
33
+ rescue javax.naming.NameAlreadyBoundException
34
+ end
35
+ init_context.bind JNDI_CONFIG[:jndi], data_source
@@ -0,0 +1,35 @@
1
+ require 'arjdbc'
2
+ require 'jdbc_common'
3
+
4
+ JNDI_POOLED_CONFIG = {
5
+ :adapter => 'jdbc', :jndi => 'jdbc/PooledDerbyDB'
6
+ }
7
+
8
+ # FS based JNDI impl borrowed from tomcat :
9
+ load 'test/jars/tomcat-juli.jar'
10
+ load 'test/jars/tomcat-catalina.jar'
11
+
12
+ java.lang.System.set_property(
13
+ javax.naming.Context::INITIAL_CONTEXT_FACTORY,
14
+ 'org.apache.naming.java.javaURLContextFactory'
15
+ )
16
+ java.lang.System.set_property(
17
+ javax.naming.Context::URL_PKG_PREFIXES,
18
+ 'org.apache.naming'
19
+ )
20
+
21
+ require 'jdbc/derby'
22
+ Jdbc::Derby.load_driver
23
+
24
+ data_source = org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource.new
25
+ data_source.database_name = "memory:PooledDerbyDB-JNDI"
26
+ data_source.create_database = "create"
27
+ data_source.user = "sa"
28
+ data_source.password = ""
29
+
30
+ init_context = javax.naming.InitialContext.new
31
+ begin
32
+ init_context.create_subcontext 'jdbc'
33
+ rescue javax.naming.NameAlreadyBoundException
34
+ end
35
+ init_context.bind JNDI_POOLED_CONFIG[:jndi], data_source
data/test/db/logger.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'logger'
2
2
  ActiveRecord::Base.logger = Logger.new($stdout)
3
- ActiveRecord::Base.logger.level = Logger::DEBUG
3
+ ActiveRecord::Base.logger.level = $DEBUG || ENV['DEBUG'] ? Logger::DEBUG : Logger::WARN
data/test/db/mssql.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'jdbc_common'
2
+
1
3
  MSSQL_CONFIG = {
2
4
  :username => 'blog',
3
5
  :password => '',
data/test/db/mysql.rb CHANGED
@@ -1,10 +1,5 @@
1
- MYSQL_CONFIG = {
2
- :username => 'arjdbc',
3
- :password => 'arjdbc',
4
- :adapter => 'mysql',
5
- :database => 'arjdbc_test',
6
- :host => 'localhost'
7
- }
1
+ require 'jdbc_common'
2
+ require 'db/mysql_config'
8
3
 
9
4
  ActiveRecord::Base.establish_connection(MYSQL_CONFIG)
10
5
 
@@ -0,0 +1,7 @@
1
+ MYSQL_CONFIG = {
2
+ :username => 'arjdbc',
3
+ :password => 'arjdbc',
4
+ :adapter => 'mysql',
5
+ :database => 'arjdbc_test',
6
+ :host => 'localhost'
7
+ }
data/test/db/oracle.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'jdbc_common'
2
+
1
3
  config = {
2
4
  :username => 'blog',
3
5
  :password => 'blog',
data/test/db/postgres.rb CHANGED
@@ -1,9 +1,11 @@
1
- POSTGRES_CONFIG = {
2
- :adapter => 'postgresql',
3
- :database => 'arjdbc_test',
4
- :host => 'localhost',
5
- :username => 'arjdbc',
6
- :password => 'arjdbc'
7
- }
1
+ require 'jdbc_common'
2
+ require 'db/postgres_config'
8
3
 
9
4
  ActiveRecord::Base.establish_connection(POSTGRES_CONFIG)
5
+
6
+ begin
7
+ result = ActiveRecord::Base.connection.execute("SHOW server_version_num")
8
+ PG_VERSION = result.first.first[1].to_i
9
+ rescue
10
+ PG_VERSION = 0
11
+ end
@@ -0,0 +1,10 @@
1
+ POSTGRES_CONFIG = {
2
+ :adapter => 'postgresql',
3
+ :database => 'arjdbc_test',
4
+ :host => 'localhost',
5
+ :username => 'arjdbc',
6
+ :password => 'arjdbc'
7
+ }
8
+
9
+ POSTGRES_CONFIG[:host] = ENV['PGHOST'] if ENV['PGHOST']
10
+ POSTGRES_CONFIG[:port] = ENV['PGPORT'] if ENV['PGPORT']
data/test/db/sqlite3.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'jdbc_common'
2
+
1
3
  config = {
2
4
  :adapter => 'sqlite3',
3
5
  :database => 'test.sqlite3.db'
@@ -1,5 +1,3 @@
1
- #! /usr/bin/env jruby
2
-
3
1
  require 'jdbc_common'
4
2
  require 'db/db2'
5
3
 
@@ -1,5 +1,4 @@
1
1
  require 'jdbc_common'
2
- require 'db/derby'
3
2
 
4
3
  class CreateDummies < ActiveRecord::Migration
5
4
  def self.up
@@ -5,7 +5,6 @@
5
5
  # grant all on weblog_development.* to blog@localhost;
6
6
 
7
7
  require 'jdbc_common'
8
- require 'db/derby'
9
8
 
10
9
  class DerbyMultibyteTest < Test::Unit::TestCase
11
10
  include MultibyteTestMethods
@@ -1,7 +1,4 @@
1
- #! /usr/bin/env jruby
2
-
3
1
  require 'jdbc_common'
4
- require 'db/derby'
5
2
 
6
3
  class DerbyResetColumnInformationTest < Test::Unit::TestCase
7
4
  include ResetColumnInformationTestMethods
@@ -1,7 +1,4 @@
1
- #! /usr/bin/env jruby
2
-
3
1
  require 'jdbc_common'
4
- require 'db/derby'
5
2
 
6
3
  class DerbyRowLockingTest < Test::Unit::TestCase
7
4
  include MigrationSetup
@@ -5,7 +5,6 @@
5
5
  # grant all on weblog_development.* to blog@localhost;
6
6
 
7
7
  require 'jdbc_common'
8
- require 'db/derby'
9
8
 
10
9
  class DerbySimpleTest < Test::Unit::TestCase
11
10
  include SimpleTestMethods
@@ -2,28 +2,83 @@ require 'jdbc_common'
2
2
  require 'db/jdbc'
3
3
 
4
4
  class GenericJdbcConnectionTest < Test::Unit::TestCase
5
+
5
6
  def test_connection_available_through_jdbc_adapter
6
- ActiveRecord::Base.connection.execute("show databases");
7
- assert ActiveRecord::Base.connected?
7
+ ActiveRecord::Base.connection.execute("show databases") # MySQL
8
+ assert ActiveRecord::Base.connected?
8
9
  end
9
10
 
10
- def test_configure_connection_url
11
- connection = Object.new
12
- connection.extend ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper
13
- connection.config = { :url => "jdbc://somehost", :options => { :hoge => "true", :fuya => "false"} }
14
- assert_equal "jdbc://somehost?hoge=true&fuya=false", connection.configure_url
11
+ class ConfigHelperTest < Test::Unit::TestCase
15
12
 
16
- connection.config = { :url => "jdbc://somehost?param=0", :options => { :hoge => "true", :fuya => "false"} }
17
- assert_equal "jdbc://somehost?param=0&hoge=true&fuya=false", connection.configure_url
18
- end
13
+ test 'configure connection url' do
14
+ connection = Object.new
15
+ connection.extend ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper
16
+ connection.config = { :url => "jdbc://somehost", :options => { :hoge => "true", :fuya => "false"} }
17
+ assert_equal "jdbc://somehost?hoge=true&fuya=false", connection.send(:configure_url)
18
+
19
+ connection.config = { :url => "jdbc://somehost?param=0", :options => { :hoge => "true", :fuya => "false"} }
20
+ assert_equal "jdbc://somehost?param=0&hoge=true&fuya=false", connection.send(:configure_url)
21
+ end
22
+
23
+ test 'connection fails without driver and url' do
24
+ with_connection_removed do
25
+ ActiveRecord::Base.establish_connection :adapter => 'jdbc'
26
+ assert_raises(ActiveRecord::ConnectionNotEstablished) do
27
+ ActiveRecord::Base.connection
28
+ end
29
+ end
30
+ end
31
+
32
+ test 'connection fails without driver' do
33
+ with_connection_removed do
34
+ ActiveRecord::Base.establish_connection :adapter => 'jdbc', :url => 'jdbc:derby:test.derby;create=true'
35
+ assert_raises(ActiveRecord::ConnectionNotEstablished) do
36
+ ActiveRecord::Base.connection
37
+ end
38
+ end
39
+ end
40
+
41
+ test 'connection does not fail with driver_instance and url' do
42
+ load_derby_driver
43
+ with_connection_removed do
44
+ driver_instance = ActiveRecord::ConnectionAdapters::JdbcDriver.new('org.apache.derby.jdbc.EmbeddedDriver')
45
+ ActiveRecord::Base.establish_connection :adapter => 'jdbc',
46
+ :url => 'jdbc:derby:memory:TestDB;create=true', :driver_instance => driver_instance
47
+ assert_nothing_raised do
48
+ ActiveRecord::Base.connection
49
+ end
19
50
 
20
- def test_connection_fails_without_driver_and_url
21
- conn = ActiveRecord::Base.remove_connection
22
- assert_raises(ActiveRecord::ConnectionNotEstablished) do
23
- ActiveRecord::Base.establish_connection :adapter => 'jdbc'
24
- ActiveRecord::Base.connection
51
+ assert ActiveRecord::Base.connected?
52
+ assert_nothing_raised do
53
+ connection = ActiveRecord::Base.connection
54
+ connection.execute("create table my_table(x int)")
55
+ #connection.execute("insert into my_table values 42")
56
+ #connection.execute("select * from my_table")
57
+ end
58
+ end
25
59
  end
26
- ensure
27
- ActiveRecord::Base.establish_connection conn
60
+
61
+ private
62
+
63
+ def with_connection_removed
64
+ connection = ActiveRecord::Base.remove_connection
65
+ begin
66
+ yield
67
+ ensure
68
+ ActiveRecord::Base.establish_connection connection
69
+ end
70
+ end
71
+
72
+ @@derby_driver_loaded = nil
73
+
74
+ def load_derby_driver
75
+ @@derby_driver_loaded ||= begin
76
+ require 'jdbc/derby'
77
+ Jdbc::Derby.load_driver
78
+ true
79
+ end
80
+ end
81
+
28
82
  end
83
+
29
84
  end
@@ -1,5 +1,4 @@
1
1
  require 'jdbc_common'
2
- require 'db/h2'
3
2
 
4
3
  class H2ChangeColumnTest < Test::Unit::TestCase
5
4
 
@@ -1,5 +1,4 @@
1
1
  require 'jdbc_common'
2
- require 'db/h2'
3
2
 
4
3
  class H2SimpleTest < Test::Unit::TestCase
5
4
  include SimpleTestMethods
data/test/helper.rb CHANGED
@@ -1,104 +1,35 @@
1
+ # Defining helper methods useful both in the definition of test tasks, as well as in the execution
2
+ # of tests themselves. Do not require test/unit within this file, as that'll make the rake process
3
+ # attempt to run tests itself. Test-specific helpers should go in test/jdbc_common.rb.
4
+
1
5
  module Kernel
2
6
  def find_executable?(name)
3
- ENV['PATH'].split(File::PATH_SEPARATOR).detect {|p| File.executable?(File.join(p, name))}
7
+ (ENV['PATH'] || '').split(File::PATH_SEPARATOR).
8
+ detect { |p| File.executable?(File.join(p, name)) }
4
9
  end
10
+ end
5
11
 
6
- def have_postgres?
12
+ module PostgresHelper
13
+ def self.pg_cmdline_params
14
+ params = ""
15
+ params += "-h #{ENV['PGHOST']} " if ENV['PGHOST']
16
+ params += "-p #{ENV['PGPORT']} " if ENV['PGPORT']
17
+ params
18
+ end
19
+
20
+ def self.have_postgres?(warn = nil)
7
21
  if find_executable?("psql")
8
- if `psql -c '\\l' -U postgres 2>&1` && $?.exitstatus == 0
22
+ if `psql -c '\\l' -U postgres #{pg_cmdline_params}2>&1` && $?.exitstatus == 0
9
23
  true
10
24
  else
11
- warn "No \"postgres\" role? You might need to execute `createuser postgres -drs' first."
25
+ if warn.nil?
26
+ warn = "No \"postgres\" role? You might need to execute `createuser postgres -drs' first."
27
+ end
28
+ send(:warn, warn) if warn # warn == false disables warnings
12
29
  false
13
30
  end
14
31
  end
15
32
  end
16
33
  end
17
34
 
18
- if defined?(::ActiveRecord::ConnectionAdapters)
19
-
20
- # assert_queries and SQLCounter taken from rails active_record tests
21
- require 'test/unit'
22
- class Test::Unit::TestCase
23
- def assert_queries(num = 1, matching = nil)
24
- ActiveRecord::SQLCounter.log = []
25
- yield
26
- ensure
27
- queries = nil
28
- ActiveRecord::SQLCounter.log.tap {|log| queries = (matching ? log.select {|s| s =~ matching } : log) }
29
- assert_equal num, queries.size, "#{queries.size} instead of #{num} queries were executed.#{queries.size == 0 ? '' : "\nQueries:\n#{queries.join("\n")}"}"
30
- end
31
- end
32
-
33
- module ActiveRecord
34
- class SQLCounter
35
- def self.ignored_sql
36
- @@ignored_sql
37
- end
38
-
39
- def self.ignored_sql=(value)
40
- @@ignored_sql = value
41
- end
42
-
43
- self.ignored_sql = [
44
- /^PRAGMA (?!(table_info))/,
45
- /^SELECT currval/,
46
- /^SELECT CAST/,
47
- /^SELECT @@IDENTITY/,
48
- /^SELECT @@ROWCOUNT/,
49
- /^SAVEPOINT/,
50
- /^ROLLBACK TO SAVEPOINT/,
51
- /^RELEASE SAVEPOINT/,
52
- /^SHOW max_identifier_length/,
53
- /^BEGIN/,
54
- /^COMMIT/
55
- ]
56
-
57
- # FIXME: this needs to be refactored so specific database can add their own
58
- # ignored SQL. This ignored SQL is for Oracle.
59
- ignored_sql.concat [/^select .*nextval/i,
60
- /^SAVEPOINT/,
61
- /^ROLLBACK TO/,
62
- /^\s*select .* from all_triggers/im
63
- ]
64
-
65
- def self.log=(v)
66
- @@log = v
67
- end
68
-
69
- def self.log
70
- @@log
71
- end
72
-
73
- self.log = []
74
-
75
- def call(name, start, finish, message_id, values)
76
- sql = values[:sql]
77
-
78
- # FIXME: this seems bad. we should probably have a better way to indicate
79
- # the query was cached
80
- unless 'CACHE' == values[:name]
81
- self.class.log << sql unless self.class.ignored_sql.
82
- any? { |r| sql =~ r }
83
- end
84
- end
85
-
86
- def self.instance
87
- @instance || self.new
88
- end
89
- end
90
-
91
- begin
92
- require 'active_support/notifications'
93
- ActiveSupport::Notifications.subscribe('sql.active_record', SQLCounter.new)
94
- rescue LoadError
95
- class ActiveRecord::ConnectionAdapters::JdbcAdapter
96
- def log_info(sql, name, ms)
97
- ActiveRecord::SQLCounter.instance.call(name, ms, ms, nil, :sql => sql)
98
- super
99
- end
100
- end
101
- end
102
- end
103
-
104
- end
35
+ require 'fileutils'