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
@@ -0,0 +1,32 @@
1
+ require 'cases/helper'
2
+ require 'models/user'
3
+
4
+ class SecureTokenTest < ActiveRecord::TestCase
5
+ setup do
6
+ @user = User.new
7
+ end
8
+
9
+ def test_token_values_are_generated_for_specified_attributes_and_persisted_on_save
10
+ @user.save
11
+ assert_not_nil @user.token
12
+ assert_not_nil @user.auth_token
13
+ end
14
+
15
+ def test_regenerating_the_secure_token
16
+ @user.save
17
+ old_token = @user.token
18
+ old_auth_token = @user.auth_token
19
+ @user.regenerate_token
20
+ @user.regenerate_auth_token
21
+
22
+ assert_not_equal @user.token, old_token
23
+ assert_not_equal @user.auth_token, old_auth_token
24
+ end
25
+
26
+ def test_token_value_not_overwritten_when_present
27
+ @user.token = "custom-secure-token"
28
+ @user.save
29
+
30
+ assert_equal @user.token, "custom-secure-token"
31
+ end
32
+ end
@@ -8,7 +8,7 @@ require 'models/post'
8
8
  class SerializationTest < ActiveRecord::TestCase
9
9
  fixtures :books
10
10
 
11
- FORMATS = [ :xml, :json ]
11
+ FORMATS = [ :json ]
12
12
 
13
13
  def setup
14
14
  @contact_attributes = {
@@ -22,12 +22,6 @@ class SerializedAttributeTest < ActiveRecord::TestCase
22
22
  end
23
23
  end
24
24
 
25
- def test_list_of_serialized_attributes
26
- assert_deprecated do
27
- assert_equal %w(content), Topic.serialized_attributes.keys
28
- end
29
- end
30
-
31
25
  def test_serialized_attribute
32
26
  Topic.serialize("content", MyObject)
33
27
 
@@ -265,6 +259,12 @@ class SerializedAttributeTest < ActiveRecord::TestCase
265
259
  assert_not topic.content_changed?
266
260
  end
267
261
 
262
+ def test_classes_without_no_arg_constructors_are_not_supported
263
+ assert_raises(ArgumentError) do
264
+ Topic.serialize(:content, Regexp)
265
+ end
266
+ end
267
+
268
268
  def test_newly_emptied_serialized_hash_is_changed
269
269
  Topic.serialize(:content, Hash)
270
270
  topic = Topic.create(content: { "things" => "stuff" })
@@ -274,4 +274,91 @@ class SerializedAttributeTest < ActiveRecord::TestCase
274
274
 
275
275
  assert_equal({}, topic.content)
276
276
  end
277
+
278
+ def test_values_cast_from_nil_are_persisted_as_nil
279
+ # This is required to fulfil the following contract, which must be universally
280
+ # true in Active Record:
281
+ #
282
+ # model.attribute = value
283
+ # assert_equal model.attribute, model.tap(&:save).reload.attribute
284
+ Topic.serialize(:content, Hash)
285
+ topic = Topic.create!(content: {})
286
+ topic2 = Topic.create!(content: nil)
287
+
288
+ assert_equal [topic, topic2], Topic.where(content: nil)
289
+ end
290
+
291
+ def test_nil_is_always_persisted_as_null
292
+ Topic.serialize(:content, Hash)
293
+
294
+ topic = Topic.create!(content: { foo: "bar" })
295
+ topic.update_attribute :content, nil
296
+ assert_equal [topic], Topic.where(content: nil)
297
+ end
298
+
299
+ def test_mutation_detection_does_not_double_serialize
300
+ coder = Object.new
301
+ def coder.dump(value)
302
+ return if value.nil?
303
+ value + " encoded"
304
+ end
305
+ def coder.load(value)
306
+ return if value.nil?
307
+ value.gsub(" encoded", "")
308
+ end
309
+ type = Class.new(ActiveModel::Type::Value) do
310
+ include ActiveModel::Type::Helpers::Mutable
311
+
312
+ def serialize(value)
313
+ return if value.nil?
314
+ value + " serialized"
315
+ end
316
+
317
+ def deserialize(value)
318
+ return if value.nil?
319
+ value.gsub(" serialized", "")
320
+ end
321
+ end.new
322
+ model = Class.new(Topic) do
323
+ attribute :foo, type
324
+ serialize :foo, coder
325
+ end
326
+
327
+ topic = model.create!(foo: "bar")
328
+ topic.foo
329
+ refute topic.changed?
330
+ end
331
+ end
332
+
333
+ class ThreadedSerializedAttributeTest < ActiveRecord::TestCase
334
+ self.use_transactional_tests = false
335
+ fixtures :topics
336
+
337
+ def test_serialized_attribute_works_under_concurrent_initial_access
338
+ model = Topic.dup
339
+
340
+ topic = model.last
341
+ topic.update group: "1"
342
+
343
+ model.serialize :group, JSON
344
+ model.reset_column_information
345
+
346
+ # This isn't strictly necessary for the test, but a little bit of
347
+ # knowledge of internals allows us to make failures far more likely.
348
+ model.define_singleton_method(:define_attribute) do |*args|
349
+ Thread.pass
350
+ super(*args)
351
+ end
352
+
353
+ threads = 4.times.map do
354
+ Thread.new do
355
+ topic.reload.group
356
+ end
357
+ end
358
+
359
+ # All the threads should retrieve the value knowing it is JSON, and
360
+ # thus decode it. If this fails, some threads will instead see the
361
+ # raw string ("1"), or raise an exception.
362
+ assert_equal [1] * threads.size, threads.map(&:value)
363
+ end
277
364
  end
@@ -94,5 +94,43 @@ module ActiveRecord
94
94
  additional_books = cache.execute([], Book, Book.connection)
95
95
  assert first_books != additional_books
96
96
  end
97
+
98
+ def test_unprepared_statements_dont_share_a_cache_with_prepared_statements
99
+ Book.create(name: "my book")
100
+ Book.create(name: "my other book")
101
+
102
+ book = Book.find_by(name: "my book")
103
+ other_book = Book.connection.unprepared_statement do
104
+ Book.find_by(name: "my other book")
105
+ end
106
+
107
+ refute_equal book, other_book
108
+ end
109
+
110
+ def test_find_by_does_not_use_statement_cache_if_table_name_is_changed
111
+ book = Book.create(name: "my book")
112
+
113
+ Book.find_by(name: book.name) # warming the statement cache.
114
+
115
+ # changing the table name should change the query that is not cached.
116
+ Book.table_name = :birds
117
+ assert_nil Book.find_by(name: "my book")
118
+ ensure
119
+ Book.table_name = :books
120
+ end
121
+
122
+ def test_find_does_not_use_statement_cache_if_table_name_is_changed
123
+ book = Book.create(name: "my book")
124
+
125
+ Book.find(book.id) # warming the statement cache.
126
+
127
+ # changing the table name should change the query that is not cached.
128
+ Book.table_name = :birds
129
+ assert_raise ActiveRecord::RecordNotFound do
130
+ Book.find(book.id)
131
+ end
132
+ ensure
133
+ Book.table_name = :books
134
+ end
97
135
  end
98
136
  end
@@ -104,7 +104,7 @@ class StoreTest < ActiveRecord::TestCase
104
104
  assert_equal true, user.settings.instance_of?(ActiveSupport::HashWithIndifferentAccess)
105
105
  end
106
106
 
107
- test "convert store attributes from any format other than Hash or HashWithIndifferent access losing the data" do
107
+ test "convert store attributes from any format other than Hash or HashWithIndifferentAccess losing the data" do
108
108
  @john.json_data = "somedata"
109
109
  @john.height = 'low'
110
110
  assert_equal true, @john.json_data.instance_of?(ActiveSupport::HashWithIndifferentAccess)
@@ -177,6 +177,7 @@ class StoreTest < ActiveRecord::TestCase
177
177
  assert_equal [:color], first_model.stored_attributes[:data]
178
178
  assert_equal [:color, :width, :height], second_model.stored_attributes[:data]
179
179
  assert_equal [:color, :area, :volume], third_model.stored_attributes[:data]
180
+ assert_equal [:color], first_model.stored_attributes[:data]
180
181
  end
181
182
 
182
183
  test "YAML coder initializes the store when a Nil value is given" do
@@ -0,0 +1,63 @@
1
+ require 'cases/helper'
2
+ require 'models/notification'
3
+ require 'models/user'
4
+
5
+ class SuppressorTest < ActiveRecord::TestCase
6
+ def test_suppresses_create
7
+ assert_no_difference -> { Notification.count } do
8
+ Notification.suppress do
9
+ Notification.create
10
+ Notification.create!
11
+ Notification.new.save
12
+ Notification.new.save!
13
+ end
14
+ end
15
+ end
16
+
17
+ def test_suppresses_update
18
+ user = User.create! token: 'asdf'
19
+
20
+ User.suppress do
21
+ user.update token: 'ghjkl'
22
+ assert_equal 'asdf', user.reload.token
23
+
24
+ user.update! token: 'zxcvbnm'
25
+ assert_equal 'asdf', user.reload.token
26
+
27
+ user.token = 'qwerty'
28
+ user.save
29
+ assert_equal 'asdf', user.reload.token
30
+
31
+ user.token = 'uiop'
32
+ user.save!
33
+ assert_equal 'asdf', user.reload.token
34
+ end
35
+ end
36
+
37
+ def test_suppresses_create_in_callback
38
+ assert_difference -> { User.count } do
39
+ assert_no_difference -> { Notification.count } do
40
+ Notification.suppress { UserWithNotification.create! }
41
+ end
42
+ end
43
+ end
44
+
45
+ def test_resumes_saving_after_suppression_complete
46
+ Notification.suppress { UserWithNotification.create! }
47
+
48
+ assert_difference -> { Notification.count } do
49
+ Notification.create!(message: "New Comment")
50
+ end
51
+ end
52
+
53
+ def test_suppresses_validations_on_create
54
+ assert_no_difference -> { Notification.count } do
55
+ Notification.suppress do
56
+ User.create
57
+ User.create!
58
+ User.new.save
59
+ User.new.save!
60
+ end
61
+ end
62
+ end
63
+ end
@@ -8,16 +8,50 @@ module ActiveRecord
8
8
  ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
9
9
  ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).returns @postgresql_tasks
10
10
  ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks
11
+
12
+ $stdout, @original_stdout = StringIO.new, $stdout
13
+ $stderr, @original_stderr = StringIO.new, $stderr
14
+ end
15
+
16
+ def teardown
17
+ $stdout, $stderr = @original_stdout, @original_stderr
11
18
  end
12
19
  end
13
20
 
14
21
  ADAPTERS_TASKS = {
15
- mysql: :mysql_tasks,
16
22
  mysql2: :mysql_tasks,
17
23
  postgresql: :postgresql_tasks,
18
24
  sqlite3: :sqlite_tasks
19
25
  }
20
26
 
27
+ class DatabaseTasksUtilsTask< ActiveRecord::TestCase
28
+ def test_raises_an_error_when_called_with_protected_environment
29
+ ActiveRecord::Migrator.stubs(:current_version).returns(1)
30
+
31
+ protected_environments = ActiveRecord::Base.protected_environments.dup
32
+ current_env = ActiveRecord::Migrator.current_environment
33
+ assert !protected_environments.include?(current_env)
34
+ # Assert no error
35
+ ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
36
+
37
+ ActiveRecord::Base.protected_environments << current_env
38
+ assert_raise(ActiveRecord::ProtectedEnvironmentError) do
39
+ ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
40
+ end
41
+ ensure
42
+ ActiveRecord::Base.protected_environments = protected_environments
43
+ end
44
+
45
+ def test_raises_an_error_if_no_migrations_have_been_made
46
+ ActiveRecord::InternalMetadata.stubs(:table_exists?).returns(false)
47
+ ActiveRecord::Migrator.stubs(:current_version).returns(1)
48
+
49
+ assert_raise(ActiveRecord::NoEnvironmentInSchemaError) do
50
+ ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
51
+ end
52
+ end
53
+ end
54
+
21
55
  class DatabaseTasksRegisterTask < ActiveRecord::TestCase
22
56
  def test_register_task
23
57
  klazz = Class.new do
@@ -134,21 +168,25 @@ module ActiveRecord
134
168
  with('database' => 'dev-db')
135
169
  ActiveRecord::Tasks::DatabaseTasks.expects(:create).
136
170
  with('database' => 'test-db')
137
- ENV.expects(:[]).with('RAILS_ENV').returns(nil)
138
171
 
139
172
  ActiveRecord::Tasks::DatabaseTasks.create_current(
140
173
  ActiveSupport::StringInquirer.new('development')
141
174
  )
142
175
  end
143
176
 
144
- def test_creates_only_development_database_when_rails_env_is_development
177
+ def test_creates_test_and_development_databases_when_rails_env_is_development
178
+ old_env = ENV['RAILS_ENV']
179
+ ENV['RAILS_ENV'] = 'development'
145
180
  ActiveRecord::Tasks::DatabaseTasks.expects(:create).
146
181
  with('database' => 'dev-db')
147
- ENV.expects(:[]).with('RAILS_ENV').returns('development')
182
+ ActiveRecord::Tasks::DatabaseTasks.expects(:create).
183
+ with('database' => 'test-db')
148
184
 
149
185
  ActiveRecord::Tasks::DatabaseTasks.create_current(
150
186
  ActiveSupport::StringInquirer.new('development')
151
187
  )
188
+ ensure
189
+ ENV['RAILS_ENV'] = old_env
152
190
  end
153
191
 
154
192
  def test_establishes_connection_for_the_given_environment
@@ -255,38 +293,64 @@ module ActiveRecord
255
293
  with('database' => 'dev-db')
256
294
  ActiveRecord::Tasks::DatabaseTasks.expects(:drop).
257
295
  with('database' => 'test-db')
258
- ENV.expects(:[]).with('RAILS_ENV').returns(nil)
259
296
 
260
297
  ActiveRecord::Tasks::DatabaseTasks.drop_current(
261
298
  ActiveSupport::StringInquirer.new('development')
262
299
  )
263
300
  end
264
301
 
265
- def test_drops_only_development_database_when_rails_env_is_development
302
+ def test_drops_testand_development_databases_when_rails_env_is_development
303
+ old_env = ENV['RAILS_ENV']
304
+ ENV['RAILS_ENV'] = 'development'
266
305
  ActiveRecord::Tasks::DatabaseTasks.expects(:drop).
267
306
  with('database' => 'dev-db')
268
- ENV.expects(:[]).with('RAILS_ENV').returns('development')
307
+ ActiveRecord::Tasks::DatabaseTasks.expects(:drop).
308
+ with('database' => 'test-db')
269
309
 
270
310
  ActiveRecord::Tasks::DatabaseTasks.drop_current(
271
311
  ActiveSupport::StringInquirer.new('development')
272
312
  )
313
+ ensure
314
+ ENV['RAILS_ENV'] = old_env
273
315
  end
274
316
  end
275
317
 
276
318
  class DatabaseTasksMigrateTest < ActiveRecord::TestCase
319
+ self.use_transactional_tests = false
320
+
321
+ def setup
322
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'custom/path'
323
+ end
324
+
325
+ def teardown
326
+ ActiveRecord::Tasks::DatabaseTasks.migrations_paths = nil
327
+ end
328
+
277
329
  def test_migrate_receives_correct_env_vars
278
330
  verbose, version = ENV['VERBOSE'], ENV['VERSION']
279
331
 
280
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'custom/path'
281
332
  ENV['VERBOSE'] = 'false'
282
333
  ENV['VERSION'] = '4'
283
334
 
284
335
  ActiveRecord::Migrator.expects(:migrate).with('custom/path', 4)
285
336
  ActiveRecord::Tasks::DatabaseTasks.migrate
286
337
  ensure
287
- ActiveRecord::Tasks::DatabaseTasks.migrations_paths = nil
288
338
  ENV['VERBOSE'], ENV['VERSION'] = verbose, version
289
339
  end
340
+
341
+ def test_migrate_raise_error_on_empty_version
342
+ version = ENV["VERSION"]
343
+ ENV["VERSION"] = ""
344
+ e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
345
+ assert_equal "Empty VERSION provided", e.message
346
+ ensure
347
+ ENV["VERSION"] = version
348
+ end
349
+
350
+ def test_migrate_clears_schema_cache_afterward
351
+ ActiveRecord::Base.expects(:clear_cache!)
352
+ ActiveRecord::Tasks::DatabaseTasks.migrate
353
+ end
290
354
  end
291
355
 
292
356
  class DatabaseTasksPurgeTest < ActiveRecord::TestCase
@@ -1,48 +1,49 @@
1
1
  require 'cases/helper'
2
+ require 'active_record/tasks/database_tasks'
2
3
 
3
- if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
4
+ if current_adapter?(:Mysql2Adapter)
4
5
  module ActiveRecord
5
6
  class MysqlDBCreateTest < ActiveRecord::TestCase
6
7
  def setup
7
8
  @connection = stub(:create_database => true)
8
9
  @configuration = {
9
- 'adapter' => 'mysql',
10
+ 'adapter' => 'mysql2',
10
11
  'database' => 'my-app-db'
11
12
  }
12
13
 
13
14
  ActiveRecord::Base.stubs(:connection).returns(@connection)
14
15
  ActiveRecord::Base.stubs(:establish_connection).returns(true)
16
+
17
+ $stdout, @original_stdout = StringIO.new, $stdout
18
+ $stderr, @original_stderr = StringIO.new, $stderr
19
+ end
20
+
21
+ def teardown
22
+ $stdout, $stderr = @original_stdout, @original_stderr
15
23
  end
16
24
 
17
25
  def test_establishes_connection_without_database
18
26
  ActiveRecord::Base.expects(:establish_connection).
19
- with('adapter' => 'mysql', 'database' => nil)
27
+ with('adapter' => 'mysql2', 'database' => nil)
20
28
 
21
29
  ActiveRecord::Tasks::DatabaseTasks.create @configuration
22
30
  end
23
31
 
24
- def test_creates_database_with_default_encoding_and_collation
32
+ def test_creates_database_with_no_default_options
25
33
  @connection.expects(:create_database).
26
- with('my-app-db', charset: 'utf8', collation: 'utf8_unicode_ci')
34
+ with('my-app-db', {})
27
35
 
28
36
  ActiveRecord::Tasks::DatabaseTasks.create @configuration
29
37
  end
30
38
 
31
- def test_creates_database_with_given_encoding_and_default_collation
32
- @connection.expects(:create_database).
33
- with('my-app-db', charset: 'utf8', collation: 'utf8_unicode_ci')
34
-
35
- ActiveRecord::Tasks::DatabaseTasks.create @configuration.merge('encoding' => 'utf8')
36
- end
37
-
38
- def test_creates_database_with_given_encoding_and_no_collation
39
+ def test_creates_database_with_given_encoding
39
40
  @connection.expects(:create_database).
40
41
  with('my-app-db', charset: 'latin1')
41
42
 
42
43
  ActiveRecord::Tasks::DatabaseTasks.create @configuration.merge('encoding' => 'latin1')
43
44
  end
44
45
 
45
- def test_creates_database_with_given_collation_and_no_encoding
46
+ def test_creates_database_with_given_collation
46
47
  @connection.expects(:create_database).
47
48
  with('my-app-db', collation: 'latin1_swedish_ci')
48
49
 
@@ -55,108 +56,118 @@ module ActiveRecord
55
56
  ActiveRecord::Tasks::DatabaseTasks.create @configuration
56
57
  end
57
58
 
58
- def test_create_when_database_exists_outputs_info_to_stderr
59
- $stderr.expects(:puts).with("my-app-db already exists").once
59
+ def test_when_database_created_successfully_outputs_info_to_stdout
60
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
60
61
 
62
+ assert_equal $stdout.string, "Created database 'my-app-db'\n"
63
+ end
64
+
65
+ def test_create_when_database_exists_outputs_info_to_stderr
61
66
  ActiveRecord::Base.connection.stubs(:create_database).raises(
62
- ActiveRecord::StatementInvalid.new("Can't create database 'dev'; database exists:")
67
+ ActiveRecord::Tasks::DatabaseAlreadyExists
63
68
  )
64
69
 
65
70
  ActiveRecord::Tasks::DatabaseTasks.create @configuration
71
+
72
+ assert_equal $stderr.string, "Database 'my-app-db' already exists\n"
66
73
  end
67
74
  end
68
75
 
69
- if current_adapter?(:MysqlAdapter)
70
- class MysqlDBCreateAsRootTest < ActiveRecord::TestCase
71
- def setup
72
- @connection = stub("Connection", create_database: true)
73
- @error = Mysql::Error.new "Invalid permissions"
74
- @configuration = {
75
- 'adapter' => 'mysql',
76
- 'database' => 'my-app-db',
77
- 'username' => 'pat',
78
- 'password' => 'wossname'
79
- }
80
-
81
- $stdin.stubs(:gets).returns("secret\n")
82
- $stdout.stubs(:print).returns(nil)
83
- @error.stubs(:errno).returns(1045)
84
- ActiveRecord::Base.stubs(:connection).returns(@connection)
85
- ActiveRecord::Base.stubs(:establish_connection).
86
- raises(@error).
87
- then.returns(true)
88
- end
76
+ class MysqlDBCreateAsRootTest < ActiveRecord::TestCase
77
+ def setup
78
+ @connection = stub("Connection", create_database: true)
79
+ @error = Mysql2::Error.new("Invalid permissions")
80
+ @configuration = {
81
+ 'adapter' => 'mysql2',
82
+ 'database' => 'my-app-db',
83
+ 'username' => 'pat',
84
+ 'password' => 'wossname'
85
+ }
89
86
 
90
- if defined?(::Mysql)
91
- def test_root_password_is_requested
92
- assert_permissions_granted_for "pat"
93
- $stdin.expects(:gets).returns("secret\n")
87
+ $stdin.stubs(:gets).returns("secret\n")
88
+ $stdout.stubs(:print).returns(nil)
89
+ @error.stubs(:errno).returns(1045)
90
+ ActiveRecord::Base.stubs(:connection).returns(@connection)
91
+ ActiveRecord::Base.stubs(:establish_connection).
92
+ raises(@error).
93
+ then.returns(true)
94
94
 
95
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
96
- end
97
- end
95
+ $stdout, @original_stdout = StringIO.new, $stdout
96
+ $stderr, @original_stderr = StringIO.new, $stderr
97
+ end
98
98
 
99
- def test_connection_established_as_root
100
- assert_permissions_granted_for "pat"
101
- ActiveRecord::Base.expects(:establish_connection).with(
102
- 'adapter' => 'mysql',
103
- 'database' => nil,
104
- 'username' => 'root',
105
- 'password' => 'secret'
106
- )
99
+ def teardown
100
+ $stdout, $stderr = @original_stdout, @original_stderr
101
+ end
107
102
 
108
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
109
- end
103
+ def test_root_password_is_requested
104
+ assert_permissions_granted_for("pat")
105
+ $stdin.expects(:gets).returns("secret\n")
110
106
 
111
- def test_database_created_by_root
112
- assert_permissions_granted_for "pat"
113
- @connection.expects(:create_database).
114
- with('my-app-db', :charset => 'utf8', :collation => 'utf8_unicode_ci')
107
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
108
+ end
115
109
 
116
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
117
- end
110
+ def test_connection_established_as_root
111
+ assert_permissions_granted_for("pat")
112
+ ActiveRecord::Base.expects(:establish_connection).with(
113
+ 'adapter' => 'mysql2',
114
+ 'database' => nil,
115
+ 'username' => 'root',
116
+ 'password' => 'secret'
117
+ )
118
118
 
119
- def test_grant_privileges_for_normal_user
120
- assert_permissions_granted_for "pat"
121
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
122
- end
119
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
120
+ end
123
121
 
124
- def test_do_not_grant_privileges_for_root_user
125
- @configuration['username'] = 'root'
126
- @configuration['password'] = ''
127
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
128
- end
122
+ def test_database_created_by_root
123
+ assert_permissions_granted_for("pat")
124
+ @connection.expects(:create_database).
125
+ with('my-app-db', {})
126
+
127
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
128
+ end
129
129
 
130
- def test_connection_established_as_normal_user
131
- assert_permissions_granted_for "pat"
132
- ActiveRecord::Base.expects(:establish_connection).returns do
133
- ActiveRecord::Base.expects(:establish_connection).with(
134
- 'adapter' => 'mysql',
135
- 'database' => 'my-app-db',
136
- 'username' => 'pat',
137
- 'password' => 'secret'
138
- )
130
+ def test_grant_privileges_for_normal_user
131
+ assert_permissions_granted_for("pat")
132
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
133
+ end
139
134
 
140
- raise @error
141
- end
135
+ def test_do_not_grant_privileges_for_root_user
136
+ @configuration['username'] = 'root'
137
+ @configuration['password'] = ''
138
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
139
+ end
142
140
 
143
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
141
+ def test_connection_established_as_normal_user
142
+ assert_permissions_granted_for("pat")
143
+ ActiveRecord::Base.expects(:establish_connection).returns do
144
+ ActiveRecord::Base.expects(:establish_connection).with(
145
+ 'adapter' => 'mysql2',
146
+ 'database' => 'my-app-db',
147
+ 'username' => 'pat',
148
+ 'password' => 'secret'
149
+ )
150
+
151
+ raise @error
144
152
  end
145
153
 
146
- def test_sends_output_to_stderr_when_other_errors
147
- @error.stubs(:errno).returns(42)
154
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
155
+ end
148
156
 
149
- $stderr.expects(:puts).at_least_once.returns(nil)
157
+ def test_sends_output_to_stderr_when_other_errors
158
+ @error.stubs(:errno).returns(42)
150
159
 
151
- ActiveRecord::Tasks::DatabaseTasks.create @configuration
152
- end
160
+ $stderr.expects(:puts).at_least_once.returns(nil)
153
161
 
154
- private
155
- def assert_permissions_granted_for(db_user)
156
- db_name = @configuration['database']
157
- db_password = @configuration['password']
158
- @connection.expects(:execute).with("GRANT ALL PRIVILEGES ON #{db_name}.* TO '#{db_user}'@'localhost' IDENTIFIED BY '#{db_password}' WITH GRANT OPTION;")
159
- end
162
+ ActiveRecord::Tasks::DatabaseTasks.create @configuration
163
+ end
164
+
165
+ private
166
+
167
+ def assert_permissions_granted_for(db_user)
168
+ db_name = @configuration['database']
169
+ db_password = @configuration['password']
170
+ @connection.expects(:execute).with("GRANT ALL PRIVILEGES ON #{db_name}.* TO '#{db_user}'@'localhost' IDENTIFIED BY '#{db_password}' WITH GRANT OPTION;")
160
171
  end
161
172
  end
162
173
 
@@ -164,12 +175,19 @@ module ActiveRecord
164
175
  def setup
165
176
  @connection = stub(:drop_database => true)
166
177
  @configuration = {
167
- 'adapter' => 'mysql',
178
+ 'adapter' => 'mysql2',
168
179
  'database' => 'my-app-db'
169
180
  }
170
181
 
171
182
  ActiveRecord::Base.stubs(:connection).returns(@connection)
172
183
  ActiveRecord::Base.stubs(:establish_connection).returns(true)
184
+
185
+ $stdout, @original_stdout = StringIO.new, $stdout
186
+ $stderr, @original_stderr = StringIO.new, $stderr
187
+ end
188
+
189
+ def teardown
190
+ $stdout, $stderr = @original_stdout, @original_stderr
173
191
  end
174
192
 
175
193
  def test_establishes_connection_to_mysql_database
@@ -183,13 +201,19 @@ module ActiveRecord
183
201
 
184
202
  ActiveRecord::Tasks::DatabaseTasks.drop @configuration
185
203
  end
204
+
205
+ def test_when_database_dropped_successfully_outputs_info_to_stdout
206
+ ActiveRecord::Tasks::DatabaseTasks.drop @configuration
207
+
208
+ assert_equal $stdout.string, "Dropped database 'my-app-db'\n"
209
+ end
186
210
  end
187
211
 
188
212
  class MySQLPurgeTest < ActiveRecord::TestCase
189
213
  def setup
190
214
  @connection = stub(:recreate_database => true)
191
215
  @configuration = {
192
- 'adapter' => 'mysql',
216
+ 'adapter' => 'mysql2',
193
217
  'database' => 'test-db'
194
218
  }
195
219
 
@@ -203,9 +227,9 @@ module ActiveRecord
203
227
  ActiveRecord::Tasks::DatabaseTasks.purge @configuration
204
228
  end
205
229
 
206
- def test_recreates_database_with_the_default_options
230
+ def test_recreates_database_with_no_default_options
207
231
  @connection.expects(:recreate_database).
208
- with('test-db', charset: 'utf8', collation: 'utf8_unicode_ci')
232
+ with('test-db', {})
209
233
 
210
234
  ActiveRecord::Tasks::DatabaseTasks.purge @configuration
211
235
  end
@@ -223,7 +247,7 @@ module ActiveRecord
223
247
  def setup
224
248
  @connection = stub(:create_database => true)
225
249
  @configuration = {
226
- 'adapter' => 'mysql',
250
+ 'adapter' => 'mysql2',
227
251
  'database' => 'my-app-db'
228
252
  }
229
253
 
@@ -241,7 +265,7 @@ module ActiveRecord
241
265
  def setup
242
266
  @connection = stub(:create_database => true)
243
267
  @configuration = {
244
- 'adapter' => 'mysql',
268
+ 'adapter' => 'mysql2',
245
269
  'database' => 'my-app-db'
246
270
  }
247
271
 
@@ -258,55 +282,53 @@ module ActiveRecord
258
282
  class MySQLStructureDumpTest < ActiveRecord::TestCase
259
283
  def setup
260
284
  @configuration = {
261
- 'adapter' => 'mysql',
285
+ 'adapter' => 'mysql2',
262
286
  'database' => 'test-db'
263
287
  }
264
288
  end
265
289
 
266
290
  def test_structure_dump
267
291
  filename = "awesome-file.sql"
268
- Kernel.expects(:system).with("mysqldump", "--result-file", filename, "--no-data", "test-db").returns(true)
292
+ Kernel.expects(:system).with("mysqldump", "--result-file", filename, "--no-data", "--routines", "test-db").returns(true)
269
293
 
270
294
  ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
271
295
  end
272
296
 
273
- def test_warn_when_external_structure_dump_fails
274
- filename = "awesome-file.sql"
275
- Kernel.expects(:system).with("mysqldump", "--result-file", filename, "--no-data", "test-db").returns(false)
276
-
277
- # There doesn't seem to be a good way to get a handle on a Process::Status object without actually
278
- # creating a child process, hence this to populate $?
279
- system("not_a_real_program_#{SecureRandom.hex}")
280
- assert_raise(RuntimeError) {
281
- ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
282
- }
283
- end
284
-
285
297
  def test_warn_when_external_structure_dump_command_execution_fails
286
298
  filename = "awesome-file.sql"
287
299
  Kernel.expects(:system)
288
- .with("mysqldump", "--result-file", filename, "--no-data", "test-db")
289
- .returns(nil)
300
+ .with("mysqldump", "--result-file", filename, "--no-data", "--routines", "test-db")
301
+ .returns(false)
290
302
 
291
- assert_raise(RuntimeError) {
303
+ e = assert_raise(RuntimeError) {
292
304
  ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename)
293
305
  }
306
+ assert_match(/^failed to execute: `mysqldump`$/, e.message)
294
307
  end
295
308
 
296
309
  def test_structure_dump_with_port_number
297
310
  filename = "awesome-file.sql"
298
- Kernel.expects(:system).with("mysqldump", "--port", "10000", "--result-file", filename, "--no-data", "test-db").returns(true)
311
+ Kernel.expects(:system).with("mysqldump", "--port=10000", "--result-file", filename, "--no-data", "--routines", "test-db").returns(true)
299
312
 
300
313
  ActiveRecord::Tasks::DatabaseTasks.structure_dump(
301
314
  @configuration.merge('port' => 10000),
302
315
  filename)
303
316
  end
317
+
318
+ def test_structure_dump_with_ssl
319
+ filename = "awesome-file.sql"
320
+ Kernel.expects(:system).with("mysqldump", "--ssl-ca=ca.crt", "--result-file", filename, "--no-data", "--routines", "test-db").returns(true)
321
+
322
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump(
323
+ @configuration.merge("sslca" => "ca.crt"),
324
+ filename)
325
+ end
304
326
  end
305
327
 
306
328
  class MySQLStructureLoadTest < ActiveRecord::TestCase
307
329
  def setup
308
330
  @configuration = {
309
- 'adapter' => 'mysql',
331
+ 'adapter' => 'mysql2',
310
332
  'database' => 'test-db'
311
333
  }
312
334
  end
@@ -319,6 +341,5 @@ module ActiveRecord
319
341
  ActiveRecord::Tasks::DatabaseTasks.structure_load(@configuration, filename)
320
342
  end
321
343
  end
322
-
323
344
  end
324
345
  end