activerecord-jdbc-adapter 1.3.0.beta2 → 1.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. data/.gitignore +14 -8
  2. data/.travis.yml +40 -31
  3. data/.yardopts +4 -0
  4. data/Appraisals +2 -5
  5. data/CONTRIBUTING.md +46 -0
  6. data/Gemfile +21 -4
  7. data/Gemfile.lock +42 -17
  8. data/{History.txt → History.md} +142 -75
  9. data/README.md +102 -104
  10. data/RUNNING_TESTS.md +76 -0
  11. data/Rakefile.jdbc +20 -0
  12. data/activerecord-jdbc-adapter.gemspec +35 -18
  13. data/gemfiles/rails23.gemfile +4 -3
  14. data/gemfiles/rails23.gemfile.lock +9 -6
  15. data/gemfiles/rails30.gemfile +4 -3
  16. data/gemfiles/rails30.gemfile.lock +9 -6
  17. data/gemfiles/rails31.gemfile +4 -3
  18. data/gemfiles/rails31.gemfile.lock +9 -6
  19. data/gemfiles/rails32.gemfile +4 -3
  20. data/gemfiles/rails32.gemfile.lock +17 -14
  21. data/gemfiles/rails40.gemfile +5 -5
  22. data/gemfiles/rails40.gemfile.lock +17 -69
  23. data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
  24. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
  25. data/lib/arel/visitors/compat.rb +22 -3
  26. data/lib/arel/visitors/db2.rb +8 -4
  27. data/lib/arel/visitors/derby.rb +14 -13
  28. data/lib/arel/visitors/firebird.rb +5 -4
  29. data/lib/arel/visitors/hsqldb.rb +11 -9
  30. data/lib/arel/visitors/sql_server.rb +89 -61
  31. data/lib/arjdbc.rb +1 -1
  32. data/lib/arjdbc/db2/adapter.rb +181 -212
  33. data/lib/arjdbc/db2/as400.rb +31 -18
  34. data/lib/arjdbc/db2/column.rb +167 -0
  35. data/lib/arjdbc/db2/connection_methods.rb +2 -0
  36. data/lib/arjdbc/derby/adapter.rb +206 -107
  37. data/lib/arjdbc/derby/connection_methods.rb +4 -9
  38. data/lib/arjdbc/firebird.rb +1 -0
  39. data/lib/arjdbc/firebird/adapter.rb +202 -64
  40. data/lib/arjdbc/firebird/connection_methods.rb +20 -0
  41. data/lib/arjdbc/h2/adapter.rb +56 -36
  42. data/lib/arjdbc/hsqldb/adapter.rb +99 -68
  43. data/lib/arjdbc/jdbc/adapter.rb +474 -265
  44. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  45. data/lib/arjdbc/jdbc/adapter_require.rb +8 -7
  46. data/lib/arjdbc/jdbc/arel_support.rb +132 -0
  47. data/lib/arjdbc/jdbc/base_ext.rb +8 -7
  48. data/lib/arjdbc/jdbc/callbacks.rb +16 -10
  49. data/lib/arjdbc/jdbc/column.rb +25 -3
  50. data/lib/arjdbc/jdbc/connection.rb +28 -55
  51. data/lib/arjdbc/jdbc/extension.rb +14 -14
  52. data/lib/arjdbc/jdbc/java.rb +6 -3
  53. data/lib/arjdbc/jdbc/jdbc.rake +1 -1
  54. data/lib/arjdbc/jdbc/quoted_primary_key.rb +2 -2
  55. data/lib/arjdbc/jdbc/rake_tasks.rb +1 -1
  56. data/lib/arjdbc/jdbc/type_converter.rb +5 -2
  57. data/lib/arjdbc/mssql/adapter.rb +160 -280
  58. data/lib/arjdbc/mssql/column.rb +182 -0
  59. data/lib/arjdbc/mssql/connection_methods.rb +37 -4
  60. data/lib/arjdbc/mssql/explain_support.rb +13 -21
  61. data/lib/arjdbc/mssql/limit_helpers.rb +79 -42
  62. data/lib/arjdbc/mssql/lock_methods.rb +77 -0
  63. data/lib/arjdbc/mssql/utils.rb +11 -11
  64. data/lib/arjdbc/mysql/adapter.rb +165 -247
  65. data/lib/arjdbc/mysql/column.rb +123 -0
  66. data/lib/arjdbc/mysql/connection_methods.rb +3 -6
  67. data/lib/arjdbc/oracle/adapter.rb +282 -288
  68. data/lib/arjdbc/oracle/column.rb +122 -0
  69. data/lib/arjdbc/oracle/connection_methods.rb +3 -0
  70. data/lib/arjdbc/postgresql/adapter.rb +336 -574
  71. data/lib/arjdbc/postgresql/column.rb +458 -0
  72. data/lib/arjdbc/postgresql/connection_methods.rb +1 -2
  73. data/lib/arjdbc/postgresql/schema_creation.rb +38 -0
  74. data/lib/arjdbc/sqlite3/adapter.rb +189 -145
  75. data/lib/arjdbc/sqlite3/explain_support.rb +1 -1
  76. data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +8 -8
  77. data/lib/arjdbc/util/quoted_cache.rb +60 -0
  78. data/lib/arjdbc/util/table_copier.rb +110 -0
  79. data/lib/arjdbc/version.rb +6 -7
  80. data/pom.xml +56 -2
  81. data/rakelib/02-test.rake +72 -83
  82. data/rakelib/db.rake +29 -17
  83. data/src/java/arjdbc/ArJdbcModule.java +21 -18
  84. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +84 -12
  85. data/src/java/arjdbc/derby/DerbyModule.java +140 -143
  86. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +58 -7
  87. data/src/java/arjdbc/h2/H2Module.java +43 -0
  88. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
  89. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1223 -648
  90. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +24 -23
  91. data/src/java/arjdbc/mysql/MySQLModule.java +33 -32
  92. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +147 -30
  93. data/src/java/arjdbc/oracle/OracleModule.java +13 -13
  94. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +114 -6
  95. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +166 -36
  96. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +101 -19
  97. data/src/java/arjdbc/util/QuotingUtils.java +19 -19
  98. metadata +240 -394
  99. data/bench/bench_attributes.rb +0 -13
  100. data/bench/bench_attributes_new.rb +0 -14
  101. data/bench/bench_create.rb +0 -12
  102. data/bench/bench_find_all.rb +0 -12
  103. data/bench/bench_find_all_mt.rb +0 -25
  104. data/bench/bench_model.rb +0 -85
  105. data/bench/bench_new.rb +0 -12
  106. data/bench/bench_new_valid.rb +0 -12
  107. data/bench/bench_valid.rb +0 -13
  108. data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
  109. data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
  110. data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
  111. data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
  112. data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
  113. data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
  114. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -98
  115. data/lib/arjdbc/mssql/lock_helpers.rb +0 -76
  116. data/lib/arjdbc/mssql/tsql_methods.rb +0 -58
  117. data/lib/arjdbc/postgresql/column_cast.rb +0 -134
  118. data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
  119. data/test/activerecord/jall.sh +0 -7
  120. data/test/activerecord/jtest.sh +0 -3
  121. data/test/assets/flowers.jpg +0 -0
  122. data/test/binary.rb +0 -67
  123. data/test/db/db2.rb +0 -43
  124. data/test/db/db2/binary_test.rb +0 -6
  125. data/test/db/db2/has_many_through_test.rb +0 -6
  126. data/test/db/db2/rake_test.rb +0 -82
  127. data/test/db/db2/rake_test_data.sql +0 -35
  128. data/test/db/db2/reset_column_information_test.rb +0 -5
  129. data/test/db/db2/serialize_test.rb +0 -6
  130. data/test/db/db2/simple_test.rb +0 -81
  131. data/test/db/db2/test_helper.rb +0 -6
  132. data/test/db/db2/unit_test.rb +0 -73
  133. data/test/db/derby.rb +0 -12
  134. data/test/db/derby/binary_test.rb +0 -6
  135. data/test/db/derby/migration_test.rb +0 -74
  136. data/test/db/derby/rake_test.rb +0 -96
  137. data/test/db/derby/reset_column_information_test.rb +0 -6
  138. data/test/db/derby/row_locking_test.rb +0 -20
  139. data/test/db/derby/schema_dump_test.rb +0 -5
  140. data/test/db/derby/serialize_test.rb +0 -6
  141. data/test/db/derby/simple_test.rb +0 -173
  142. data/test/db/derby/test_helper.rb +0 -6
  143. data/test/db/derby/unit_test.rb +0 -32
  144. data/test/db/derby/xml_column_test.rb +0 -17
  145. data/test/db/h2.rb +0 -11
  146. data/test/db/h2/binary_test.rb +0 -6
  147. data/test/db/h2/change_column_test.rb +0 -68
  148. data/test/db/h2/identity_column_test.rb +0 -35
  149. data/test/db/h2/offset_test.rb +0 -49
  150. data/test/db/h2/rake_test.rb +0 -98
  151. data/test/db/h2/schema_dump_test.rb +0 -29
  152. data/test/db/h2/serialize_test.rb +0 -6
  153. data/test/db/h2/simple_test.rb +0 -56
  154. data/test/db/hsqldb.rb +0 -11
  155. data/test/db/hsqldb/binary_test.rb +0 -6
  156. data/test/db/hsqldb/rake_test.rb +0 -101
  157. data/test/db/hsqldb/schema_dump_test.rb +0 -19
  158. data/test/db/hsqldb/serialize_test.rb +0 -6
  159. data/test/db/hsqldb/simple_test.rb +0 -17
  160. data/test/db/informix.rb +0 -13
  161. data/test/db/jdbc.rb +0 -16
  162. data/test/db/jdbc_derby.rb +0 -14
  163. data/test/db/jdbc_h2.rb +0 -17
  164. data/test/db/jdbc_mysql.rb +0 -13
  165. data/test/db/jdbc_postgres.rb +0 -23
  166. data/test/db/jndi_config.rb +0 -32
  167. data/test/db/jndi_pooled_config.rb +0 -32
  168. data/test/db/mssql.rb +0 -11
  169. data/test/db/mssql/binary_test.rb +0 -6
  170. data/test/db/mssql/exec_proc_test.rb +0 -46
  171. data/test/db/mssql/identity_insert_test.rb +0 -18
  172. data/test/db/mssql/ignore_system_views_test.rb +0 -40
  173. data/test/db/mssql/limit_offset_test.rb +0 -190
  174. data/test/db/mssql/multibyte_test.rb +0 -16
  175. data/test/db/mssql/multiple_connections_test.rb +0 -71
  176. data/test/db/mssql/rake_test.rb +0 -143
  177. data/test/db/mssql/reset_column_information_test.rb +0 -6
  178. data/test/db/mssql/row_locking_test.rb +0 -7
  179. data/test/db/mssql/serialize_test.rb +0 -6
  180. data/test/db/mssql/simple_test.rb +0 -140
  181. data/test/db/mssql/transaction_test.rb +0 -6
  182. data/test/db/mssql/types_test.rb +0 -205
  183. data/test/db/mssql/unit_test.rb +0 -249
  184. data/test/db/mysql.rb +0 -4
  185. data/test/db/mysql/_rails_test_mysql.32.out +0 -6585
  186. data/test/db/mysql/binary_test.rb +0 -6
  187. data/test/db/mysql/connection_test.rb +0 -51
  188. data/test/db/mysql/index_length_test.rb +0 -58
  189. data/test/db/mysql/multibyte_test.rb +0 -10
  190. data/test/db/mysql/nonstandard_primary_key_test.rb +0 -39
  191. data/test/db/mysql/rake_test.rb +0 -97
  192. data/test/db/mysql/reset_column_information_test.rb +0 -6
  193. data/test/db/mysql/schema_dump_test.rb +0 -228
  194. data/test/db/mysql/serialize_test.rb +0 -6
  195. data/test/db/mysql/simple_test.rb +0 -187
  196. data/test/db/mysql/statement_escaping_test.rb +0 -46
  197. data/test/db/mysql/transaction_test.rb +0 -6
  198. data/test/db/mysql/types_test.rb +0 -30
  199. data/test/db/mysql/unit_test.rb +0 -93
  200. data/test/db/mysql_config.rb +0 -7
  201. data/test/db/oracle.rb +0 -27
  202. data/test/db/oracle/binary_test.rb +0 -6
  203. data/test/db/oracle/limit_test.rb +0 -24
  204. data/test/db/oracle/multibyte_test.rb +0 -22
  205. data/test/db/oracle/rake_test.rb +0 -100
  206. data/test/db/oracle/reset_column_information_test.rb +0 -6
  207. data/test/db/oracle/serialize_test.rb +0 -6
  208. data/test/db/oracle/simple_test.rb +0 -140
  209. data/test/db/oracle/specific_test.rb +0 -180
  210. data/test/db/oracle/transaction_test.rb +0 -31
  211. data/test/db/oracle/unit_test.rb +0 -31
  212. data/test/db/postgres.rb +0 -11
  213. data/test/db/postgres/_rails_test_postgres.32.out +0 -6405
  214. data/test/db/postgres/a_custom_primary_key_test.rb +0 -50
  215. data/test/db/postgres/active_schema_unit_test.rb +0 -68
  216. data/test/db/postgres/array_type_test.rb +0 -101
  217. data/test/db/postgres/binary_test.rb +0 -6
  218. data/test/db/postgres/connection_test.rb +0 -63
  219. data/test/db/postgres/data_types_test.rb +0 -703
  220. data/test/db/postgres/hstore_test.rb +0 -200
  221. data/test/db/postgres/information_schema_leak_test.rb +0 -30
  222. data/test/db/postgres/json_test.rb +0 -86
  223. data/test/db/postgres/ltree_test.rb +0 -51
  224. data/test/db/postgres/mixed_case_test.rb +0 -29
  225. data/test/db/postgres/native_types_test.rb +0 -124
  226. data/test/db/postgres/rake_test.rb +0 -117
  227. data/test/db/postgres/reserved_test.rb +0 -22
  228. data/test/db/postgres/reset_column_information_test.rb +0 -6
  229. data/test/db/postgres/row_locking_test.rb +0 -21
  230. data/test/db/postgres/schema_dump_test.rb +0 -95
  231. data/test/db/postgres/schema_test.rb +0 -115
  232. data/test/db/postgres/simple_test.rb +0 -260
  233. data/test/db/postgres/table_alias_length_test.rb +0 -16
  234. data/test/db/postgres/transaction_test.rb +0 -6
  235. data/test/db/postgres/unit_test.rb +0 -31
  236. data/test/db/postgres_config.rb +0 -10
  237. data/test/db/sqlite3.rb +0 -6
  238. data/test/db/sqlite3/_rails_test_sqlite3.32.out +0 -6274
  239. data/test/db/sqlite3/has_many_though_test.rb +0 -6
  240. data/test/db/sqlite3/rake_test.rb +0 -71
  241. data/test/db/sqlite3/reset_column_information_test.rb +0 -6
  242. data/test/db/sqlite3/schema_dump_test.rb +0 -6
  243. data/test/db/sqlite3/serialize_test.rb +0 -6
  244. data/test/db/sqlite3/simple_test.rb +0 -268
  245. data/test/db/sqlite3/transaction_test.rb +0 -32
  246. data/test/db/sqlite3/type_conversion_test.rb +0 -104
  247. data/test/has_many_through.rb +0 -61
  248. data/test/informix_simple_test.rb +0 -48
  249. data/test/jdbc/db2.rb +0 -36
  250. data/test/jdbc/oracle.rb +0 -34
  251. data/test/jdbc_column_test.rb +0 -23
  252. data/test/jdbc_common.rb +0 -16
  253. data/test/jdbc_connection_test.rb +0 -196
  254. data/test/jndi_callbacks_test.rb +0 -33
  255. data/test/jndi_test.rb +0 -55
  256. data/test/manualTestDatabase.rb +0 -191
  257. data/test/models/add_not_null_column_to_table.rb +0 -9
  258. data/test/models/auto_id.rb +0 -15
  259. data/test/models/binary.rb +0 -18
  260. data/test/models/custom_pk_name.rb +0 -15
  261. data/test/models/data_types.rb +0 -40
  262. data/test/models/entry.rb +0 -41
  263. data/test/models/mixed_case.rb +0 -22
  264. data/test/models/reserved_word.rb +0 -15
  265. data/test/models/rights_and_roles.rb +0 -57
  266. data/test/models/string_id.rb +0 -17
  267. data/test/models/thing.rb +0 -17
  268. data/test/models/topic.rb +0 -32
  269. data/test/models/validates_uniqueness_of_string.rb +0 -19
  270. data/test/rails/mysql.rb +0 -13
  271. data/test/rails/sqlite3/version.rb +0 -6
  272. data/test/rails_stub.rb +0 -31
  273. data/test/rake_test_support.rb +0 -298
  274. data/test/row_locking.rb +0 -102
  275. data/test/schema_dump.rb +0 -182
  276. data/test/serialize.rb +0 -275
  277. data/test/shared_helper.rb +0 -35
  278. data/test/simple.rb +0 -1317
  279. data/test/sybase_jtds_simple_test.rb +0 -28
  280. data/test/sybase_reset_column_information_test.rb +0 -6
  281. data/test/test_helper.rb +0 -304
  282. data/test/transaction.rb +0 -109
@@ -1,117 +0,0 @@
1
- require 'rake_test_support'
2
- require 'db/postgres'
3
-
4
- class PostgresRakeTest < Test::Unit::TestCase
5
- include RakeTestSupport
6
-
7
- def db_config
8
- POSTGRES_CONFIG
9
- end
10
-
11
- def do_teardown
12
- drop_rake_test_database(:silence)
13
- end
14
-
15
- PSQL_EXECUTABLE = find_executable?("psql")
16
-
17
- test 'rake db:create (and db:drop)' do
18
- Rake::Task["db:create"].invoke
19
- if PSQL_EXECUTABLE
20
- output = psql("-d template1 -c '\\\l'")
21
- assert_match /#{db_name}/m, output
22
- end
23
-
24
- Rake::Task["db:drop"].invoke
25
- if PSQL_EXECUTABLE
26
- output = psql("-d template1 -c '\\\l'")
27
- assert_no_match /#{db_name}/m, output
28
- end
29
- end
30
-
31
- test 'rake db:drop (non-existing database)' do
32
- drop_rake_test_database(:silence)
33
- Rake::Task["db:drop"].invoke
34
- end
35
-
36
- test 'rake db:test:purge' do
37
- # Rake::Task["db:create"].invoke
38
- create_rake_test_database do |connection|
39
- connection.create_table('users') { |t| t.string :name }
40
- end
41
-
42
- Rake::Task["db:test:purge"].invoke
43
-
44
- ActiveRecord::Base.establish_connection db_config.merge :database => db_name
45
- assert_false ActiveRecord::Base.connection.table_exists?('users')
46
- ActiveRecord::Base.connection.disconnect!
47
- end
48
-
49
- test 'rake db:charset' do
50
- create_rake_test_database
51
- expect_rake_output 'UTF8'
52
- Rake::Task["db:charset"].invoke
53
- end
54
-
55
- test 'rake db:collation' do
56
- create_rake_test_database
57
- expect_rake_output /\w*?\.UTF-8/ # en_US.UTF-8
58
- Rake::Task["db:collation"].invoke
59
- end
60
-
61
- test 'rake db:structure:dump (and db:structure:load)' do
62
- omit('pg_dump not available') unless self.class.find_executable?('pg_dump')
63
- # Rake::Task["db:create"].invoke
64
- create_rake_test_database do |connection|
65
- create_schema_migrations_table(connection)
66
- connection.create_table('users') { |t| t.string :name; t.timestamps }
67
- end
68
-
69
- structure_sql = File.join('db', structure_sql_filename)
70
- begin
71
- Dir.mkdir 'db' # db/structure.sql
72
- Rake::Task["db:structure:dump"].invoke
73
-
74
- assert File.exists?(structure_sql)
75
- assert_match /CREATE TABLE users/, File.read(structure_sql)
76
-
77
- # db:structure:load
78
- drop_rake_test_database(:silence)
79
- create_rake_test_database
80
- Rake::Task["db:structure:load"].invoke
81
-
82
- ActiveRecord::Base.establish_connection db_config.merge :database => db_name
83
- assert ActiveRecord::Base.connection.table_exists?('users')
84
- ActiveRecord::Base.connection.disconnect!
85
- ensure
86
- File.delete(structure_sql) if File.exists?(structure_sql)
87
- Dir.rmdir 'db'
88
- end
89
- end
90
-
91
- setup { rm_r 'db' if File.exist?('db') }
92
-
93
- test 'rake db:create does not load full environment' do
94
- begin
95
- Rake::Task["db:create"].invoke
96
- assert @rails_env_set
97
- assert ! ( @full_environment_loaded ||= nil )
98
- ensure
99
- # Rake::Task["db:drop"].invoke rescue nil
100
- drop_rake_test_database(:silence)
101
- end
102
- end if ActiveRecord::VERSION::MAJOR < 4
103
-
104
- private
105
-
106
- def psql(args)
107
- args = args.join(' ') unless args.is_a?(String)
108
- if db_config[:host] != 'localhost'
109
- args = "--host=#{db_config[:host]} #{args}"
110
- end
111
- if username = ENV['PSQL_USERNAME']
112
- args = "--username=#{username} #{args}"
113
- end
114
- `psql #{args}`
115
- end
116
-
117
- end
@@ -1,22 +0,0 @@
1
- require 'jdbc_common'
2
- require 'db/postgres'
3
- require 'models/reserved_word'
4
-
5
- class PostgresReservedWordsTest < Test::Unit::TestCase
6
- def setup
7
- CreateReservedWords.up
8
- end
9
- def teardown
10
- CreateReservedWords.down
11
- end
12
-
13
- def test_quote_reserved_word_column
14
- columns = ReservedWord.column_names - ["id"]
15
- ReservedWord.connection.add_index :reserved_words, columns
16
- indexes = ReservedWord.connection.indexes("reserved_words")
17
- assert_equal 1, indexes.size
18
- columns.each do |c|
19
- assert indexes[0].columns.include?(c), "#{indexes[0].columns.inspect} does not include #{c.inspect}"
20
- end
21
- end
22
- end
@@ -1,6 +0,0 @@
1
- require 'jdbc_common'
2
- require 'db/postgres'
3
-
4
- class PostgresResetColumnInformationTest < Test::Unit::TestCase
5
- include ResetColumnInformationTestMethods
6
- end
@@ -1,21 +0,0 @@
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
@@ -1,95 +0,0 @@
1
- # encoding: utf-8
2
- require 'db/postgres'
3
- require 'schema_dump'
4
-
5
- class PostgresSchemaDumpTest < Test::Unit::TestCase
6
- include SchemaDumpTestMethods
7
-
8
- def self.startup
9
- super
10
- MigrationSetup.setup!
11
- end
12
-
13
- def self.shutdown
14
- MigrationSetup.teardown!
15
- super
16
- end
17
-
18
- def setup!; end # MigrationSetup#setup!
19
- def teardown!; end # MigrationSetup#teardown!
20
-
21
- def test_schema_dump_includes_xml_shorthand_definition
22
- output = standard_dump
23
- if %r{create_table "postgresql_xml_data_type"} =~ output
24
- assert_match %r{t.xml "data"}, output
25
- end
26
- end
27
-
28
- def test_schema_dump_includes_tsvector_shorthand_definition
29
- output = standard_dump
30
- if %r{create_table "postgresql_tsvectors"} =~ output
31
- assert_match %r{t.tsvector "text_vector"}, output
32
- end
33
- end
34
-
35
- #
36
-
37
- # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-135
38
- def test_schema_dump_should_not_have_limits_on_boolean
39
- dump = dump_with_data_types
40
- lines = dump.lines.grep(/boolean/)
41
- assert ! lines.empty?, "no boolean type definition found in: #{dump}"
42
- lines.each {|line| assert line !~ /limit/ }
43
- end
44
-
45
- def test_schema_dump_should_not_have_limits_on_binaries
46
- dump = dump_with_data_types
47
- lines = dump.lines.grep(/binary/)
48
- assert ! lines.empty?, "no binary type definitions found in: #{dump}"
49
- lines.each {|line| assert line !~ /limit/, 'binary definition contains limit' }
50
- end
51
-
52
- # http://kenai.com/jira/browse/ACTIVERECORD_JDBC-139
53
- def test_schema_dump_should_not_have_limits_on_text_or_date
54
- dump = dump_with_data_types
55
- lines = dump.lines.grep(/date|text/)
56
- assert ! lines.empty?
57
- lines.each {|line| assert line !~ /limit/ }
58
- end
59
-
60
- def test_schema_dump_integer_with_no_limit_should_have_no_limit
61
- dump = dump_with_data_types
62
- lines = dump.lines.grep(/sample_integer_no_limit/)
63
- assert ! lines.empty?
64
- lines.each { |line| assert line !~ /:limit|limit:/ }
65
- end
66
-
67
- def test_schema_dump_integer_with_limit_2_should_have_limit_2
68
- dump = dump_with_data_types
69
- lines = dump.lines.grep(/sample_integer_with_limit_2/)
70
- assert ! lines.empty?
71
- lines.each {|line| assert line =~ /(limit => 2)|(limit: 2)/ }
72
- end
73
-
74
- def test_schema_dump_integer_with_limit_8_should_have_limit_8
75
- dump = dump_with_data_types
76
- lines = dump.lines.grep(/sample_integer_with_limit_8/)
77
- assert ! lines.empty?
78
- lines.each {|line| assert line =~ /(limit => 8)|(limit: 8)/ }
79
- end
80
-
81
- def test_schema_dumps_partial_indices
82
- index_definition = standard_dump.split(/\n/).grep(/add_index.*thing_partial_index/).first.strip
83
-
84
- assert_equal 'add_index "things", ["created_at"], name: "thing_partial_index", where: "(name IS NOT NULL)", using: :btree', index_definition
85
- end if ar_version('4.0')
86
-
87
- private
88
-
89
- def dump_with_data_types(io = StringIO.new)
90
- ActiveRecord::SchemaDumper.ignore_tables = [/^[^d]/] # keep data_types
91
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io)
92
- io.string
93
- end
94
-
95
- end
@@ -1,115 +0,0 @@
1
- require 'test_helper'
2
- require 'db/postgres'
3
-
4
- class PostgresSchemaTest < Test::Unit::TestCase
5
-
6
- def test_create_schema
7
- begin
8
- connection.create_schema "test_schema3"
9
- assert connection.schema_names.include? "test_schema3"
10
- ensure
11
- connection.drop_schema "test_schema3"
12
- end
13
- end
14
-
15
- def test_raise_create_schema_with_existing_schema
16
- begin
17
- connection.create_schema "test_schema3"
18
- disable_logger(connection) do
19
- assert_raise(ActiveRecord::StatementInvalid) do
20
- connection.create_schema "test_schema3"
21
- end
22
- end
23
- ensure
24
- connection.drop_schema "test_schema3"
25
- end
26
- end
27
-
28
- def test_drop_schema
29
- begin
30
- connection.create_schema "test_schema3"
31
- ensure
32
- connection.drop_schema "test_schema3"
33
- end
34
- assert ! connection.schema_names.include?("test_schema3")
35
- end
36
-
37
- def test_collation
38
- assert_equal 'en_US.UTF-8', connection.collation
39
- end
40
-
41
- def test_encoding
42
- assert_equal 'UTF8', connection.encoding
43
- end
44
-
45
- def test_ctype
46
- assert connection.ctype
47
- end
48
-
49
- def test_current_database
50
- db = ActiveRecord::Base.connection.config[:database]
51
- assert_equal db, connection.current_database
52
- end
53
-
54
- def test_current_schema
55
- assert_equal 'public', connection.current_schema
56
- end
57
-
58
- def test_schema_exists?
59
- assert connection.schema_exists?('public')
60
- assert ! connection.schema_exists?('missing')
61
- end
62
-
63
- def test_schema_names
64
- assert_equal [ "public" ], connection.schema_names
65
- end
66
-
67
- context "search path" do
68
-
69
- def test_schema_names
70
- assert_equal [ "public", "test" ], connection.schema_names
71
- end
72
-
73
- class CreateSchema < ActiveRecord::Migration
74
- def self.up
75
- execute "CREATE SCHEMA test"
76
- execute "CREATE TABLE test.people (id serial, name text)"
77
- execute "INSERT INTO test.people (name) VALUES ('Alex')"
78
- execute "CREATE TABLE public.people (id serial, wrongname text)"
79
- end
80
-
81
- def self.down
82
- execute "DROP SCHEMA test CASCADE"
83
- execute "DROP TABLE people"
84
- end
85
- end
86
-
87
- class Person < ActiveRecord::Base
88
- establish_connection POSTGRES_CONFIG.merge(:schema_search_path => 'test,public')
89
- end
90
-
91
- setup { CreateSchema.up }
92
- teardown { CreateSchema.down }
93
-
94
- def test_columns
95
- assert_equal(%w{id name}, Person.column_names)
96
- end
97
-
98
- def test_find_right
99
- assert_not_nil Person.find_by_name("Alex")
100
- end
101
-
102
- def test_find_wrong
103
- assert_raise NoMethodError do
104
- Person.find_by_wrongname("Alex")
105
- end
106
- end
107
-
108
- def test_column_information
109
- assert_include Person.columns.map{ |col| col.name }, "name"
110
- assert ! Person.columns.map{ |col| col.name }.include?("wrongname")
111
- end
112
-
113
- end
114
-
115
- end
@@ -1,260 +0,0 @@
1
- # To run this script, set up the following postgres user and database:
2
- #
3
- # sudo -u postgres createuser -D -A -P blog
4
- # sudo -u postgres createdb -O blog weblog_development
5
- #
6
-
7
- require 'jdbc_common'
8
- require 'db/postgres'
9
-
10
- class PostgresSimpleTest < Test::Unit::TestCase
11
- include SimpleTestMethods
12
- include ActiveRecord3TestMethods
13
- include ColumnNameQuotingTests
14
- include DirtyAttributeTests
15
- include XmlColumnTests
16
- include CustomSelectTestMethods
17
-
18
- def test_adapter_class_name_equals_native_adapter_class_name
19
- classname = connection.class.name[/[^:]*$/]
20
- assert_equal 'PostgreSQLAdapter', classname
21
- end
22
-
23
- def test_schema_search_path
24
- assert_equal connection.schema_search_path, "\"$user\",public"
25
- end
26
-
27
- def test_current_schema
28
- assert_equal connection.current_schema, "public"
29
- end
30
-
31
- def test_encoding
32
- assert_not_nil connection.encoding
33
- end
34
-
35
- def test_multi_statement_support
36
- user = User.create! :login => 'jozko'
37
- Entry.create! :title => 'eee', :user_id => user.id
38
-
39
- results = connection.execute "SELECT title FROM entries; SELECT login FROM users"
40
-
41
- assert_equal 2, results.length
42
- assert_equal ["title"], results[0].first.keys
43
- assert_equal ["login"], results[1].first.keys
44
- end
45
-
46
- def test_find_by_sql_WITH_statement
47
- user = User.create! :login => 'ferko'
48
- Entry.create! :title => 'aaa', :user_id => user.id
49
- entries = Entry.find_by_sql '' +
50
- '( ' +
51
- 'WITH EntryAndUser (title, login, updated_on) AS ' +
52
- ' ( ' +
53
- ' SELECT e.title, u.login, e.updated_on ' +
54
- ' FROM entries e INNER JOIN users u ON e.user_id = u.id ' +
55
- ' ) ' +
56
- 'SELECT * FROM EntryAndUser ORDER BY title ASC ' +
57
- ') '
58
- assert entries.first
59
- assert entries.first.title
60
- assert entries.first.login
61
- end
62
-
63
- def test_create_xml_column
64
- return unless PG_VERSION >= 80300
65
- super
66
- end if ar_version('3.1')
67
- def xml_sql_type; 'xml'; end
68
-
69
- def test_create_table_with_limits
70
- if ar_version('4.0')
71
- # No integer type has byte size 11. Use a numeric with precision 0 instead.
72
- connection.create_table :testings do |t|
73
- t.column :an_int, :integer, :limit => 8
74
- end
75
-
76
- columns = connection.columns(:testings)
77
- an_int = columns.detect { |c| c.name == "an_int" }
78
- assert_equal "bigint", an_int.sql_type
79
- else
80
- assert_nothing_raised do
81
- connection.create_table :testings do |t|
82
- t.column :an_int, :integer, :limit => 11
83
- end
84
- end
85
-
86
- columns = connection.columns(:testings)
87
- an_int = columns.detect { |c| c.name == "an_int" }
88
- assert_equal "integer", an_int.sql_type
89
- end
90
- ensure
91
- connection.drop_table :testings rescue nil
92
- end
93
-
94
- def test_resolves_correct_columns_default
95
- assert column = DbType.columns.find { |col| col.name == 'sample_small_decimal' }
96
- assert_equal 3.14, column.default
97
- assert column = DbType.columns.find { |col| col.name == 'sample_integer_no_limit' }
98
- assert_equal 42, column.default
99
- assert column = DbType.columns.find { |col| col.name == 'sample_integer_neg_default' }
100
- assert_equal -1, column.default
101
- end
102
-
103
- def test_supports_standard_conforming_string
104
- assert([true, false].include?(connection.supports_standard_conforming_strings?))
105
- end
106
-
107
- def test_standard_conforming_string_default_set_on_new_connections
108
- c = ActiveRecord::Base.postgresql_connection(POSTGRES_CONFIG)
109
- assert_equal true, c.instance_variable_get("@standard_conforming_strings")
110
- end
111
-
112
- def test_default_standard_conforming_string
113
- if connection.supports_standard_conforming_strings?
114
- assert_equal true, connection.standard_conforming_strings?
115
- else
116
- assert_equal false, connection.standard_conforming_strings?
117
- end
118
- end
119
-
120
- def test_string_quoting_with_standard_conforming_strings
121
- if connection.supports_standard_conforming_strings?
122
- s = "\\m it's \\M"
123
- assert_equal "'\\m it''s \\M'", connection.quote(s)
124
- end
125
- end
126
-
127
- def test_string_quoting_without_standard_conforming_strings
128
- connection.standard_conforming_strings = false
129
- s = "\\m it's \\M"
130
- assert_equal "'\\\\m it''s \\\\M'", connection.quote(s)
131
- connection.standard_conforming_strings = true
132
- end
133
-
134
- include ExplainSupportTestMethods if ar_version("3.1")
135
-
136
- def test_primary_key
137
- assert_equal 'id', connection.primary_key('entries')
138
- assert_equal 'custom_id', connection.primary_key('custom_pk_names')
139
- # assert_equal 'id', connection.primary_key('auto_ids')
140
- end
141
-
142
- def test_primary_key_without_sequence
143
- connection.execute "CREATE TABLE uid_table (uid UUID PRIMARY KEY, name TEXT)"
144
- assert_equal 'uid', connection.primary_key('uid_table')
145
- ensure
146
- connection.execute "DROP TABLE uid_table"
147
- end
148
-
149
- def test_extensions
150
- if connection.supports_extensions?
151
- assert_include connection.extensions, 'plpgsql'
152
- assert connection.extension_enabled?('plpgsql')
153
- assert ! connection.extension_enabled?('invalid')
154
- else
155
- assert_empty connection.extensions
156
- end
157
- end
158
-
159
- end
160
-
161
- class PostgresTimestampTest < Test::Unit::TestCase
162
-
163
- def self.startup
164
- DbTypeMigration.up
165
- end
166
-
167
- def self.shutdown
168
- DbTypeMigration.down
169
- end
170
-
171
- def test_string_is_character_varying
172
- sample_string = DbType.connection.columns(:db_types).detect do |c|
173
- c.name == "sample_string"
174
- end
175
-
176
- assert_match(/^character varying/, sample_string.sql_type)
177
- end
178
-
179
- def test_select_infinity
180
- d = DbType.find_by_sql("select 'infinity'::timestamp as sample_timestamp").first
181
- assert d.sample_timestamp.infinite?, "timestamp: #{d.sample_timestamp.inspect} should be infinite"
182
-
183
- d = DbType.find_by_sql("select '-infinity'::timestamp as sample_timestamp").first
184
-
185
- time = d.sample_timestamp
186
- assert time.infinite?, "timestamp: #{time.inspect} should be infinte"
187
- assert_operator time, :<, 0
188
- end
189
-
190
- def test_save_infinity
191
- if ar_version('4.0')
192
- # NOTE: likely an AR issue - it only works when time_zone_aware_attributes
193
- # are disabled otherwise TimeZoneConversion's define_method_attribute=(attr_name)
194
- # does the following code ("infinite" time instance ending as nil):
195
- # time_with_zone = time.respond_to?(:in_time_zone) ? time.in_time_zone : nil
196
- tz_aware_attributes = ActiveRecord::Base.time_zone_aware_attributes
197
- begin
198
- ActiveRecord::Base.time_zone_aware_attributes = false
199
- do_test_save_infinity
200
- ensure
201
- ActiveRecord::Base.time_zone_aware_attributes = tz_aware_attributes
202
- end
203
- else
204
- do_test_save_infinity
205
- end
206
- end
207
-
208
- def do_test_save_infinity
209
- d = DbType.new
210
- d.sample_datetime = 1.0 / 0.0
211
- d.save!
212
-
213
- if ar_version('3.0')
214
- assert_equal 1.0 / 0.0, d.reload.sample_datetime # sample_timestamp
215
- else # 2.3
216
- assert_equal nil, d.reload.sample_datetime # d.sample_timestamp
217
- end
218
-
219
- d = DbType.create!(:sample_timestamp => -1.0 / 0.0)
220
- if ar_version('3.0')
221
- assert_equal -1.0 / 0.0, d.sample_timestamp
222
- else # 2.3
223
- assert_equal nil, d.sample_timestamp
224
- end
225
- end
226
- private :do_test_save_infinity
227
-
228
- def test_bc_timestamp
229
- if RUBY_VERSION == '1.9.3' && defined?(JRUBY_VERSION) && JRUBY_VERSION =~ /1\.7\.3|4/
230
- omit "Date.new(0) issue on JRuby 1.7.3/4"
231
- end
232
- # JRuby 1.7.3 (--1.9) bug: `Date.new(0) + 1.seconds` "1753-08-29 22:43:42 +0057"
233
- date = Date.new(0) - 1.second
234
- db_type = DbType.create!(:sample_timestamp => date)
235
- assert_equal date, db_type.reload.sample_timestamp
236
- end if ar_version('3.0')
237
-
238
- end
239
-
240
- class PostgresDeserializationTest < Test::Unit::TestCase
241
-
242
- def self.startup
243
- DbTypeMigration.up
244
- end
245
-
246
- def self.shutdown
247
- DbTypeMigration.down
248
- end
249
-
250
- def test_should_keep_float_precision
251
- expected = DbType.create(:sample_float => 7.3)
252
- actual = DbType.find(expected.id)
253
-
254
- assert_equal expected.sample_float, actual.sample_float
255
- end
256
- end
257
-
258
- class PostgresHasManyThroughTest < Test::Unit::TestCase
259
- include HasManyThroughMethods
260
- end