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
data/test/schema_dump.rb DELETED
@@ -1,182 +0,0 @@
1
- require 'stringio'
2
- require 'test_helper'
3
- require 'simple' # due MigrationSetup
4
- require 'active_record/schema_dumper'
5
-
6
- module SchemaDumpTestMethods
7
- include MigrationSetup
8
-
9
- def test_dumping_schema_with_index
10
- connection = ActiveRecord::Base.connection
11
- connection.add_index :entries, :title
12
- StringIO.open do |io|
13
- ActiveRecord::SchemaDumper.dump(connection, io)
14
- assert_match(/add_index "entries",/, io.string)
15
- end
16
- ensure
17
- connection.remove_index :entries, :title
18
- end
19
-
20
- def standard_dump(io = StringIO.new, ignore_tables = [])
21
- io = StringIO.new
22
- ActiveRecord::SchemaDumper.ignore_tables = ignore_tables
23
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, io)
24
- io.string
25
- end
26
- private :standard_dump
27
-
28
- def test_magic_comment
29
- standard_dump(strio = StringIO.new)
30
- assert_match "# encoding: #{strio.external_encoding.name}", standard_dump
31
- end if ( "string".encoding_aware? rescue nil )
32
-
33
- def test_schema_dump
34
- output = standard_dump
35
- assert_match %r{create_table "users"}, output
36
- assert_match %r{create_table "entries"}, output
37
- assert_no_match %r{create_table "schema_migrations"}, output
38
- end
39
-
40
- def test_schema_dump_excludes_sqlite_sequence
41
- output = standard_dump
42
- assert_no_match %r{create_table "sqlite_sequence"}, output
43
- end
44
-
45
- def assert_line_up(lines, pattern, required = false)
46
- return assert(true) if lines.empty?
47
- matches = lines.map { |line| line.match(pattern) }
48
- assert matches.all? if required
49
- matches.compact!
50
- return assert(true) if matches.empty?
51
- assert_equal 1, matches.map{ |match| match.offset(0).first }.uniq.length
52
- end
53
-
54
- def column_definition_lines(output = standard_dump)
55
- output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map{ |m| m.last.split(/\n/) }
56
- end
57
- private :column_definition_lines
58
-
59
- def test_types_line_up
60
- column_definition_lines.each do |column_set|
61
- next if column_set.empty?
62
-
63
- lengths = column_set.map do |column|
64
- if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean)\s+"/)
65
- match[0].length
66
- end
67
- end
68
-
69
- assert_equal 1, lengths.uniq.length
70
- end
71
- end
72
-
73
- def test_arguments_line_up
74
- column_definition_lines.each do |column_set|
75
- assert_line_up(column_set, /(:default => )|(default: )/)
76
- assert_line_up(column_set, /(:limit => )|(limit: )/)
77
- assert_line_up(column_set, /(:null => )|(null: )/)
78
- end
79
- end
80
-
81
- def test_no_dump_errors
82
- output = standard_dump
83
- assert_no_match %r{\# Could not dump table}, output
84
- end
85
-
86
- def test_schema_dump_includes_not_null_columns
87
- output = standard_dump(StringIO.new, [/^[^u]/]) # keep users
88
- assert_match %r{(:null => false)|(null: false)}, output
89
- end
90
-
91
- def test_schema_dump_with_string_ignored_table
92
- stream = StringIO.new
93
-
94
- ActiveRecord::SchemaDumper.ignore_tables = ['users']
95
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
96
- output = stream.string
97
- assert_no_match %r{create_table "users"}, output
98
- assert_match %r{create_table "entries"}, output
99
- assert_no_match %r{create_table "schema_migrations"}, output
100
- end
101
-
102
- def test_schema_dump_with_regexp_ignored_table
103
- output = standard_dump(StringIO.new, [/^user/]) # ignore users
104
- assert_no_match %r{create_table "users"}, output
105
- assert_match %r{create_table "entries"}, output
106
- assert_no_match %r{create_table "schema_migrations"}, output
107
- end
108
-
109
- def test_schema_dump_should_honor_nonstandard_primary_keys
110
- output = standard_dump
111
- match = output.match(%r{create_table "custom_pk_names"(.*)do})
112
- assert_not_nil(match, "nonstandardpk table not found")
113
- assert_match %r((:primary_key => "custom_id")|(primary_key: "custom_id")), match[1], "non-standard primary key not preserved"
114
- end
115
-
116
- def test_schema_dump_includes_decimal_options
117
- output = standard_dump(StringIO.new, [/^[^d]/]) # keep db_types
118
- # t.column :sample_small_decimal, :decimal, :precision => 3, :scale => 2, :default => 3.14
119
- if ar_version('4.0')
120
- assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 3.14}, output
121
- else
122
- assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 3.14}, output
123
- end
124
- end
125
-
126
- def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
127
- output = standard_dump
128
- precision = DbTypeMigration.big_decimal_precision
129
- if ar_version('4.0')
130
- assert_match %r{t.decimal\s+"big_decimal",\s+precision: #{precision},\s+scale: 0}, output
131
- else
132
- assert_match %r{t.decimal\s+"big_decimal",\s+:precision => #{precision},\s+:scale => 0}, output
133
- end
134
- end if Test::Unit::TestCase.ar_version('3.0') # does not work in 2.3 :
135
- # t.integer "big_decimal", :limit => 38, :precision => 38, :scale => 0
136
-
137
- def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added
138
- output = standard_dump
139
- match = output.match(%r{create_table "string_ids"(.*)do.*\n(.*)\n})
140
- assert_not_nil(match, "string_ids table not found")
141
- assert_match %r((:id => false)|(id: false)), match[1], "no table id not preserved"
142
- if ar_version('4.0')
143
- assert_match %r{t.string[[:space:]]+"id",[[:space:]]+null: false$}, match[2], "non-primary key id column not preserved"
144
- else
145
- assert_match %r{t.string[[:space:]]+"id",[[:space:]]+:null => false$}, match[2], "non-primary key id column not preserved"
146
- end
147
- end
148
-
149
- def test_schema_dump_keeps_id_false_when_id_is_false_and_unique_not_null_column_added
150
- output = standard_dump
151
- assert_match %r{create_table "things", (:id => false)|(id: false)}, output
152
- end
153
-
154
- class CreateDogMigration < ActiveRecord::Migration
155
- def up
156
- create_table :dogs do |t|
157
- t.column :name, :string
158
- end
159
- end
160
- def down
161
- drop_table :dogs
162
- end
163
- end
164
-
165
- def test_schema_dump_with_table_name_prefix_and_suffix
166
- ActiveRecord::Base.table_name_prefix = 'foo_'
167
- ActiveRecord::Base.table_name_suffix = '_bar'
168
-
169
- migration = CreateDogMigration.new
170
- migration.migrate(:up)
171
-
172
- output = standard_dump
173
- assert_no_match %r{create_table "foo_.+_bar"}, output
174
- assert_no_match %r{create_index "foo_.+_bar"}, output
175
- assert_no_match %r{create_table "schema_migrations"}, output
176
- ensure
177
- migration.migrate(:down)
178
-
179
- ActiveRecord::Base.table_name_suffix = ActiveRecord::Base.table_name_prefix = ''
180
- end if Test::Unit::TestCase.ar_version('3.2')
181
-
182
- end
data/test/serialize.rb DELETED
@@ -1,275 +0,0 @@
1
- require 'models/topic'
2
- require 'ostruct'
3
-
4
- # borrosed from AR/test/cases/serialized_attribute_test.rb
5
-
6
- module SerializeTestMethods
7
-
8
- def self.included(base)
9
- base.extend UpAndDown
10
- end
11
-
12
- module UpAndDown
13
-
14
- def startup
15
- super
16
- TopicMigration.up
17
- end
18
-
19
- def shutdown
20
- super
21
- TopicMigration.down
22
- end
23
-
24
- end
25
-
26
- def setup
27
- super
28
- end
29
-
30
- def teardown
31
- super
32
- Topic.serialize("content")
33
- end
34
-
35
- MyObject = Struct.new :attribute1, :attribute2
36
-
37
- def test_list_of_serialized_attributes
38
- assert_equal %w(content), Topic.serialized_attributes.keys
39
- end
40
-
41
- def test_serialized_attribute
42
- Topic.serialize("content", MyObject)
43
-
44
- myobj = MyObject.new('value1', 'value2')
45
- topic = Topic.create("content" => myobj)
46
- assert_equal(myobj, topic.content)
47
-
48
- topic.reload
49
- assert_equal(myobj, topic.content)
50
- end
51
-
52
- def test_serialized_attribute_init_with
53
- topic = Topic.allocate
54
- topic.init_with('attributes' => { 'content' => '--- foo' })
55
- assert_equal 'foo', topic.content
56
- end if Test::Unit::TestCase.ar_version('3.0')
57
-
58
- def test_serialized_attribute_in_base_class
59
- Topic.serialize("content", Hash)
60
-
61
- hash = { 'content1' => 'value1', 'content2' => 'value2' }
62
- important_topic = ImportantTopic.create("content" => hash)
63
- assert_equal(hash, important_topic.content)
64
-
65
- important_topic.reload
66
- assert_equal(hash, important_topic.content)
67
- end
68
-
69
- # This test was added to fix GH #4004. Obviously the value returned
70
- # is not really the value 'before type cast' so we should maybe think
71
- # about changing that in the future.
72
- # def test_serialized_attribute_before_type_cast_returns_unserialized_value
73
- # Topic.serialize :content, Hash
74
- #
75
- # t = Topic.new :content => { :foo => :bar }
76
- # assert_equal({ :foo => :bar }, t.content_before_type_cast)
77
- # t.save!
78
- # t.reload
79
- # assert_equal({ :foo => :bar }, t.content_before_type_cast)
80
- # end
81
-
82
- # def test_serialized_attributes_before_type_cast_returns_unserialized_value
83
- # Topic.serialize :content, Hash
84
- #
85
- # t = Topic.new :content => { :foo => :bar }
86
- # assert_equal({ :foo => :bar }, t.attributes_before_type_cast["content"])
87
- # t.save!
88
- # t.reload
89
- # assert_equal({ :foo => :bar }, t.attributes_before_type_cast["content"])
90
- # end
91
-
92
- def test_serialized_ostruct
93
- Topic.serialize :content, OpenStruct
94
-
95
- t = Topic.new
96
- t.content.foo = 'bar'
97
- t.save!
98
- assert_equal 'bar', t.reload.content.foo
99
- end if Test::Unit::TestCase.ar_version('3.1')
100
-
101
- def test_serialized_attribute_declared_in_subclass
102
- hash = { 'important1' => 'value1', 'important2' => 'value2' }
103
- important_topic = ImportantTopic.create("important" => hash)
104
- assert_equal(hash, important_topic.important)
105
-
106
- important_topic.reload
107
- assert_equal(hash, important_topic.important)
108
- assert_equal(hash, important_topic.read_attribute(:important))
109
- end
110
-
111
- def test_serialized_time_attribute
112
- myobj = Time.local(2008,1,1,1,0)
113
- topic = Topic.create("content" => myobj).reload
114
- assert_equal(myobj, topic.content)
115
- end
116
-
117
- def test_serialized_string_attribute
118
- myobj = "Yes"
119
- topic = Topic.create("content" => myobj).reload
120
- assert_equal(myobj, topic.content)
121
- end
122
-
123
- def test_nil_serialized_attribute_with_class_constraint
124
- topic = ImportantTopic.new
125
- assert_nil topic.content
126
- end
127
-
128
- def test_nil_serialized_attribute_without_class_constraint
129
- topic = Topic.new
130
- assert_nil topic.content
131
- end
132
-
133
- def test_nil_not_serialized_without_class_constraint
134
- #ActiveRecord::Base.logger.level = Logger::DEBUG
135
- topic = Topic.new(:content => nil); topic.save!
136
- # NOTE: seems smt broken on AR 3.2's side inserts '--- \n' !
137
- #assert_equal 1, Topic.where(:content => nil).count
138
- assert_nil topic.reload.content
139
- ensure
140
- #ActiveRecord::Base.logger.level = Logger::WARN
141
- end
142
-
143
- def test_nil_not_serialized_with_class_constraint
144
- #ActiveRecord::Base.logger.level = Logger::DEBUG
145
- topic = ImportantTopic.new(:content => nil); topic.save!
146
- # NOTE: seems smt broken on AR 3.2's side inserts '--- \n' !
147
- #assert_equal 1, ImportantTopic.where(:content => nil).count
148
- assert_nil topic.reload.content
149
- ensure
150
- #ActiveRecord::Base.logger.level = Logger::WARN
151
- end
152
-
153
- def test_serialized_attribute_should_raise_exception_on_save_with_wrong_type
154
- Topic.serialize(:content, Hash)
155
- topic = Topic.new(:content => "string")
156
- assert_raise(ActiveRecord::SerializationTypeMismatch) { topic.save }
157
- end if Test::Unit::TestCase.ar_version('3.2')
158
-
159
- def test_should_raise_exception_on_serialized_attribute_with_type_mismatch
160
- myobj = MyObject.new('value1', 'value2')
161
- topic = Topic.new(:content => myobj)
162
- assert topic.save
163
- Topic.serialize(:content, Hash)
164
- assert_raise(ActiveRecord::SerializationTypeMismatch) { Topic.find(topic.id).content }
165
- end if Test::Unit::TestCase.ar_version('3.2')
166
-
167
- def test_serialized_attribute_with_class_constraint
168
- settings = { "color" => "blue" }
169
- Topic.serialize(:content, Hash)
170
- topic = Topic.new(:content => settings)
171
- assert topic.save
172
- assert_equal(settings, Topic.find(topic.id).content)
173
- end
174
-
175
- def test_serialized_default_class
176
- Topic.serialize(:content, Hash)
177
- topic = Topic.new
178
- assert_equal Hash, topic.content.class
179
- assert_equal Hash, topic.read_attribute(:content).class
180
- topic.content["beer"] = "MadridRb"
181
- assert topic.save
182
- topic.reload
183
- assert_equal Hash, topic.content.class
184
- assert_equal "MadridRb", topic.content["beer"]
185
- end if Test::Unit::TestCase.ar_version('3.1')
186
-
187
- def test_serialized_no_default_class_for_object
188
- topic = Topic.new
189
- assert_nil topic.content
190
- end
191
-
192
- def test_serialized_boolean_value_true
193
- Topic.serialize(:content)
194
- topic = Topic.new(:content => true)
195
- assert topic.save
196
- topic = topic.reload
197
- assert_equal topic.content, true
198
- end if Test::Unit::TestCase.ar_version('3.0')
199
-
200
- def test_serialized_boolean_value_false
201
- Topic.serialize(:content)
202
- topic = Topic.new(:content => false)
203
- assert topic.save
204
- topic = topic.reload
205
- assert_equal topic.content, false
206
- end if Test::Unit::TestCase.ar_version('3.0')
207
-
208
- def test_serialize_with_coder
209
- coder = Class.new {
210
- # Identity
211
- def load(thing)
212
- thing
213
- end
214
-
215
- # base 64
216
- def dump(thing)
217
- [thing].pack('m')
218
- end
219
- }.new
220
-
221
- Topic.serialize(:content, coder)
222
- s = 'hello world'
223
- topic = Topic.new(:content => s)
224
- assert topic.save
225
- topic = topic.reload
226
- assert_equal [s].pack('m'), topic.content
227
- ensure
228
- Topic.serialize(:content)
229
- end if Test::Unit::TestCase.ar_version('3.1')
230
-
231
- def test_serialize_with_bcrypt_coder
232
- require 'bcrypt'
233
- crypt_coder = Class.new {
234
- def load(thing)
235
- return unless thing
236
- BCrypt::Password.new thing
237
- end
238
-
239
- def dump(thing)
240
- BCrypt::Password.create(thing).to_s
241
- end
242
- }.new
243
-
244
- Topic.serialize(:content, crypt_coder)
245
- password = 'password'
246
- topic = Topic.new(:content => password)
247
- assert topic.save
248
- topic = topic.reload
249
- assert_kind_of BCrypt::Password, topic.content
250
- assert_equal(true, topic.content == password, 'password should equal')
251
- end if Test::Unit::TestCase.ar_version('3.1')
252
-
253
- def test_serialize_attribute_via_select_method_when_time_zone_available
254
- ActiveRecord::Base.time_zone_aware_attributes = true
255
- Topic.serialize(:content, MyObject)
256
-
257
- myobj = MyObject.new('value1', 'value2')
258
- topic = Topic.create(:content => myobj)
259
-
260
- assert_equal myobj, Topic.select(:content).find(topic.id).content
261
- assert_raise(ActiveModel::MissingAttributeError) { Topic.select(:id).find(topic.id).content }
262
- ensure
263
- ActiveRecord::Base.time_zone_aware_attributes = false
264
- end if Test::Unit::TestCase.ar_version('3.2')
265
-
266
- # def test_serialize_attribute_can_be_serialized_in_an_integer_column
267
- # insures = ['life']
268
- # person = SerializedPerson.new(:first_name => 'David', :insures => insures)
269
- # assert person.save
270
- # person = person.reload
271
- # assert_equal(insures, person.insures)
272
- # end
273
-
274
- end
275
-