ibm_db 3.0.4 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (351) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +8 -1
  3. data/LICENSE +1 -1
  4. data/ParameterizedQueries README +6 -6
  5. data/README +38 -55
  6. data/ext/Makefile +266 -0
  7. data/ext/extconf.rb +34 -3
  8. data/ext/gil_release_version +3 -0
  9. data/ext/ibm_db.c +106 -111
  10. data/ext/ibm_db.o +0 -0
  11. data/ext/ibm_db.so +0 -0
  12. data/ext/mkmf.log +103 -0
  13. data/ext/ruby_ibm_db_cli.o +0 -0
  14. data/ext/unicode_support_version +3 -0
  15. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +911 -527
  16. data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
  17. data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
  18. data/test/cases/adapter_test.rb +148 -58
  19. data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
  20. data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
  21. data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
  22. data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
  23. data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
  24. data/test/cases/adapters/mysql2/connection_test.rb +210 -0
  25. data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
  26. data/test/cases/adapters/mysql2/enum_test.rb +26 -0
  27. data/test/cases/adapters/mysql2/explain_test.rb +21 -0
  28. data/test/cases/adapters/mysql2/json_test.rb +195 -0
  29. data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
  30. data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
  31. data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
  32. data/test/cases/adapters/mysql2/schema_test.rb +126 -0
  33. data/test/cases/adapters/mysql2/sp_test.rb +36 -0
  34. data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
  35. data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
  36. data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
  37. data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
  38. data/test/cases/adapters/postgresql/array_test.rb +339 -0
  39. data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
  40. data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
  41. data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
  42. data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
  43. data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
  44. data/test/cases/adapters/postgresql/citext_test.rb +78 -0
  45. data/test/cases/adapters/postgresql/collation_test.rb +53 -0
  46. data/test/cases/adapters/postgresql/composite_test.rb +132 -0
  47. data/test/cases/adapters/postgresql/connection_test.rb +257 -0
  48. data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
  49. data/test/cases/adapters/postgresql/domain_test.rb +47 -0
  50. data/test/cases/adapters/postgresql/enum_test.rb +91 -0
  51. data/test/cases/adapters/postgresql/explain_test.rb +20 -0
  52. data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
  53. data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
  54. data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
  55. data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
  56. data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
  57. data/test/cases/adapters/postgresql/integer_test.rb +25 -0
  58. data/test/cases/adapters/postgresql/json_test.rb +237 -0
  59. data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
  60. data/test/cases/adapters/postgresql/money_test.rb +96 -0
  61. data/test/cases/adapters/postgresql/network_test.rb +94 -0
  62. data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
  63. data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
  64. data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
  65. data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
  66. data/test/cases/adapters/postgresql/range_test.rb +343 -0
  67. data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
  68. data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
  69. data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
  70. data/test/cases/adapters/postgresql/schema_test.rb +597 -0
  71. data/test/cases/adapters/postgresql/serial_test.rb +154 -0
  72. data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
  73. data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
  74. data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
  75. data/test/cases/adapters/postgresql/utils_test.rb +62 -0
  76. data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
  77. data/test/cases/adapters/postgresql/xml_test.rb +54 -0
  78. data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
  79. data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
  80. data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
  81. data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
  82. data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
  83. data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
  84. data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
  85. data/test/cases/aggregations_test.rb +11 -1
  86. data/test/cases/ar_schema_test.rb +35 -50
  87. data/test/cases/associations/association_scope_test.rb +1 -6
  88. data/test/cases/associations/belongs_to_associations_test.rb +122 -10
  89. data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
  90. data/test/cases/associations/callbacks_test.rb +5 -7
  91. data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
  92. data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
  93. data/test/cases/associations/eager_test.rb +176 -73
  94. data/test/cases/associations/extension_test.rb +7 -2
  95. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +104 -32
  96. data/test/cases/associations/has_many_associations_test.rb +382 -43
  97. data/test/cases/associations/has_many_through_associations_test.rb +108 -41
  98. data/test/cases/associations/has_one_associations_test.rb +105 -8
  99. data/test/cases/associations/has_one_through_associations_test.rb +6 -3
  100. data/test/cases/associations/inner_join_association_test.rb +3 -3
  101. data/test/cases/associations/inverse_associations_test.rb +51 -11
  102. data/test/cases/associations/join_model_test.rb +59 -36
  103. data/test/cases/associations/left_outer_join_association_test.rb +88 -0
  104. data/test/cases/associations/nested_through_associations_test.rb +2 -2
  105. data/test/cases/associations/required_test.rb +25 -5
  106. data/test/cases/associations_test.rb +39 -34
  107. data/test/cases/attribute_decorators_test.rb +9 -8
  108. data/test/cases/attribute_methods/read_test.rb +5 -5
  109. data/test/cases/attribute_methods_test.rb +97 -40
  110. data/test/cases/attribute_set_test.rb +74 -4
  111. data/test/cases/attribute_test.rb +84 -18
  112. data/test/cases/attributes_test.rb +151 -34
  113. data/test/cases/autosave_association_test.rb +149 -36
  114. data/test/cases/base_test.rb +311 -236
  115. data/test/cases/batches_test.rb +299 -22
  116. data/test/cases/binary_test.rb +2 -10
  117. data/test/cases/bind_parameter_test.rb +76 -66
  118. data/test/cases/cache_key_test.rb +26 -0
  119. data/test/cases/calculations_test.rb +167 -15
  120. data/test/cases/callbacks_test.rb +161 -68
  121. data/test/cases/coders/json_test.rb +15 -0
  122. data/test/cases/collection_cache_key_test.rb +115 -0
  123. data/test/cases/column_definition_test.rb +26 -57
  124. data/test/cases/comment_test.rb +145 -0
  125. data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
  126. data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
  127. data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
  128. data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
  129. data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
  130. data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
  131. data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
  132. data/test/cases/connection_management_test.rb +46 -56
  133. data/test/cases/connection_pool_test.rb +195 -20
  134. data/test/cases/connection_specification/resolver_test.rb +15 -0
  135. data/test/cases/counter_cache_test.rb +10 -5
  136. data/test/cases/custom_locking_test.rb +1 -1
  137. data/test/cases/database_statements_test.rb +18 -3
  138. data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
  139. data/test/cases/date_time_precision_test.rb +107 -0
  140. data/test/cases/defaults_test.rb +85 -89
  141. data/test/cases/dirty_test.rb +32 -44
  142. data/test/cases/disconnected_test.rb +4 -2
  143. data/test/cases/enum_test.rb +178 -24
  144. data/test/cases/errors_test.rb +16 -0
  145. data/test/cases/explain_test.rb +32 -21
  146. data/test/cases/finder_test.rb +279 -151
  147. data/test/cases/fixture_set/file_test.rb +18 -0
  148. data/test/cases/fixtures_test.rb +123 -32
  149. data/test/cases/forbidden_attributes_protection_test.rb +69 -3
  150. data/test/cases/helper.rb +10 -16
  151. data/test/cases/hot_compatibility_test.rb +89 -1
  152. data/test/cases/inheritance_test.rb +284 -53
  153. data/test/cases/integration_test.rb +23 -7
  154. data/test/cases/invalid_connection_test.rb +4 -2
  155. data/test/cases/invertible_migration_test.rb +124 -32
  156. data/test/cases/json_serialization_test.rb +11 -2
  157. data/test/cases/locking_test.rb +22 -6
  158. data/test/cases/log_subscriber_test.rb +106 -17
  159. data/test/cases/migration/change_schema_test.rb +118 -132
  160. data/test/cases/migration/change_table_test.rb +34 -2
  161. data/test/cases/migration/column_attributes_test.rb +7 -23
  162. data/test/cases/migration/column_positioning_test.rb +8 -8
  163. data/test/cases/migration/columns_test.rb +17 -11
  164. data/test/cases/migration/command_recorder_test.rb +47 -2
  165. data/test/cases/migration/compatibility_test.rb +118 -0
  166. data/test/cases/migration/create_join_table_test.rb +21 -12
  167. data/test/cases/migration/foreign_key_test.rb +68 -66
  168. data/test/cases/migration/index_test.rb +14 -12
  169. data/test/cases/migration/logger_test.rb +1 -1
  170. data/test/cases/migration/pending_migrations_test.rb +0 -1
  171. data/test/cases/migration/references_foreign_key_test.rb +114 -107
  172. data/test/cases/migration/references_index_test.rb +4 -4
  173. data/test/cases/migration/references_statements_test.rb +26 -6
  174. data/test/cases/migration/rename_table_test.rb +25 -25
  175. data/test/cases/migration_test.rb +279 -81
  176. data/test/cases/migrator_test.rb +91 -8
  177. data/test/cases/mixin_test.rb +0 -2
  178. data/test/cases/modules_test.rb +3 -4
  179. data/test/cases/multiparameter_attributes_test.rb +24 -2
  180. data/test/cases/multiple_db_test.rb +18 -11
  181. data/test/cases/nested_attributes_test.rb +74 -33
  182. data/test/cases/persistence_test.rb +102 -10
  183. data/test/cases/pooled_connections_test.rb +3 -3
  184. data/test/cases/primary_keys_test.rb +170 -31
  185. data/test/cases/query_cache_test.rb +216 -96
  186. data/test/cases/quoting_test.rb +65 -19
  187. data/test/cases/readonly_test.rb +2 -1
  188. data/test/cases/reflection_test.rb +77 -22
  189. data/test/cases/relation/delegation_test.rb +3 -8
  190. data/test/cases/relation/merging_test.rb +10 -14
  191. data/test/cases/relation/mutation_test.rb +42 -24
  192. data/test/cases/relation/or_test.rb +92 -0
  193. data/test/cases/relation/predicate_builder_test.rb +4 -2
  194. data/test/cases/relation/record_fetch_warning_test.rb +40 -0
  195. data/test/cases/relation/where_chain_test.rb +23 -99
  196. data/test/cases/relation/where_clause_test.rb +182 -0
  197. data/test/cases/relation/where_test.rb +45 -23
  198. data/test/cases/relation_test.rb +89 -58
  199. data/test/cases/relations_test.rb +249 -38
  200. data/test/cases/result_test.rb +10 -0
  201. data/test/cases/sanitize_test.rb +108 -15
  202. data/test/cases/schema_dumper_test.rb +119 -125
  203. data/test/cases/schema_loading_test.rb +52 -0
  204. data/test/cases/scoping/default_scoping_test.rb +113 -39
  205. data/test/cases/scoping/named_scoping_test.rb +46 -9
  206. data/test/cases/scoping/relation_scoping_test.rb +47 -4
  207. data/test/cases/secure_token_test.rb +32 -0
  208. data/test/cases/serialization_test.rb +1 -1
  209. data/test/cases/serialized_attribute_test.rb +93 -6
  210. data/test/cases/statement_cache_test.rb +38 -0
  211. data/test/cases/store_test.rb +2 -1
  212. data/test/cases/suppressor_test.rb +63 -0
  213. data/test/cases/tasks/database_tasks_test.rb +74 -8
  214. data/test/cases/tasks/mysql_rake_test.rb +143 -109
  215. data/test/cases/tasks/postgresql_rake_test.rb +71 -12
  216. data/test/cases/tasks/sqlite_rake_test.rb +30 -3
  217. data/test/cases/test_case.rb +28 -20
  218. data/test/cases/test_fixtures_test.rb +36 -0
  219. data/test/cases/time_precision_test.rb +103 -0
  220. data/test/cases/timestamp_test.rb +47 -14
  221. data/test/cases/touch_later_test.rb +121 -0
  222. data/test/cases/transaction_callbacks_test.rb +128 -62
  223. data/test/cases/transaction_isolation_test.rb +2 -2
  224. data/test/cases/transactions_test.rb +61 -43
  225. data/test/cases/type/adapter_specific_registry_test.rb +133 -0
  226. data/test/cases/type/date_time_test.rb +14 -0
  227. data/test/cases/type/integer_test.rb +2 -96
  228. data/test/cases/type/string_test.rb +0 -14
  229. data/test/cases/type_test.rb +39 -0
  230. data/test/cases/types_test.rb +1 -118
  231. data/test/cases/unconnected_test.rb +1 -1
  232. data/test/cases/validations/absence_validation_test.rb +73 -0
  233. data/test/cases/validations/association_validation_test.rb +13 -2
  234. data/test/cases/validations/i18n_validation_test.rb +6 -10
  235. data/test/cases/validations/length_validation_test.rb +62 -30
  236. data/test/cases/validations/presence_validation_test.rb +36 -1
  237. data/test/cases/validations/uniqueness_validation_test.rb +150 -36
  238. data/test/cases/validations_repair_helper.rb +2 -6
  239. data/test/cases/validations_test.rb +36 -7
  240. data/test/cases/view_test.rb +108 -5
  241. data/test/cases/yaml_serialization_test.rb +36 -1
  242. data/test/config.example.yml +97 -0
  243. data/test/fixtures/bad_posts.yml +9 -0
  244. data/test/fixtures/books.yml +20 -0
  245. data/test/fixtures/content.yml +3 -0
  246. data/test/fixtures/content_positions.yml +3 -0
  247. data/test/fixtures/dead_parrots.yml +5 -0
  248. data/test/fixtures/live_parrots.yml +4 -0
  249. data/test/fixtures/naked/yml/parrots.yml +2 -0
  250. data/test/fixtures/naked/yml/trees.yml +3 -0
  251. data/test/fixtures/nodes.yml +29 -0
  252. data/test/fixtures/other_comments.yml +6 -0
  253. data/test/fixtures/other_dogs.yml +2 -0
  254. data/test/fixtures/other_posts.yml +7 -0
  255. data/test/fixtures/price_estimates.yml +10 -1
  256. data/test/fixtures/trees.yml +3 -0
  257. data/test/migrations/10_urban/9_add_expressions.rb +1 -1
  258. data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
  259. data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
  260. data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
  261. data/test/migrations/missing/1_people_have_last_names.rb +2 -2
  262. data/test/migrations/missing/3_we_need_reminders.rb +2 -2
  263. data/test/migrations/missing/4_innocent_jointable.rb +2 -2
  264. data/test/migrations/rename/1_we_need_things.rb +2 -2
  265. data/test/migrations/rename/2_rename_things.rb +2 -2
  266. data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
  267. data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
  268. data/test/migrations/to_copy2/1_create_articles.rb +1 -1
  269. data/test/migrations/to_copy2/2_create_comments.rb +1 -1
  270. data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
  271. data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
  272. data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
  273. data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
  274. data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
  275. data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
  276. data/test/migrations/valid/2_we_need_reminders.rb +2 -2
  277. data/test/migrations/valid/3_innocent_jointable.rb +2 -2
  278. data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
  279. data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
  280. data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
  281. data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
  282. data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
  283. data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
  284. data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
  285. data/test/models/admin/randomly_named_c1.rb +6 -2
  286. data/test/models/aircraft.rb +1 -0
  287. data/test/models/author.rb +4 -7
  288. data/test/models/bird.rb +1 -1
  289. data/test/models/book.rb +5 -0
  290. data/test/models/bulb.rb +2 -1
  291. data/test/models/car.rb +3 -0
  292. data/test/models/cat.rb +10 -0
  293. data/test/models/chef.rb +5 -0
  294. data/test/models/club.rb +2 -0
  295. data/test/models/comment.rb +17 -5
  296. data/test/models/company.rb +7 -2
  297. data/test/models/company_in_module.rb +1 -1
  298. data/test/models/contact.rb +1 -1
  299. data/test/models/content.rb +40 -0
  300. data/test/models/customer.rb +8 -2
  301. data/test/models/developer.rb +22 -0
  302. data/test/models/face.rb +1 -1
  303. data/test/models/guitar.rb +4 -0
  304. data/test/models/hotel.rb +5 -0
  305. data/test/models/member.rb +1 -0
  306. data/test/models/member_detail.rb +4 -3
  307. data/test/models/mentor.rb +3 -0
  308. data/test/models/mocktail_designer.rb +2 -0
  309. data/test/models/node.rb +5 -0
  310. data/test/models/non_primary_key.rb +2 -0
  311. data/test/models/notification.rb +3 -0
  312. data/test/models/other_dog.rb +5 -0
  313. data/test/models/owner.rb +4 -1
  314. data/test/models/parrot.rb +6 -7
  315. data/test/models/person.rb +0 -1
  316. data/test/models/pet.rb +3 -0
  317. data/test/models/pet_treasure.rb +6 -0
  318. data/test/models/pirate.rb +3 -3
  319. data/test/models/post.rb +18 -9
  320. data/test/models/project.rb +11 -0
  321. data/test/models/randomly_named_c1.rb +1 -1
  322. data/test/models/recipe.rb +3 -0
  323. data/test/models/ship.rb +8 -2
  324. data/test/models/tag.rb +6 -0
  325. data/test/models/topic.rb +2 -8
  326. data/test/models/tree.rb +3 -0
  327. data/test/models/tuning_peg.rb +4 -0
  328. data/test/models/user.rb +14 -0
  329. data/test/models/uuid_item.rb +6 -0
  330. data/test/schema/mysql2_specific_schema.rb +33 -23
  331. data/test/schema/oracle_specific_schema.rb +1 -4
  332. data/test/schema/postgresql_specific_schema.rb +36 -124
  333. data/test/schema/schema.rb +183 -64
  334. data/test/schema/schema.rb.original +1057 -0
  335. data/test/schema/sqlite_specific_schema.rb +1 -5
  336. data/test/support/connection.rb +1 -0
  337. data/test/support/schema_dumping_helper.rb +1 -1
  338. data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
  339. data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
  340. metadata +145 -26
  341. data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
  342. data/test/cases/attribute_methods/serialization_test.rb +0 -29
  343. data/test/cases/migration/change_schema_test - Copy.rb +0 -448
  344. data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
  345. data/test/cases/migration/table_and_index_test.rb +0 -24
  346. data/test/cases/relation/where_test2.rb +0 -36
  347. data/test/cases/type/decimal_test.rb +0 -51
  348. data/test/cases/type/unsigned_integer_test.rb +0 -18
  349. data/test/cases/xml_serialization_test.rb +0 -457
  350. data/test/fixtures/naked/csv/accounts.csv +0 -1
  351. data/test/schema/mysql_specific_schema.rb +0 -70
@@ -1,5 +1,4 @@
1
1
  require "cases/migration/helper"
2
- require "minitest/mock"
3
2
 
4
3
  module ActiveRecord
5
4
  class Migration
@@ -13,7 +12,7 @@ module ActiveRecord
13
12
  end
14
13
 
15
14
  def with_change_table
16
- yield ConnectionAdapters::Table.new(:delete_me, @connection)
15
+ yield ActiveRecord::Base.connection.update_table_definition(:delete_me, @connection)
17
16
  end
18
17
 
19
18
  def test_references_column_type_adds_id
@@ -100,6 +99,13 @@ module ActiveRecord
100
99
  end
101
100
  end
102
101
 
102
+ def test_primary_key_creates_primary_key_column
103
+ with_change_table do |t|
104
+ @connection.expect :add_column, nil, [:delete_me, :id, :primary_key, primary_key: true, first: true]
105
+ t.primary_key :id, first: true
106
+ end
107
+ end
108
+
103
109
  def test_integer_creates_integer_column
104
110
  with_change_table do |t|
105
111
  @connection.expect :add_column, nil, [:delete_me, :foo, :integer, {}]
@@ -108,6 +114,14 @@ module ActiveRecord
108
114
  end
109
115
  end
110
116
 
117
+ def test_bigint_creates_bigint_column
118
+ with_change_table do |t|
119
+ @connection.expect :add_column, nil, [:delete_me, :foo, :bigint, {}]
120
+ @connection.expect :add_column, nil, [:delete_me, :bar, :bigint, {}]
121
+ t.bigint :foo, :bar
122
+ end
123
+ end
124
+
111
125
  def test_string_creates_string_column
112
126
  with_change_table do |t|
113
127
  @connection.expect :add_column, nil, [:delete_me, :foo, :string, {}]
@@ -116,6 +130,24 @@ module ActiveRecord
116
130
  end
117
131
  end
118
132
 
133
+ if current_adapter?(:PostgreSQLAdapter)
134
+ def test_json_creates_json_column
135
+ with_change_table do |t|
136
+ @connection.expect :add_column, nil, [:delete_me, :foo, :json, {}]
137
+ @connection.expect :add_column, nil, [:delete_me, :bar, :json, {}]
138
+ t.json :foo, :bar
139
+ end
140
+ end
141
+
142
+ def test_xml_creates_xml_column
143
+ with_change_table do |t|
144
+ @connection.expect :add_column, nil, [:delete_me, :foo, :xml, {}]
145
+ @connection.expect :add_column, nil, [:delete_me, :bar, :xml, {}]
146
+ t.xml :foo, :bar
147
+ end
148
+ end
149
+ end
150
+
119
151
  def test_column_creates_column
120
152
  with_change_table do |t|
121
153
  @connection.expect :add_column, nil, [:delete_me, :bar, :integer, {}]
@@ -5,7 +5,7 @@ module ActiveRecord
5
5
  class ColumnAttributesTest < ActiveRecord::TestCase
6
6
  include ActiveRecord::Migration::TestHelper
7
7
 
8
- self.use_transactional_fixtures = false
8
+ self.use_transactional_tests = false
9
9
 
10
10
  def test_add_column_newline_default
11
11
  string = "foo\nbar"
@@ -37,13 +37,13 @@ module ActiveRecord
37
37
 
38
38
  def test_add_column_without_limit
39
39
  # TODO: limit: nil should work with all adapters.
40
- skip "MySQL wrongly enforces a limit of 255" if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
40
+ skip "MySQL wrongly enforces a limit of 255" if current_adapter?(:Mysql2Adapter)
41
41
  add_column :test_models, :description, :string, limit: nil
42
42
  TestModel.reset_column_information
43
43
  assert_nil TestModel.columns_hash["description"].limit
44
44
  end
45
45
 
46
- if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
46
+ if current_adapter?(:Mysql2Adapter)
47
47
  def test_unabstracted_database_dependent_types
48
48
  add_column :test_models, :intelligence_quotient, :tinyint
49
49
  TestModel.reset_column_information
@@ -63,12 +63,8 @@ module ActiveRecord
63
63
  # Do a manual insertion
64
64
  if current_adapter?(:OracleAdapter)
65
65
  connection.execute "insert into test_models (id, wealth) values (people_seq.nextval, 12345678901234567890.0123456789)"
66
- elsif current_adapter?(:MysqlAdapter) && Mysql.client_version < 50003 #before MySQL 5.0.3 decimals stored as strings
67
- connection.execute "insert into test_models (wealth) values ('12345678901234567890.0123456789')"
68
66
  elsif current_adapter?(:PostgreSQLAdapter)
69
67
  connection.execute "insert into test_models (wealth) values (12345678901234567890.0123456789)"
70
- elsif current_adapter?(:IBM_DBAdapter)
71
- Person.connection.execute "insert into people (wealth, created_at, updated_at, lock_version, first_name) values (12345678901234567890.0123456789, CURRENT TIMESTAMP, CURRENT TIMESTAMP, 0, 'Jim')"
72
68
  else
73
69
  connection.execute "insert into test_models (wealth) values (12345678901234567890.0123456789)"
74
70
  end
@@ -86,12 +82,7 @@ module ActiveRecord
86
82
  TestModel.delete_all
87
83
 
88
84
  # Now use the Rails insertion
89
- unless current_adapter?(:IBM_DBAdapter)
90
- assert_nothing_raised { Person.create :wealth => BigDecimal.new("12345678901234567890.0123456789") }
91
- else
92
- # First_name is a not null column, hence ensure a value is specified
93
- assert_nothing_raised { Person.create ({:wealth => BigDecimal.new("12345678901234567890.0123456789"), :first_name => "James"}) }
94
- end
85
+ TestModel.create :wealth => BigDecimal.new("12345678901234567890.0123456789")
95
86
 
96
87
  # SELECT
97
88
  row = TestModel.first
@@ -163,22 +154,15 @@ module ActiveRecord
163
154
  assert_equal String, bob.first_name.class
164
155
  assert_equal String, bob.last_name.class
165
156
  assert_equal String, bob.bio.class
166
- assert_equal Fixnum, bob.age.class
157
+ assert_kind_of Integer, bob.age
167
158
  assert_equal Time, bob.birthday.class
168
-
169
- if current_adapter?(:OracleAdapter)
170
- # Oracle doesn't differentiate between date/time
171
- assert_equal Time, bob.favorite_day.class
172
- else
173
- assert_equal Date, bob.favorite_day.class
174
- end
175
-
159
+ assert_equal Date, bob.favorite_day.class
176
160
  assert_instance_of TrueClass, bob.male?
177
161
  assert_kind_of BigDecimal, bob.wealth
178
162
  end
179
163
  end
180
164
 
181
- if current_adapter?(:MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)
165
+ if current_adapter?(:Mysql2Adapter, :PostgreSQLAdapter)
182
166
  def test_out_of_range_limit_should_raise
183
167
  assert_raise(ActiveRecordError) { add_column :test_models, :integer_too_big, :integer, :limit => 10 }
184
168
 
@@ -3,7 +3,7 @@ require 'cases/helper'
3
3
  module ActiveRecord
4
4
  class Migration
5
5
  class ColumnPositioningTest < ActiveRecord::TestCase
6
- attr_reader :connection, :table_name
6
+ attr_reader :connection
7
7
  alias :conn :connection
8
8
 
9
9
  def setup
@@ -23,32 +23,32 @@ module ActiveRecord
23
23
  ActiveRecord::Base.primary_key_prefix_type = nil
24
24
  end
25
25
 
26
- if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
26
+ if current_adapter?(:Mysql2Adapter)
27
27
  def test_column_positioning
28
- assert_equal %w(first second third), conn.columns(:testings).map {|c| c.name }
28
+ assert_equal %w(first second third), conn.columns(:testings).map(&:name)
29
29
  end
30
30
 
31
31
  def test_add_column_with_positioning
32
32
  conn.add_column :testings, :new_col, :integer
33
- assert_equal %w(first second third new_col), conn.columns(:testings).map {|c| c.name }
33
+ assert_equal %w(first second third new_col), conn.columns(:testings).map(&:name)
34
34
  end
35
35
 
36
36
  def test_add_column_with_positioning_first
37
37
  conn.add_column :testings, :new_col, :integer, :first => true
38
- assert_equal %w(new_col first second third), conn.columns(:testings).map {|c| c.name }
38
+ assert_equal %w(new_col first second third), conn.columns(:testings).map(&:name)
39
39
  end
40
40
 
41
41
  def test_add_column_with_positioning_after
42
42
  conn.add_column :testings, :new_col, :integer, :after => :first
43
- assert_equal %w(first new_col second third), conn.columns(:testings).map {|c| c.name }
43
+ assert_equal %w(first new_col second third), conn.columns(:testings).map(&:name)
44
44
  end
45
45
 
46
46
  def test_change_column_with_positioning
47
47
  conn.change_column :testings, :second, :integer, :first => true
48
- assert_equal %w(second first third), conn.columns(:testings).map {|c| c.name }
48
+ assert_equal %w(second first third), conn.columns(:testings).map(&:name)
49
49
 
50
50
  conn.change_column :testings, :second, :integer, :after => :third
51
- assert_equal %w(first third second), conn.columns(:testings).map {|c| c.name }
51
+ assert_equal %w(first third second), conn.columns(:testings).map(&:name)
52
52
  end
53
53
  end
54
54
  end
@@ -5,10 +5,8 @@ module ActiveRecord
5
5
  class ColumnsTest < ActiveRecord::TestCase
6
6
  include ActiveRecord::Migration::TestHelper
7
7
 
8
- self.use_transactional_fixtures = false
8
+ self.use_transactional_tests = false
9
9
 
10
- if(!current_adapter?(:IBM_DBAdapter) )
11
- #|| @ibm_db_rename_supported)
12
10
  # FIXME: this is more of an integration test with AR::Base and the
13
11
  # schema modifications. Maybe we should move this?
14
12
  def test_add_rename
@@ -64,10 +62,10 @@ if(!current_adapter?(:IBM_DBAdapter) )
64
62
  assert_equal '70000', default_after
65
63
  end
66
64
 
67
- if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
65
+ if current_adapter?(:Mysql2Adapter)
68
66
  def test_mysql_rename_column_preserves_auto_increment
69
67
  rename_column "test_models", "id", "id_test"
70
- assert_equal "auto_increment", connection.columns("test_models").find { |c| c.name == "id_test" }.extra
68
+ assert connection.columns("test_models").find { |c| c.name == "id_test" }.auto_increment?
71
69
  TestModel.reset_column_information
72
70
  ensure
73
71
  rename_column "test_models", "id_test", "id"
@@ -130,7 +128,6 @@ if(!current_adapter?(:IBM_DBAdapter) )
130
128
  rename_column "test_models", "hat_name", "name"
131
129
  assert_equal ['idx_hat_name'], connection.indexes('test_models').map(&:name)
132
130
  end
133
- end
134
131
 
135
132
  def test_remove_column_with_index
136
133
  add_column "test_models", :hat_name, :string
@@ -142,6 +139,10 @@ end
142
139
  end
143
140
 
144
141
  def test_remove_column_with_multi_column_index
142
+ # MariaDB starting with 10.2.8
143
+ # Dropping a column that is part of a multi-column UNIQUE constraint is not permitted.
144
+ skip if current_adapter?(:Mysql2Adapter) && connection.mariadb? && connection.version >= "10.2.8"
145
+
145
146
  add_column "test_models", :hat_size, :integer
146
147
  add_column "test_models", :hat_style, :string, :limit => 100
147
148
  add_index "test_models", ["hat_style", "hat_size"], :unique => true
@@ -182,7 +183,6 @@ end
182
183
  assert TestModel.columns_hash["funny"].null, "Column 'funny' must allow nulls again at this point"
183
184
  end
184
185
 
185
- unless current_adapter?(:IBM_DBAdapter)
186
186
  def test_change_column
187
187
  add_column 'test_models', 'age', :integer
188
188
  add_column 'test_models', 'approved', :boolean, :default => true
@@ -200,7 +200,7 @@ unless current_adapter?(:IBM_DBAdapter)
200
200
 
201
201
  old_columns = connection.columns(TestModel.table_name)
202
202
  assert old_columns.find { |c|
203
- default = c.type_cast_from_database(c.default)
203
+ default = connection.lookup_cast_type_from_column(c).deserialize(c.default)
204
204
  c.name == 'approved' && c.type == :boolean && default == true
205
205
  }
206
206
 
@@ -208,16 +208,15 @@ unless current_adapter?(:IBM_DBAdapter)
208
208
  new_columns = connection.columns(TestModel.table_name)
209
209
 
210
210
  assert_not new_columns.find { |c|
211
- default = c.type_cast_from_database(c.default)
211
+ default = connection.lookup_cast_type_from_column(c).deserialize(c.default)
212
212
  c.name == 'approved' and c.type == :boolean and default == true
213
213
  }
214
214
  assert new_columns.find { |c|
215
- default = c.type_cast_from_database(c.default)
215
+ default = connection.lookup_cast_type_from_column(c).deserialize(c.default)
216
216
  c.name == 'approved' and c.type == :boolean and default == false
217
217
  }
218
218
  change_column :test_models, :approved, :boolean, :default => true
219
219
  end
220
- end
221
220
 
222
221
  def test_change_column_with_nil_default
223
222
  add_column "test_models", "contributor", :boolean, :default => true
@@ -272,6 +271,13 @@ end
272
271
  assert_nil TestModel.new.first_name
273
272
  end
274
273
 
274
+ def test_change_column_default_with_from_and_to
275
+ add_column "test_models", "first_name", :string
276
+ connection.change_column_default "test_models", "first_name", from: nil, to: "Tester"
277
+
278
+ assert_equal "Tester", TestModel.new.first_name
279
+ end
280
+
275
281
  def test_remove_column_no_second_parameter_raises_exception
276
282
  assert_raise(ArgumentError) { connection.remove_column("funny") }
277
283
  end
@@ -31,7 +31,8 @@ module ActiveRecord
31
31
  end
32
32
 
33
33
  def test_unknown_commands_delegate
34
- recorder = CommandRecorder.new(stub(:foo => 'bar'))
34
+ recorder = Struct.new(:foo)
35
+ recorder = CommandRecorder.new(recorder.new('bar'))
35
36
  assert_equal 'bar', recorder.foo
36
37
  end
37
38
 
@@ -169,6 +170,16 @@ module ActiveRecord
169
170
  end
170
171
  end
171
172
 
173
+ def test_invert_change_column_default_with_from_and_to
174
+ change = @recorder.inverse_of :change_column_default, [:table, :column, from: "old_value", to: "new_value"]
175
+ assert_equal [:change_column_default, [:table, :column, from: "new_value", to: "old_value"]], change
176
+ end
177
+
178
+ def test_invert_change_column_default_with_from_and_to_with_boolean
179
+ change = @recorder.inverse_of :change_column_default, [:table, :column, from: true, to: false]
180
+ assert_equal [:change_column_default, [:table, :column, from: false, to: true]], change
181
+ end
182
+
172
183
  def test_invert_change_column_null
173
184
  add = @recorder.inverse_of :change_column_null, [:table, :column, true]
174
185
  assert_equal [:change_column_null, [:table, :column, false]], add
@@ -206,6 +217,11 @@ module ActiveRecord
206
217
  end
207
218
 
208
219
  def test_invert_remove_index
220
+ add = @recorder.inverse_of :remove_index, [:table, :one]
221
+ assert_equal [:add_index, [:table, :one]], add
222
+ end
223
+
224
+ def test_invert_remove_index_with_column
209
225
  add = @recorder.inverse_of :remove_index, [:table, {column: [:one, :two], options: true}]
210
226
  assert_equal [:add_index, [:table, [:one, :two], options: true]], add
211
227
  end
@@ -281,17 +297,42 @@ module ActiveRecord
281
297
  assert_equal [:remove_foreign_key, [:dogs, :people]], enable
282
298
  end
283
299
 
300
+ def test_invert_remove_foreign_key
301
+ enable = @recorder.inverse_of :remove_foreign_key, [:dogs, :people]
302
+ assert_equal [:add_foreign_key, [:dogs, :people]], enable
303
+ end
304
+
284
305
  def test_invert_add_foreign_key_with_column
285
306
  enable = @recorder.inverse_of :add_foreign_key, [:dogs, :people, column: "owner_id"]
286
307
  assert_equal [:remove_foreign_key, [:dogs, column: "owner_id"]], enable
287
308
  end
288
309
 
310
+ def test_invert_remove_foreign_key_with_column
311
+ enable = @recorder.inverse_of :remove_foreign_key, [:dogs, :people, column: "owner_id"]
312
+ assert_equal [:add_foreign_key, [:dogs, :people, column: "owner_id"]], enable
313
+ end
314
+
289
315
  def test_invert_add_foreign_key_with_column_and_name
290
316
  enable = @recorder.inverse_of :add_foreign_key, [:dogs, :people, column: "owner_id", name: "fk"]
291
317
  assert_equal [:remove_foreign_key, [:dogs, name: "fk"]], enable
292
318
  end
293
319
 
294
- def test_remove_foreign_key_is_irreversible
320
+ def test_invert_remove_foreign_key_with_column_and_name
321
+ enable = @recorder.inverse_of :remove_foreign_key, [:dogs, :people, column: "owner_id", name: "fk"]
322
+ assert_equal [:add_foreign_key, [:dogs, :people, column: "owner_id", name: "fk"]], enable
323
+ end
324
+
325
+ def test_invert_remove_foreign_key_with_primary_key
326
+ enable = @recorder.inverse_of :remove_foreign_key, [:dogs, :people, primary_key: "person_id"]
327
+ assert_equal [:add_foreign_key, [:dogs, :people, primary_key: "person_id"]], enable
328
+ end
329
+
330
+ def test_invert_remove_foreign_key_with_on_delete_on_update
331
+ enable = @recorder.inverse_of :remove_foreign_key, [:dogs, :people, on_delete: :nullify, on_update: :cascade]
332
+ assert_equal [:add_foreign_key, [:dogs, :people, on_delete: :nullify, on_update: :cascade]], enable
333
+ end
334
+
335
+ def test_invert_remove_foreign_key_is_irreversible_without_to_table
295
336
  assert_raises ActiveRecord::IrreversibleMigration do
296
337
  @recorder.inverse_of :remove_foreign_key, [:dogs, column: "owner_id"]
297
338
  end
@@ -299,6 +340,10 @@ module ActiveRecord
299
340
  assert_raises ActiveRecord::IrreversibleMigration do
300
341
  @recorder.inverse_of :remove_foreign_key, [:dogs, name: "fk"]
301
342
  end
343
+
344
+ assert_raises ActiveRecord::IrreversibleMigration do
345
+ @recorder.inverse_of :remove_foreign_key, [:dogs]
346
+ end
302
347
  end
303
348
  end
304
349
  end
@@ -0,0 +1,118 @@
1
+ require 'cases/helper'
2
+
3
+ module ActiveRecord
4
+ class Migration
5
+ class CompatibilityTest < ActiveRecord::TestCase
6
+ attr_reader :connection
7
+ self.use_transactional_tests = false
8
+
9
+ def setup
10
+ super
11
+ @connection = ActiveRecord::Base.connection
12
+ @verbose_was = ActiveRecord::Migration.verbose
13
+ ActiveRecord::Migration.verbose = false
14
+
15
+ connection.create_table :testings do |t|
16
+ t.column :foo, :string, :limit => 100
17
+ t.column :bar, :string, :limit => 100
18
+ end
19
+ end
20
+
21
+ teardown do
22
+ connection.drop_table :testings rescue nil
23
+ ActiveRecord::Migration.verbose = @verbose_was
24
+ ActiveRecord::SchemaMigration.delete_all rescue nil
25
+ end
26
+
27
+ def test_migration_doesnt_remove_named_index
28
+ connection.add_index :testings, :foo, :name => "custom_index_name"
29
+
30
+ migration = Class.new(ActiveRecord::Migration[4.2]) {
31
+ def version; 101 end
32
+ def migrate(x)
33
+ remove_index :testings, :foo
34
+ end
35
+ }.new
36
+
37
+ assert connection.index_exists?(:testings, :foo, name: "custom_index_name")
38
+ assert_raise(StandardError) { ActiveRecord::Migrator.new(:up, [migration]).migrate }
39
+ assert connection.index_exists?(:testings, :foo, name: "custom_index_name")
40
+ end
41
+
42
+ def test_migration_does_remove_unnamed_index
43
+ connection.add_index :testings, :bar
44
+
45
+ migration = Class.new(ActiveRecord::Migration[4.2]) {
46
+ def version; 101 end
47
+ def migrate(x)
48
+ remove_index :testings, :bar
49
+ end
50
+ }.new
51
+
52
+ assert connection.index_exists?(:testings, :bar)
53
+ ActiveRecord::Migrator.new(:up, [migration]).migrate
54
+ assert_not connection.index_exists?(:testings, :bar)
55
+ end
56
+
57
+ def test_references_does_not_add_index_by_default
58
+ migration = Class.new(ActiveRecord::Migration) {
59
+ def migrate(x)
60
+ create_table :more_testings do |t|
61
+ t.references :foo
62
+ t.belongs_to :bar, index: false
63
+ end
64
+ end
65
+ }.new
66
+
67
+ ActiveRecord::Migrator.new(:up, [migration]).migrate
68
+
69
+ assert_not connection.index_exists?(:more_testings, :foo_id)
70
+ assert_not connection.index_exists?(:more_testings, :bar_id)
71
+ ensure
72
+ connection.drop_table :more_testings rescue nil
73
+ end
74
+
75
+ def test_timestamps_have_null_constraints_if_not_present_in_migration_of_create_table
76
+ migration = Class.new(ActiveRecord::Migration) {
77
+ def migrate(x)
78
+ create_table :more_testings do |t|
79
+ t.timestamps
80
+ end
81
+ end
82
+ }.new
83
+
84
+ ActiveRecord::Migrator.new(:up, [migration]).migrate
85
+
86
+ assert connection.columns(:more_testings).find { |c| c.name == 'created_at' }.null
87
+ assert connection.columns(:more_testings).find { |c| c.name == 'updated_at' }.null
88
+ ensure
89
+ connection.drop_table :more_testings rescue nil
90
+ end
91
+
92
+ def test_timestamps_have_null_constraints_if_not_present_in_migration_for_adding_timestamps_to_existing_table
93
+ migration = Class.new(ActiveRecord::Migration) {
94
+ def migrate(x)
95
+ add_timestamps :testings
96
+ end
97
+ }.new
98
+
99
+ ActiveRecord::Migrator.new(:up, [migration]).migrate
100
+
101
+ assert connection.columns(:testings).find { |c| c.name == 'created_at' }.null
102
+ assert connection.columns(:testings).find { |c| c.name == 'updated_at' }.null
103
+ end
104
+
105
+ def test_legacy_migrations_get_deprecation_warning_when_run
106
+ migration = Class.new(ActiveRecord::Migration) {
107
+ def up
108
+ add_column :testings, :baz, :string
109
+ end
110
+ }
111
+
112
+ assert_deprecated do
113
+ migration.migrate :up
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end