activerecord-jdbc-adapter 1.2.5 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +5 -1
  3. data/Appraisals +5 -5
  4. data/Gemfile +9 -1
  5. data/Gemfile.lock +44 -10
  6. data/History.txt +126 -2
  7. data/README.md +246 -0
  8. data/Rakefile +34 -25
  9. data/activerecord-jdbc-adapter.gemspec +1 -1
  10. data/gemfiles/rails23.gemfile +5 -3
  11. data/gemfiles/rails23.gemfile.lock +26 -18
  12. data/gemfiles/rails30.gemfile +4 -2
  13. data/gemfiles/rails30.gemfile.lock +16 -8
  14. data/gemfiles/rails31.gemfile +4 -2
  15. data/gemfiles/rails31.gemfile.lock +16 -9
  16. data/gemfiles/rails32.gemfile +4 -2
  17. data/gemfiles/rails32.gemfile.lock +15 -8
  18. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  19. data/lib/arel/visitors/sql_server.rb +3 -0
  20. data/lib/arjdbc.rb +3 -5
  21. data/lib/arjdbc/db2.rb +1 -0
  22. data/lib/arjdbc/db2/adapter.rb +302 -196
  23. data/lib/arjdbc/db2/connection_methods.rb +18 -0
  24. data/lib/arjdbc/derby/active_record_patch.rb +12 -0
  25. data/lib/arjdbc/derby/adapter.rb +180 -158
  26. data/lib/arjdbc/derby/connection_methods.rb +5 -1
  27. data/lib/arjdbc/firebird/adapter.rb +27 -19
  28. data/lib/arjdbc/h2/adapter.rb +162 -7
  29. data/lib/arjdbc/h2/connection_methods.rb +5 -1
  30. data/lib/arjdbc/hsqldb.rb +1 -1
  31. data/lib/arjdbc/hsqldb/adapter.rb +96 -61
  32. data/lib/arjdbc/hsqldb/connection_methods.rb +5 -1
  33. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  34. data/lib/arjdbc/informix/adapter.rb +56 -55
  35. data/lib/arjdbc/jdbc/adapter.rb +173 -86
  36. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  37. data/lib/arjdbc/jdbc/column.rb +28 -23
  38. data/lib/arjdbc/jdbc/connection.rb +10 -6
  39. data/lib/arjdbc/jdbc/driver.rb +13 -5
  40. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +21 -0
  41. data/lib/arjdbc/mssql.rb +1 -1
  42. data/lib/arjdbc/mssql/adapter.rb +51 -53
  43. data/lib/arjdbc/mssql/connection_methods.rb +8 -1
  44. data/lib/arjdbc/mysql.rb +1 -1
  45. data/lib/arjdbc/mysql/adapter.rb +186 -150
  46. data/lib/arjdbc/mysql/connection_methods.rb +9 -9
  47. data/lib/arjdbc/mysql/explain_support.rb +85 -0
  48. data/lib/arjdbc/oracle.rb +1 -1
  49. data/lib/arjdbc/oracle/adapter.rb +232 -125
  50. data/lib/arjdbc/oracle/connection_methods.rb +2 -2
  51. data/lib/arjdbc/postgresql.rb +1 -1
  52. data/lib/arjdbc/postgresql/adapter.rb +134 -86
  53. data/lib/arjdbc/postgresql/connection_methods.rb +6 -4
  54. data/lib/arjdbc/postgresql/explain_support.rb +55 -0
  55. data/lib/arjdbc/sqlite3.rb +1 -1
  56. data/lib/arjdbc/sqlite3/adapter.rb +176 -108
  57. data/lib/arjdbc/sqlite3/connection_methods.rb +5 -5
  58. data/lib/arjdbc/sqlite3/explain_support.rb +32 -0
  59. data/lib/arjdbc/sybase/adapter.rb +7 -6
  60. data/lib/arjdbc/version.rb +1 -1
  61. data/pom.xml +1 -1
  62. data/rakelib/02-test.rake +9 -11
  63. data/rakelib/rails.rake +18 -10
  64. data/src/java/arjdbc/db2/DB2Module.java +70 -0
  65. data/src/java/arjdbc/derby/DerbyModule.java +24 -5
  66. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +66 -0
  67. data/src/java/arjdbc/jdbc/AdapterJavaService.java +14 -7
  68. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +111 -89
  69. data/src/java/arjdbc/mysql/MySQLModule.java +79 -70
  70. data/src/java/arjdbc/oracle/OracleModule.java +74 -0
  71. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +5 -10
  72. data/src/java/arjdbc/sqlite3/SQLite3Module.java +77 -0
  73. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +127 -0
  74. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +25 -111
  75. data/src/java/arjdbc/util/QuotingUtils.java +104 -0
  76. data/test/abstract_db_create.rb +6 -6
  77. data/test/activerecord/connection_adapters/type_conversion_test.rb +2 -2
  78. data/test/assets/flowers.jpg +0 -0
  79. data/test/binary.rb +67 -0
  80. data/test/db/db2.rb +30 -7
  81. data/test/db/jdbc.rb +4 -2
  82. data/test/db/oracle.rb +18 -27
  83. data/test/db2_binary_test.rb +6 -0
  84. data/test/db2_serialize_test.rb +6 -0
  85. data/test/db2_simple_test.rb +20 -25
  86. data/test/db2_test.rb +71 -0
  87. data/test/derby_binary_test.rb +6 -0
  88. data/test/derby_migration_test.rb +42 -35
  89. data/test/derby_reset_column_information_test.rb +1 -0
  90. data/test/derby_row_locking_test.rb +17 -0
  91. data/test/derby_schema_dump_test.rb +9 -0
  92. data/test/derby_serialize_test.rb +6 -0
  93. data/test/derby_simple_test.rb +59 -17
  94. data/test/generic_jdbc_connection_test.rb +112 -5
  95. data/test/h2_binary_test.rb +6 -0
  96. data/test/h2_change_column_test.rb +1 -1
  97. data/test/h2_schema_dump_test.rb +25 -0
  98. data/test/h2_serialize_test.rb +6 -0
  99. data/test/h2_simple_test.rb +23 -9
  100. data/test/has_many_through.rb +18 -4
  101. data/test/hsqldb_binary_test.rb +6 -0
  102. data/test/hsqldb_schema_dump_test.rb +15 -0
  103. data/test/hsqldb_serialize_test.rb +6 -0
  104. data/test/hsqldb_simple_test.rb +1 -0
  105. data/test/informix_simple_test.rb +1 -1
  106. data/test/jdbc/db2.rb +23 -0
  107. data/test/jdbc/oracle.rb +23 -0
  108. data/test/jdbc_common.rb +3 -110
  109. data/test/jndi_callbacks_test.rb +0 -2
  110. data/test/jndi_test.rb +2 -0
  111. data/test/models/binary.rb +18 -0
  112. data/test/models/custom_pk_name.rb +1 -0
  113. data/test/models/data_types.rb +11 -2
  114. data/test/models/entry.rb +1 -1
  115. data/test/models/string_id.rb +2 -2
  116. data/test/models/thing.rb +1 -1
  117. data/test/models/topic.rb +32 -0
  118. data/test/mssql_legacy_types_test.rb +1 -1
  119. data/test/mssql_limit_offset_test.rb +13 -3
  120. data/test/mssql_serialize_test.rb +6 -0
  121. data/test/mysql_binary_test.rb +6 -0
  122. data/test/mysql_schema_dump_test.rb +220 -0
  123. data/test/mysql_serialize_test.rb +6 -0
  124. data/test/mysql_simple_test.rb +22 -2
  125. data/test/mysql_test.rb +93 -0
  126. data/test/oracle_binary_test.rb +6 -0
  127. data/test/oracle_limit_test.rb +2 -1
  128. data/test/oracle_serialize_test.rb +6 -0
  129. data/test/oracle_simple_test.rb +61 -0
  130. data/test/oracle_specific_test.rb +77 -26
  131. data/test/postgres_binary_test.rb +6 -0
  132. data/test/postgres_native_type_mapping_test.rb +12 -11
  133. data/test/postgres_nonseq_pkey_test.rb +1 -0
  134. data/test/postgres_reserved_test.rb +1 -0
  135. data/test/postgres_reset_column_information_test.rb +1 -0
  136. data/test/postgres_row_locking_test.rb +21 -0
  137. data/test/postgres_schema_dump_test.rb +88 -0
  138. data/test/postgres_schema_search_path_test.rb +1 -0
  139. data/test/postgres_simple_test.rb +62 -89
  140. data/test/postgres_table_alias_length_test.rb +1 -0
  141. data/test/postgres_test.rb +31 -0
  142. data/test/postgres_type_conversion_test.rb +16 -16
  143. data/test/row_locking.rb +69 -64
  144. data/test/schema_dump.rb +168 -0
  145. data/test/serialize.rb +277 -0
  146. data/test/simple.rb +326 -122
  147. data/test/sqlite3_serialize_test.rb +6 -0
  148. data/test/sqlite3_simple_test.rb +51 -84
  149. data/test/sqlite3_type_conversion_test.rb +101 -0
  150. data/test/test_helper.rb +224 -0
  151. metadata +325 -366
  152. data/README.rdoc +0 -214
  153. data/test/db/logger.rb +0 -3
  154. data/test/derby_multibyte_test.rb +0 -11
  155. data/test/mysql_info_test.rb +0 -123
@@ -0,0 +1,6 @@
1
+ require 'db/oracle'
2
+ require 'binary'
3
+
4
+ class OracleBinaryTest < Test::Unit::TestCase
5
+ include BinaryTestMethods
6
+ end
@@ -19,5 +19,6 @@ class OracleLimitTest < Test::Unit::TestCase
19
19
  assert_nothing_thrown do
20
20
  Entry.includes(:user).all
21
21
  end
22
- end
22
+ end if ar_version('3.1') # in_clause_limit not supported in AR <= 3.0
23
+
23
24
  end
@@ -0,0 +1,6 @@
1
+ require 'db/oracle'
2
+ require 'serialize'
3
+
4
+ class OracleSerializeTest < Test::Unit::TestCase
5
+ include SerializeTestMethods
6
+ end
@@ -15,4 +15,65 @@ class OracleSimpleTest < Test::Unit::TestCase
15
15
  assert e1.id != e2.id
16
16
  end
17
17
  end
18
+
19
+ def test_find_by_sql_WITH_statement
20
+ user = User.create! :login => 'ferko'
21
+ Entry.create! :title => 'aaa', :user_id => user.id
22
+ entries = Entry.find_by_sql '' +
23
+ ' WITH EntryLogin (title, login) AS ' +
24
+ ' ( ' +
25
+ ' SELECT e.title, u.login ' +
26
+ ' FROM entries e INNER JOIN users u ON e.user_id = u.id ' +
27
+ ' ) ' +
28
+ ' ' +
29
+ ' SELECT * FROM EntryLogin ORDER BY title ASC '
30
+ assert entries.first
31
+ assert entries.first.title
32
+ assert entries.first.login
33
+ end
34
+
35
+ include ExplainSupportTestMethods if ar_version("3.1")
36
+
37
+ protected
38
+
39
+ def assert_empty_string value
40
+ # An empty string is treated as a null value in Oracle :
41
+ # http://www.techonthenet.com/oracle/questions/empty_null.php
42
+ assert_equal nil, value
43
+ end
44
+
45
+ def assert_null_text value
46
+ # Oracle adapter initializes all CLOB fields with empty_clob()
47
+ # fn, so they all have a initial value of an empty string ''
48
+ assert_equal '', value
49
+ end
50
+
51
+ def assert_date_equal expected, actual
52
+ # Oracle doesn't distinguish btw date/datetime
53
+ assert_equal expected, actual.to_date
54
+ end
55
+
56
+ def assert_date_type(value)
57
+ # NOTE: no support for bare Date type in Oracle :
58
+ assert_instance_of Date, value.to_date
59
+ end
60
+
61
+ end
62
+
63
+ class OracleMultibyteTest < Test::Unit::TestCase
64
+ include MultibyteTestMethods
65
+
66
+ def self.startup
67
+ super
68
+ MigrationSetup.setup!
69
+ end
70
+
71
+ def self.shutdown
72
+ MigrationSetup.teardown!
73
+ super
74
+ end
75
+
76
+ def setup!; end # MigrationSetup#setup!
77
+ def teardown!; end # MigrationSetup#teardown!
78
+
18
79
  end
@@ -1,40 +1,64 @@
1
+ require 'test_helper'
1
2
  require 'jdbc_common'
2
3
  require 'db/oracle'
3
4
 
4
- class DefaultNumber < ActiveRecord::Base
5
- end
6
-
7
5
  class OracleSpecificTest < Test::Unit::TestCase
8
- include MultibyteTestMethods # so we can get @java_con
9
-
10
- def setup
11
- super
12
- @java_con.createStatement.execute "
6
+ include MigrationSetup
7
+
8
+ @@java_connection = nil
9
+
10
+ def self.startup
11
+ config = ActiveRecord::Base.connection.config
12
+ jdbc_driver = ActiveRecord::ConnectionAdapters::JdbcDriver.new(config[:driver])
13
+ @@java_connection = jdbc_driver.connection(config[:url], config[:username], config[:password])
14
+ @@java_connection.setAutoCommit(true)
15
+
16
+ java_connection = @@java_connection
17
+ java_connection.createStatement.execute "
13
18
  CREATE TABLE DEFAULT_NUMBERS (
14
- ID INTEGER NOT NULL PRIMARY KEY, VALUE NUMBER, DATUM DATE, FPOINT NUMBER(10,2), VALUE2 NUMBER(15)
19
+ ID INTEGER NOT NULL PRIMARY KEY, VALUE NUMBER, DATUM DATE, FPOINT NUMBER(10,2), VALUE2 NUMBER(15)
15
20
  )"
16
- @java_con.createStatement.execute "
21
+ java_connection.createStatement.execute "
17
22
  INSERT INTO DEFAULT_NUMBERS (ID, VALUE, DATUM, FPOINT, VALUE2)
18
- VALUES (1, 0.076, TIMESTAMP'2009-11-05 00:00:00', 1000.01, 1234)"
19
- @java_con.createStatement.execute "CREATE SYNONYM POSTS FOR ENTRIES"
23
+ VALUES (1, 0.076, TIMESTAMP'2009-11-05 00:00:00', 1000.01, 1234)"
24
+ java_connection.createStatement.execute "CREATE SYNONYM POSTS FOR ENTRIES"
25
+
26
+ MigrationSetup.setup!
20
27
  end
21
28
 
22
- def teardown
23
- @java_con.createStatement.execute "DROP TABLE DEFAULT_NUMBERS"
24
- @java_con.createStatement.execute "DROP SYNONYM POSTS"
29
+ def self.shutdown
30
+ MigrationSetup.teardown!
31
+
32
+ java_connection = @@java_connection
33
+ java_connection.createStatement.execute "DROP TABLE DEFAULT_NUMBERS"
34
+ java_connection.createStatement.execute "DROP SYNONYM POSTS"
35
+
36
+ @@java_connection.close
25
37
  super
26
38
  end
27
39
 
40
+ def setup! # MigrationSetup#setup!
41
+ # speedup by creating tables once only on startup !
42
+ # before: Finished in 174.545 seconds.
43
+ # after: Finished in 22.504 seconds.
44
+ end
45
+
46
+ def teardown! # MigrationSetup#teardown!
47
+ # speedup by creating tables once only on startup !
48
+ end
49
+
50
+ class DefaultNumber < ActiveRecord::Base; end
51
+
28
52
  def test_default_number_precision
29
- assert_equal 0.076, DefaultNumber.find(:first).value
53
+ assert_equal 0.076, DefaultNumber.first.value
30
54
  end
31
55
 
32
56
  def test_number_with_precision_and_scale
33
- assert_equal 1000.01, DefaultNumber.find(:first).fpoint
57
+ assert_equal 1000.01, DefaultNumber.first.fpoint
34
58
  end
35
59
 
36
60
  def test_number_with_precision
37
- assert_equal 1234, DefaultNumber.find(:first).value2
61
+ assert_equal 1234, DefaultNumber.first.value2
38
62
  end
39
63
 
40
64
  def test_number_type_with_precision_and_scale_is_reported_correctly
@@ -45,39 +69,66 @@ class OracleSpecificTest < Test::Unit::TestCase
45
69
 
46
70
  # JRUBY-3675, ACTIVERECORD_JDBC-22
47
71
  def test_load_date
48
- obj = DefaultNumber.find(:first)
72
+ obj = DefaultNumber.first
49
73
  assert_not_nil obj.datum, "no date"
50
74
  end
51
75
 
52
76
  # ACTIVERECORD_JDBC-127
53
77
  def test_save_date
54
- obj = DefaultNumber.find(:first)
78
+ obj = DefaultNumber.first
55
79
  obj.datum = '01Jan2010'
56
80
  obj.save!
57
81
  end
58
82
 
59
83
  def test_save_timestamp
60
- obj = DefaultNumber.find(:first)
84
+ obj = DefaultNumber.first
61
85
  obj.datum = Time.now
62
86
  obj.save!
63
87
  end
64
88
 
65
89
  def test_load_null_date
66
- @java_con.createStatement.execute "UPDATE DEFAULT_NUMBERS SET DATUM = NULL"
67
- obj = DefaultNumber.find(:first)
90
+ java_connection.createStatement.execute "UPDATE DEFAULT_NUMBERS SET DATUM = NULL"
91
+ obj = DefaultNumber.first
68
92
  assert obj.datum.nil?
69
93
  end
70
94
 
71
95
  def test_model_access_by_synonym
72
96
  @klass = Class.new(ActiveRecord::Base)
73
- @klass.table_name = "POSTS"
97
+ @klass.table_name = "POSTS" # alias
74
98
  entry_columns = Entry.columns_hash
75
99
  @klass.columns.each do |c|
76
- ec = entry_columns[c.name]
77
- assert ec
100
+ assert ec = entry_columns[c.name]
78
101
  assert_equal ec.sql_type, c.sql_type
79
102
  assert_equal ec.type, c.type
80
103
  end
81
104
  end
82
105
 
106
+ #
107
+
108
+ def test_oracle_identifier_lengths
109
+ assert_equal 30, connection.table_alias_length
110
+ assert_equal 30, connection.table_name_length
111
+ assert_equal 30, connection.index_name_length
112
+ assert_equal 30, connection.column_name_length
113
+ end
114
+
115
+ def test_current_user
116
+ puts "ORA current_user: #{connection.current_user}"
117
+ assert_instance_of String, connection.current_user
118
+ end
119
+
120
+ def test_current_database
121
+ puts "ORA current_database: #{connection.current_database}"
122
+ assert_instance_of String, connection.current_database
123
+ end
124
+
125
+ def test_current_schema
126
+ puts "ORA current_schema: #{connection.current_schema}"
127
+ assert_instance_of String, connection.current_schema
128
+ end
129
+
130
+ private
131
+
132
+ def java_connection; @@java_connection; end
133
+
83
134
  end if defined?(JRUBY_VERSION)
@@ -0,0 +1,6 @@
1
+ require 'db/postgres'
2
+ require 'binary'
3
+
4
+ class PostgresBinaryTest < Test::Unit::TestCase
5
+ include BinaryTestMethods
6
+ end
@@ -1,21 +1,22 @@
1
1
  require 'jdbc_common'
2
+ require 'db/postgres'
2
3
 
3
4
  class CreateNativeTypeMappingTestSchema < ActiveRecord::Migration
4
5
  def self.up
5
6
  execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
6
7
  execute "CREATE SEQUENCE seq_pk_customers"
7
8
  columns = [
8
- "bigint_serial_should_be_integer bigint default nextval('seq_pk_customers')",
9
- "integer_serial_should_be_integer integer default nextval('seq_pk_customers')",
10
- "varchar_should_be_string varchar(2)",
11
- "timestamp_should_be_datetime timestamp",
12
- "bytea_should_be_binary bytea",
13
- "double_precision_should_be_float double precision",
14
- "real_should_be_float real",
15
- "bool_should_be_boolean bool",
16
- "interval_should_be_string interval",
17
- "bigint_should_be_integer bigint"
18
- ]
9
+ "bigint_serial_should_be_integer bigint default nextval('seq_pk_customers')",
10
+ "integer_serial_should_be_integer integer default nextval('seq_pk_customers')",
11
+ "varchar_should_be_string varchar(2)",
12
+ "timestamp_should_be_datetime timestamp",
13
+ "bytea_should_be_binary bytea",
14
+ "double_precision_should_be_float double precision",
15
+ "real_should_be_float real",
16
+ "bool_should_be_boolean bool",
17
+ "interval_should_be_string interval",
18
+ "bigint_should_be_integer bigint"
19
+ ]
19
20
  columns << "uuid_should_be_string uuid" if PG_VERSION >= 80300
20
21
  table_sql = %Q{
21
22
  CREATE TABLE customers (
@@ -1,4 +1,5 @@
1
1
  require 'jdbc_common'
2
+ require 'db/postgres'
2
3
 
3
4
  class CreateUrls < ActiveRecord::Migration
4
5
  def self.up
@@ -1,4 +1,5 @@
1
1
  require 'jdbc_common'
2
+ require 'db/postgres'
2
3
  require 'models/reserved_word'
3
4
 
4
5
  class PostgresReservedWordsTest < Test::Unit::TestCase
@@ -1,4 +1,5 @@
1
1
  require 'jdbc_common'
2
+ require 'db/postgres'
2
3
 
3
4
  class PostgresResetColumnInformationTest < Test::Unit::TestCase
4
5
  include ResetColumnInformationTestMethods
@@ -0,0 +1,21 @@
1
+ require 'jdbc_common'
2
+ require 'db/postgres'
3
+ require 'row_locking'
4
+
5
+ class PostgresRowLockingTest < Test::Unit::TestCase
6
+ include MigrationSetup
7
+ include RowLockingTestMethods
8
+
9
+ def self.startup
10
+ MigrationSetup.setup!
11
+ end
12
+
13
+ def setup!; nil; end
14
+
15
+ def self.shutdown
16
+ MigrationSetup.teardown!
17
+ end
18
+
19
+ def teardown!; nil; end
20
+
21
+ end
@@ -0,0 +1,88 @@
1
+ require 'db/postgres'
2
+ require 'schema_dump'
3
+
4
+ class PostgresSchemaDumpTest < Test::Unit::TestCase
5
+ include SchemaDumpTestMethods
6
+
7
+ def self.startup
8
+ super
9
+ MigrationSetup.setup!
10
+ end
11
+
12
+ def self.shutdown
13
+ MigrationSetup.teardown!
14
+ super
15
+ end
16
+
17
+ def setup!; end # MigrationSetup#setup!
18
+ def teardown!; end # MigrationSetup#teardown!
19
+
20
+ def test_schema_dump_includes_xml_shorthand_definition
21
+ output = standard_dump
22
+ if %r{create_table "postgresql_xml_data_type"} =~ output
23
+ assert_match %r{t.xml "data"}, output
24
+ end
25
+ end
26
+
27
+ def test_schema_dump_includes_tsvector_shorthand_definition
28
+ output = standard_dump
29
+ if %r{create_table "postgresql_tsvectors"} =~ output
30
+ assert_match %r{t.tsvector "text_vector"}, output
31
+ end
32
+ end
33
+
34
+ #
35
+
36
+ # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
37
+ def test_schema_dump_should_not_have_limits_on_boolean
38
+ dump = dump_with_data_types
39
+ lines = dump.lines.grep(/boolean/)
40
+ assert ! lines.empty?, "no boolean type definition found in: #{dump}"
41
+ lines.each {|line| assert line !~ /limit/ }
42
+ end
43
+
44
+ def test_schema_dump_should_not_have_limits_on_binaries
45
+ dump = dump_with_data_types
46
+ lines = dump.lines.grep(/binary/)
47
+ assert ! lines.empty?, "no binary type definitions found in: #{dump}"
48
+ lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
49
+ end
50
+
51
+ # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
52
+ def test_schema_dump_should_not_have_limits_on_text_or_date
53
+ dump = dump_with_data_types
54
+ lines = dump.lines.grep(/date|text/)
55
+ assert ! lines.empty?
56
+ lines.each {|line| assert line !~ /limit/ }
57
+ end
58
+
59
+ def test_schema_dump_integer_with_no_limit_should_have_no_limit
60
+ dump = dump_with_data_types
61
+ lines = dump.lines.grep(/sample_integer_no_limit/)
62
+ assert ! lines.empty?
63
+ lines.each {|line| assert line !~ /:limit/ }
64
+ end
65
+
66
+ def test_schema_dump_integer_with_limit_2_should_have_limit_2
67
+ dump = dump_with_data_types
68
+ lines = dump.lines.grep(/sample_integer_with_limit_2/)
69
+ assert ! lines.empty?
70
+ lines.each {|line| assert line =~ /limit => 2/ }
71
+ end
72
+
73
+ def test_schema_dump_integer_with_limit_8_should_have_limit_8
74
+ dump = dump_with_data_types
75
+ lines = dump.lines.grep(/sample_integer_with_limit_8/)
76
+ assert ! lines.empty?
77
+ lines.each {|line| assert line =~ /limit => 8/ }
78
+ end
79
+
80
+ private
81
+
82
+ def dump_with_data_types(io = StringIO.new)
83
+ ActiveRecord::SchemaDumper.ignore_tables = [/^[^d]/] # keep data_types
84
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io)
85
+ io.string
86
+ end
87
+
88
+ end
@@ -1,4 +1,5 @@
1
1
  require 'jdbc_common'
2
+ require 'db/postgres'
2
3
 
3
4
  class CreateSchema < ActiveRecord::Migration
4
5
  def self.up
@@ -5,69 +5,77 @@
5
5
  #
6
6
 
7
7
  require 'jdbc_common'
8
+ require 'db/postgres'
8
9
 
9
10
  class PostgresSimpleTest < Test::Unit::TestCase
10
11
  include SimpleTestMethods
11
12
  include ActiveRecord3TestMethods
12
13
  include ColumnNameQuotingTests
14
+ include XmlColumnTests
13
15
 
14
16
  def test_adapter_class_name_equals_native_adapter_class_name
15
- classname = @connection.class.name[/[^:]*$/]
17
+ classname = connection.class.name[/[^:]*$/]
16
18
  assert_equal 'PostgreSQLAdapter', classname
17
19
  end
18
20
 
19
21
  def test_schema_search_path
20
- assert_equal @connection.schema_search_path, "\"$user\",public"
22
+ assert_equal connection.schema_search_path, "\"$user\",public"
21
23
  end
22
24
 
23
25
  def test_current_schema
24
- assert_equal @connection.current_schema, "public"
26
+ assert_equal connection.current_schema, "public"
25
27
  end
26
28
 
27
29
  def test_encoding
28
- assert_not_nil @connection.encoding
30
+ assert_not_nil connection.encoding
29
31
  end
30
32
 
31
33
  def test_multi_statement_support
32
- results = @connection.execute "SELECT title from entries; SELECT login from users"
34
+ results = connection.execute "SELECT title from entries; SELECT login from users"
33
35
  assert_equal 2, results.length
34
36
  assert_equal ["title"], results[0].first.keys
35
37
  assert_equal ["login"], results[1].first.keys
36
38
  end
37
39
 
40
+ def test_find_by_sql_WITH_statement
41
+ user = User.create! :login => 'ferko'
42
+ Entry.create! :title => 'aaa', :user_id => user.id
43
+ entries = Entry.find_by_sql '' +
44
+ '( ' +
45
+ 'WITH EntryAndUser (title, login, updated_on) AS ' +
46
+ ' ( ' +
47
+ ' SELECT e.title, u.login, e.updated_on ' +
48
+ ' FROM entries e INNER JOIN users u ON e.user_id = u.id ' +
49
+ ' ) ' +
50
+ 'SELECT * FROM EntryAndUser ORDER BY title ASC ' +
51
+ ') '
52
+ assert entries.first
53
+ assert entries.first.title
54
+ assert entries.first.login
55
+ end
56
+
38
57
  def test_create_xml_column
39
58
  return unless PG_VERSION >= 80300
40
- assert_nothing_raised do
41
- @connection.create_table :xml_testings do |t|
42
- t.column :xml_test, :xml
43
- end
44
- end
45
-
46
- xml_test = @connection.columns(:xml_testings).detect do
47
- |c| c.name == "xml_test"
48
- end
49
-
50
- assert_equal "xml", xml_test.sql_type
51
- ensure
52
- @connection.drop_table :xml_testings rescue nil
53
- end
54
-
59
+ super
60
+ end if ar_version('3.1')
61
+ def xml_sql_type; 'xml'; end
62
+
55
63
  def test_create_table_with_limits
56
64
  assert_nothing_raised do
57
- @connection.create_table :testings do |t|
65
+ connection.create_table :testings do |t|
58
66
  t.column :eleven_int, :integer, :limit => 11
59
67
  end
60
68
  end
61
69
 
62
- columns = @connection.columns(:testings)
70
+ columns = connection.columns(:testings)
63
71
  eleven = columns.detect { |c| c.name == "eleven_int" }
64
72
  assert_equal "integer", eleven.sql_type
65
73
  ensure
66
- @connection.drop_table :testings rescue nil
74
+ connection.drop_table :testings rescue nil
67
75
  end
68
76
 
69
77
  def test_supports_standard_conforming_string
70
- assert([true, false].include?(@connection.supports_standard_conforming_strings?))
78
+ assert([true, false].include?(connection.supports_standard_conforming_strings?))
71
79
  end
72
80
 
73
81
  def test_standard_conforming_string_default_set_on_new_connections
@@ -76,34 +84,38 @@ class PostgresSimpleTest < Test::Unit::TestCase
76
84
  end
77
85
 
78
86
  def test_default_standard_conforming_string
79
- if @connection.supports_standard_conforming_strings?
80
- assert_equal true, @connection.standard_conforming_strings?
87
+ if connection.supports_standard_conforming_strings?
88
+ assert_equal true, connection.standard_conforming_strings?
81
89
  else
82
- assert_equal false, @connection.standard_conforming_strings?
90
+ assert_equal false, connection.standard_conforming_strings?
83
91
  end
84
92
  end
85
93
 
86
94
  def test_string_quoting_with_standard_conforming_strings
87
- if @connection.supports_standard_conforming_strings?
95
+ if connection.supports_standard_conforming_strings?
88
96
  s = "\\m it's \\M"
89
- assert_equal "'\\m it''s \\M'", @connection.quote(s)
97
+ assert_equal "'\\m it''s \\M'", connection.quote(s)
90
98
  end
91
99
  end
92
100
 
93
101
  def test_string_quoting_without_standard_conforming_strings
94
- @connection.standard_conforming_strings = false
102
+ connection.standard_conforming_strings = false
95
103
  s = "\\m it's \\M"
96
- assert_equal "'\\\\m it''s \\\\M'", @connection.quote(s)
97
- @connection.standard_conforming_strings = true
104
+ assert_equal "'\\\\m it''s \\\\M'", connection.quote(s)
105
+ connection.standard_conforming_strings = true
98
106
  end
107
+
108
+ include ExplainSupportTestMethods if ar_version("3.1")
109
+
99
110
  end
100
111
 
101
112
  class PostgresTimestampTest < Test::Unit::TestCase
102
- def setup
113
+
114
+ def self.startup
103
115
  DbTypeMigration.up
104
116
  end
105
117
 
106
- def teardown
118
+ def self.shutdown
107
119
  DbTypeMigration.down
108
120
  end
109
121
 
@@ -128,19 +140,29 @@ class PostgresTimestampTest < Test::Unit::TestCase
128
140
 
129
141
  def test_save_infinity_and_beyond
130
142
  d = DbType.create!(:sample_timestamp => 1.0 / 0.0)
131
- assert_equal(1.0 / 0.0, d.sample_timestamp)
143
+ if ar_version('3.0')
144
+ assert_equal(1.0 / 0.0, d.sample_timestamp)
145
+ else # 2.3
146
+ assert_equal(nil, d.sample_timestamp)
147
+ end
132
148
 
133
149
  e = DbType.create!(:sample_timestamp => -1.0 / 0.0)
134
- assert_equal(-1.0 / 0.0, e.sample_timestamp)
150
+ if ar_version('3.0')
151
+ assert_equal(-1.0 / 0.0, e.sample_timestamp)
152
+ else # 2.3
153
+ assert_equal(nil, e.sample_timestamp)
154
+ end
135
155
  end
156
+
136
157
  end
137
158
 
138
159
  class PostgresDeserializationTest < Test::Unit::TestCase
139
- def setup
160
+
161
+ def self.startup
140
162
  DbTypeMigration.up
141
163
  end
142
164
 
143
- def teardown
165
+ def self.shutdown
144
166
  DbTypeMigration.down
145
167
  end
146
168
 
@@ -152,55 +174,6 @@ class PostgresDeserializationTest < Test::Unit::TestCase
152
174
  end
153
175
  end
154
176
 
155
- class PostgresSchemaDumperTest < Test::Unit::TestCase
156
- def setup
157
- DbTypeMigration.up
158
- @connection = ActiveRecord::Base.connection
159
- strio = StringIO.new
160
- ActiveRecord::SchemaDumper::dump(ActiveRecord::Base.connection, strio)
161
- @dump = strio.string
162
- end
163
-
164
- def teardown
165
- DbTypeMigration.down
166
- end
167
-
168
- # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
169
- def test_schema_dump_should_not_have_limits_on_boolean
170
- lines = @dump.lines.grep(/boolean/)
171
- assert !lines.empty?
172
- lines.each {|line| assert line !~ /limit/ }
173
- end
174
-
175
-
176
- def test_schema_dump_should_not_have_limits_on_binaries
177
- lines = @dump.lines.grep(/binary/)
178
- assert !lines.empty?, 'no binary type definitions found'
179
- lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
180
- end
181
-
182
- # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
183
- def test_schema_dump_should_not_have_limits_on_text_or_date
184
- lines = @dump.lines.grep(/date|text/)
185
- assert !lines.empty?
186
- lines.each {|line| assert line !~ /limit/ }
187
- end
188
-
189
- def test_schema_dump_integer_with_no_limit_should_have_no_limit
190
- lines = @dump.lines.grep(/sample_integer_no_limit/)
191
- assert !lines.empty?
192
- lines.each {|line| assert line !~ /:limit/ }
193
- end
194
-
195
- def test_schema_dump_integer_with_limit_2_should_have_limit_2
196
- lines = @dump.lines.grep(/sample_integer_with_limit_2/)
197
- assert !lines.empty?
198
- lines.each {|line| assert line =~ /limit => 2/ }
199
- end
200
-
201
- def test_schema_dump_integer_with_limit_8_should_have_limit_8
202
- lines = @dump.lines.grep(/sample_integer_with_limit_8/)
203
- assert !lines.empty?
204
- lines.each {|line| assert line =~ /limit => 8/ }
205
- end
177
+ class PostgresHasManyThroughTest < Test::Unit::TestCase
178
+ include HasManyThroughMethods
206
179
  end