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
@@ -0,0 +1,6 @@
1
+ require 'db/sqlite3'
2
+ require 'has_many_through'
3
+
4
+ class SQLite3HasManyThroughTest < Test::Unit::TestCase
5
+ include HasManyThroughMethods
6
+ end
@@ -1,13 +1,8 @@
1
- require 'jdbc_common'
2
1
  require 'db/sqlite3'
3
2
  require 'models/data_types'
4
3
  require 'models/validates_uniqueness_of_string'
5
-
6
- #module Rails
7
- # def self.logger
8
- # ActiveRecord::Base.logger
9
- # end
10
- #end
4
+ require 'simple'
5
+ require 'jdbc_common'
11
6
 
12
7
  class SQLite3SimpleTest < Test::Unit::TestCase
13
8
  include SimpleTestMethods
@@ -15,7 +10,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
15
10
  include ColumnNameQuotingTests
16
11
  include DirtyAttributeTests
17
12
  include XmlColumnTests
18
-
13
+ include ExplainSupportTestMethods if ar_version("3.1")
14
+ include CustomSelectTestMethods
15
+
19
16
  def test_recreate_database
20
17
  assert connection.tables.include?(Entry.table_name)
21
18
  db = connection.database_name
@@ -25,6 +22,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
25
22
  end
26
23
 
27
24
  def test_execute_insert
25
+ user = User.create! :login => 'user1'
26
+ Entry.create! :title => 'E1', :user_id => user.id
27
+
28
28
  assert_equal 1, Entry.count
29
29
  id = connection.execute "INSERT INTO entries (title, content) VALUES ('Execute Insert', 'This now works with SQLite3')"
30
30
  assert_equal Entry.last.id, id
@@ -32,6 +32,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
32
32
  end
33
33
 
34
34
  def test_execute_update
35
+ user = User.create! :login => 'user1'
36
+ Entry.create! :title => 'E1', :user_id => user.id
37
+
35
38
  affected_rows = connection.execute "UPDATE entries SET title = 'Execute Update' WHERE id = #{Entry.first.id}"
36
39
  assert_equal 1, affected_rows
37
40
  assert_equal 'Execute Update', Entry.first.title
@@ -85,21 +88,26 @@ class SQLite3SimpleTest < Test::Unit::TestCase
85
88
  end
86
89
 
87
90
  def test_rename_column_preserves_content
88
- post = Entry.first
89
- assert_equal @title, post.title
90
- assert_equal @content, post.content
91
- assert_equal @rating, post.rating
92
-
93
- assert_nothing_raised do
94
- ActiveRecord::Schema.define do
95
- rename_column "entries", "title", "name"
96
- end
91
+ title = "First post!"
92
+ content = "Hello from JRuby on Rails!"
93
+ rating = 205.76
94
+ user = User.create! :login => "something"
95
+ entry = Entry.create! :title => title, :content => content, :rating => rating, :user => user
96
+
97
+ entry.reload
98
+ #assert_equal title, entry.title
99
+ #assert_equal content, entry.content
100
+ #assert_equal rating, entry.rating
101
+
102
+ ActiveRecord::Schema.define do
103
+ rename_column "entries", "title", "name"
104
+ rename_column "entries", "rating", "popularity"
97
105
  end
98
-
99
- post = Entry.first
100
- assert_equal @title, post.name
101
- assert_equal @content, post.content
102
- assert_equal @rating, post.rating
106
+
107
+ entry = Entry.find(entry.id)
108
+ assert_equal title, entry.name
109
+ assert_equal content, entry.content
110
+ assert_equal rating, entry.popularity
103
111
  end
104
112
 
105
113
  def test_rename_column_preserves_index
@@ -107,30 +115,26 @@ class SQLite3SimpleTest < Test::Unit::TestCase
107
115
 
108
116
  index_name = "entries_index"
109
117
 
110
- assert_nothing_raised do
111
- ActiveRecord::Schema.define do
112
- add_index "entries", "title", :name => index_name
113
- end
118
+ ActiveRecord::Schema.define do
119
+ add_index "entries", "title", :name => index_name
114
120
  end
115
121
 
116
122
  indexes = connection.indexes(:entries)
117
123
  assert_equal(1, indexes.size)
118
124
  assert_equal "entries", indexes.first.table.to_s
119
125
  assert_equal index_name, indexes.first.name
120
- assert !indexes.first.unique
126
+ assert ! indexes.first.unique
121
127
  assert_equal ["title"], indexes.first.columns
122
128
 
123
- assert_nothing_raised do
124
- ActiveRecord::Schema.define do
125
- rename_column "entries", "title", "name"
126
- end
129
+ ActiveRecord::Schema.define do
130
+ rename_column "entries", "title", "name"
127
131
  end
128
132
 
129
133
  indexes = connection.indexes(:entries)
130
134
  assert_equal(1, indexes.size)
131
135
  assert_equal "entries", indexes.first.table.to_s
132
136
  assert_equal index_name, indexes.first.name
133
- assert !indexes.first.unique
137
+ assert ! indexes.first.unique
134
138
  assert_equal ["name"], indexes.first.columns
135
139
  end
136
140
 
@@ -141,11 +145,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
141
145
  end
142
146
  end
143
147
 
144
- cols = ActiveRecord::Base.connection.columns("entries")
145
- col = cols.find{|col| col.name == "test_column_default"}
146
- assert col
147
- assert_equal col.default, nil
148
-
148
+ columns = ActiveRecord::Base.connection.columns("entries")
149
+ assert column = columns.find{ |c| c.name == "test_column_default" }
150
+ assert_equal column.default, nil
149
151
  end
150
152
 
151
153
  def test_change_column_default
@@ -155,10 +157,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
155
157
  end
156
158
  end
157
159
 
158
- cols = ActiveRecord::Base.connection.columns("entries")
159
- col = cols.find{|col| col.name == "test_change_column_default"}
160
- assert col
161
- assert_equal col.default, 'unchanged'
160
+ columns = ActiveRecord::Base.connection.columns("entries")
161
+ assert column = columns.find{ |c| c.name == "test_change_column_default" }
162
+ assert_equal column.default, 'unchanged'
162
163
 
163
164
  assert_nothing_raised do
164
165
  ActiveRecord::Schema.define do
@@ -166,10 +167,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
166
167
  end
167
168
  end
168
169
 
169
- cols = ActiveRecord::Base.connection.columns("entries")
170
- col = cols.find{|col| col.name == "test_change_column_default"}
171
- assert col
172
- assert_equal col.default, 'changed'
170
+ columns = ActiveRecord::Base.connection.columns("entries")
171
+ assert column = columns.find{ |c| c.name == "test_change_column_default" }
172
+ assert_equal column.default, 'changed'
173
173
  end
174
174
 
175
175
  def test_change_column
@@ -179,10 +179,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
179
179
  end
180
180
  end
181
181
 
182
- cols = ActiveRecord::Base.connection.columns("entries")
183
- col = cols.find{|col| col.name == "test_change_column"}
184
- assert col
185
- assert_equal col.type, :string
182
+ columns = ActiveRecord::Base.connection.columns("entries")
183
+ assert column = columns.find{ |c| c.name == "test_change_column" }
184
+ assert_equal column.type, :string
186
185
 
187
186
  assert_nothing_raised do
188
187
  ActiveRecord::Schema.define do
@@ -190,10 +189,9 @@ class SQLite3SimpleTest < Test::Unit::TestCase
190
189
  end
191
190
  end
192
191
 
193
- cols = ActiveRecord::Base.connection.columns("entries")
194
- col = cols.find{|col| col.name == "test_change_column"}
195
- assert col
196
- assert_equal col.type, :integer
192
+ columns = ActiveRecord::Base.connection.columns("entries")
193
+ assert column = columns.find{ |c| c.name == "test_change_column" }
194
+ assert_equal column.type, :integer
197
195
  end
198
196
 
199
197
  def test_change_column_with_new_precision_and_scale
@@ -233,10 +231,8 @@ class SQLite3SimpleTest < Test::Unit::TestCase
233
231
  assert Entry.all.empty?
234
232
  end
235
233
 
236
- # #override
234
+ # @override
237
235
  def test_big_decimal
238
- #ActiveRecord::Base.logger.level = Logger::DEBUG
239
-
240
236
  test_value = 1234567890.0 # FINE just like native adapter
241
237
  db_type = DbType.create!(:big_decimal => test_value)
242
238
  db_type = DbType.find(db_type.id)
@@ -255,14 +251,18 @@ class SQLite3SimpleTest < Test::Unit::TestCase
255
251
  # TODO native gets us 12345678901234567000.0 JDBC gets us 1
256
252
  #assert_equal test_value, db_type.big_decimal
257
253
  #super
258
- ensure
259
- #ActiveRecord::Base.logger.level = Logger::WARN
260
254
  end
261
255
 
262
- include ExplainSupportTestMethods if ar_version("3.1")
256
+ # @override SQLite3 returns FLOAT (JDBC type) for DECIMAL columns
257
+ def test_custom_select_decimal
258
+ model = DbType.create! :sample_small_decimal => ( decimal = BigDecimal.new('5.45') )
259
+ if ActiveRecord::VERSION::MAJOR >= 3
260
+ model = DbType.where("id = #{model.id}").select('sample_small_decimal AS custom_decimal').first
261
+ else
262
+ model = DbType.find(:first, :conditions => "id = #{model.id}", :select => 'sample_small_decimal AS custom_decimal')
263
+ end
264
+ assert_equal decimal, model.custom_decimal
265
+ #assert_instance_of BigDecimal, model.custom_decimal
266
+ end
263
267
 
264
268
  end
265
-
266
- class SQLite3HasManyThroughTest < Test::Unit::TestCase
267
- include HasManyThroughMethods
268
- end
@@ -0,0 +1,32 @@
1
+ require 'db/sqlite3'
2
+ require 'transaction'
3
+
4
+ class SQLite3TransactionTest < Test::Unit::TestCase
5
+ include TransactionTestMethods
6
+
7
+ def test_supports_transaction_isolation
8
+ assert ActiveRecord::Base.connection.supports_transaction_isolation?
9
+ # NOTE: adapter tell us it supports but JDBC meta-data API returns false ?!
10
+ #assert ActiveRecord::Base.connection.supports_transaction_isolation?(:read_uncommitted)
11
+ assert ActiveRecord::Base.connection.supports_transaction_isolation?(:serializable)
12
+ end
13
+
14
+ # supports only TRANSACTION_SERIALIZABLE and TRANSACTION_READ_UNCOMMITTED
15
+
16
+ def test_transaction_isolation_read_committed
17
+ assert ! ActiveRecord::Base.connection.supports_transaction_isolation?(:read_committed)
18
+
19
+ assert_raise ActiveRecord::TransactionIsolationError do
20
+ super
21
+ end
22
+ end if Test::Unit::TestCase.ar_version('4.0')
23
+
24
+ def test_transaction_isolation_repeatable_read
25
+ assert ! ActiveRecord::Base.connection.supports_transaction_isolation?(:repeatable_read)
26
+
27
+ assert_raise ActiveRecord::TransactionIsolationError do
28
+ super
29
+ end
30
+ end if Test::Unit::TestCase.ar_version('4.0')
31
+
32
+ end
@@ -1,78 +1,25 @@
1
- class CreateRbac < ActiveRecord::Migration
2
- def self.up
3
- create_table :role_assignments do |t|
4
- t.column :role_id, :integer
5
- t.column :user_id, :integer
6
- end
7
-
8
- create_table :roles do |t|
9
- t.column :name, :string
10
- t.column :description, :string
11
- end
12
-
13
- create_table :permission_groups do |t|
14
- t.column :right_id, :integer, :null => false
15
- t.column :role_id, :integer, :null => false
16
- end
17
-
18
- create_table :rights do |t|
19
- t.column :name, :string
20
- t.column :controller_name, :string
21
- t.column :actions, :string
22
- t.column :hours, :float, :null => false
23
- end
24
- end
25
-
26
- def self.down
27
- drop_table :role_assignments
28
- drop_table :roles
29
- drop_table :permission_groups
30
- drop_table :rights
31
- end
32
- end
33
-
34
- class Right < ActiveRecord::Base
35
- has_many :permission_groups, :dependent => :destroy
36
- has_many :roles, :through => :permission_groups
37
- end
38
-
39
- class Role < ActiveRecord::Base
40
- has_many :permission_groups, :dependent => :destroy
41
- has_many :rights, :through => :permission_groups
42
- has_many :role_assignments, :dependent => :destroy
43
-
44
- def has_right?(right)
45
- rights.include? right
46
- end
47
- end
48
-
49
- class PermissionGroup < ActiveRecord::Base
50
- belongs_to :right
51
- belongs_to :role
52
- end
53
-
54
- class RoleAssignment < ActiveRecord::Base
55
- belongs_to :user
56
- belongs_to :role
57
- end
1
+ require 'models/rights_and_roles'
58
2
 
59
3
  module HasManyThroughMethods
4
+
60
5
  def setup
61
- CreateRbac.up
6
+ CreateRightsAndRoles.up
62
7
  end
63
8
 
64
9
  def teardown
65
- CreateRbac.down
10
+ CreateRightsAndRoles.down
66
11
  end
67
12
 
68
13
  def test_has_many_through
69
- admin_role = Role.create( {:name => "Administrator", :description => "System defined super user - access to right and role management."} )
70
- admin_role.save!
14
+ admin_role = Role.create! :name => "Administrator",
15
+ :description => "super user - access to right and role management"
71
16
 
72
17
  assert_equal(0, admin_role.rights.sum(:hours))
73
18
 
74
- role_rights = Right.create( {:name => "Administrator - Full Access To Roles", :actions => "*", :controller_name => "Admin::RolesController", :hours => 0} )
75
- right_rights = Right.create( {:name => "Administrator - Full Access To Rights", :actions => "*", :controller_name => "Admin::RightsController", :hours => 1.5} )
19
+ role_rights = Right.create :name => "Administrator - Full Access To Roles",
20
+ :actions => "*", :controller_name => "Admin::RolesController", :hours => 0
21
+ right_rights = Right.create :name => "Administrator - Full Access To Rights",
22
+ :actions => "*", :controller_name => "Admin::RightsController", :hours => 1.5
76
23
 
77
24
  admin_role.rights << role_rights
78
25
  admin_role.rights << right_rights
@@ -80,7 +27,8 @@ module HasManyThroughMethods
80
27
 
81
28
  assert_equal(1.5, admin_role.rights.sum(:hours))
82
29
 
83
- rights_only_role = Role.create!(:name => "Rights Manager", :description => "access to rights management")
30
+ rights_only_role = Role.create! :name => "Rights Manager",
31
+ :description => "access to rights management"
84
32
  rights_only_role.rights << right_rights
85
33
  rights_only_role.save!
86
34
  rights_only_role.reload
@@ -90,4 +38,21 @@ module HasManyThroughMethods
90
38
  assert admin_role.reload.has_right?(role_rights)
91
39
  assert ! rights_only_role.has_right?(role_rights)
92
40
  end
41
+
42
+ def test_has_many_select_rows_with_relation
43
+ role = Role.create! :name => "main", :description => "main role"
44
+ Role.create! :name => "user", :description => "user role"
45
+
46
+ Right.create! :name => "r0", :hours => 0
47
+ r1 = Right.create! :name => "r1", :hours => 1
48
+ r2 = Right.create! :name => "r2", :hours => 2
49
+ Right.create! :name => "r3", :hours => 3
50
+
51
+ role.permission_groups.create! :right => r1.reload
52
+ role.permission_groups.create! :right => r2.reload
53
+
54
+ groups = role.reload.permission_groups.select('right_id')
55
+ assert_equal [ [ r1.id ], [ r2.id ] ], role.connection.select_rows(groups)
56
+ end if Test::Unit::TestCase.ar_version('3.0')
57
+
93
58
  end
data/test/jdbc/oracle.rb CHANGED
@@ -8,8 +8,19 @@ module Jdbc
8
8
  end
9
9
  end
10
10
 
11
+ def self.optional_jars
12
+ [ 'xdb6.jar', 'orai18n.jar' ] # 'xmlparserv2.jar'
13
+ end
14
+
11
15
  def self.load_driver(method = :load)
12
16
  send method, driver_jar
17
+ optional_jars.each do |optional_jar|
18
+ begin
19
+ send method, optional_jar
20
+ rescue LoadError => e
21
+ puts "failed to load optional driver jar: #{optional_jar} (#{e})"
22
+ end
23
+ end
13
24
  end
14
25
 
15
26
  def self.driver_name
data/test/jndi_test.rb CHANGED
@@ -8,10 +8,19 @@ require 'db/jndi_config'
8
8
  class DerbyJndiTest < Test::Unit::TestCase
9
9
  include SimpleTestMethods
10
10
 
11
+ # Derby specifics :
12
+ DbTypeMigration.big_decimal_precision = 31
13
+ ALIVE_SQL = 'SELECT 1 FROM SYS.SYSSCHEMAS'
14
+
11
15
  def self.startup
12
- ActiveRecord::Base.establish_connection JNDI_CONFIG
16
+ ActiveRecord::Base.establish_connection( {
17
+ :connection_alive_sql => ALIVE_SQL
18
+ }.merge(JNDI_CONFIG) )
13
19
  end
14
20
 
21
+ # @override
22
+ #def test_connection_alive_sql; end
23
+
15
24
  test "(raw) connection is a jndi connection" do
16
25
  connection = ActiveRecord::Base.connection.raw_connection
17
26
  assert_true connection.jndi_connection?
@@ -37,13 +46,16 @@ require 'db/jndi_pooled_config'
37
46
 
38
47
  class DerbyJndiPooledTest < Test::Unit::TestCase
39
48
  include SimpleTestMethods
40
-
41
- DbTypeMigration.big_decimal_precision = 31
42
49
 
43
50
  def self.startup
44
- ActiveRecord::Base.establish_connection JNDI_POOLED_CONFIG
51
+ ActiveRecord::Base.establish_connection( {
52
+ :connection_alive_sql => DerbyJndiTest::ALIVE_SQL
53
+ }.merge(JNDI_POOLED_CONFIG) )
45
54
  end
46
55
 
56
+ # @override
57
+ #def test_connection_alive_sql; end
58
+
47
59
  test "(raw) connection is a jndi connection" do
48
60
  connection = ActiveRecord::Base.connection.raw_connection
49
61
  assert_true connection.jndi_connection?