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
@@ -17,7 +17,10 @@ require 'models/minivan'
17
17
  require 'models/owner'
18
18
  require 'models/person'
19
19
  require 'models/pet'
20
+ require 'models/ship'
20
21
  require 'models/toy'
22
+ require 'models/admin'
23
+ require 'models/admin/user'
21
24
  require 'rexml/document'
22
25
 
23
26
  class PersistenceTest < ActiveRecord::TestCase
@@ -42,8 +45,7 @@ class PersistenceTest < ActiveRecord::TestCase
42
45
  end
43
46
  end
44
47
 
45
- if !current_adapter?(:IBM_DBAdapter) && test_update_with_order_succeeds.call('id DESC')
46
- # The update below goes on successfully in DB2.
48
+ if test_update_with_order_succeeds.call('id DESC')
47
49
  assert !test_update_with_order_succeeds.call('id ASC') # test that this wasn't a fluke and using an incorrect order results in an exception
48
50
  else
49
51
  # test that we're failing because the current Arel's engine doesn't support UPDATE ORDER BY queries is using subselects instead
@@ -120,15 +122,24 @@ class PersistenceTest < ActiveRecord::TestCase
120
122
  assert_equal 59, accounts(:signals37, :reload).credit_limit
121
123
  end
122
124
 
125
+ def test_increment_updates_counter_in_db_using_offset
126
+ a1 = accounts(:signals37)
127
+ initial_credit = a1.credit_limit
128
+ a2 = Account.find(accounts(:signals37).id)
129
+ a1.increment!(:credit_limit)
130
+ a2.increment!(:credit_limit)
131
+ assert_equal initial_credit + 2, a1.reload.credit_limit
132
+ end
133
+
123
134
  def test_destroy_all
124
135
  conditions = "author_name = 'Mary'"
125
136
  topics_by_mary = Topic.all.merge!(:where => conditions, :order => 'id').to_a
126
137
  assert ! topics_by_mary.empty?
127
138
 
128
139
  assert_difference('Topic.count', -topics_by_mary.size) do
129
- destroyed = Topic.destroy_all(conditions).sort_by(&:id)
140
+ destroyed = Topic.where(conditions).destroy_all.sort_by(&:id)
130
141
  assert_equal topics_by_mary, destroyed
131
- assert destroyed.all? { |topic| topic.frozen? }, "destroyed topics should be frozen"
142
+ assert destroyed.all?(&:frozen?), "destroyed topics should be frozen"
132
143
  end
133
144
  end
134
145
 
@@ -138,7 +149,7 @@ class PersistenceTest < ActiveRecord::TestCase
138
149
  assert_difference('Client.count', -2) do
139
150
  destroyed = Client.destroy([2, 3]).sort_by(&:id)
140
151
  assert_equal clients, destroyed
141
- assert destroyed.all? { |client| client.frozen? }, "destroyed clients should be frozen"
152
+ assert destroyed.all?(&:frozen?), "destroyed clients should be frozen"
142
153
  end
143
154
  end
144
155
 
@@ -152,10 +163,27 @@ class PersistenceTest < ActiveRecord::TestCase
152
163
  assert !company.valid?
153
164
  original_errors = company.errors
154
165
  client = company.becomes(Client)
155
- assert_equal original_errors, client.errors
166
+ assert_equal original_errors.keys, client.errors.keys
167
+ end
168
+
169
+ def test_becomes_errors_base
170
+ child_class = Class.new(Admin::User) do
171
+ store_accessor :settings, :foo
172
+
173
+ def self.name; 'Admin::ChildUser'; end
174
+ end
175
+
176
+ admin = Admin::User.new
177
+ admin.errors.add :token, :invalid
178
+ child = admin.becomes(child_class)
179
+
180
+ assert_equal [:token], child.errors.keys
181
+ assert_nothing_raised do
182
+ child.errors.add :foo, :invalid
183
+ end
156
184
  end
157
185
 
158
- def test_dupd_becomes_persists_changes_from_the_original
186
+ def test_duped_becomes_persists_changes_from_the_original
159
187
  original = topics(:first)
160
188
  copy = original.dup.becomes(Reply)
161
189
  copy.save!
@@ -253,8 +281,10 @@ class PersistenceTest < ActiveRecord::TestCase
253
281
 
254
282
  def test_create_columns_not_equal_attributes
255
283
  topic = Topic.instantiate(
256
- 'title' => 'Another New Topic',
257
- 'does_not_exist' => 'test'
284
+ 'attributes' => {
285
+ 'title' => 'Another New Topic',
286
+ 'does_not_exist' => 'test'
287
+ }
258
288
  )
259
289
  assert_nothing_raised { topic.save }
260
290
  end
@@ -355,6 +385,22 @@ class PersistenceTest < ActiveRecord::TestCase
355
385
  assert_equal("David", topic_reloaded.author_name)
356
386
  end
357
387
 
388
+ def test_update_attribute_does_not_run_sql_if_attribute_is_not_changed
389
+ klass = Class.new(Topic) do
390
+ def self.name; 'Topic'; end
391
+ end
392
+ topic = klass.create(title: 'Another New Topic')
393
+ assert_queries(0) do
394
+ assert topic.update_attribute(:title, "Another New Topic")
395
+ end
396
+ end
397
+
398
+ def test_update_does_not_run_sql_if_record_has_not_changed
399
+ topic = Topic.create(title: "Another New Topic")
400
+ assert_queries(0) { assert topic.update(title: "Another New Topic") }
401
+ assert_queries(0) { assert topic.update_attributes(title: "Another New Topic") }
402
+ end
403
+
358
404
  def test_delete
359
405
  topic = Topic.find(1)
360
406
  assert_equal topic, topic.delete, 'topic.delete did not return self'
@@ -717,9 +763,10 @@ class PersistenceTest < ActiveRecord::TestCase
717
763
  assert !topic.approved?
718
764
  assert_equal "The First Topic", topic.title
719
765
 
720
- assert_raise(ActiveRecord::RecordNotUnique, ActiveRecord::StatementInvalid) do
766
+ error = assert_raise(ActiveRecord::RecordNotUnique, ActiveRecord::StatementInvalid) do
721
767
  topic.update_attributes(id: 3, title: "Hm is it possible?")
722
768
  end
769
+ assert_not_nil error.cause
723
770
  assert_not_equal "Hm is it possible?", Topic.find(3).title
724
771
 
725
772
  topic.update_attributes(id: 1234)
@@ -906,4 +953,49 @@ class PersistenceTest < ActiveRecord::TestCase
906
953
  ensure
907
954
  ActiveRecord::Base.connection.disable_query_cache!
908
955
  end
956
+
957
+ class SaveTest < ActiveRecord::TestCase
958
+ self.use_transactional_tests = false
959
+
960
+ def test_save_touch_false
961
+ widget = Class.new(ActiveRecord::Base) do
962
+ connection.create_table :widgets, force: true do |t|
963
+ t.string :name
964
+ t.timestamps null: false
965
+ end
966
+
967
+ self.table_name = :widgets
968
+ end
969
+
970
+ instance = widget.create!({
971
+ name: 'Bob',
972
+ created_at: 1.day.ago,
973
+ updated_at: 1.day.ago
974
+ })
975
+
976
+ created_at = instance.created_at
977
+ updated_at = instance.updated_at
978
+
979
+ instance.name = 'Barb'
980
+ instance.save!(touch: false)
981
+ assert_equal instance.created_at, created_at
982
+ assert_equal instance.updated_at, updated_at
983
+ ensure
984
+ ActiveRecord::Base.connection.drop_table widget.table_name
985
+ widget.reset_column_information
986
+ end
987
+ end
988
+
989
+ def test_reset_column_information_resets_children
990
+ child = Class.new(Topic)
991
+ child.new # force schema to load
992
+
993
+ ActiveRecord::Base.connection.add_column(:topics, :foo, :string)
994
+ Topic.reset_column_information
995
+
996
+ assert_equal "bar", child.new(foo: :bar).foo
997
+ ensure
998
+ ActiveRecord::Base.connection.remove_column(:topics, :foo)
999
+ Topic.reset_column_information
1000
+ end
909
1001
  end
@@ -3,7 +3,7 @@ require "models/project"
3
3
  require "timeout"
4
4
 
5
5
  class PooledConnectionsTest < ActiveRecord::TestCase
6
- self.use_transactional_fixtures = false
6
+ self.use_transactional_tests = false
7
7
 
8
8
  def setup
9
9
  @per_test_teardown = []
@@ -13,7 +13,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
13
13
  teardown do
14
14
  ActiveRecord::Base.clear_all_connections!
15
15
  ActiveRecord::Base.establish_connection(@connection)
16
- @per_test_teardown.each {|td| td.call }
16
+ @per_test_teardown.each(&:call)
17
17
  end
18
18
 
19
19
  # Will deadlock due to lack of Monitor timeouts in 1.9
@@ -44,7 +44,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
44
44
  conn = ActiveRecord::Base.connection_pool.checkout
45
45
  ActiveRecord::Base.connection_pool.checkin conn
46
46
  @connection_count += 1
47
- ActiveRecord::Base.connection.tables
47
+ ActiveRecord::Base.connection.data_sources
48
48
  rescue ActiveRecord::ConnectionTimeoutError
49
49
  @timed_out += 1
50
50
  end
@@ -1,4 +1,5 @@
1
1
  require "cases/helper"
2
+ require 'support/schema_dumping_helper'
2
3
  require 'models/topic'
3
4
  require 'models/reply'
4
5
  require 'models/subscriber'
@@ -6,6 +7,7 @@ require 'models/movie'
6
7
  require 'models/keyboard'
7
8
  require 'models/mixed_case_monkey'
8
9
  require 'models/dashboard'
10
+ require 'models/non_primary_key'
9
11
 
10
12
  class PrimaryKeysTest < ActiveRecord::TestCase
11
13
  fixtures :topics, :subscribers, :movies, :mixed_case_monkeys
@@ -88,6 +90,12 @@ class PrimaryKeysTest < ActiveRecord::TestCase
88
90
  assert_equal("John Doe", subscriberReloaded.name)
89
91
  end
90
92
 
93
+ def test_id_column_that_is_not_primary_key
94
+ NonPrimaryKey.create!(id: 100)
95
+ actual = NonPrimaryKey.find_by(id: 100)
96
+ assert_match %r{<NonPrimaryKey id: 100}, actual.inspect
97
+ end
98
+
91
99
  def test_find_with_more_than_one_string_key
92
100
  assert_equal 2, Subscriber.find(subscribers(:first).nick, subscribers(:second).nick).length
93
101
  end
@@ -113,7 +121,7 @@ class PrimaryKeysTest < ActiveRecord::TestCase
113
121
  assert_nothing_raised { MixedCaseMonkey.delete(1) }
114
122
  end
115
123
  def test_update_counters_should_quote_pkey_and_quote_counter_columns
116
- assert_nothing_raised { MixedCaseMonkey.update_counters(1, :fleacount => 99) }
124
+ assert_nothing_raised { MixedCaseMonkey.update_counters(1, :fleaCount => 99) }
117
125
  end
118
126
  def test_find_with_one_id_should_quote_pkey
119
127
  assert_nothing_raised { MixedCaseMonkey.find(1) }
@@ -129,27 +137,25 @@ class PrimaryKeysTest < ActiveRecord::TestCase
129
137
  end
130
138
 
131
139
  def test_supports_primary_key
132
- assert_nothing_raised NoMethodError do
140
+ assert_nothing_raised do
133
141
  ActiveRecord::Base.connection.supports_primary_key?
134
142
  end
135
143
  end
136
144
 
137
- def test_primary_key_returns_value_if_it_exists
138
- klass = Class.new(ActiveRecord::Base) do
139
- self.table_name = 'developers'
140
- end
145
+ if ActiveRecord::Base.connection.supports_primary_key?
146
+ def test_primary_key_returns_value_if_it_exists
147
+ klass = Class.new(ActiveRecord::Base) do
148
+ self.table_name = 'developers'
149
+ end
141
150
 
142
- if ActiveRecord::Base.connection.supports_primary_key?
143
151
  assert_equal 'id', klass.primary_key
144
152
  end
145
- end
146
153
 
147
- def test_primary_key_returns_nil_if_it_does_not_exist
148
- klass = Class.new(ActiveRecord::Base) do
149
- self.table_name = 'developers_projects'
150
- end
154
+ def test_primary_key_returns_nil_if_it_does_not_exist
155
+ klass = Class.new(ActiveRecord::Base) do
156
+ self.table_name = 'developers_projects'
157
+ end
151
158
 
152
- if ActiveRecord::Base.connection.supports_primary_key?
153
159
  assert_nil klass.primary_key
154
160
  end
155
161
  end
@@ -163,8 +169,7 @@ class PrimaryKeysTest < ActiveRecord::TestCase
163
169
 
164
170
  def test_auto_detect_primary_key_from_schema
165
171
  MixedCaseMonkey.reset_primary_key
166
- #assert_equal "monkeyID", MixedCaseMonkey.primary_key
167
- assert_equal "monkeyid", MixedCaseMonkey.primary_key
172
+ assert_equal "monkeyID", MixedCaseMonkey.primary_key
168
173
  end
169
174
 
170
175
  def test_primary_key_update_with_custom_key_name
@@ -175,10 +180,24 @@ class PrimaryKeysTest < ActiveRecord::TestCase
175
180
  dashboard = Dashboard.first
176
181
  assert_equal '2', dashboard.id
177
182
  end
183
+
184
+ if current_adapter?(:PostgreSQLAdapter)
185
+ def test_serial_with_quoted_sequence_name
186
+ column = MixedCaseMonkey.columns_hash[MixedCaseMonkey.primary_key]
187
+ assert_equal "nextval('\"mixed_case_monkeys_monkeyID_seq\"'::regclass)", column.default_function
188
+ assert column.serial?
189
+ end
190
+
191
+ def test_serial_with_unquoted_sequence_name
192
+ column = Topic.columns_hash[Topic.primary_key]
193
+ assert_equal "nextval('topics_id_seq'::regclass)", column.default_function
194
+ assert column.serial?
195
+ end
196
+ end
178
197
  end
179
198
 
180
199
  class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase
181
- self.use_transactional_fixtures = false
200
+ self.use_transactional_tests = false
182
201
 
183
202
  unless in_memory_db?
184
203
  def test_set_primary_key_with_no_connection
@@ -196,42 +215,162 @@ class PrimaryKeyWithNoConnectionTest < ActiveRecord::TestCase
196
215
  end
197
216
  end
198
217
 
199
- if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
200
- class PrimaryKeyWithAnsiQuotesTest < ActiveRecord::TestCase
201
- self.use_transactional_fixtures = false
218
+ class PrimaryKeyAnyTypeTest < ActiveRecord::TestCase
219
+ include SchemaDumpingHelper
220
+
221
+ self.use_transactional_tests = false
222
+
223
+ class Barcode < ActiveRecord::Base
224
+ end
225
+
226
+ setup do
227
+ @connection = ActiveRecord::Base.connection
228
+ @connection.create_table(:barcodes, primary_key: "code", id: :string, limit: 42, force: true)
229
+ end
230
+
231
+ teardown do
232
+ @connection.drop_table(:barcodes)
233
+ #, if_exists: true)
234
+ end
235
+
236
+ def test_any_type_primary_key
237
+ assert_equal "code", Barcode.primary_key
238
+
239
+ column = Barcode.column_for_attribute(Barcode.primary_key)
240
+ assert_not column.null
241
+ assert_equal :string, column.type
242
+ assert_equal 42, column.limit
243
+ end
244
+
245
+ test "schema dump primary key includes type and options" do
246
+ schema = dump_table_schema "barcodes"
247
+ assert_match %r{create_table "barcodes", primary_key: "code", id: :string, limit: 42}, schema
248
+ end
249
+ end
250
+
251
+ class CompositePrimaryKeyTest < ActiveRecord::TestCase
252
+ include SchemaDumpingHelper
253
+
254
+ self.use_transactional_tests = false
255
+
256
+ def setup
257
+ @connection = ActiveRecord::Base.connection
258
+ @connection.schema_cache.clear!
259
+ @connection.create_table(:barcodes, primary_key: ["region", "code"], force: true) do |t|
260
+ t.string :region, null: false
261
+ t.integer :code, null: false
262
+ end
263
+ end
264
+
265
+ def teardown
266
+ @connection.drop_table(:barcodes)
267
+ #, if_exists: true)
268
+ end
269
+
270
+ def test_composite_primary_key
271
+ assert_equal ["region", "code"], @connection.primary_keys("barcodes")
272
+ end
273
+
274
+ def test_primary_key_issues_warning
275
+ model = Class.new(ActiveRecord::Base) do
276
+ def self.table_name
277
+ "barcodes"
278
+ end
279
+ end
280
+ warning = capture(:stderr) do
281
+ assert_nil model.primary_key
282
+ end
283
+ assert_match(/WARNING: Active Record does not support composite primary key\./, warning)
284
+ end
285
+
286
+ def test_collectly_dump_composite_primary_key
287
+ schema = dump_table_schema "barcodes"
288
+ assert_match %r{create_table "barcodes", primary_key: \["region", "code"\]}, schema
289
+ end
290
+ end
291
+
292
+ if current_adapter?(:Mysql2Adapter)
293
+ class PrimaryKeyBigintNilDefaultTest < ActiveRecord::TestCase
294
+ include SchemaDumpingHelper
295
+
296
+ self.use_transactional_tests = false
202
297
 
203
- def test_primary_key_method_with_ansi_quotes
204
- con = ActiveRecord::Base.connection
205
- con.execute("SET SESSION sql_mode='ANSI_QUOTES'")
206
- assert_equal "id", con.primary_key("topics")
207
- ensure
208
- con.reconnect!
298
+ def setup
299
+ @connection = ActiveRecord::Base.connection
300
+ @connection.create_table(:bigint_defaults, id: :bigint, default: nil, force: true)
301
+ end
302
+
303
+ def teardown
304
+ @connection.drop_table :bigint_defaults
305
+ #, if_exists: true
306
+ end
307
+
308
+ test "primary key with bigint allows default override via nil" do
309
+ column = @connection.columns(:bigint_defaults).find { |c| c.name == 'id' }
310
+ assert column.bigint?
311
+ assert_not column.auto_increment?
312
+ end
313
+
314
+ test "schema dump primary key with bigint default nil" do
315
+ schema = dump_table_schema "bigint_defaults"
316
+ assert_match %r{create_table "bigint_defaults", id: :bigint, default: nil}, schema
209
317
  end
210
318
  end
211
319
  end
212
320
 
213
- if current_adapter?(:PostgreSQLAdapter)
321
+ if current_adapter?(:PostgreSQLAdapter, :Mysql2Adapter)
214
322
  class PrimaryKeyBigSerialTest < ActiveRecord::TestCase
215
- self.use_transactional_fixtures = false
323
+ include SchemaDumpingHelper
324
+
325
+ self.use_transactional_tests = false
216
326
 
217
327
  class Widget < ActiveRecord::Base
218
328
  end
219
329
 
220
330
  setup do
221
331
  @connection = ActiveRecord::Base.connection
222
- @connection.create_table(:widgets, id: :bigserial) { |t| }
332
+ if current_adapter?(:PostgreSQLAdapter)
333
+ @connection.create_table(:widgets, id: :bigserial, force: true)
334
+ else
335
+ @connection.create_table(:widgets, id: :bigint, force: true)
336
+ end
223
337
  end
224
338
 
225
339
  teardown do
226
340
  @connection.drop_table :widgets
341
+ #, if_exists: true
342
+ Widget.reset_column_information
227
343
  end
228
344
 
229
- def test_bigserial_primary_key
230
- assert_equal "id", Widget.primary_key
231
- assert_equal :integer, Widget.columns_hash[Widget.primary_key].type
345
+ test "primary key column type with bigserial" do
346
+ column_type = Widget.type_for_attribute(Widget.primary_key)
347
+ assert_equal :integer, column_type.type
348
+ assert_equal 8, column_type.limit
349
+ end
232
350
 
351
+ test "primary key with bigserial are automatically numbered" do
233
352
  widget = Widget.create!
234
353
  assert_not_nil widget.id
235
354
  end
355
+
356
+ test "schema dump primary key with bigserial" do
357
+ schema = dump_table_schema "widgets"
358
+ if current_adapter?(:PostgreSQLAdapter)
359
+ assert_match %r{create_table "widgets", id: :bigserial, force: :cascade}, schema
360
+ else
361
+ assert_match %r{create_table "widgets", id: :bigint, force: :cascade}, schema
362
+ end
363
+ end
364
+
365
+ if current_adapter?(:Mysql2Adapter)
366
+ test "primary key column type with options" do
367
+ @connection.create_table(:widgets, id: :primary_key, limit: 8, unsigned: true, force: true)
368
+ column = @connection.columns(:widgets).find { |c| c.name == 'id' }
369
+ assert column.auto_increment?
370
+ assert_equal :integer, column.type
371
+ assert_equal 8, column.limit
372
+ assert column.unsigned?
373
+ end
374
+ end
236
375
  end
237
376
  end