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,8 +1,7 @@
1
- require File.expand_path('../../../../load_paths', __FILE__)
2
-
3
1
  require 'config'
4
2
 
5
3
  require 'active_support/testing/autorun'
4
+ require 'active_support/testing/method_call_assertions'
6
5
  require 'stringio'
7
6
 
8
7
  require 'active_record'
@@ -24,15 +23,15 @@ ActiveSupport::Deprecation.debug = true
24
23
  # Disable available locale checks to avoid warnings running the test suite.
25
24
  I18n.enforce_available_locales = false
26
25
 
27
- # Enable raise errors in after_commit and after_rollback.
28
- ActiveRecord::Base.raise_in_transactional_callbacks = true
29
-
30
26
  # Connect to the database
31
27
  ARTest.connect
32
28
 
33
29
  # Quote "type" if it's a reserved word for the current connection.
34
30
  QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
35
31
 
32
+ # FIXME: Remove this when the deprecation cycle on TZ aware types by default ends.
33
+ ActiveRecord::Base.time_zone_aware_types << :time
34
+
36
35
  def current_adapter?(*types)
37
36
  types.any? do |type|
38
37
  ActiveRecord::ConnectionAdapters.const_defined?(type) &&
@@ -45,13 +44,12 @@ def in_memory_db?
45
44
  ActiveRecord::Base.connection_pool.spec.config[:database] == ":memory:"
46
45
  end
47
46
 
48
- def mysql_56?
49
- current_adapter?(:Mysql2Adapter) &&
50
- ActiveRecord::Base.connection.send(:version).join(".") >= "5.6.0"
47
+ def subsecond_precision_supported?
48
+ ActiveRecord::Base.connection.supports_datetime_with_precision?
51
49
  end
52
50
 
53
51
  def mysql_enforcing_gtid_consistency?
54
- current_adapter?(:MysqlAdapter, :Mysql2Adapter) && 'ON' == ActiveRecord::Base.connection.show_variable('enforce_gtid_consistency')
52
+ current_adapter?(:Mysql2Adapter) && 'ON' == ActiveRecord::Base.connection.show_variable('enforce_gtid_consistency')
55
53
  end
56
54
 
57
55
  def supports_savepoints?
@@ -124,7 +122,7 @@ def enable_extension!(extension, connection)
124
122
  return connection.reconnect! if connection.extension_enabled?(extension)
125
123
 
126
124
  connection.enable_extension extension
127
- connection.commit_db_transaction
125
+ connection.commit_db_transaction if connection.transaction_open?
128
126
  connection.reconnect!
129
127
  end
130
128
 
@@ -140,10 +138,11 @@ require "cases/validations_repair_helper"
140
138
  class ActiveSupport::TestCase
141
139
  include ActiveRecord::TestFixtures
142
140
  include ActiveRecord::ValidationsRepairHelper
141
+ include ActiveSupport::Testing::MethodCallAssertions
143
142
 
144
143
  self.fixture_path = FIXTURES_ROOT
145
144
  self.use_instantiated_fixtures = false
146
- self.use_transactional_fixtures = true
145
+ self.use_transactional_tests = true
147
146
 
148
147
  def create_fixtures(*fixture_set_names, &block)
149
148
  ActiveRecord::FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, fixture_class_names, &block)
@@ -203,8 +202,3 @@ module InTimeZone
203
202
  end
204
203
 
205
204
  require 'mocha/setup' # FIXME: stop using mocha
206
-
207
- # FIXME: we have tests that depend on run order, we should fix that and
208
- # remove this method call.
209
- require 'active_support/test_case'
210
- ActiveSupport::TestCase.test_order = :sorted
@@ -1,7 +1,9 @@
1
1
  require 'cases/helper'
2
+ require 'support/connection_helper'
2
3
 
3
4
  class HotCompatibilityTest < ActiveRecord::TestCase
4
- self.use_transactional_fixtures = false
5
+ self.use_transactional_tests = false
6
+ include ConnectionHelper
5
7
 
6
8
  setup do
7
9
  @klass = Class.new(ActiveRecord::Base) do
@@ -51,4 +53,90 @@ class HotCompatibilityTest < ActiveRecord::TestCase
51
53
  record.reload
52
54
  assert_equal 'bar', record.foo
53
55
  end
56
+
57
+ if current_adapter?(:PostgreSQLAdapter)
58
+ test "cleans up after prepared statement failure in a transaction" do
59
+ with_two_connections do |original_connection, ddl_connection|
60
+ record = @klass.create! bar: 'bar'
61
+
62
+ # prepare the reload statement in a transaction
63
+ @klass.transaction do
64
+ record.reload
65
+ end
66
+
67
+ assert get_prepared_statement_cache(@klass.connection).any?,
68
+ "expected prepared statement cache to have something in it"
69
+
70
+ # add a new column
71
+ ddl_connection.add_column :hot_compatibilities, :baz, :string
72
+
73
+ assert_raise(ActiveRecord::PreparedStatementCacheExpired) do
74
+ @klass.transaction do
75
+ record.reload
76
+ end
77
+ end
78
+
79
+ assert_empty get_prepared_statement_cache(@klass.connection),
80
+ "expected prepared statement cache to be empty but it wasn't"
81
+ end
82
+ end
83
+
84
+ test "cleans up after prepared statement failure in nested transactions" do
85
+ with_two_connections do |original_connection, ddl_connection|
86
+ record = @klass.create! bar: 'bar'
87
+
88
+ # prepare the reload statement in a transaction
89
+ @klass.transaction do
90
+ record.reload
91
+ end
92
+
93
+ assert get_prepared_statement_cache(@klass.connection).any?,
94
+ "expected prepared statement cache to have something in it"
95
+
96
+ # add a new column
97
+ ddl_connection.add_column :hot_compatibilities, :baz, :string
98
+
99
+ assert_raise(ActiveRecord::PreparedStatementCacheExpired) do
100
+ @klass.transaction do
101
+ @klass.transaction do
102
+ @klass.transaction do
103
+ record.reload
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ assert_empty get_prepared_statement_cache(@klass.connection),
110
+ "expected prepared statement cache to be empty but it wasn't"
111
+ end
112
+ end
113
+ end
114
+
115
+ private
116
+
117
+ def get_prepared_statement_cache(connection)
118
+ connection.instance_variable_get(:@statements)
119
+ .instance_variable_get(:@cache)[Process.pid]
120
+ end
121
+
122
+ # Rails will automatically clear the prepared statements on the connection
123
+ # that runs the migration, so we use two connections to simulate what would
124
+ # actually happen on a production system; we'd have one connection running the
125
+ # migration from the rake task ("ddl_connection" here), and we'd have another
126
+ # connection in a web worker.
127
+ def with_two_connections
128
+ run_without_connection do |original_connection|
129
+ ActiveRecord::Base.establish_connection(original_connection.merge(pool_size: 2))
130
+ begin
131
+ ddl_connection = ActiveRecord::Base.connection_pool.checkout
132
+ begin
133
+ yield original_connection, ddl_connection
134
+ ensure
135
+ ActiveRecord::Base.connection_pool.checkin ddl_connection
136
+ end
137
+ ensure
138
+ ActiveRecord::Base.clear_all_connections!
139
+ end
140
+ end
141
+ end
54
142
  end
@@ -1,21 +1,41 @@
1
1
  require 'cases/helper'
2
+ require 'models/author'
2
3
  require 'models/company'
4
+ require 'models/membership'
3
5
  require 'models/person'
4
6
  require 'models/post'
5
7
  require 'models/project'
6
8
  require 'models/subscriber'
7
9
  require 'models/vegetables'
8
10
  require 'models/shop'
11
+ require 'models/sponsor'
12
+
13
+ module InheritanceTestHelper
14
+ def with_store_full_sti_class(&block)
15
+ assign_store_full_sti_class true, &block
16
+ end
17
+
18
+ def without_store_full_sti_class(&block)
19
+ assign_store_full_sti_class false, &block
20
+ end
21
+
22
+ def assign_store_full_sti_class(flag)
23
+ old_store_full_sti_class = ActiveRecord::Base.store_full_sti_class
24
+ ActiveRecord::Base.store_full_sti_class = flag
25
+ yield
26
+ ensure
27
+ ActiveRecord::Base.store_full_sti_class = old_store_full_sti_class
28
+ end
29
+ end
9
30
 
10
31
  class InheritanceTest < ActiveRecord::TestCase
11
- fixtures :companies, :projects, :subscribers, :accounts, :vegetables
32
+ include InheritanceTestHelper
33
+ fixtures :companies, :projects, :subscribers, :accounts, :vegetables, :memberships
12
34
 
13
35
  def test_class_with_store_full_sti_class_returns_full_name
14
- old = ActiveRecord::Base.store_full_sti_class
15
- ActiveRecord::Base.store_full_sti_class = true
16
- assert_equal 'Namespaced::Company', Namespaced::Company.sti_name
17
- ensure
18
- ActiveRecord::Base.store_full_sti_class = old
36
+ with_store_full_sti_class do
37
+ assert_equal 'Namespaced::Company', Namespaced::Company.sti_name
38
+ end
19
39
  end
20
40
 
21
41
  def test_class_with_blank_sti_name
@@ -33,39 +53,104 @@ class InheritanceTest < ActiveRecord::TestCase
33
53
  end
34
54
 
35
55
  def test_class_without_store_full_sti_class_returns_demodulized_name
36
- old = ActiveRecord::Base.store_full_sti_class
37
- ActiveRecord::Base.store_full_sti_class = false
38
- assert_equal 'Company', Namespaced::Company.sti_name
39
- ensure
40
- ActiveRecord::Base.store_full_sti_class = old
56
+ without_store_full_sti_class do
57
+ assert_equal 'Company', Namespaced::Company.sti_name
58
+ end
59
+ end
60
+
61
+ def test_compute_type_success
62
+ assert_equal Author, ActiveRecord::Base.send(:compute_type, 'Author')
63
+ end
64
+
65
+ def test_compute_type_nonexistent_constant
66
+ e = assert_raises NameError do
67
+ ActiveRecord::Base.send :compute_type, 'NonexistentModel'
68
+ end
69
+ assert_equal 'uninitialized constant ActiveRecord::Base::NonexistentModel', e.message
70
+ assert_equal 'ActiveRecord::Base::NonexistentModel', e.name
71
+ end
72
+
73
+ def test_compute_type_no_method_error
74
+ ActiveSupport::Dependencies.stub(:safe_constantize, proc{ raise NoMethodError }) do
75
+ assert_raises NoMethodError do
76
+ ActiveRecord::Base.send :compute_type, 'InvalidModel'
77
+ end
78
+ end
79
+ end
80
+
81
+ def test_compute_type_on_undefined_method
82
+ error = nil
83
+ begin
84
+ Class.new(Author) do
85
+ alias_method :foo, :bar
86
+ end
87
+ rescue => e
88
+ error = e
89
+ end
90
+
91
+ ActiveSupport::Dependencies.stub(:safe_constantize, proc{ raise e }) do
92
+
93
+ exception = assert_raises NameError do
94
+ ActiveRecord::Base.send :compute_type, 'InvalidModel'
95
+ end
96
+ assert_equal error.message, exception.message
97
+ end
98
+ end
99
+
100
+ def test_compute_type_argument_error
101
+ ActiveSupport::Dependencies.stub(:safe_constantize, proc{ raise ArgumentError }) do
102
+ assert_raises ArgumentError do
103
+ ActiveRecord::Base.send :compute_type, 'InvalidModel'
104
+ end
105
+ end
41
106
  end
42
107
 
43
108
  def test_should_store_demodulized_class_name_with_store_full_sti_class_option_disabled
44
- old = ActiveRecord::Base.store_full_sti_class
45
- ActiveRecord::Base.store_full_sti_class = false
46
- item = Namespaced::Company.new
47
- assert_equal 'Company', item[:type]
48
- ensure
49
- ActiveRecord::Base.store_full_sti_class = old
109
+ without_store_full_sti_class do
110
+ item = Namespaced::Company.new
111
+ assert_equal 'Company', item[:type]
112
+ end
50
113
  end
51
114
 
52
115
  def test_should_store_full_class_name_with_store_full_sti_class_option_enabled
53
- old = ActiveRecord::Base.store_full_sti_class
54
- ActiveRecord::Base.store_full_sti_class = true
55
- item = Namespaced::Company.new
56
- assert_equal 'Namespaced::Company', item[:type]
57
- ensure
58
- ActiveRecord::Base.store_full_sti_class = old
116
+ with_store_full_sti_class do
117
+ item = Namespaced::Company.new
118
+ assert_equal 'Namespaced::Company', item[:type]
119
+ end
59
120
  end
60
121
 
61
122
  def test_different_namespace_subclass_should_load_correctly_with_store_full_sti_class_option
62
- old = ActiveRecord::Base.store_full_sti_class
63
- ActiveRecord::Base.store_full_sti_class = true
64
- item = Namespaced::Company.create :name => "Wolverine 2"
65
- assert_not_nil Company.find(item.id)
66
- assert_not_nil Namespaced::Company.find(item.id)
67
- ensure
68
- ActiveRecord::Base.store_full_sti_class = old
123
+ with_store_full_sti_class do
124
+ item = Namespaced::Company.create name: "Wolverine 2"
125
+ assert_not_nil Company.find(item.id)
126
+ assert_not_nil Namespaced::Company.find(item.id)
127
+ end
128
+ end
129
+
130
+ def test_descends_from_active_record
131
+ assert !ActiveRecord::Base.descends_from_active_record?
132
+
133
+ # Abstract subclass of AR::Base.
134
+ assert LoosePerson.descends_from_active_record?
135
+
136
+ # Concrete subclass of an abstract class.
137
+ assert LooseDescendant.descends_from_active_record?
138
+
139
+ # Concrete subclass of AR::Base.
140
+ assert TightPerson.descends_from_active_record?
141
+
142
+ # Concrete subclass of a concrete class but has no type column.
143
+ assert TightDescendant.descends_from_active_record?
144
+
145
+ # Concrete subclass of AR::Base.
146
+ assert Post.descends_from_active_record?
147
+
148
+ # Abstract subclass of a concrete class which has a type column.
149
+ # This is pathological, as you'll never have Sub < Abstract < Concrete.
150
+ assert !StiPost.descends_from_active_record?
151
+
152
+ # Concrete subclasses an abstract class which has a type column.
153
+ assert !SubStiPost.descends_from_active_record?
69
154
  end
70
155
 
71
156
  def test_company_descends_from_active_record
@@ -75,6 +160,12 @@ class InheritanceTest < ActiveRecord::TestCase
75
160
  assert !Class.new(Company).descends_from_active_record?, 'Company subclass should not descend from ActiveRecord::Base'
76
161
  end
77
162
 
163
+ def test_abstract_class
164
+ assert !ActiveRecord::Base.abstract_class?
165
+ assert LoosePerson.abstract_class?
166
+ assert !LooseDescendant.abstract_class?
167
+ end
168
+
78
169
  def test_inheritance_base_class
79
170
  assert_equal Post, Post.base_class
80
171
  assert_equal Post, SpecialPost.base_class
@@ -204,10 +295,27 @@ class InheritanceTest < ActiveRecord::TestCase
204
295
  assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'Account') }
205
296
  end
206
297
 
298
+ def test_new_with_unrelated_namespaced_type
299
+ without_store_full_sti_class do
300
+ e = assert_raises ActiveRecord::SubclassNotFound do
301
+ Namespaced::Company.new(type: 'Firm')
302
+ end
303
+
304
+ assert_equal "Invalid single-table inheritance type: Namespaced::Firm is not a subclass of Namespaced::Company", e.message
305
+ end
306
+ end
307
+
207
308
  def test_new_with_complex_inheritance
208
309
  assert_nothing_raised { Client.new(type: 'VerySpecialClient') }
209
310
  end
210
311
 
312
+ def test_new_without_storing_full_sti_class
313
+ without_store_full_sti_class do
314
+ item = Company.new(type: 'SpecialCo')
315
+ assert_instance_of Company::SpecialCo, item
316
+ end
317
+ end
318
+
211
319
  def test_new_with_autoload_paths
212
320
  path = File.expand_path('../../models/autoloadable', __FILE__)
213
321
  ActiveSupport::Dependencies.autoload_paths << path
@@ -310,7 +418,7 @@ class InheritanceTest < ActiveRecord::TestCase
310
418
 
311
419
  def test_eager_load_belongs_to_primary_key_quoting
312
420
  con = Account.connection
313
- assert_sql(/#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} IN \(1\)/) do
421
+ assert_sql(/#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} = 1/) do
314
422
  Account.all.merge!(:includes => :firm).find(1)
315
423
  end
316
424
  end
@@ -328,43 +436,42 @@ class InheritanceTest < ActiveRecord::TestCase
328
436
  assert_nothing_raised { Company.of_first_firm }
329
437
  assert_nothing_raised { Client.of_first_firm }
330
438
  end
439
+
440
+ def test_inheritance_with_default_scope
441
+ assert_equal 1, SelectedMembership.count(:all)
442
+ end
331
443
  end
332
444
 
333
445
  class InheritanceComputeTypeTest < ActiveRecord::TestCase
446
+ include InheritanceTestHelper
334
447
  fixtures :companies
335
448
 
336
- def setup
337
- ActiveSupport::Dependencies.log_activity = true
338
- end
339
-
340
449
  teardown do
341
- ActiveSupport::Dependencies.log_activity = false
342
450
  self.class.const_remove :FirmOnTheFly rescue nil
343
451
  Firm.const_remove :FirmOnTheFly rescue nil
344
452
  end
345
453
 
346
454
  def test_instantiation_doesnt_try_to_require_corresponding_file
347
- ActiveRecord::Base.store_full_sti_class = false
348
- foo = Firm.first.clone
349
- foo.type = 'FirmOnTheFly'
350
- foo.save!
455
+ without_store_full_sti_class do
456
+ foo = Firm.first.clone
457
+ foo.type = 'FirmOnTheFly'
458
+ foo.save!
351
459
 
352
- # Should fail without FirmOnTheFly in the type condition.
353
- assert_raise(ActiveRecord::RecordNotFound) { Firm.find(foo.id) }
460
+ # Should fail without FirmOnTheFly in the type condition.
461
+ assert_raise(ActiveRecord::RecordNotFound) { Firm.find(foo.id) }
354
462
 
355
- # Nest FirmOnTheFly in the test case where Dependencies won't see it.
356
- self.class.const_set :FirmOnTheFly, Class.new(Firm)
357
- assert_raise(ActiveRecord::SubclassNotFound) { Firm.find(foo.id) }
463
+ # Nest FirmOnTheFly in the test case where Dependencies won't see it.
464
+ self.class.const_set :FirmOnTheFly, Class.new(Firm)
465
+ assert_raise(ActiveRecord::SubclassNotFound) { Firm.find(foo.id) }
358
466
 
359
- # Nest FirmOnTheFly in Firm where Dependencies will see it.
360
- # This is analogous to nesting models in a migration.
361
- Firm.const_set :FirmOnTheFly, Class.new(Firm)
467
+ # Nest FirmOnTheFly in Firm where Dependencies will see it.
468
+ # This is analogous to nesting models in a migration.
469
+ Firm.const_set :FirmOnTheFly, Class.new(Firm)
362
470
 
363
- # And instantiate will find the existing constant rather than trying
364
- # to require firm_on_the_fly.
365
- assert_nothing_raised { assert_kind_of Firm::FirmOnTheFly, Firm.find(foo.id) }
366
- ensure
367
- ActiveRecord::Base.store_full_sti_class = true
471
+ # And instantiate will find the existing constant rather than trying
472
+ # to require firm_on_the_fly.
473
+ assert_nothing_raised { assert_kind_of Firm::FirmOnTheFly, Firm.find(foo.id) }
474
+ end
368
475
  end
369
476
 
370
477
  def test_sti_type_from_attributes_disabled_in_non_sti_class
@@ -372,4 +479,128 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase
372
479
  product = Shop::Product.new(:type => phone)
373
480
  assert product.save
374
481
  end
482
+
483
+ def test_inheritance_new_with_subclass_as_default
484
+ original_type = Company.columns_hash["type"].default
485
+ ActiveRecord::Base.connection.change_column_default :companies, :type, 'Firm'
486
+ Company.reset_column_information
487
+
488
+ firm = Company.new # without arguments
489
+ assert_equal 'Firm', firm.type
490
+ assert_instance_of Firm, firm
491
+
492
+ firm = Company.new(firm_name: 'Shri Hans Plastic') # with arguments
493
+ assert_equal 'Firm', firm.type
494
+ assert_instance_of Firm, firm
495
+
496
+ client = Client.new
497
+ assert_equal 'Client', client.type
498
+ assert_instance_of Client, client
499
+
500
+ firm = Company.new(type: 'Client') # overwrite the default type
501
+ assert_equal 'Client', firm.type
502
+ assert_instance_of Client, firm
503
+ ensure
504
+ ActiveRecord::Base.connection.change_column_default :companies, :type, original_type
505
+ Company.reset_column_information
506
+ end
507
+ end
508
+
509
+ class InheritanceAttributeTest < ActiveRecord::TestCase
510
+
511
+ class Company < ActiveRecord::Base
512
+ self.table_name = 'companies'
513
+ attribute :type, :string, default: "InheritanceAttributeTest::Startup"
514
+ end
515
+
516
+ class Startup < Company
517
+ end
518
+
519
+ class Empire < Company
520
+ end
521
+
522
+ def test_inheritance_new_with_subclass_as_default
523
+ startup = Company.new # without arguments
524
+ assert_equal 'InheritanceAttributeTest::Startup', startup.type
525
+ assert_instance_of Startup, startup
526
+
527
+ empire = Company.new(type: 'InheritanceAttributeTest::Empire') # without arguments
528
+ assert_equal 'InheritanceAttributeTest::Empire', empire.type
529
+ assert_instance_of Empire, empire
530
+ end
531
+ end
532
+
533
+ class InheritanceAttributeMappingTest < ActiveRecord::TestCase
534
+ setup do
535
+ @old_registry = ActiveRecord::Type.registry
536
+ ActiveRecord::Type.registry = ActiveRecord::Type::AdapterSpecificRegistry.new
537
+ ActiveRecord::Type.register :omg_sti, InheritanceAttributeMappingTest::OmgStiType
538
+ Company.delete_all
539
+ Sponsor.delete_all
540
+ end
541
+
542
+ teardown do
543
+ ActiveRecord::Type.registry = @old_registry
544
+ end
545
+
546
+ class OmgStiType < ActiveRecord::Type::String
547
+ def cast_value(value)
548
+ if value =~ /\Aomg_(.+)\z/
549
+ $1.classify
550
+ else
551
+ value
552
+ end
553
+ end
554
+
555
+ def serialize(value)
556
+ if value
557
+ "omg_%s" % value.underscore
558
+ end
559
+ end
560
+ end
561
+
562
+ class Company < ActiveRecord::Base
563
+ self.table_name = 'companies'
564
+ attribute :type, :omg_sti
565
+ end
566
+
567
+ class Startup < Company; end
568
+ class Empire < Company; end
569
+
570
+ class Sponsor < ActiveRecord::Base
571
+ self.table_name = 'sponsors'
572
+ attribute :sponsorable_type, :omg_sti
573
+
574
+ belongs_to :sponsorable, polymorphic: true
575
+ end
576
+
577
+ def test_sti_with_custom_type
578
+ Startup.create! name: 'a Startup'
579
+ Empire.create! name: 'an Empire'
580
+
581
+ assert_equal [["a Startup", "omg_inheritance_attribute_mapping_test/startup"],
582
+ ["an Empire", "omg_inheritance_attribute_mapping_test/empire"]], ActiveRecord::Base.connection.select_rows('SELECT name, type FROM companies').sort
583
+ assert_equal [["a Startup", "InheritanceAttributeMappingTest::Startup"],
584
+ ["an Empire", "InheritanceAttributeMappingTest::Empire"]], Company.all.map { |a| [a.name, a.type] }.sort
585
+
586
+ startup = Startup.first
587
+ startup.becomes! Empire
588
+ startup.save!
589
+
590
+ assert_equal [["a Startup", "omg_inheritance_attribute_mapping_test/empire"],
591
+ ["an Empire", "omg_inheritance_attribute_mapping_test/empire"]], ActiveRecord::Base.connection.select_rows('SELECT name, type FROM companies').sort
592
+
593
+ assert_equal [["a Startup", "InheritanceAttributeMappingTest::Empire"],
594
+ ["an Empire", "InheritanceAttributeMappingTest::Empire"]], Company.all.map { |a| [a.name, a.type] }.sort
595
+ end
596
+
597
+ def test_polymorphic_associations_custom_type
598
+ startup = Startup.create! name: 'a Startup'
599
+ sponsor = Sponsor.create! sponsorable: startup
600
+
601
+ assert_equal ["omg_inheritance_attribute_mapping_test/company"], ActiveRecord::Base.connection.select_values('SELECT sponsorable_type FROM sponsors')
602
+
603
+ sponsor = Sponsor.first
604
+ assert_equal startup, sponsor.sponsorable
605
+ end
375
606
  end