ibm_db 3.0.5-x86-mingw32 → 5.0.5-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (358) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +4 -0
  3. data/LICENSE +1 -1
  4. data/ParameterizedQueries README +6 -6
  5. data/README +38 -55
  6. data/ext/Makefile +269 -0
  7. data/ext/extconf.rb +34 -3
  8. data/ext/gil_release_version +3 -0
  9. data/ext/ibm_db-i386-mingw32.def +2 -0
  10. data/ext/ibm_db.c +100 -108
  11. data/ext/ibm_db.o +0 -0
  12. data/ext/ibm_db.so +0 -0
  13. data/ext/mkmf.log +110 -0
  14. data/ext/ruby_ibm_db_cli.o +0 -0
  15. data/ext/unicode_support_version +3 -0
  16. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +923 -527
  17. data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
  18. data/lib/mswin32/ibm_db.rb +7 -39
  19. data/lib/mswin32/rb2x/i386/ibm_db.so +0 -0
  20. data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
  21. data/test/cases/adapter_test.rb +133 -58
  22. data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
  23. data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
  24. data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
  25. data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
  26. data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
  27. data/test/cases/adapters/mysql2/connection_test.rb +210 -0
  28. data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
  29. data/test/cases/adapters/mysql2/enum_test.rb +26 -0
  30. data/test/cases/adapters/mysql2/explain_test.rb +21 -0
  31. data/test/cases/adapters/mysql2/json_test.rb +195 -0
  32. data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
  33. data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
  34. data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
  35. data/test/cases/adapters/mysql2/schema_test.rb +126 -0
  36. data/test/cases/adapters/mysql2/sp_test.rb +36 -0
  37. data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
  38. data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
  39. data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
  40. data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
  41. data/test/cases/adapters/postgresql/array_test.rb +339 -0
  42. data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
  43. data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
  44. data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
  45. data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
  46. data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
  47. data/test/cases/adapters/postgresql/citext_test.rb +78 -0
  48. data/test/cases/adapters/postgresql/collation_test.rb +53 -0
  49. data/test/cases/adapters/postgresql/composite_test.rb +132 -0
  50. data/test/cases/adapters/postgresql/connection_test.rb +257 -0
  51. data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
  52. data/test/cases/adapters/postgresql/domain_test.rb +47 -0
  53. data/test/cases/adapters/postgresql/enum_test.rb +91 -0
  54. data/test/cases/adapters/postgresql/explain_test.rb +20 -0
  55. data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
  56. data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
  57. data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
  58. data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
  59. data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
  60. data/test/cases/adapters/postgresql/integer_test.rb +25 -0
  61. data/test/cases/adapters/postgresql/json_test.rb +237 -0
  62. data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
  63. data/test/cases/adapters/postgresql/money_test.rb +96 -0
  64. data/test/cases/adapters/postgresql/network_test.rb +94 -0
  65. data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
  66. data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
  67. data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
  68. data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
  69. data/test/cases/adapters/postgresql/range_test.rb +343 -0
  70. data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
  71. data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
  72. data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
  73. data/test/cases/adapters/postgresql/schema_test.rb +597 -0
  74. data/test/cases/adapters/postgresql/serial_test.rb +154 -0
  75. data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
  76. data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
  77. data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
  78. data/test/cases/adapters/postgresql/utils_test.rb +62 -0
  79. data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
  80. data/test/cases/adapters/postgresql/xml_test.rb +54 -0
  81. data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
  82. data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
  83. data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
  84. data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
  85. data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
  86. data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
  87. data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
  88. data/test/cases/aggregations_test.rb +11 -1
  89. data/test/cases/ar_schema_test.rb +35 -50
  90. data/test/cases/associations/association_scope_test.rb +1 -6
  91. data/test/cases/associations/belongs_to_associations_test.rb +122 -10
  92. data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
  93. data/test/cases/associations/callbacks_test.rb +5 -7
  94. data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
  95. data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
  96. data/test/cases/associations/eager_test.rb +158 -73
  97. data/test/cases/associations/extension_test.rb +7 -2
  98. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +64 -32
  99. data/test/cases/associations/has_many_associations_test.rb +362 -43
  100. data/test/cases/associations/has_many_through_associations_test.rb +108 -41
  101. data/test/cases/associations/has_one_associations_test.rb +105 -8
  102. data/test/cases/associations/has_one_through_associations_test.rb +6 -3
  103. data/test/cases/associations/inner_join_association_test.rb +3 -3
  104. data/test/cases/associations/inverse_associations_test.rb +38 -11
  105. data/test/cases/associations/join_model_test.rb +59 -36
  106. data/test/cases/associations/left_outer_join_association_test.rb +88 -0
  107. data/test/cases/associations/nested_through_associations_test.rb +2 -2
  108. data/test/cases/associations/required_test.rb +25 -5
  109. data/test/cases/associations_test.rb +39 -34
  110. data/test/cases/attribute_decorators_test.rb +9 -8
  111. data/test/cases/attribute_methods/read_test.rb +5 -5
  112. data/test/cases/attribute_methods_test.rb +97 -40
  113. data/test/cases/attribute_set_test.rb +64 -4
  114. data/test/cases/attribute_test.rb +84 -18
  115. data/test/cases/attributes_test.rb +151 -34
  116. data/test/cases/autosave_association_test.rb +149 -36
  117. data/test/cases/base_test.rb +290 -241
  118. data/test/cases/batches_test.rb +299 -22
  119. data/test/cases/binary_test.rb +2 -10
  120. data/test/cases/bind_parameter_test.rb +76 -66
  121. data/test/cases/cache_key_test.rb +26 -0
  122. data/test/cases/calculations_test.rb +167 -15
  123. data/test/cases/callbacks_test.rb +161 -68
  124. data/test/cases/coders/json_test.rb +15 -0
  125. data/test/cases/collection_cache_key_test.rb +115 -0
  126. data/test/cases/column_definition_test.rb +26 -57
  127. data/test/cases/comment_test.rb +145 -0
  128. data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
  129. data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
  130. data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
  131. data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
  132. data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
  133. data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
  134. data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
  135. data/test/cases/connection_management_test.rb +46 -56
  136. data/test/cases/connection_pool_test.rb +195 -20
  137. data/test/cases/connection_specification/resolver_test.rb +15 -0
  138. data/test/cases/counter_cache_test.rb +10 -5
  139. data/test/cases/custom_locking_test.rb +1 -1
  140. data/test/cases/database_statements_test.rb +18 -3
  141. data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
  142. data/test/cases/date_time_precision_test.rb +107 -0
  143. data/test/cases/defaults_test.rb +85 -89
  144. data/test/cases/dirty_test.rb +30 -52
  145. data/test/cases/disconnected_test.rb +4 -2
  146. data/test/cases/enum_test.rb +178 -24
  147. data/test/cases/errors_test.rb +16 -0
  148. data/test/cases/explain_test.rb +32 -21
  149. data/test/cases/finder_test.rb +273 -148
  150. data/test/cases/fixture_set/file_test.rb +18 -0
  151. data/test/cases/fixtures_test.rb +112 -32
  152. data/test/cases/forbidden_attributes_protection_test.rb +69 -3
  153. data/test/cases/helper.rb +10 -16
  154. data/test/cases/hot_compatibility_test.rb +89 -1
  155. data/test/cases/inheritance_test.rb +284 -53
  156. data/test/cases/integration_test.rb +23 -7
  157. data/test/cases/invalid_connection_test.rb +4 -2
  158. data/test/cases/invertible_migration_test.rb +124 -32
  159. data/test/cases/json_serialization_test.rb +11 -2
  160. data/test/cases/locking_test.rb +22 -6
  161. data/test/cases/log_subscriber_test.rb +106 -17
  162. data/test/cases/migration/change_schema_test.rb +60 -114
  163. data/test/cases/migration/change_table_test.rb +34 -2
  164. data/test/cases/migration/column_attributes_test.rb +7 -23
  165. data/test/cases/migration/column_positioning_test.rb +8 -8
  166. data/test/cases/migration/columns_test.rb +17 -11
  167. data/test/cases/migration/command_recorder_test.rb +47 -2
  168. data/test/cases/migration/compatibility_test.rb +118 -0
  169. data/test/cases/migration/create_join_table_test.rb +21 -12
  170. data/test/cases/migration/foreign_key_test.rb +52 -18
  171. data/test/cases/migration/index_test.rb +14 -12
  172. data/test/cases/migration/logger_test.rb +1 -1
  173. data/test/cases/migration/pending_migrations_test.rb +0 -1
  174. data/test/cases/migration/references_foreign_key_test.rb +59 -7
  175. data/test/cases/migration/references_index_test.rb +4 -4
  176. data/test/cases/migration/references_statements_test.rb +26 -6
  177. data/test/cases/migration/rename_table_test.rb +25 -25
  178. data/test/cases/migration_test.rb +279 -81
  179. data/test/cases/migrator_test.rb +91 -8
  180. data/test/cases/mixin_test.rb +0 -2
  181. data/test/cases/modules_test.rb +3 -4
  182. data/test/cases/multiparameter_attributes_test.rb +24 -2
  183. data/test/cases/multiple_db_test.rb +11 -4
  184. data/test/cases/nested_attributes_test.rb +61 -33
  185. data/test/cases/persistence_test.rb +102 -10
  186. data/test/cases/pooled_connections_test.rb +3 -3
  187. data/test/cases/primary_keys_test.rb +170 -31
  188. data/test/cases/query_cache_test.rb +216 -96
  189. data/test/cases/quoting_test.rb +65 -19
  190. data/test/cases/readonly_test.rb +2 -1
  191. data/test/cases/reflection_test.rb +68 -22
  192. data/test/cases/relation/delegation_test.rb +3 -8
  193. data/test/cases/relation/merging_test.rb +10 -14
  194. data/test/cases/relation/mutation_test.rb +42 -24
  195. data/test/cases/relation/or_test.rb +92 -0
  196. data/test/cases/relation/predicate_builder_test.rb +4 -2
  197. data/test/cases/relation/record_fetch_warning_test.rb +40 -0
  198. data/test/cases/relation/where_chain_test.rb +23 -99
  199. data/test/cases/relation/where_clause_test.rb +182 -0
  200. data/test/cases/relation/where_test.rb +45 -23
  201. data/test/cases/relation_test.rb +67 -58
  202. data/test/cases/relations_test.rb +249 -38
  203. data/test/cases/result_test.rb +10 -0
  204. data/test/cases/sanitize_test.rb +108 -15
  205. data/test/cases/schema_dumper_test.rb +119 -125
  206. data/test/cases/schema_loading_test.rb +52 -0
  207. data/test/cases/scoping/default_scoping_test.rb +113 -39
  208. data/test/cases/scoping/named_scoping_test.rb +46 -9
  209. data/test/cases/scoping/relation_scoping_test.rb +47 -4
  210. data/test/cases/secure_token_test.rb +32 -0
  211. data/test/cases/serialization_test.rb +1 -1
  212. data/test/cases/serialized_attribute_test.rb +93 -6
  213. data/test/cases/statement_cache_test.rb +38 -0
  214. data/test/cases/store_test.rb +2 -1
  215. data/test/cases/suppressor_test.rb +63 -0
  216. data/test/cases/tasks/database_tasks_test.rb +73 -9
  217. data/test/cases/tasks/mysql_rake_test.rb +139 -118
  218. data/test/cases/tasks/postgresql_rake_test.rb +60 -6
  219. data/test/cases/tasks/sqlite_rake_test.rb +30 -3
  220. data/test/cases/test_case.rb +28 -20
  221. data/test/cases/test_fixtures_test.rb +36 -0
  222. data/test/cases/time_precision_test.rb +103 -0
  223. data/test/cases/timestamp_test.rb +44 -10
  224. data/test/cases/touch_later_test.rb +121 -0
  225. data/test/cases/transaction_callbacks_test.rb +128 -62
  226. data/test/cases/transaction_isolation_test.rb +2 -2
  227. data/test/cases/transactions_test.rb +61 -43
  228. data/test/cases/type/adapter_specific_registry_test.rb +133 -0
  229. data/test/cases/type/date_time_test.rb +14 -0
  230. data/test/cases/type/integer_test.rb +2 -96
  231. data/test/cases/type/string_test.rb +0 -14
  232. data/test/cases/type_test.rb +39 -0
  233. data/test/cases/types_test.rb +1 -118
  234. data/test/cases/unconnected_test.rb +1 -1
  235. data/test/cases/validations/absence_validation_test.rb +73 -0
  236. data/test/cases/validations/association_validation_test.rb +13 -2
  237. data/test/cases/validations/i18n_validation_test.rb +6 -10
  238. data/test/cases/validations/length_validation_test.rb +62 -30
  239. data/test/cases/validations/presence_validation_test.rb +36 -1
  240. data/test/cases/validations/uniqueness_validation_test.rb +128 -37
  241. data/test/cases/validations_repair_helper.rb +2 -6
  242. data/test/cases/validations_test.rb +36 -7
  243. data/test/cases/view_test.rb +102 -5
  244. data/test/cases/yaml_serialization_test.rb +21 -26
  245. data/test/config.example.yml +97 -0
  246. data/test/fixtures/bad_posts.yml +9 -0
  247. data/test/fixtures/books.yml +20 -0
  248. data/test/fixtures/content.yml +3 -0
  249. data/test/fixtures/content_positions.yml +3 -0
  250. data/test/fixtures/dead_parrots.yml +5 -0
  251. data/test/fixtures/live_parrots.yml +4 -0
  252. data/test/fixtures/naked/yml/parrots.yml +2 -0
  253. data/test/fixtures/naked/yml/trees.yml +3 -0
  254. data/test/fixtures/nodes.yml +29 -0
  255. data/test/fixtures/other_comments.yml +6 -0
  256. data/test/fixtures/other_dogs.yml +2 -0
  257. data/test/fixtures/other_posts.yml +7 -0
  258. data/test/fixtures/price_estimates.yml +10 -1
  259. data/test/fixtures/trees.yml +3 -0
  260. data/test/migrations/10_urban/9_add_expressions.rb +1 -1
  261. data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
  262. data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
  263. data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
  264. data/test/migrations/missing/1_people_have_last_names.rb +2 -2
  265. data/test/migrations/missing/3_we_need_reminders.rb +2 -2
  266. data/test/migrations/missing/4_innocent_jointable.rb +2 -2
  267. data/test/migrations/rename/1_we_need_things.rb +2 -2
  268. data/test/migrations/rename/2_rename_things.rb +2 -2
  269. data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
  270. data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
  271. data/test/migrations/to_copy2/1_create_articles.rb +1 -1
  272. data/test/migrations/to_copy2/2_create_comments.rb +1 -1
  273. data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
  274. data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
  275. data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
  276. data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
  277. data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
  278. data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
  279. data/test/migrations/valid/2_we_need_reminders.rb +2 -2
  280. data/test/migrations/valid/3_innocent_jointable.rb +2 -2
  281. data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
  282. data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
  283. data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
  284. data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
  285. data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
  286. data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
  287. data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
  288. data/test/models/admin/randomly_named_c1.rb +6 -2
  289. data/test/models/aircraft.rb +1 -0
  290. data/test/models/author.rb +4 -7
  291. data/test/models/bird.rb +1 -1
  292. data/test/models/book.rb +5 -0
  293. data/test/models/bulb.rb +2 -1
  294. data/test/models/car.rb +3 -0
  295. data/test/models/cat.rb +10 -0
  296. data/test/models/chef.rb +1 -0
  297. data/test/models/club.rb +2 -0
  298. data/test/models/comment.rb +17 -5
  299. data/test/models/company.rb +4 -2
  300. data/test/models/company_in_module.rb +1 -1
  301. data/test/models/contact.rb +1 -1
  302. data/test/models/content.rb +40 -0
  303. data/test/models/customer.rb +8 -2
  304. data/test/models/developer.rb +19 -0
  305. data/test/models/face.rb +1 -1
  306. data/test/models/guitar.rb +4 -0
  307. data/test/models/hotel.rb +2 -0
  308. data/test/models/member.rb +1 -0
  309. data/test/models/member_detail.rb +4 -3
  310. data/test/models/mentor.rb +3 -0
  311. data/test/models/mocktail_designer.rb +2 -0
  312. data/test/models/node.rb +5 -0
  313. data/test/models/non_primary_key.rb +2 -0
  314. data/test/models/notification.rb +3 -0
  315. data/test/models/other_dog.rb +5 -0
  316. data/test/models/owner.rb +4 -1
  317. data/test/models/parrot.rb +6 -7
  318. data/test/models/person.rb +0 -1
  319. data/test/models/pet.rb +3 -0
  320. data/test/models/pet_treasure.rb +6 -0
  321. data/test/models/pirate.rb +3 -3
  322. data/test/models/post.rb +18 -9
  323. data/test/models/project.rb +9 -0
  324. data/test/models/randomly_named_c1.rb +1 -1
  325. data/test/models/recipe.rb +3 -0
  326. data/test/models/ship.rb +8 -2
  327. data/test/models/tag.rb +6 -0
  328. data/test/models/topic.rb +2 -8
  329. data/test/models/tree.rb +3 -0
  330. data/test/models/tuning_peg.rb +4 -0
  331. data/test/models/user.rb +14 -0
  332. data/test/models/uuid_item.rb +6 -0
  333. data/test/schema/mysql2_specific_schema.rb +33 -23
  334. data/test/schema/oracle_specific_schema.rb +1 -4
  335. data/test/schema/postgresql_specific_schema.rb +36 -124
  336. data/test/schema/schema.rb +170 -65
  337. data/test/schema/schema.rb.original +1057 -0
  338. data/test/schema/sqlite_specific_schema.rb +1 -5
  339. data/test/support/connection.rb +1 -0
  340. data/test/support/schema_dumping_helper.rb +1 -1
  341. data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
  342. data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
  343. metadata +146 -30
  344. data/lib/mswin32/rb19x/ibm_db.so +0 -0
  345. data/lib/mswin32/rb21x/i386/ibm_db.so +0 -0
  346. data/lib/mswin32/rb22x/i386/ibm_db.so +0 -0
  347. data/lib/mswin32/rb23x/i386/ibm_db.so +0 -0
  348. data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
  349. data/test/cases/attribute_methods/serialization_test.rb +0 -29
  350. data/test/cases/migration/change_schema_test - Copy.rb +0 -448
  351. data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
  352. data/test/cases/migration/table_and_index_test.rb +0 -24
  353. data/test/cases/relation/where_test2.rb +0 -36
  354. data/test/cases/type/decimal_test.rb +0 -56
  355. data/test/cases/type/unsigned_integer_test.rb +0 -18
  356. data/test/cases/xml_serialization_test.rb +0 -457
  357. data/test/fixtures/naked/csv/accounts.csv +0 -1
  358. data/test/schema/mysql_specific_schema.rb +0 -70
@@ -1,2 +1,5 @@
1
1
  #rb file to support alising of adapter name as ibmdb [without underscore] that will require ibm_db_adapter.rb
2
- require 'active_record/connection_adapters/ibm_db_adapter'
2
+ require 'active_record/connection_adapters/ibm_db_adapter'
3
+
4
+ require 'active_record/connection_adapters/ibm_schema_dumper'
5
+
@@ -82,42 +82,10 @@ if (RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/)
82
82
  end
83
83
 
84
84
 
85
- if (RUBY_VERSION =~ /1.9./ )
86
- require 'rb19x/ibm_db.so'
87
- elsif (RUBY_VERSION =~ /2.0./)
88
- #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
89
- machine_bits = ['ibm'].pack('p').size * 8
90
- if machine_bits == 64
91
- #require 'rb2x/x64/ibm_db.so'
92
- raise NotImplementedError, "ibm_db with Ruby 2.0 64-bit on Windows platform is not supported. Refer to README for more details"
93
- else
94
- require 'rb2x/i386/ibm_db.so'
95
- end
96
- elsif (RUBY_VERSION =~ /2.1./)
97
- #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
98
- machine_bits = ['ibm'].pack('p').size * 8
99
- if machine_bits == 64
100
- #require 'rb21x/x64/ibm_db.so'
101
- raise NotImplementedError, "ibm_db with Ruby 2.1 64-bit on Windows platform is not supported. Refer to README for more details"
102
- else
103
- require 'rb21x/i386/ibm_db.so'
104
- end
105
- elsif (RUBY_VERSION =~ /2.2./ )
106
- #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
107
- machine_bits = ['ibm'].pack('p').size * 8
108
- if machine_bits == 64
109
- raise NotImplementedError, "ibm_db with Ruby 2.2 64-bit on Windows platform is not supported. Refer to README for more details"
110
- else
111
- require 'rb22x/i386/ibm_db.so'
112
- end
113
- elsif (RUBY_VERSION =~ /2.3./ )
114
- #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
115
- machine_bits = ['ibm'].pack('p').size * 8
116
- if machine_bits == 64
117
- raise NotImplementedError, "ibm_db with Ruby 2.2 64-bit on Windows platform is not supported. Refer to README for more details"
118
- else
119
- require 'rb23x/i386/ibm_db.so'
120
- end
121
- else
122
- require 'rb18x/ibm_db.so'
123
- end
85
+ #Check if we are on 64-bit or 32-bit ruby and load binary accordingly
86
+ machine_bits = ['ibm'].pack('p').size * 8
87
+ if machine_bits == 64
88
+ raise NotImplementedError, "ibm_db with Ruby 64-bit on Windows platform is not supported. Refer to README for more details"
89
+ else
90
+ require 'rb2x/i386/ibm_db.so'
91
+ end
@@ -7,7 +7,7 @@ module ActiveRecord
7
7
 
8
8
  module ConnectionAdapters
9
9
  class FakeAdapter < AbstractAdapter
10
- attr_accessor :tables, :primary_keys
10
+ attr_accessor :data_sources, :primary_keys
11
11
 
12
12
  @columns = Hash.new { |h,k| h[k] = [] }
13
13
  class << self
@@ -16,21 +16,20 @@ module ActiveRecord
16
16
 
17
17
  def initialize(connection, logger)
18
18
  super
19
- @tables = []
19
+ @data_sources = []
20
20
  @primary_keys = {}
21
21
  @columns = self.class.columns
22
22
  end
23
23
 
24
24
  def primary_key(table)
25
- @primary_keys[table]
25
+ @primary_keys[table] || "id"
26
26
  end
27
27
 
28
28
  def merge_column(table_name, name, sql_type = nil, options = {})
29
29
  @columns[table_name] << ActiveRecord::ConnectionAdapters::Column.new(
30
30
  name.to_s,
31
31
  options[:default],
32
- lookup_cast_type(sql_type.to_s),
33
- sql_type.to_s,
32
+ fetch_type_metadata(sql_type),
34
33
  options[:null])
35
34
  end
36
35
 
@@ -38,6 +37,10 @@ module ActiveRecord
38
37
  @columns[table_name]
39
38
  end
40
39
 
40
+ def data_source_exists?(*)
41
+ true
42
+ end
43
+
41
44
  def active?
42
45
  true
43
46
  end
@@ -1,19 +1,19 @@
1
- # encoding: utf-8
2
-
3
1
  require "cases/helper"
4
2
  require "models/book"
5
3
  require "models/post"
6
4
  require "models/author"
5
+ require "models/event"
7
6
 
8
7
  module ActiveRecord
9
8
  class AdapterTest < ActiveRecord::TestCase
10
- def setup
9
+ def setup
11
10
  @connection = ActiveRecord::Base.connection
12
11
  end
13
12
 
14
13
  ##
15
14
  # PostgreSQL does not support null bytes in strings
16
- unless current_adapter?(:PostgreSQLAdapter)
15
+ unless current_adapter?(:PostgreSQLAdapter, :IBM_DBAdapter) ||
16
+ (current_adapter?(:SQLite3Adapter) && !ActiveRecord::Base.connection.prepared_statements)
17
17
  def test_update_prepared_statement
18
18
  b = Book.create(name: "my \x00 book")
19
19
  b.reload
@@ -24,18 +24,34 @@ module ActiveRecord
24
24
  end
25
25
  end
26
26
 
27
+ unless current_adapter?(:IBM_DBAdapter)
28
+ def test_create_record_with_pk_as_zero
29
+ Book.create(id: 0)
30
+ assert_equal 0, Book.find(0).id
31
+ assert_nothing_raised { Book.destroy(0) }
32
+ end
33
+ end
34
+
27
35
  def test_tables
28
- tables = @connection.tables
36
+ tables = nil
37
+ ActiveSupport::Deprecation.silence { tables = @connection.tables }
29
38
  assert tables.include?("accounts")
30
39
  assert tables.include?("authors")
31
40
  assert tables.include?("tasks")
32
41
  assert tables.include?("topics")
33
42
  end
34
43
 
44
+
35
45
  def test_table_exists?
36
- assert @connection.table_exists?("accounts")
37
- assert !@connection.table_exists?("nonexistingtable")
38
- assert !@connection.table_exists?(nil)
46
+ ActiveSupport::Deprecation.silence do
47
+ assert @connection.table_exists?("accounts")
48
+ assert !@connection.table_exists?("nonexistingtable")
49
+ assert !@connection.table_exists?(nil)
50
+ end
51
+ end
52
+
53
+ def test_table_exists_checking_both_tables_and_views_is_deprecated
54
+ assert_deprecated { @connection.table_exists?("accounts") }
39
55
  end
40
56
 
41
57
  def test_data_sources
@@ -74,13 +90,26 @@ module ActiveRecord
74
90
  @connection.remove_index(:accounts, :name => idx_name) rescue nil
75
91
  end
76
92
 
93
+ unless current_adapter?(:IBM_DBAdapter)
94
+ def test_remove_index_when_name_and_wrong_column_name_specified
95
+ index_name = "accounts_idx"
96
+
97
+ @connection.add_index :accounts, :firm_id, :name => index_name
98
+ assert_raises ArgumentError do
99
+ @connection.remove_index :accounts, :name => index_name, :column => :wrong_column_name
100
+ end
101
+ ensure
102
+ @connection.remove_index(:accounts, :name => index_name)
103
+ end
104
+ end
105
+
77
106
  def test_current_database
78
107
  if @connection.respond_to?(:current_database)
79
108
  assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
80
109
  end
81
110
  end
82
111
 
83
- if current_adapter?(:MysqlAdapter)
112
+ if current_adapter?(:Mysql2Adapter)
84
113
  def test_charset
85
114
  assert_not_nil @connection.charset
86
115
  assert_not_equal 'character_set_database', @connection.charset
@@ -150,17 +179,21 @@ module ActiveRecord
150
179
  assert_nothing_raised { sub.save! }
151
180
  end
152
181
  end
153
-
154
- def test_uniqueness_violations_are_translated_to_specific_exception
155
- @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
156
- assert_raises(ActiveRecord::RecordNotUnique) do
157
- @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
158
- end
159
- end
160
-
161
- unless current_adapter?(:SQLite3Adapter)
182
+
183
+ unless current_adapter?(:IBM_DBAdapter)
184
+ def test_uniqueness_violations_are_translated_to_specific_exception
185
+ @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
186
+ error = assert_raises(ActiveRecord::RecordNotUnique) do
187
+ @connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
188
+ end
189
+
190
+ assert_not_nil error.cause
191
+ end
192
+ end
193
+
194
+ unless current_adapter?(:SQLite3Adapter, :IBM_DBAdapter)
162
195
  def test_foreign_key_violations_are_translated_to_specific_exception
163
- assert_raises(ActiveRecord::InvalidForeignKey) do
196
+ error = assert_raises(ActiveRecord::InvalidForeignKey) do
164
197
  # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
165
198
  if @connection.prefetch_primary_key?
166
199
  id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
@@ -169,6 +202,8 @@ module ActiveRecord
169
202
  @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
170
203
  end
171
204
  end
205
+
206
+ assert_not_nil error.cause
172
207
  end
173
208
 
174
209
  def test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false
@@ -176,11 +211,21 @@ module ActiveRecord
176
211
  self.table_name = 'fk_test_has_fk'
177
212
  end
178
213
 
179
- assert_raises(ActiveRecord::InvalidForeignKey) do
214
+ error = assert_raises(ActiveRecord::InvalidForeignKey) do
180
215
  has_fk = klass_has_fk.new
181
216
  has_fk.fk_id = 1231231231
182
217
  has_fk.save(validate: false)
183
218
  end
219
+
220
+ assert_not_nil error.cause
221
+ end
222
+
223
+ def test_value_limit_violations_are_translated_to_specific_exception
224
+ error = assert_raises(ActiveRecord::ValueTooLong) do
225
+ Event.create(title: 'abcdefgh')
226
+ end
227
+
228
+ assert_not_nil error.cause
184
229
  end
185
230
  end
186
231
 
@@ -206,44 +251,69 @@ module ActiveRecord
206
251
  assert result.is_a?(ActiveRecord::Result)
207
252
  end
208
253
 
209
- def test_select_methods_passing_a_association_relation
210
- author = Author.create!(name: 'john')
211
- Post.create!(author: author, title: 'foo', body: 'bar')
212
- query = author.posts.where(title: 'foo').select(:title)
213
- assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bind_values))
214
- assert_equal({"title" => "foo"}, @connection.select_one(query))
215
- assert @connection.select_all(query).is_a?(ActiveRecord::Result)
216
- assert_equal "foo", @connection.select_value(query)
217
- assert_equal ["foo"], @connection.select_values(query)
254
+ if ActiveRecord::Base.connection.prepared_statements
255
+ def test_select_all_with_legacy_binds
256
+ post = Post.create!(title: "foo", body: "bar")
257
+ expected = @connection.select_all("SELECT * FROM posts WHERE id = #{post.id}")
258
+ result = @connection.select_all("SELECT * FROM posts WHERE id = #{Arel::Nodes::BindParam.new.to_sql}", nil, [[nil, post.id]])
259
+ assert_equal expected.to_hash, result.to_hash
260
+ end
218
261
  end
219
262
 
220
- def test_select_methods_passing_a_relation
221
- Post.create!(title: 'foo', body: 'bar')
222
- query = Post.where(title: 'foo').select(:title)
223
- assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bind_values))
224
- assert_equal({"title" => "foo"}, @connection.select_one(query))
225
- assert @connection.select_all(query).is_a?(ActiveRecord::Result)
226
- assert_equal "foo", @connection.select_value(query)
227
- assert_equal ["foo"], @connection.select_values(query)
228
- end
263
+ unless current_adapter?(:IBM_DBAdapter)
264
+ def test_select_methods_passing_a_association_relation
265
+ author = Author.create!(name: 'john')
266
+ Post.create!(author: author, title: 'foo', body: 'bar')
267
+ query = author.posts.where(title: 'foo').select(:title)
268
+ assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes))
269
+ assert_equal({"title" => "foo"}, @connection.select_one(query))
270
+ assert @connection.select_all(query).is_a?(ActiveRecord::Result)
271
+ assert_equal "foo", @connection.select_value(query)
272
+ assert_equal ["foo"], @connection.select_values(query)
273
+ end
274
+ end
275
+
276
+ unless current_adapter?(:IBM_DBAdapter)
277
+ def test_select_methods_passing_a_relation
278
+ Post.create!(title: 'foo', body: 'bar')
279
+ query = Post.where(title: 'foo').select(:title)
280
+ assert_equal({"title" => "foo"}, @connection.select_one(query.arel, nil, query.bound_attributes))
281
+ assert_equal({"title" => "foo"}, @connection.select_one(query))
282
+ assert @connection.select_all(query).is_a?(ActiveRecord::Result)
283
+ assert_equal "foo", @connection.select_value(query)
284
+ assert_equal ["foo"], @connection.select_values(query)
285
+ end
286
+ end
229
287
 
230
288
  test "type_to_sql returns a String for unmapped types" do
231
289
  assert_equal "special_db_type", @connection.type_to_sql(:special_db_type)
232
290
  end
233
291
 
234
- unless current_adapter?(:PostgreSQLAdapter)
292
+ unless current_adapter?(:PostgreSQLAdapter, :IBM_DBAdapter)
235
293
  def test_log_invalid_encoding
236
- assert_raise ActiveRecord::StatementInvalid do
237
- @connection.send :log, "SELECT '?' FROM DUAL" do
238
- raise '?'.force_encoding(Encoding::ASCII_8BIT)
294
+ error = assert_raise ActiveRecord::StatementInvalid do
295
+ @connection.send :log, "SELECT 'ы' FROM DUAL" do
296
+ raise 'ы'.force_encoding(Encoding::ASCII_8BIT)
239
297
  end
240
298
  end
299
+
300
+ assert_not_nil error.cause
301
+ end
302
+ end
303
+
304
+ if current_adapter?(:Mysql2Adapter, :SQLite3Adapter)
305
+ def test_tables_returning_both_tables_and_views_is_deprecated
306
+ assert_deprecated { @connection.tables }
241
307
  end
242
308
  end
309
+
310
+ def test_passing_arguments_to_tables_is_deprecated
311
+ assert_deprecated { @connection.tables(:books) }
312
+ end
243
313
  end
244
314
 
245
315
  class AdapterTestWithoutTransaction < ActiveRecord::TestCase
246
- self.use_transactional_fixtures = false
316
+ self.use_transactional_tests = false
247
317
 
248
318
  class Klass < ActiveRecord::Base
249
319
  end
@@ -257,20 +327,25 @@ module ActiveRecord
257
327
  Klass.remove_connection
258
328
  end
259
329
 
260
- unless in_memory_db?
261
- test "transaction state is reset after a reconnect" do
262
- @connection.begin_transaction
263
- assert @connection.transaction_open?
264
- @connection.reconnect!
265
- assert !@connection.transaction_open?
266
- end
267
-
268
- test "transaction state is reset after a disconnect" do
269
- @connection.begin_transaction
270
- assert @connection.transaction_open?
271
- @connection.disconnect!
272
- assert !@connection.transaction_open?
273
- end
274
- end
330
+ unless current_adapter?(:IBM_DBAdapter)
331
+ unless in_memory_db?
332
+ test "transaction state is reset after a reconnect" do
333
+ @connection.begin_transaction
334
+ assert @connection.transaction_open?
335
+ @connection.reconnect!
336
+ assert !@connection.transaction_open?
337
+ end
338
+
339
+ test "transaction state is reset after a disconnect" do
340
+ @connection.begin_transaction
341
+ assert @connection.transaction_open?
342
+ @connection.disconnect!
343
+ assert !@connection.transaction_open?
344
+ end
345
+ end
346
+ end
347
+
275
348
  end
349
+
350
+
276
351
  end
@@ -0,0 +1,193 @@
1
+ require "cases/helper"
2
+ require 'support/connection_helper'
3
+
4
+ class Mysql2ActiveSchemaTest < ActiveRecord::Mysql2TestCase
5
+ include ConnectionHelper
6
+
7
+ def setup
8
+ ActiveRecord::Base.connection.singleton_class.class_eval do
9
+ alias_method :execute_without_stub, :execute
10
+ def execute(sql, name = nil) return sql end
11
+ end
12
+ end
13
+
14
+ teardown do
15
+ reset_connection
16
+ end
17
+
18
+ def test_add_index
19
+ # add_index calls data_source_exists? and index_name_exists? which can't work since execute is stubbed
20
+ def (ActiveRecord::Base.connection).data_source_exists?(*); true; end
21
+ def (ActiveRecord::Base.connection).index_name_exists?(*); false; end
22
+
23
+ expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`) "
24
+ assert_equal expected, add_index(:people, :last_name, :length => nil)
25
+
26
+ expected = "CREATE INDEX `index_people_on_last_name` ON `people` (`last_name`(10)) "
27
+ assert_equal expected, add_index(:people, :last_name, :length => 10)
28
+
29
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(15)) "
30
+ assert_equal expected, add_index(:people, [:last_name, :first_name], length: 15)
31
+ assert_equal expected, add_index(:people, ["last_name", "first_name"], length: 15)
32
+
33
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`) "
34
+ assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15 })
35
+ assert_equal expected, add_index(:people, ["last_name", "first_name"], length: { last_name: 15 })
36
+
37
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` ON `people` (`last_name`(15), `first_name`(10)) "
38
+ assert_equal expected, add_index(:people, [:last_name, :first_name], length: { last_name: 15, first_name: 10 })
39
+ assert_equal expected, add_index(:people, ["last_name", :first_name], length: { last_name: 15, "first_name" => 10 })
40
+
41
+ %w(SPATIAL FULLTEXT UNIQUE).each do |type|
42
+ expected = "CREATE #{type} INDEX `index_people_on_last_name` ON `people` (`last_name`) "
43
+ assert_equal expected, add_index(:people, :last_name, :type => type)
44
+ end
45
+
46
+ %w(btree hash).each do |using|
47
+ expected = "CREATE INDEX `index_people_on_last_name` USING #{using} ON `people` (`last_name`) "
48
+ assert_equal expected, add_index(:people, :last_name, :using => using)
49
+ end
50
+
51
+ expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) "
52
+ assert_equal expected, add_index(:people, :last_name, :length => 10, :using => :btree)
53
+
54
+ expected = "CREATE INDEX `index_people_on_last_name` USING btree ON `people` (`last_name`(10)) ALGORITHM = COPY"
55
+ assert_equal expected, add_index(:people, :last_name, :length => 10, using: :btree, algorithm: :copy)
56
+
57
+ assert_raise ArgumentError do
58
+ add_index(:people, :last_name, algorithm: :coyp)
59
+ end
60
+
61
+ expected = "CREATE INDEX `index_people_on_last_name_and_first_name` USING btree ON `people` (`last_name`(15), `first_name`(15)) "
62
+ assert_equal expected, add_index(:people, [:last_name, :first_name], :length => 15, :using => :btree)
63
+ end
64
+
65
+ def test_index_in_create
66
+ def (ActiveRecord::Base.connection).data_source_exists?(*); false; end
67
+
68
+ %w(SPATIAL FULLTEXT UNIQUE).each do |type|
69
+ expected = "CREATE TABLE `people` (#{type} INDEX `index_people_on_last_name` (`last_name`)) ENGINE=InnoDB"
70
+ actual = ActiveRecord::Base.connection.create_table(:people, id: false) do |t|
71
+ t.index :last_name, type: type
72
+ end
73
+ assert_equal expected, actual
74
+ end
75
+
76
+ expected = "CREATE TABLE `people` ( INDEX `index_people_on_last_name` USING btree (`last_name`(10))) ENGINE=InnoDB"
77
+ actual = ActiveRecord::Base.connection.create_table(:people, id: false) do |t|
78
+ t.index :last_name, length: 10, using: :btree
79
+ end
80
+ assert_equal expected, actual
81
+ end
82
+
83
+ def test_index_in_bulk_change
84
+ def (ActiveRecord::Base.connection).data_source_exists?(*); true; end
85
+ def (ActiveRecord::Base.connection).index_name_exists?(*); false; end
86
+
87
+ %w(SPATIAL FULLTEXT UNIQUE).each do |type|
88
+ expected = "ALTER TABLE `people` ADD #{type} INDEX `index_people_on_last_name` (`last_name`)"
89
+ actual = ActiveRecord::Base.connection.change_table(:people, bulk: true) do |t|
90
+ t.index :last_name, type: type
91
+ end
92
+ assert_equal expected, actual
93
+ end
94
+
95
+ expected = "ALTER TABLE `peaple` ADD INDEX `index_peaple_on_last_name` USING btree (`last_name`(10)), ALGORITHM = COPY"
96
+ actual = ActiveRecord::Base.connection.change_table(:peaple, bulk: true) do |t|
97
+ t.index :last_name, length: 10, using: :btree, algorithm: :copy
98
+ end
99
+ assert_equal expected, actual
100
+ end
101
+
102
+ def test_drop_table
103
+ assert_equal "DROP TABLE `people`", drop_table(:people)
104
+ end
105
+
106
+ def test_create_mysql_database_with_encoding
107
+ assert_equal "CREATE DATABASE `matt` DEFAULT CHARACTER SET `utf8`", create_database(:matt)
108
+ assert_equal "CREATE DATABASE `aimonetti` DEFAULT CHARACTER SET `latin1`", create_database(:aimonetti, {:charset => 'latin1'})
109
+ assert_equal "CREATE DATABASE `matt_aimonetti` DEFAULT CHARACTER SET `big5` COLLATE `big5_chinese_ci`", create_database(:matt_aimonetti, {:charset => :big5, :collation => :big5_chinese_ci})
110
+ end
111
+
112
+ def test_recreate_mysql_database_with_encoding
113
+ create_database(:luca, {:charset => 'latin1'})
114
+ assert_equal "CREATE DATABASE `luca` DEFAULT CHARACTER SET `latin1`", recreate_database(:luca, {:charset => 'latin1'})
115
+ end
116
+
117
+ def test_add_column
118
+ assert_equal "ALTER TABLE `people` ADD `last_name` varchar(255)", add_column(:people, :last_name, :string)
119
+ end
120
+
121
+ def test_add_column_with_limit
122
+ assert_equal "ALTER TABLE `people` ADD `key` varchar(32)", add_column(:people, :key, :string, :limit => 32)
123
+ end
124
+
125
+ def test_drop_table_with_specific_database
126
+ assert_equal "DROP TABLE `otherdb`.`people`", drop_table('otherdb.people')
127
+ end
128
+
129
+ def test_add_timestamps
130
+ with_real_execute do
131
+ begin
132
+ ActiveRecord::Base.connection.create_table :delete_me
133
+ ActiveRecord::Base.connection.add_timestamps :delete_me, null: true
134
+ assert column_present?('delete_me', 'updated_at', 'datetime')
135
+ assert column_present?('delete_me', 'created_at', 'datetime')
136
+ ensure
137
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
138
+ end
139
+ end
140
+ end
141
+
142
+ def test_remove_timestamps
143
+ with_real_execute do
144
+ begin
145
+ ActiveRecord::Base.connection.create_table :delete_me do |t|
146
+ t.timestamps null: true
147
+ end
148
+ ActiveRecord::Base.connection.remove_timestamps :delete_me, { null: true }
149
+ assert !column_present?('delete_me', 'updated_at', 'datetime')
150
+ assert !column_present?('delete_me', 'created_at', 'datetime')
151
+ ensure
152
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
153
+ end
154
+ end
155
+ end
156
+
157
+ def test_indexes_in_create
158
+ ActiveRecord::Base.connection.stubs(:data_source_exists?).with(:temp).returns(false)
159
+ ActiveRecord::Base.connection.stubs(:index_name_exists?).with(:index_temp_on_zip).returns(false)
160
+
161
+ expected = "CREATE TEMPORARY TABLE `temp` ( INDEX `index_temp_on_zip` (`zip`)) ENGINE=InnoDB AS SELECT id, name, zip FROM a_really_complicated_query"
162
+ actual = ActiveRecord::Base.connection.create_table(:temp, temporary: true, as: "SELECT id, name, zip FROM a_really_complicated_query") do |t|
163
+ t.index :zip
164
+ end
165
+
166
+ assert_equal expected, actual
167
+ end
168
+
169
+ private
170
+ def with_real_execute
171
+ ActiveRecord::Base.connection.singleton_class.class_eval do
172
+ alias_method :execute_with_stub, :execute
173
+ remove_method :execute
174
+ alias_method :execute, :execute_without_stub
175
+ end
176
+
177
+ yield
178
+ ensure
179
+ ActiveRecord::Base.connection.singleton_class.class_eval do
180
+ remove_method :execute
181
+ alias_method :execute, :execute_with_stub
182
+ end
183
+ end
184
+
185
+ def method_missing(method_symbol, *arguments)
186
+ ActiveRecord::Base.connection.send(method_symbol, *arguments)
187
+ end
188
+
189
+ def column_present?(table_name, column_name, type)
190
+ results = ActiveRecord::Base.connection.select_all("SHOW FIELDS FROM #{table_name} LIKE '#{column_name}'")
191
+ results.first && results.first['Type'] == type
192
+ end
193
+ end