activerecord-jdbc-adapter 1.2.9.1 → 1.3.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/.travis.yml +3 -0
  2. data/Appraisals +12 -4
  3. data/Gemfile +3 -3
  4. data/Gemfile.lock +19 -19
  5. data/History.txt +90 -16
  6. data/LICENSE.txt +2 -1
  7. data/README.md +14 -1
  8. data/activerecord-jdbc-adapter.gemspec +2 -2
  9. data/gemfiles/rails23.gemfile +5 -5
  10. data/gemfiles/rails23.gemfile.lock +27 -27
  11. data/gemfiles/rails30.gemfile +3 -3
  12. data/gemfiles/rails30.gemfile.lock +8 -8
  13. data/gemfiles/rails31.gemfile +4 -4
  14. data/gemfiles/rails31.gemfile.lock +18 -18
  15. data/gemfiles/rails32.gemfile +4 -4
  16. data/gemfiles/rails32.gemfile.lock +17 -17
  17. data/gemfiles/rails40.gemfile +17 -0
  18. data/gemfiles/rails40.gemfile.lock +126 -0
  19. data/lib/activerecord-jdbc-adapter.rb +0 -7
  20. data/lib/arjdbc.rb +6 -5
  21. data/lib/arjdbc/db2.rb +1 -1
  22. data/lib/arjdbc/db2/adapter.rb +52 -29
  23. data/lib/arjdbc/db2/connection_methods.rb +13 -14
  24. data/lib/arjdbc/derby.rb +1 -1
  25. data/lib/arjdbc/derby/adapter.rb +29 -9
  26. data/lib/arjdbc/derby/connection_methods.rb +17 -20
  27. data/lib/arjdbc/firebird.rb +1 -1
  28. data/lib/arjdbc/h2.rb +2 -2
  29. data/lib/arjdbc/h2/adapter.rb +1 -1
  30. data/lib/arjdbc/h2/connection_methods.rb +12 -16
  31. data/lib/arjdbc/hsqldb.rb +1 -1
  32. data/lib/arjdbc/hsqldb/connection_methods.rb +13 -16
  33. data/lib/arjdbc/informix.rb +1 -1
  34. data/lib/arjdbc/informix/connection_methods.rb +8 -10
  35. data/lib/arjdbc/jdbc.rb +1 -1
  36. data/lib/arjdbc/jdbc/adapter.rb +125 -53
  37. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  38. data/lib/arjdbc/jdbc/base_ext.rb +34 -9
  39. data/lib/arjdbc/jdbc/column.rb +15 -2
  40. data/lib/arjdbc/jdbc/connection.rb +0 -2
  41. data/lib/arjdbc/jdbc/connection_methods.rb +10 -3
  42. data/lib/arjdbc/jdbc/driver.rb +2 -2
  43. data/lib/arjdbc/jdbc/extension.rb +35 -21
  44. data/lib/arjdbc/jdbc/java.rb +0 -2
  45. data/lib/arjdbc/jdbc/missing_functionality_helper.rb +35 -25
  46. data/lib/arjdbc/jdbc/railtie.rb +2 -9
  47. data/lib/arjdbc/mimer.rb +1 -1
  48. data/lib/arjdbc/mssql.rb +2 -2
  49. data/lib/arjdbc/mssql/adapter.rb +271 -92
  50. data/lib/arjdbc/mssql/connection_methods.rb +30 -32
  51. data/lib/arjdbc/mssql/explain_support.rb +107 -0
  52. data/lib/arjdbc/mssql/limit_helpers.rb +48 -18
  53. data/lib/arjdbc/mysql.rb +1 -1
  54. data/lib/arjdbc/mysql/adapter.rb +63 -14
  55. data/lib/arjdbc/mysql/connection_methods.rb +22 -24
  56. data/lib/arjdbc/mysql/explain_support.rb +2 -5
  57. data/lib/arjdbc/oracle.rb +1 -1
  58. data/lib/arjdbc/oracle/adapter.rb +78 -38
  59. data/lib/arjdbc/oracle/connection_methods.rb +9 -10
  60. data/lib/arjdbc/postgresql.rb +1 -1
  61. data/lib/arjdbc/postgresql/adapter.rb +964 -380
  62. data/lib/arjdbc/postgresql/column_cast.rb +136 -0
  63. data/lib/arjdbc/postgresql/connection_methods.rb +19 -21
  64. data/lib/arjdbc/postgresql/explain_support.rb +3 -6
  65. data/lib/arjdbc/railtie.rb +9 -0
  66. data/lib/arjdbc/sqlite3.rb +1 -1
  67. data/lib/arjdbc/sqlite3/adapter.rb +73 -26
  68. data/lib/arjdbc/sqlite3/connection_methods.rb +27 -28
  69. data/lib/arjdbc/sqlite3/explain_support.rb +2 -5
  70. data/lib/arjdbc/sybase.rb +1 -1
  71. data/lib/arjdbc/version.rb +5 -4
  72. data/pom.xml +8 -0
  73. data/rakelib/02-test.rake +57 -51
  74. data/rakelib/compile.rake +17 -5
  75. data/rakelib/rails.rake +42 -31
  76. data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +4 -3
  77. data/src/java/arjdbc/derby/DerbyModule.java +98 -85
  78. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +70 -0
  79. data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +0 -4
  80. data/src/java/arjdbc/jdbc/AdapterJavaService.java +26 -15
  81. data/src/java/arjdbc/jdbc/Callable.java +44 -0
  82. data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +10 -2
  83. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1675 -834
  84. data/src/java/arjdbc/jdbc/SQLBlock.java +9 -3
  85. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +73 -36
  86. data/src/java/arjdbc/mysql/MySQLModule.java +11 -10
  87. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +86 -80
  88. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +27 -7
  89. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -0
  90. data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +25 -67
  91. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +52 -49
  92. data/src/java/arjdbc/util/QuotingUtils.java +6 -6
  93. data/test/abstract_db_create.rb +11 -11
  94. data/test/activerecord/connection_adapters/type_conversion_test.rb +18 -12
  95. data/test/db/db2.rb +1 -1
  96. data/test/{db2_binary_test.rb → db/db2/binary_test.rb} +0 -0
  97. data/test/db/db2/has_many_through_test.rb +6 -0
  98. data/test/{db2_reset_column_information_test.rb → db/db2/reset_column_information_test.rb} +1 -2
  99. data/test/{db2_serialize_test.rb → db/db2/serialize_test.rb} +0 -0
  100. data/test/{db2_simple_test.rb → db/db2/simple_test.rb} +1 -8
  101. data/test/db/db2/test_helper.rb +6 -0
  102. data/test/{db2_test.rb → db/db2/unit_test.rb} +1 -1
  103. data/test/db/derby.rb +1 -1
  104. data/test/{derby_binary_test.rb → db/derby/binary_test.rb} +0 -0
  105. data/test/{derby_migration_test.rb → db/derby/migration_test.rb} +0 -0
  106. data/test/{derby_reset_column_information_test.rb → db/derby/reset_column_information_test.rb} +0 -0
  107. data/test/{derby_row_locking_test.rb → db/derby/row_locking_test.rb} +1 -4
  108. data/test/db/derby/schema_dump_test.rb +5 -0
  109. data/test/{derby_serialize_test.rb → db/derby/serialize_test.rb} +0 -0
  110. data/test/{derby_simple_test.rb → db/derby/simple_test.rb} +23 -38
  111. data/test/db/derby/test_helper.rb +6 -0
  112. data/test/db/derby/unit_test.rb +32 -0
  113. data/test/db/derby/xml_column_test.rb +17 -0
  114. data/test/db/h2.rb +1 -1
  115. data/test/{h2_binary_test.rb → db/h2/binary_test.rb} +0 -0
  116. data/test/{h2_change_column_test.rb → db/h2/change_column_test.rb} +1 -0
  117. data/test/{h2_schema_dump_test.rb → db/h2/schema_dump_test.rb} +0 -0
  118. data/test/{h2_serialize_test.rb → db/h2/serialize_test.rb} +0 -0
  119. data/test/{h2_simple_test.rb → db/h2/simple_test.rb} +3 -1
  120. data/test/db/hsqldb.rb +1 -1
  121. data/test/{hsqldb_binary_test.rb → db/hsqldb/binary_test.rb} +0 -0
  122. data/test/{hsqldb_schema_dump_test.rb → db/hsqldb/schema_dump_test.rb} +0 -0
  123. data/test/{hsqldb_serialize_test.rb → db/hsqldb/serialize_test.rb} +0 -0
  124. data/test/{hsqldb_simple_test.rb → db/hsqldb/simple_test.rb} +3 -1
  125. data/test/db/informix.rb +1 -1
  126. data/test/db/jdbc.rb +3 -2
  127. data/test/db/jdbc_derby.rb +1 -1
  128. data/test/db/jdbc_h2.rb +1 -1
  129. data/test/db/jdbc_mysql.rb +1 -1
  130. data/test/db/jdbc_postgres.rb +1 -1
  131. data/test/db/jndi_config.rb +1 -2
  132. data/test/db/jndi_pooled_config.rb +2 -3
  133. data/test/db/mssql.rb +2 -2
  134. data/test/{mssql_binary_test.rb → db/mssql/binary_test.rb} +0 -0
  135. data/test/{mssql_db_create_test.rb → db/mssql/db_create_test.rb} +1 -1
  136. data/test/db/mssql/exec_proc_test.rb +46 -0
  137. data/test/{mssql_identity_insert_test.rb → db/mssql/identity_insert_test.rb} +0 -0
  138. data/test/db/mssql/ignore_system_views_test.rb +40 -0
  139. data/test/{mssql_limit_offset_test.rb → db/mssql/limit_offset_test.rb} +10 -1
  140. data/test/{mssql_multibyte_test.rb → db/mssql/multibyte_test.rb} +0 -0
  141. data/test/db/mssql/multiple_connections_test.rb +71 -0
  142. data/test/{mssql_reset_column_information_test.rb → db/mssql/reset_column_information_test.rb} +0 -0
  143. data/test/{mssql_row_locking_test.rb → db/mssql/row_locking_test.rb} +0 -0
  144. data/test/{mssql_serialize_test.rb → db/mssql/serialize_test.rb} +1 -1
  145. data/test/db/mssql/simple_test.rb +140 -0
  146. data/test/db/mssql/transaction_test.rb +6 -0
  147. data/test/db/mssql/types_test.rb +205 -0
  148. data/test/{mssql_test.rb → db/mssql/unit_test.rb} +2 -2
  149. data/test/db/mysql.rb +1 -2
  150. data/test/db/mysql/_rails_test_mysql.32.out +6768 -0
  151. data/test/{mysql_binary_test.rb → db/mysql/binary_test.rb} +0 -0
  152. data/test/db/mysql/connection_test.rb +51 -0
  153. data/test/{mysql_db_create_test.rb → db/mysql/db_create_test.rb} +0 -0
  154. data/test/{mysql_index_length_test.rb → db/mysql/index_length_test.rb} +0 -0
  155. data/test/{mysql_multibyte_test.rb → db/mysql/multibyte_test.rb} +0 -0
  156. data/test/{mysql_nonstandard_primary_key_test.rb → db/mysql/nonstandard_primary_key_test.rb} +0 -0
  157. data/test/{mysql_reset_column_information_test.rb → db/mysql/reset_column_information_test.rb} +0 -0
  158. data/test/{mysql_schema_dump_test.rb → db/mysql/schema_dump_test.rb} +9 -1
  159. data/test/{mysql_serialize_test.rb → db/mysql/serialize_test.rb} +0 -0
  160. data/test/{mysql_simple_test.rb → db/mysql/simple_test.rb} +16 -8
  161. data/test/db/mysql/transaction_test.rb +6 -0
  162. data/test/db/mysql/types_test.rb +30 -0
  163. data/test/{mysql_test.rb → db/mysql/unit_test.rb} +1 -1
  164. data/test/db/mysql_config.rb +1 -1
  165. data/test/db/oracle.rb +1 -1
  166. data/test/{oracle_binary_test.rb → db/oracle/binary_test.rb} +0 -0
  167. data/test/{oracle_limit_test.rb → db/oracle/limit_test.rb} +0 -0
  168. data/test/db/oracle/multibyte_test.rb +22 -0
  169. data/test/{oracle_reset_column_information_test.rb → db/oracle/reset_column_information_test.rb} +0 -0
  170. data/test/{oracle_serialize_test.rb → db/oracle/serialize_test.rb} +0 -0
  171. data/test/{oracle_simple_test.rb → db/oracle/simple_test.rb} +14 -19
  172. data/test/{oracle_specific_test.rb → db/oracle/specific_test.rb} +62 -16
  173. data/test/db/oracle/transaction_test.rb +31 -0
  174. data/test/db/oracle/unit_test.rb +31 -0
  175. data/test/db/postgres.rb +1 -1
  176. data/test/db/postgres/_rails_test_postgres.32.out +6777 -0
  177. data/test/db/postgres/a_custom_primary_key_test.rb +50 -0
  178. data/test/db/postgres/array_type_test.rb +101 -0
  179. data/test/{postgres_binary_test.rb → db/postgres/binary_test.rb} +0 -0
  180. data/test/db/postgres/connection_test.rb +55 -0
  181. data/test/db/postgres/data_types_test.rb +703 -0
  182. data/test/{postgres_db_create_test.rb → db/postgres/db_create_test.rb} +1 -1
  183. data/test/{postgres_drop_db_test.rb → db/postgres/db_drop_test.rb} +2 -0
  184. data/test/db/postgres/hstore_test.rb +200 -0
  185. data/test/db/postgres/information_schema_leak_test.rb +30 -0
  186. data/test/db/postgres/json_test.rb +86 -0
  187. data/test/db/postgres/ltree_test.rb +50 -0
  188. data/test/{postgres_mixed_case_test.rb → db/postgres/mixed_case_test.rb} +0 -0
  189. data/test/db/postgres/native_types_test.rb +128 -0
  190. data/test/{postgres_reserved_test.rb → db/postgres/reserved_test.rb} +0 -0
  191. data/test/{postgres_reset_column_information_test.rb → db/postgres/reset_column_information_test.rb} +0 -0
  192. data/test/{postgres_row_locking_test.rb → db/postgres/row_locking_test.rb} +0 -0
  193. data/test/{postgres_schema_dump_test.rb → db/postgres/schema_dump_test.rb} +4 -4
  194. data/test/db/postgres/schema_test.rb +113 -0
  195. data/test/{postgres_simple_test.rb → db/postgres/simple_test.rb} +48 -8
  196. data/test/{postgres_table_alias_length_test.rb → db/postgres/table_alias_length_test.rb} +2 -1
  197. data/test/db/postgres/transaction_test.rb +6 -0
  198. data/test/{postgres_test.rb → db/postgres/unit_test.rb} +3 -3
  199. data/test/db/sqlite3.rb +1 -1
  200. data/test/db/sqlite3/_rails_test_sqlite3.32.out +6502 -0
  201. data/test/db/sqlite3/has_many_though_test.rb +6 -0
  202. data/test/{sqlite3_reset_column_information_test.rb → db/sqlite3/reset_column_information_test.rb} +0 -0
  203. data/test/{sqlite3_schema_dump_test.rb → db/sqlite3/schema_dump_test.rb} +0 -0
  204. data/test/{sqlite3_serialize_test.rb → db/sqlite3/serialize_test.rb} +0 -0
  205. data/test/{sqlite3_simple_test.rb → db/sqlite3/simple_test.rb} +63 -63
  206. data/test/db/sqlite3/transaction_test.rb +32 -0
  207. data/test/{sqlite3_type_conversion_test.rb → db/sqlite3/type_conversion_test.rb} +0 -0
  208. data/test/has_many_through.rb +29 -64
  209. data/test/jdbc/oracle.rb +11 -0
  210. data/test/jndi_test.rb +16 -4
  211. data/test/models/auto_id.rb +1 -1
  212. data/test/models/rights_and_roles.rb +57 -0
  213. data/test/row_locking.rb +3 -0
  214. data/test/schema_dump.rb +24 -10
  215. data/test/simple.rb +359 -104
  216. data/test/test_helper.rb +4 -2
  217. data/test/transaction.rb +109 -0
  218. metadata +119 -86
  219. data/lib/arjdbc/jdbc/compatibility.rb +0 -51
  220. data/lib/arjdbc/jdbc/core_ext.rb +0 -24
  221. data/lib/arjdbc/jdbc/discover.rb +0 -18
  222. data/test/derby_schema_dump_test.rb +0 -9
  223. data/test/mssql_ignore_system_views_test.rb +0 -30
  224. data/test/mssql_legacy_types_test.rb +0 -58
  225. data/test/mssql_null_test.rb +0 -14
  226. data/test/mssql_simple_test.rb +0 -51
  227. data/test/postgres_information_schema_leak_test.rb +0 -28
  228. data/test/postgres_native_type_mapping_test.rb +0 -93
  229. data/test/postgres_nonseq_pkey_test.rb +0 -38
  230. data/test/postgres_schema_search_path_test.rb +0 -48
  231. data/test/postgres_type_conversion_test.rb +0 -33
@@ -1,5 +1,5 @@
1
- require 'abstract_db_create'
2
1
  require 'db/postgres'
2
+ require 'abstract_db_create'
3
3
 
4
4
  class PostgresDbCreateTest < Test::Unit::TestCase
5
5
  include AbstractDbCreate
@@ -1,3 +1,4 @@
1
+ require 'db/postgres'
1
2
  require 'abstract_db_create'
2
3
 
3
4
  class PostgresDbDropTest < Test::Unit::TestCase
@@ -12,4 +13,5 @@ class PostgresDbDropTest < Test::Unit::TestCase
12
13
  Rake::Task["db:drop"].invoke
13
14
  end
14
15
  end
16
+
15
17
  end
@@ -0,0 +1,200 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'db/postgres'
4
+
5
+ class PostgresqlHstoreTest < Test::Unit::TestCase
6
+
7
+ class Hstore < ActiveRecord::Base
8
+ self.table_name = 'hstores'
9
+ end
10
+
11
+ def setup
12
+ @connection = ActiveRecord::Base.connection
13
+
14
+ unless @connection.supports_extensions?
15
+ return skip "do not test on PG without hstore"
16
+ end
17
+
18
+ unless @connection.extension_enabled?('hstore')
19
+ @connection.enable_extension 'hstore'
20
+ @connection.commit_db_transaction
21
+ end
22
+
23
+ @connection.reconnect!
24
+
25
+ @connection.transaction do
26
+ @connection.create_table('hstores') do |t|
27
+ t.hstore 'tags', :default => ''
28
+ end
29
+ end
30
+ @column = Hstore.columns.find { |c| c.name == 'tags' }
31
+ end
32
+
33
+ def teardown
34
+ @connection.execute 'drop table if exists hstores'
35
+ end
36
+
37
+ def test_hstore_included_in_extensions
38
+ assert @connection.respond_to?(:extensions), "connection should have a list of extensions"
39
+ assert @connection.extensions.include?('hstore'), "extension list should include hstore"
40
+ end
41
+
42
+ def test_disable_enable_hstore
43
+ assert_true @connection.extension_enabled?('hstore')
44
+ @connection.disable_extension 'hstore'
45
+ assert_false @connection.extension_enabled?('hstore')
46
+ @connection.enable_extension 'hstore'
47
+ assert_true @connection.extension_enabled?('hstore')
48
+ ensure
49
+ # Restore column(s) dropped by `drop extension hstore cascade;`
50
+ # load_schema
51
+ end
52
+
53
+ def test_column
54
+ assert_equal :hstore, @column.type
55
+ end
56
+
57
+ def test_change_table_supports_hstore
58
+ @connection.transaction do
59
+ @connection.change_table('hstores') do |t|
60
+ t.hstore 'users', :default => ''
61
+ end
62
+ Hstore.reset_column_information
63
+ column = Hstore.columns.find { |c| c.name == 'users' }
64
+ assert_equal :hstore, column.type
65
+
66
+ raise ActiveRecord::Rollback # reset the schema change
67
+ end
68
+ ensure
69
+ Hstore.reset_column_information
70
+ end
71
+
72
+ def test_type_cast_hstore
73
+ assert @column
74
+
75
+ data = "\"1\"=>\"2\""
76
+ hash = @column.class.string_to_hstore data
77
+ assert_equal({'1' => '2'}, hash)
78
+ assert_equal({'1' => '2'}, @column.type_cast(data))
79
+
80
+ assert_equal({}, @column.type_cast(""))
81
+ assert_equal({'key'=>nil}, @column.type_cast('key => NULL'))
82
+ assert_equal({'c'=>'}','"a"'=>'b "a b'}, @column.type_cast(%q(c=>"}", "\"a\""=>"b \"a b")))
83
+ end
84
+
85
+ def test_gen1
86
+ assert_equal(%q(" "=>""), @column.class.hstore_to_string({' '=>''}))
87
+ end
88
+
89
+ def test_gen2
90
+ assert_equal(%q(","=>""), @column.class.hstore_to_string({','=>''}))
91
+ end
92
+
93
+ def test_gen3
94
+ assert_equal(%q("="=>""), @column.class.hstore_to_string({'='=>''}))
95
+ end
96
+
97
+ def test_gen4
98
+ assert_equal(%q(">"=>""), @column.class.hstore_to_string({'>'=>''}))
99
+ end
100
+
101
+ def test_parse1
102
+ assert_equal({'a'=>nil,'b'=>nil,'c'=>'NuLl','null'=>'c'}, @column.type_cast('a=>null,b=>NuLl,c=>"NuLl",null=>c'))
103
+ end
104
+
105
+ def test_parse2
106
+ assert_equal({" " => " "}, @column.type_cast("\\ =>\\ "))
107
+ end
108
+
109
+ def test_parse3
110
+ assert_equal({"=" => ">"}, @column.type_cast("==>>"))
111
+ end
112
+
113
+ def test_parse4
114
+ assert_equal({"=a"=>"q=w"}, @column.type_cast('\=a=>q=w'))
115
+ end
116
+
117
+ def test_parse5
118
+ assert_equal({"=a"=>"q=w"}, @column.type_cast('"=a"=>q\=w'))
119
+ end
120
+
121
+ def test_parse6
122
+ assert_equal({"\"a"=>"q>w"}, @column.type_cast('"\"a"=>q>w'))
123
+ end
124
+
125
+ def test_parse7
126
+ assert_equal({"\"a"=>"q\"w"}, @column.type_cast('\"a=>q"w'))
127
+ end
128
+
129
+ def test_rewrite
130
+ @connection.execute "insert into hstores (tags) VALUES ('1=>2')"
131
+ x = Hstore.first
132
+ x.tags = { '"a\'' => 'b' }
133
+ assert x.save!
134
+ end
135
+
136
+
137
+ def test_select
138
+ @connection.execute "insert into hstores (tags) VALUES ('1=>2')"
139
+ x = Hstore.first
140
+ assert_equal({'1' => '2'}, x.tags)
141
+ end
142
+
143
+ def test_select_multikey
144
+ @connection.execute "insert into hstores (tags) VALUES ('1=>2,2=>3')"
145
+ x = Hstore.first
146
+ assert_equal({'1' => '2', '2' => '3'}, x.tags)
147
+ end
148
+
149
+ def test_create
150
+ assert_cycle('a' => 'b', '1' => '2')
151
+ end
152
+
153
+ def test_nil
154
+ assert_cycle('a' => nil)
155
+ end
156
+
157
+ def test_quotes
158
+ assert_cycle('a' => 'b"ar', '1"foo' => '2')
159
+ end
160
+
161
+ def test_whitespace
162
+ assert_cycle('a b' => 'b ar', '1"foo' => '2')
163
+ end
164
+
165
+ def test_backslash
166
+ assert_cycle('a\\b' => 'b\\ar', '1"foo' => '2')
167
+ end
168
+
169
+ def test_comma
170
+ assert_cycle('a, b' => 'bar', '1"foo' => '2')
171
+ end
172
+
173
+ def test_arrow
174
+ assert_cycle('a=>b' => 'bar', '1"foo' => '2')
175
+ end
176
+
177
+ def test_quoting_special_characters
178
+ assert_cycle('ca' => 'cà', 'ac' => 'àc')
179
+ end
180
+
181
+ def test_multiline
182
+ assert_cycle("a\nb" => "c\nd")
183
+ end
184
+
185
+ private
186
+ def assert_cycle hash
187
+ # test creation
188
+ x = Hstore.create!(:tags => hash)
189
+ x.reload
190
+ assert_equal(hash, x.tags)
191
+
192
+ # test updating
193
+ x = Hstore.create!(:tags => {})
194
+ x.tags = hash
195
+ x.save!
196
+ x.reload
197
+ assert_equal(hash, x.tags)
198
+ end
199
+
200
+ end if Test::Unit::TestCase.ar_version('4.0')
@@ -0,0 +1,30 @@
1
+ require 'db/postgres'
2
+
3
+ class PostgresInformationSchemaLeakTest < Test::Unit::TestCase
4
+
5
+ class CreateISLSchema < ActiveRecord::Migration
6
+ def self.up
7
+ execute "CREATE TABLE domains (id int, name varchar(16))"
8
+ end
9
+
10
+ def self.down
11
+ execute "DROP TABLE domains"
12
+ end
13
+ end
14
+
15
+ class Domain < ActiveRecord::Base
16
+ end
17
+
18
+ def setup
19
+ CreateISLSchema.up
20
+ end
21
+
22
+ def teardown
23
+ CreateISLSchema.down
24
+ end
25
+
26
+ def test_domain_columns
27
+ assert_equal(%w{id name}, Domain.column_names)
28
+ end
29
+
30
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'db/postgres'
4
+
5
+ class PostgresqlJSONTest < Test::Unit::TestCase
6
+
7
+ class JsonDataType < ActiveRecord::Base
8
+ self.table_name = 'json_data_type'
9
+ end
10
+
11
+ def setup
12
+ @connection = ActiveRecord::Base.connection
13
+ begin
14
+ @connection.transaction do
15
+ @connection.create_table('json_data_type') do |t|
16
+ t.json 'payload', :default => {}
17
+ end
18
+ end
19
+ rescue ActiveRecord::StatementInvalid
20
+ return skip "do not test on PG without json"
21
+ end
22
+ end
23
+
24
+ def teardown
25
+ @connection.execute 'drop table if exists json_data_type'
26
+ end
27
+
28
+ def test_column
29
+ column = JsonDataType.columns.find { |c| c.name == 'payload' }
30
+ assert_equal :json, column.type
31
+ end
32
+
33
+ def test_change_table_supports_json
34
+ @connection.transaction do
35
+ @connection.change_table('json_data_type') do |t|
36
+ t.json 'users', :default => '{}'
37
+ end
38
+ JsonDataType.reset_column_information
39
+ column = JsonDataType.columns.find { |c| c.name == 'users' }
40
+ assert_equal :json, column.type
41
+
42
+ raise ActiveRecord::Rollback # reset the schema change
43
+ end
44
+ ensure
45
+ JsonDataType.reset_column_information
46
+ end
47
+
48
+ def test_type_cast_json
49
+ assert @column = JsonDataType.columns.find { |c| c.name == 'payload' }
50
+
51
+ data = "{\"a_key\":\"a_value\"}"
52
+ hash = @column.class.string_to_json data
53
+ assert_equal({'a_key' => 'a_value'}, hash)
54
+ assert_equal({'a_key' => 'a_value'}, @column.type_cast(data))
55
+
56
+ assert_equal({}, @column.type_cast("{}"))
57
+ assert_equal({'key'=>nil}, @column.type_cast('{"key": null}'))
58
+ assert_equal({'c'=>'}','"a"'=>'b "a b'}, @column.type_cast(%q({"c":"}", "\"a\"":"b \"a b"})))
59
+ end
60
+
61
+ def test_rewrite
62
+ @connection.execute "insert into json_data_type (payload) VALUES ('{\"k\":\"v\"}')"
63
+ x = JsonDataType.first
64
+ x.payload = { '"a\'' => 'b' }
65
+ assert x.save!
66
+ end
67
+
68
+ def test_select
69
+ @connection.execute "insert into json_data_type (payload) VALUES ('{\"k\":\"v\"}')"
70
+ x = JsonDataType.first
71
+ assert_equal({'k' => 'v'}, x.payload)
72
+ end
73
+
74
+ def test_select_multikey
75
+ @connection.execute %q|insert into json_data_type (payload) VALUES ('{"k1":"v1", "k2":"v2", "k3":[1,2,3]}')|
76
+ x = JsonDataType.first
77
+ assert_equal({'k1' => 'v1', 'k2' => 'v2', 'k3' => [1,2,3]}, x.payload)
78
+ end
79
+
80
+ def test_null_json
81
+ @connection.execute %q|insert into json_data_type (payload) VALUES(null)|
82
+ x = JsonDataType.first
83
+ assert_equal(nil, x.payload)
84
+ end
85
+
86
+ end if Test::Unit::TestCase.ar_version('4.0')
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'db/postgres'
4
+
5
+ class PostgresqlLtreeTest < Test::Unit::TestCase
6
+
7
+ class Ltree < ActiveRecord::Base
8
+ self.table_name = 'ltrees'
9
+ end
10
+
11
+ @@ltree_support = nil
12
+
13
+ def self.startup
14
+ connection = ActiveRecord::Base.connection
15
+ connection = ActiveRecord::Base.connection
16
+ connection.transaction do
17
+ connection.create_table('ltrees') do |t|
18
+ t.ltree 'path'
19
+ end
20
+ end
21
+ @@ltree_support = true
22
+ rescue ActiveRecord::StatementInvalid => e
23
+ puts "skiping ltree tests due: #{e.message}"
24
+ @@ltree_support = false
25
+ end
26
+
27
+ def self.shutdown
28
+ ActiveRecord::Base.connection.execute 'drop table if exists ltrees'
29
+ end
30
+
31
+ def test_column
32
+ skip unless @@ltree_support
33
+ column = Ltree.columns_hash['path']
34
+ assert_equal :ltree, column.type
35
+ end
36
+
37
+ def test_write
38
+ skip unless @@ltree_support
39
+ ltree = Ltree.new(:path => '1.2.3.4')
40
+ assert ltree.save!
41
+ end
42
+
43
+ def test_select
44
+ skip unless @@ltree_support
45
+ @connection.execute "insert into ltrees (path) VALUES ('1.2.3')"
46
+ ltree = Ltree.first
47
+ assert_equal '1.2.3', ltree.path
48
+ end
49
+
50
+ end if Test::Unit::TestCase.ar_version('4.0')
@@ -0,0 +1,128 @@
1
+ require 'db/postgres'
2
+
3
+ class PostgresNativeTypesTest < Test::Unit::TestCase
4
+
5
+ class CustomersMigration < ActiveRecord::Migration
6
+ def self.up
7
+ execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
8
+ execute "CREATE SEQUENCE seq_pk_customers"
9
+ columns = [
10
+ "bigint_serial_should_be_integer bigint default nextval('seq_pk_customers')",
11
+ "integer_serial_should_be_integer integer default nextval('seq_pk_customers')",
12
+ "varchar_should_be_string varchar(2)",
13
+ "timestamp_should_be_datetime timestamp",
14
+ "bytea_should_be_binary bytea",
15
+ "double_precision_should_be_float double precision",
16
+ "real_should_be_float real",
17
+ "bool_should_be_boolean bool",
18
+ "interval_should_be_string interval",
19
+ "bigint_should_be_integer bigint"
20
+ ]
21
+ columns << "uuid_should_be_string uuid" if PG_VERSION >= 80300
22
+ execute %Q{CREATE TABLE customers (\n #{columns.join(",\n")} \n)}
23
+ end
24
+
25
+ def self.down
26
+ execute "DROP TABLE customers"
27
+ execute "DROP SEQUENCE IF EXISTS seq_pk_customers"
28
+ end
29
+ end
30
+
31
+ class Customer < ActiveRecord::Base; end
32
+
33
+ def self.startup
34
+ CustomersMigration.up
35
+ end
36
+
37
+ def self.shutdown
38
+ CustomersMigration.down
39
+ end
40
+
41
+ def column_type(column_name)
42
+ Customer.columns.detect { |c| c.name == column_name }.type
43
+ end
44
+
45
+ def test_uuid_column_should_map_to_string
46
+ return unless PG_VERSION >= 80300
47
+ if ar_version('4.0')
48
+ assert_equal :uuid, column_type("uuid_should_be_string")
49
+ else
50
+ assert_equal :string, column_type("uuid_should_be_string")
51
+ end
52
+ end
53
+
54
+ def test_interval_should_be_mapped_to_string
55
+ if ar_version('4.0')
56
+ assert_equal :interval, column_type("interval_should_be_string")
57
+ else
58
+ assert_equal :string, column_type("interval_should_be_string")
59
+ end
60
+ end
61
+
62
+ def test_bigint_serial_should_be_mapped_to_integer
63
+ assert_equal :integer, column_type("bigint_serial_should_be_integer")
64
+ end
65
+
66
+ def test_integer_serial_should_be_mapped_to_integer
67
+ assert_equal :integer, column_type("integer_serial_should_be_integer")
68
+ end
69
+
70
+ def test_varchar_should_be_mapped_to_string
71
+ assert_equal :string, column_type("varchar_should_be_string")
72
+ end
73
+
74
+ def test_timestamp_should_be_mapped_to_datetime
75
+ assert_equal :datetime, column_type("timestamp_should_be_datetime")
76
+ end
77
+
78
+ def test_bytea_should_be_mapped_to_binary
79
+ assert_equal :binary, column_type("bytea_should_be_binary")
80
+ end
81
+
82
+ def test_double_precision_should_be_mapped_to_float
83
+ assert_equal :float, column_type("double_precision_should_be_float")
84
+ end
85
+
86
+ def test_real_should_be_mapped_to_float
87
+ assert_equal :float, column_type("real_should_be_float")
88
+ end
89
+
90
+ def test_bool_should_be_mapped_to_boolean
91
+ assert_equal :boolean, column_type("bool_should_be_boolean")
92
+ end
93
+
94
+ def test_bigint_should_be_mapped_to_integer
95
+ assert_equal :integer, column_type("bigint_should_be_integer")
96
+ end
97
+
98
+ end
99
+
100
+ class PostgresTypeConversionTest < Test::Unit::TestCase
101
+
102
+ class BooleansMigration < ActiveRecord::Migration
103
+ def self.up
104
+ create_table :booleans do |t|
105
+ t.boolean :value, :default => false, :null => false
106
+ end
107
+ end
108
+
109
+ def self.down
110
+ drop_table :booleans
111
+ end
112
+ end
113
+
114
+ class Boolean < ActiveRecord::Base; end
115
+
116
+ def self.startup
117
+ BooleansMigration.up
118
+ end
119
+
120
+ def self.shutdown
121
+ BooleansMigration.down
122
+ end
123
+
124
+ def test_conversion_with_boolean_relation
125
+ ActiveRecord::Base.connection.raw_connection.set_native_database_types
126
+ end
127
+
128
+ end