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
@@ -24,6 +24,8 @@ require 'models/molecule'
24
24
  require 'models/member'
25
25
  require 'models/member_detail'
26
26
  require 'models/organization'
27
+ require 'models/guitar'
28
+ require 'models/tuning_peg'
27
29
 
28
30
  class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase
29
31
  def test_autosave_validation
@@ -67,6 +69,14 @@ class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase
67
69
  assert_no_difference_when_adding_callbacks_twice_for Pirate, :parrots
68
70
  end
69
71
 
72
+ def test_cyclic_autosaves_do_not_add_multiple_validations
73
+ ship = ShipWithoutNestedAttributes.new
74
+ ship.prisoners.build
75
+
76
+ assert_not ship.valid?
77
+ assert_equal 1, ship.errors[:name].length
78
+ end
79
+
70
80
  private
71
81
 
72
82
  def assert_no_difference_when_adding_callbacks_twice_for(model, association_name)
@@ -149,7 +159,8 @@ class TestDefaultAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCas
149
159
  assert_equal a, firm.account
150
160
  assert firm.save
151
161
  assert_equal a, firm.account
152
- assert_equal a, firm.account(true)
162
+ firm.association(:account).reload
163
+ assert_equal a, firm.account
153
164
  end
154
165
 
155
166
  def test_assignment_before_either_saved
@@ -162,7 +173,8 @@ class TestDefaultAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCas
162
173
  assert firm.persisted?
163
174
  assert a.persisted?
164
175
  assert_equal a, firm.account
165
- assert_equal a, firm.account(true)
176
+ firm.association(:account).reload
177
+ assert_equal a, firm.account
166
178
  end
167
179
 
168
180
  def test_not_resaved_when_unchanged
@@ -248,7 +260,8 @@ class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::Test
248
260
  assert apple.save
249
261
  assert apple.persisted?
250
262
  assert_equal apple, client.firm
251
- assert_equal apple, client.firm(true)
263
+ client.association(:firm).reload
264
+ assert_equal apple, client.firm
252
265
  end
253
266
 
254
267
  def test_assignment_before_either_saved
@@ -261,7 +274,8 @@ class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::Test
261
274
  assert final_cut.persisted?
262
275
  assert apple.persisted?
263
276
  assert_equal apple, final_cut.firm
264
- assert_equal apple, final_cut.firm(true)
277
+ final_cut.association(:firm).reload
278
+ assert_equal apple, final_cut.firm
265
279
  end
266
280
 
267
281
  def test_store_two_association_with_one_save
@@ -385,6 +399,87 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociationWithAcceptsNestedAttrib
385
399
  assert_not molecule.persisted?, 'Molecule should not be persisted when its electrons are invalid'
386
400
  end
387
401
 
402
+ def test_errors_should_be_indexed_when_passed_as_array
403
+ guitar = Guitar.new
404
+ tuning_peg_valid = TuningPeg.new
405
+ tuning_peg_valid.pitch = 440.0
406
+ tuning_peg_invalid = TuningPeg.new
407
+
408
+ guitar.tuning_pegs = [tuning_peg_valid, tuning_peg_invalid]
409
+
410
+ assert_not tuning_peg_invalid.valid?
411
+ assert tuning_peg_valid.valid?
412
+ assert_not guitar.valid?
413
+ assert_equal ["is not a number"], guitar.errors["tuning_pegs[1].pitch"]
414
+ assert_not_equal ["is not a number"], guitar.errors["tuning_pegs.pitch"]
415
+ end
416
+
417
+ def test_errors_should_be_indexed_when_global_flag_is_set
418
+ old_attribute_config = ActiveRecord::Base.index_nested_attribute_errors
419
+ ActiveRecord::Base.index_nested_attribute_errors = true
420
+
421
+ molecule = Molecule.new
422
+ valid_electron = Electron.new(name: 'electron')
423
+ invalid_electron = Electron.new
424
+
425
+ molecule.electrons = [valid_electron, invalid_electron]
426
+
427
+ assert_not invalid_electron.valid?
428
+ assert valid_electron.valid?
429
+ assert_not molecule.valid?
430
+ assert_equal ["can't be blank"], molecule.errors["electrons[1].name"]
431
+ assert_not_equal ["can't be blank"], molecule.errors["electrons.name"]
432
+ ensure
433
+ ActiveRecord::Base.index_nested_attribute_errors = old_attribute_config
434
+ end
435
+
436
+ def test_errors_details_should_be_set
437
+ molecule = Molecule.new
438
+ valid_electron = Electron.new(name: 'electron')
439
+ invalid_electron = Electron.new
440
+
441
+ molecule.electrons = [valid_electron, invalid_electron]
442
+
443
+ assert_not invalid_electron.valid?
444
+ assert valid_electron.valid?
445
+ assert_not molecule.valid?
446
+ assert_equal [{ error: :blank }], molecule.errors.details[:"electrons.name"]
447
+ end
448
+
449
+ def test_errors_details_should_be_indexed_when_passed_as_array
450
+ guitar = Guitar.new
451
+ tuning_peg_valid = TuningPeg.new
452
+ tuning_peg_valid.pitch = 440.0
453
+ tuning_peg_invalid = TuningPeg.new
454
+
455
+ guitar.tuning_pegs = [tuning_peg_valid, tuning_peg_invalid]
456
+
457
+ assert_not tuning_peg_invalid.valid?
458
+ assert tuning_peg_valid.valid?
459
+ assert_not guitar.valid?
460
+ assert_equal [{ error: :not_a_number, value: nil }], guitar.errors.details[:"tuning_pegs[1].pitch"]
461
+ assert_equal [], guitar.errors.details[:"tuning_pegs.pitch"]
462
+ end
463
+
464
+ def test_errors_details_should_be_indexed_when_global_flag_is_set
465
+ old_attribute_config = ActiveRecord::Base.index_nested_attribute_errors
466
+ ActiveRecord::Base.index_nested_attribute_errors = true
467
+
468
+ molecule = Molecule.new
469
+ valid_electron = Electron.new(name: 'electron')
470
+ invalid_electron = Electron.new
471
+
472
+ molecule.electrons = [valid_electron, invalid_electron]
473
+
474
+ assert_not invalid_electron.valid?
475
+ assert valid_electron.valid?
476
+ assert_not molecule.valid?
477
+ assert_equal [{ error: :blank }], molecule.errors.details[:"electrons[1].name"]
478
+ assert_equal [], molecule.errors.details[:"electrons.name"]
479
+ ensure
480
+ ActiveRecord::Base.index_nested_attribute_errors = old_attribute_config
481
+ end
482
+
388
483
  def test_valid_adding_with_nested_attributes
389
484
  molecule = Molecule.new
390
485
  valid_electron = Electron.new(name: 'electron')
@@ -456,7 +551,7 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
456
551
  assert_equal new_client, companies(:first_firm).clients_of_firm.last
457
552
  assert !companies(:first_firm).save
458
553
  assert !new_client.persisted?
459
- assert_equal 2, companies(:first_firm).clients_of_firm(true).size
554
+ assert_equal 2, companies(:first_firm).clients_of_firm.reload.size
460
555
  end
461
556
 
462
557
  def test_adding_before_save
@@ -481,7 +576,7 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
481
576
  assert_equal no_of_clients + 2, Client.count # Clients were saved to database.
482
577
 
483
578
  assert_equal 2, new_firm.clients_of_firm.size
484
- assert_equal 2, new_firm.clients_of_firm(true).size
579
+ assert_equal 2, new_firm.clients_of_firm.reload.size
485
580
  end
486
581
 
487
582
  def test_assign_ids
@@ -510,7 +605,7 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
510
605
  company.name += '-changed'
511
606
  assert_queries(2) { assert company.save }
512
607
  assert new_client.persisted?
513
- assert_equal 3, company.clients_of_firm(true).size
608
+ assert_equal 3, company.clients_of_firm.reload.size
514
609
  end
515
610
 
516
611
  def test_build_many_before_save
@@ -519,7 +614,7 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
519
614
 
520
615
  company.name += '-changed'
521
616
  assert_queries(3) { assert company.save }
522
- assert_equal 4, company.clients_of_firm(true).size
617
+ assert_equal 4, company.clients_of_firm.reload.size
523
618
  end
524
619
 
525
620
  def test_build_via_block_before_save
@@ -530,7 +625,7 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
530
625
  company.name += '-changed'
531
626
  assert_queries(2) { assert company.save }
532
627
  assert new_client.persisted?
533
- assert_equal 3, company.clients_of_firm(true).size
628
+ assert_equal 3, company.clients_of_firm.reload.size
534
629
  end
535
630
 
536
631
  def test_build_many_via_block_before_save
@@ -543,7 +638,7 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
543
638
 
544
639
  company.name += '-changed'
545
640
  assert_queries(3) { assert company.save }
546
- assert_equal 4, company.clients_of_firm(true).size
641
+ assert_equal 4, company.clients_of_firm.reload.size
547
642
  end
548
643
 
549
644
  def test_replace_on_new_object
@@ -629,7 +724,7 @@ class TestDefaultAutosaveAssociationOnNewRecord < ActiveRecord::TestCase
629
724
  end
630
725
 
631
726
  class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
632
- self.use_transactional_fixtures = false
727
+ self.use_transactional_tests = false
633
728
 
634
729
  setup do
635
730
  @pirate = Pirate.create(:catchphrase => "Don' botharrr talkin' like one, savvy?")
@@ -637,7 +732,7 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
637
732
  end
638
733
 
639
734
  teardown do
640
- # We are running without transactional fixtures and need to cleanup.
735
+ # We are running without transactional tests and need to cleanup.
641
736
  Bird.delete_all
642
737
  Parrot.delete_all
643
738
  @ship.delete
@@ -654,7 +749,7 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
654
749
  end
655
750
 
656
751
  # has_one
657
- def test_should_destroy_a_child_association_as_part_of_the_save_transaction_if_it_was_marked_for_destroyal
752
+ def test_should_destroy_a_child_association_as_part_of_the_save_transaction_if_it_was_marked_for_destruction
658
753
  assert !@pirate.ship.marked_for_destruction?
659
754
 
660
755
  @pirate.ship.mark_for_destruction
@@ -714,7 +809,7 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
714
809
  end
715
810
 
716
811
  # belongs_to
717
- def test_should_destroy_a_parent_association_as_part_of_the_save_transaction_if_it_was_marked_for_destroyal
812
+ def test_should_destroy_a_parent_association_as_part_of_the_save_transaction_if_it_was_marked_for_destruction
718
813
  assert !@ship.pirate.marked_for_destruction?
719
814
 
720
815
  @ship.pirate.mark_for_destruction
@@ -774,13 +869,13 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
774
869
  def test_should_destroy_has_many_as_part_of_the_save_transaction_if_they_were_marked_for_destruction
775
870
  2.times { |i| @pirate.birds.create!(:name => "birds_#{i}") }
776
871
 
777
- assert !@pirate.birds.any? { |child| child.marked_for_destruction? }
872
+ assert !@pirate.birds.any?(&:marked_for_destruction?)
778
873
 
779
- @pirate.birds.each { |child| child.mark_for_destruction }
874
+ @pirate.birds.each(&:mark_for_destruction)
780
875
  klass = @pirate.birds.first.class
781
876
  ids = @pirate.birds.map(&:id)
782
877
 
783
- assert @pirate.birds.all? { |child| child.marked_for_destruction? }
878
+ assert @pirate.birds.all?(&:marked_for_destruction?)
784
879
  ids.each { |id| assert klass.find_by_id(id) }
785
880
 
786
881
  @pirate.save
@@ -814,14 +909,14 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
814
909
  @pirate.birds.each { |bird| bird.name = '' }
815
910
  assert !@pirate.valid?
816
911
 
817
- @pirate.birds.each { |bird| bird.destroy }
912
+ @pirate.birds.each(&:destroy)
818
913
  assert @pirate.valid?
819
914
  end
820
915
 
821
916
  def test_a_child_marked_for_destruction_should_not_be_destroyed_twice_while_saving_has_many
822
917
  @pirate.birds.create!(:name => "birds_1")
823
918
 
824
- @pirate.birds.each { |bird| bird.mark_for_destruction }
919
+ @pirate.birds.each(&:mark_for_destruction)
825
920
  assert @pirate.save
826
921
 
827
922
  @pirate.birds.each { |bird| bird.expects(:destroy).never }
@@ -888,7 +983,7 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
888
983
  association_name_with_callbacks = "birds_with_#{callback_type}_callbacks"
889
984
 
890
985
  @pirate.send(association_name_with_callbacks).create!(:name => "Crowe the One-Eyed")
891
- @pirate.send(association_name_with_callbacks).each { |c| c.mark_for_destruction }
986
+ @pirate.send(association_name_with_callbacks).each(&:mark_for_destruction)
892
987
  child_id = @pirate.send(association_name_with_callbacks).first.id
893
988
 
894
989
  @pirate.ship_log.clear
@@ -906,8 +1001,8 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
906
1001
  def test_should_destroy_habtm_as_part_of_the_save_transaction_if_they_were_marked_for_destruction
907
1002
  2.times { |i| @pirate.parrots.create!(:name => "parrots_#{i}") }
908
1003
 
909
- assert !@pirate.parrots.any? { |parrot| parrot.marked_for_destruction? }
910
- @pirate.parrots.each { |parrot| parrot.mark_for_destruction }
1004
+ assert !@pirate.parrots.any?(&:marked_for_destruction?)
1005
+ @pirate.parrots.each(&:mark_for_destruction)
911
1006
 
912
1007
  assert_no_difference "Parrot.count" do
913
1008
  @pirate.save
@@ -940,14 +1035,14 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
940
1035
  @pirate.parrots.each { |parrot| parrot.name = '' }
941
1036
  assert !@pirate.valid?
942
1037
 
943
- @pirate.parrots.each { |parrot| parrot.destroy }
1038
+ @pirate.parrots.each(&:destroy)
944
1039
  assert @pirate.valid?
945
1040
  end
946
1041
 
947
1042
  def test_a_child_marked_for_destruction_should_not_be_destroyed_twice_while_saving_habtm
948
1043
  @pirate.parrots.create!(:name => "parrots_1")
949
1044
 
950
- @pirate.parrots.each { |parrot| parrot.mark_for_destruction }
1045
+ @pirate.parrots.each(&:mark_for_destruction)
951
1046
  assert @pirate.save
952
1047
 
953
1048
  Pirate.transaction do
@@ -992,7 +1087,7 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
992
1087
  association_name_with_callbacks = "parrots_with_#{callback_type}_callbacks"
993
1088
 
994
1089
  @pirate.send(association_name_with_callbacks).create!(:name => "Crowe the One-Eyed")
995
- @pirate.send(association_name_with_callbacks).each { |c| c.mark_for_destruction }
1090
+ @pirate.send(association_name_with_callbacks).each(&:mark_for_destruction)
996
1091
  child_id = @pirate.send(association_name_with_callbacks).first.id
997
1092
 
998
1093
  @pirate.ship_log.clear
@@ -1009,7 +1104,7 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
1009
1104
  end
1010
1105
 
1011
1106
  class TestAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCase
1012
- self.use_transactional_fixtures = false unless supports_savepoints?
1107
+ self.use_transactional_tests = false unless supports_savepoints?
1013
1108
 
1014
1109
  def setup
1015
1110
  super
@@ -1152,7 +1247,7 @@ class TestAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCase
1152
1247
  end
1153
1248
 
1154
1249
  class TestAutosaveAssociationOnAHasOneThroughAssociation < ActiveRecord::TestCase
1155
- self.use_transactional_fixtures = false unless supports_savepoints?
1250
+ self.use_transactional_tests = false unless supports_savepoints?
1156
1251
 
1157
1252
  def setup
1158
1253
  super
@@ -1173,7 +1268,7 @@ class TestAutosaveAssociationOnAHasOneThroughAssociation < ActiveRecord::TestCas
1173
1268
  end
1174
1269
 
1175
1270
  class TestAutosaveAssociationOnABelongsToAssociation < ActiveRecord::TestCase
1176
- self.use_transactional_fixtures = false unless supports_savepoints?
1271
+ self.use_transactional_tests = false unless supports_savepoints?
1177
1272
 
1178
1273
  def setup
1179
1274
  super
@@ -1285,6 +1380,24 @@ module AutosaveAssociationOnACollectionAssociationTests
1285
1380
  assert_equal new_names, @pirate.reload.send(@association_name).map(&:name)
1286
1381
  end
1287
1382
 
1383
+ def test_should_update_children_when_autosave_is_true_and_parent_is_new_but_child_is_not
1384
+ parrot = Parrot.create!(name: "Polly")
1385
+ parrot.name = "Squawky"
1386
+ pirate = Pirate.new(parrots: [parrot], catchphrase: "Arrrr")
1387
+
1388
+ pirate.save!
1389
+
1390
+ assert_equal "Squawky", parrot.reload.name
1391
+ end
1392
+
1393
+ def test_should_not_update_children_when_parent_creation_with_no_reason
1394
+ parrot = Parrot.create!(name: "Polly")
1395
+ assert_equal 0, parrot.updated_count
1396
+
1397
+ Pirate.create!(parrot_ids: [parrot.id], catchphrase: "Arrrr")
1398
+ assert_equal 0, parrot.reload.updated_count
1399
+ end
1400
+
1288
1401
  def test_should_automatically_validate_the_associated_models
1289
1402
  @pirate.send(@association_name).each { |child| child.name = '' }
1290
1403
 
@@ -1421,7 +1534,7 @@ module AutosaveAssociationOnACollectionAssociationTests
1421
1534
  end
1422
1535
 
1423
1536
  class TestAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCase
1424
- self.use_transactional_fixtures = false unless supports_savepoints?
1537
+ self.use_transactional_tests = false unless supports_savepoints?
1425
1538
 
1426
1539
  def setup
1427
1540
  super
@@ -1437,7 +1550,7 @@ class TestAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCase
1437
1550
  end
1438
1551
 
1439
1552
  class TestAutosaveAssociationOnAHasAndBelongsToManyAssociation < ActiveRecord::TestCase
1440
- self.use_transactional_fixtures = false unless supports_savepoints?
1553
+ self.use_transactional_tests = false unless supports_savepoints?
1441
1554
 
1442
1555
  def setup
1443
1556
  super
@@ -1454,7 +1567,7 @@ class TestAutosaveAssociationOnAHasAndBelongsToManyAssociation < ActiveRecord::T
1454
1567
  end
1455
1568
 
1456
1569
  class TestAutosaveAssociationOnAHasAndBelongsToManyAssociationWithAcceptsNestedAttributes < ActiveRecord::TestCase
1457
- self.use_transactional_fixtures = false unless supports_savepoints?
1570
+ self.use_transactional_tests = false unless supports_savepoints?
1458
1571
 
1459
1572
  def setup
1460
1573
  super
@@ -1471,7 +1584,7 @@ class TestAutosaveAssociationOnAHasAndBelongsToManyAssociationWithAcceptsNestedA
1471
1584
  end
1472
1585
 
1473
1586
  class TestAutosaveAssociationValidationsOnAHasManyAssociation < ActiveRecord::TestCase
1474
- self.use_transactional_fixtures = false unless supports_savepoints?
1587
+ self.use_transactional_tests = false unless supports_savepoints?
1475
1588
 
1476
1589
  def setup
1477
1590
  super
@@ -1488,7 +1601,7 @@ class TestAutosaveAssociationValidationsOnAHasManyAssociation < ActiveRecord::Te
1488
1601
  end
1489
1602
 
1490
1603
  class TestAutosaveAssociationValidationsOnAHasOneAssociation < ActiveRecord::TestCase
1491
- self.use_transactional_fixtures = false unless supports_savepoints?
1604
+ self.use_transactional_tests = false unless supports_savepoints?
1492
1605
 
1493
1606
  def setup
1494
1607
  super
@@ -1511,7 +1624,7 @@ class TestAutosaveAssociationValidationsOnAHasOneAssociation < ActiveRecord::Tes
1511
1624
  end
1512
1625
 
1513
1626
  class TestAutosaveAssociationValidationsOnABelongsToAssociation < ActiveRecord::TestCase
1514
- self.use_transactional_fixtures = false unless supports_savepoints?
1627
+ self.use_transactional_tests = false unless supports_savepoints?
1515
1628
 
1516
1629
  def setup
1517
1630
  super
@@ -1532,7 +1645,7 @@ class TestAutosaveAssociationValidationsOnABelongsToAssociation < ActiveRecord::
1532
1645
  end
1533
1646
 
1534
1647
  class TestAutosaveAssociationValidationsOnAHABTMAssociation < ActiveRecord::TestCase
1535
- self.use_transactional_fixtures = false unless supports_savepoints?
1648
+ self.use_transactional_tests = false unless supports_savepoints?
1536
1649
 
1537
1650
  def setup
1538
1651
  super
@@ -1555,7 +1668,7 @@ class TestAutosaveAssociationValidationsOnAHABTMAssociation < ActiveRecord::Test
1555
1668
  end
1556
1669
 
1557
1670
  class TestAutosaveAssociationValidationMethodsGeneration < ActiveRecord::TestCase
1558
- self.use_transactional_fixtures = false unless supports_savepoints?
1671
+ self.use_transactional_tests = false unless supports_savepoints?
1559
1672
 
1560
1673
  def setup
1561
1674
  super
@@ -1,7 +1,4 @@
1
- # encoding: utf-8
2
-
3
1
  require "cases/helper"
4
- require 'active_support/concurrency/latch'
5
2
  require 'models/post'
6
3
  require 'models/author'
7
4
  require 'models/topic'
@@ -29,6 +26,7 @@ require 'models/bird'
29
26
  require 'models/car'
30
27
  require 'models/bulb'
31
28
  require 'rexml/document'
29
+ require 'concurrent/atomic/count_down_latch'
32
30
 
33
31
  class FirstAbstractClass < ActiveRecord::Base
34
32
  self.abstract_class = true
@@ -77,18 +75,20 @@ class LintTest < ActiveRecord::TestCase
77
75
  end
78
76
 
79
77
  class BasicsTest < ActiveRecord::TestCase
80
- fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse_things', :authors, :categorizations, :categories, :posts, :author_addresses
78
+ #fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse_things', :authors, :categorizations, :categories, :posts
79
+ fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse_things', :categorizations, :categories, :posts
81
80
 
82
81
  def test_column_names_are_escaped
82
+ puts "In base_test test_column_names_are_escaped"
83
83
  conn = ActiveRecord::Base.connection
84
84
  classname = conn.class.name[/[^:]*$/]
85
85
  badchar = {
86
86
  'SQLite3Adapter' => '"',
87
- 'MysqlAdapter' => '`',
88
87
  'Mysql2Adapter' => '`',
89
88
  'PostgreSQLAdapter' => '"',
90
89
  'OracleAdapter' => '"',
91
90
  'IBM_DBAdapter' => '"',
91
+ 'FbAdapter' => '"'
92
92
  }.fetch(classname) {
93
93
  raise "need a bad char for #{classname}"
94
94
  }
@@ -106,64 +106,81 @@ class BasicsTest < ActiveRecord::TestCase
106
106
  end
107
107
 
108
108
  def test_columns_should_obey_set_primary_key
109
+ puts "In base_test test_columns_should_obey_set_primary_key"
109
110
  pk = Subscriber.columns_hash[Subscriber.primary_key]
110
111
  assert_equal 'nick', pk.name, 'nick should be primary key'
111
112
  end
112
113
 
113
114
  def test_primary_key_with_no_id
115
+ puts "In base_test test_primary_key_with_no_id"
114
116
  assert_nil Edge.primary_key
115
117
  end
116
118
 
117
- unless current_adapter?(:PostgreSQLAdapter, :OracleAdapter, :SQLServerAdapter, :IBM_DBAdapter)
119
+ unless current_adapter?(:PostgreSQLAdapter, :OracleAdapter, :SQLServerAdapter, :IBM_DBAdapter, :FbAdapter)
118
120
  def test_limit_with_comma
119
- assert Topic.limit("1,2").to_a
121
+ puts "In base_test test_limit_with_comma"
122
+ assert_deprecated do
123
+ assert Topic.limit("1,2").to_a
124
+ end
120
125
  end
121
126
  end
122
127
 
128
+ def test_many_mutations
129
+ puts "In base_test test_many_mutations"
130
+ car = Car.new name: "<3<3<3"
131
+ car.engines_count = 0
132
+ 20_000.times { car.engines_count += 1 }
133
+ assert car.save
134
+ end
135
+
123
136
  def test_limit_without_comma
137
+ puts "In base_test test_limit_without_comma"
124
138
  assert_equal 1, Topic.limit("1").to_a.length
125
139
  assert_equal 1, Topic.limit(1).to_a.length
126
140
  end
127
141
 
128
142
  def test_limit_should_take_value_from_latest_limit
143
+ puts "In base_test test_limit_should_take_value_from_latest_limit"
129
144
  assert_equal 1, Topic.limit(2).limit(1).to_a.length
130
145
  end
131
146
 
132
147
  def test_invalid_limit
148
+ puts "In base_test test_invalid_limit"
133
149
  assert_raises(ArgumentError) do
134
150
  Topic.limit("asdfadf").to_a
135
151
  end
136
152
  end
137
153
 
138
154
  def test_limit_should_sanitize_sql_injection_for_limit_without_commas
155
+ puts "In base_test test_limit_should_sanitize_sql_injection_for_limit_without_commas"
139
156
  assert_raises(ArgumentError) do
140
157
  Topic.limit("1 select * from schema").to_a
141
158
  end
142
159
  end
143
160
 
144
161
  def test_limit_should_sanitize_sql_injection_for_limit_with_commas
145
- assert_raises(ArgumentError) do
146
- Topic.limit("1, 7 procedure help()").to_a
147
- end
148
- end
149
-
150
- unless current_adapter?(:MysqlAdapter, :Mysql2Adapter, :IBM_DBAdapter)
151
- def test_limit_should_allow_sql_literal
152
- assert_equal 1, Topic.limit(Arel.sql('2-1')).to_a.length
162
+ puts "In base_test test_limit_should_sanitize_sql_injection_for_limit_with_commas"
163
+ assert_deprecated do
164
+ assert_raises(ArgumentError) do
165
+ Topic.limit("1, 7 procedure help()").to_a
166
+ end
153
167
  end
154
168
  end
155
169
 
156
170
  def test_select_symbol
171
+ puts "In base_test test_select_symbol"
157
172
  topic_ids = Topic.select(:id).map(&:id).sort
158
173
  assert_equal Topic.pluck(:id).sort, topic_ids
159
174
  end
160
175
 
161
176
  def test_table_exists
177
+ puts "In base_test test_table_exists"
162
178
  assert !NonExistentTable.table_exists?
163
179
  assert Topic.table_exists?
164
180
  end
165
181
 
166
182
  def test_preserving_date_objects
183
+ puts "In base_test test_preserving_date_objects"
167
184
  # Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
168
185
  assert_kind_of(
169
186
  Date, Topic.find(1).last_read,
@@ -172,6 +189,7 @@ class BasicsTest < ActiveRecord::TestCase
172
189
  end
173
190
 
174
191
  def test_previously_changed
192
+ puts "In base_test test_previously_changed"
175
193
  topic = Topic.first
176
194
  topic.title = '<3<3<3'
177
195
  assert_equal({}, topic.previous_changes)
@@ -182,6 +200,7 @@ class BasicsTest < ActiveRecord::TestCase
182
200
  end
183
201
 
184
202
  def test_previously_changed_dup
203
+ puts "In base_test test_previously_changed_dup"
185
204
  topic = Topic.first
186
205
  topic.title = '<3<3<3'
187
206
  topic.save!
@@ -197,6 +216,7 @@ class BasicsTest < ActiveRecord::TestCase
197
216
  end
198
217
 
199
218
  def test_preserving_time_objects
219
+ puts "In base_test test_preserving_time_objects"
200
220
  assert_kind_of(
201
221
  Time, Topic.find(1).bonus_time,
202
222
  "The bonus_time attribute should be of the Time class"
@@ -208,7 +228,7 @@ class BasicsTest < ActiveRecord::TestCase
208
228
  )
209
229
 
210
230
  # For adapters which support microsecond resolution.
211
- if current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter) || mysql_56?
231
+ if subsecond_precision_supported?
212
232
  assert_equal 11, Topic.find(1).written_on.sec
213
233
  assert_equal 223300, Topic.find(1).written_on.usec
214
234
  assert_equal 9900, Topic.find(2).written_on.usec
@@ -217,7 +237,8 @@ class BasicsTest < ActiveRecord::TestCase
217
237
  end
218
238
 
219
239
  def test_preserving_time_objects_with_local_time_conversion_to_default_timezone_utc
220
- with_env_tz 'America/New_York' do
240
+ puts "In base_test test_preserving_time_objects_with_local_time_conversion_to_default_timezone_utc"
241
+ with_env_tz eastern_time_zone do
221
242
  with_timezone_config default: :utc do
222
243
  time = Time.local(2000)
223
244
  topic = Topic.create('written_on' => time)
@@ -230,7 +251,8 @@ class BasicsTest < ActiveRecord::TestCase
230
251
  end
231
252
 
232
253
  def test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_utc
233
- with_env_tz 'America/New_York' do
254
+ puts "In base_test test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_utc"
255
+ with_env_tz eastern_time_zone do
234
256
  with_timezone_config default: :utc do
235
257
  Time.use_zone 'Central Time (US & Canada)' do
236
258
  time = Time.zone.local(2000)
@@ -245,7 +267,8 @@ class BasicsTest < ActiveRecord::TestCase
245
267
  end
246
268
 
247
269
  def test_preserving_time_objects_with_utc_time_conversion_to_default_timezone_local
248
- with_env_tz 'America/New_York' do
270
+ puts "In base_test test_preserving_time_objects_with_utc_time_conversion_to_default_timezone_local"
271
+ with_env_tz eastern_time_zone do
249
272
  with_timezone_config default: :local do
250
273
  time = Time.utc(2000)
251
274
  topic = Topic.create('written_on' => time)
@@ -258,7 +281,8 @@ class BasicsTest < ActiveRecord::TestCase
258
281
  end
259
282
 
260
283
  def test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_local
261
- with_env_tz 'America/New_York' do
284
+ puts "In base_test test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_local"
285
+ with_env_tz eastern_time_zone do
262
286
  with_timezone_config default: :local do
263
287
  Time.use_zone 'Central Time (US & Canada)' do
264
288
  time = Time.zone.local(2000)
@@ -272,7 +296,16 @@ class BasicsTest < ActiveRecord::TestCase
272
296
  end
273
297
  end
274
298
 
299
+ def eastern_time_zone
300
+ if Gem.win_platform?
301
+ "EST5EDT"
302
+ else
303
+ "America/New_York"
304
+ end
305
+ end
306
+
275
307
  def test_custom_mutator
308
+ puts "In base_test test_custom_mutator"
276
309
  topic = Topic.find(1)
277
310
  # This mutator is protected in the class definition
278
311
  topic.send(:approved=, true)
@@ -280,6 +313,7 @@ class BasicsTest < ActiveRecord::TestCase
280
313
  end
281
314
 
282
315
  def test_initialize_with_attributes
316
+ puts "In base_test test_initialize_with_attributes"
283
317
  topic = Topic.new({
284
318
  "title" => "initialized from attributes", "written_on" => "2003-12-12 23:23"
285
319
  })
@@ -288,6 +322,7 @@ class BasicsTest < ActiveRecord::TestCase
288
322
  end
289
323
 
290
324
  def test_initialize_with_invalid_attribute
325
+ puts "In base_test test_initialize_with_invalid_attribute"
291
326
  Topic.new({ "title" => "test",
292
327
  "last_read(1i)" => "2005", "last_read(2i)" => "2", "last_read(3i)" => "31"})
293
328
  rescue ActiveRecord::MultiparameterAssignmentErrors => ex
@@ -296,18 +331,21 @@ class BasicsTest < ActiveRecord::TestCase
296
331
  end
297
332
 
298
333
  def test_create_after_initialize_without_block
334
+ puts "In base_test test_create_after_initialize_without_block"
299
335
  cb = CustomBulb.create(:name => 'Dude')
300
336
  assert_equal('Dude', cb.name)
301
337
  assert_equal(true, cb.frickinawesome)
302
338
  end
303
339
 
304
340
  def test_create_after_initialize_with_block
341
+ puts "In base_test test_create_after_initialize_with_block"
305
342
  cb = CustomBulb.create {|c| c.name = 'Dude' }
306
343
  assert_equal('Dude', cb.name)
307
344
  assert_equal(true, cb.frickinawesome)
308
345
  end
309
346
 
310
347
  def test_create_after_initialize_with_array_param
348
+ puts "In base_test test_create_after_initialize_with_array_param"
311
349
  cbs = CustomBulb.create([{ name: 'Dude' }, { name: 'Bob' }])
312
350
  assert_equal 'Dude', cbs[0].name
313
351
  assert_equal 'Bob', cbs[1].name
@@ -316,12 +354,14 @@ class BasicsTest < ActiveRecord::TestCase
316
354
  end
317
355
 
318
356
  def test_load
357
+ puts "In base_test test_load"
319
358
  topics = Topic.all.merge!(:order => 'id').to_a
320
359
  assert_equal(5, topics.size)
321
360
  assert_equal(topics(:first).title, topics.first.title)
322
361
  end
323
362
 
324
363
  def test_load_with_condition
364
+ puts "In base_test test_load_with_condition"
325
365
  topics = Topic.all.merge!(:where => "author_name = 'Mary'").to_a
326
366
 
327
367
  assert_equal(1, topics.size)
@@ -331,6 +371,7 @@ class BasicsTest < ActiveRecord::TestCase
331
371
  GUESSED_CLASSES = [Category, Smarts, CreditCard, CreditCard::PinNumber, CreditCard::PinNumber::CvvCode, CreditCard::SubPinNumber, CreditCard::Brand, MasterCreditCard]
332
372
 
333
373
  def test_table_name_guesses
374
+ puts "In base_test test_table_name_guesses"
334
375
  assert_equal "topics", Topic.table_name
335
376
 
336
377
  assert_equal "categories", Category.table_name
@@ -346,6 +387,7 @@ class BasicsTest < ActiveRecord::TestCase
346
387
  end
347
388
 
348
389
  def test_singular_table_name_guesses
390
+ puts "In base_test test_singular_table_name_guesses"
349
391
  ActiveRecord::Base.pluralize_table_names = false
350
392
  GUESSED_CLASSES.each(&:reset_table_name)
351
393
 
@@ -363,6 +405,7 @@ class BasicsTest < ActiveRecord::TestCase
363
405
  end
364
406
 
365
407
  def test_table_name_guesses_with_prefixes_and_suffixes
408
+ puts "In base_test test_table_name_guesses_with_prefixes_and_suffixes"
366
409
  ActiveRecord::Base.table_name_prefix = "test_"
367
410
  Category.reset_table_name
368
411
  assert_equal "test_categories", Category.table_name
@@ -382,6 +425,7 @@ class BasicsTest < ActiveRecord::TestCase
382
425
  end
383
426
 
384
427
  def test_singular_table_name_guesses_with_prefixes_and_suffixes
428
+ puts "In base_test test_singular_table_name_guesses_with_prefixes_and_suffixes"
385
429
  ActiveRecord::Base.pluralize_table_names = false
386
430
 
387
431
  ActiveRecord::Base.table_name_prefix = "test_"
@@ -404,6 +448,7 @@ class BasicsTest < ActiveRecord::TestCase
404
448
  end
405
449
 
406
450
  def test_table_name_guesses_with_inherited_prefixes_and_suffixes
451
+ puts "In base_test test_table_name_guesses_with_inherited_prefixes_and_suffixes"
407
452
  GUESSED_CLASSES.each(&:reset_table_name)
408
453
 
409
454
  CreditCard.table_name_prefix = "test_"
@@ -433,6 +478,7 @@ class BasicsTest < ActiveRecord::TestCase
433
478
  end
434
479
 
435
480
  def test_singular_table_name_guesses_for_individual_table
481
+ puts "In base_test test_singular_table_name_guesses_for_individual_table"
436
482
  Post.pluralize_table_names = false
437
483
  Post.reset_table_name
438
484
  assert_equal "post", Post.table_name
@@ -442,18 +488,21 @@ class BasicsTest < ActiveRecord::TestCase
442
488
  Post.reset_table_name
443
489
  end
444
490
 
445
- if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
491
+ if current_adapter?(:Mysql2Adapter)
492
+ puts "In base_test test_update_all_with_order_and_limit"
446
493
  def test_update_all_with_order_and_limit
447
494
  assert_equal 1, Topic.limit(1).order('id DESC').update_all(:content => 'bulk updated!')
448
495
  end
449
496
  end
450
497
 
451
498
  def test_null_fields
499
+ puts "In base_test test_null_fields"
452
500
  assert_nil Topic.find(1).parent_id
453
501
  assert_nil Topic.create("title" => "Hey you").parent_id
454
502
  end
455
503
 
456
504
  def test_default_values
505
+ puts "In base_test test_default_values"
457
506
  topic = Topic.new
458
507
  assert topic.approved?
459
508
  assert_nil topic.written_on
@@ -477,17 +526,20 @@ class BasicsTest < ActiveRecord::TestCase
477
526
  end
478
527
 
479
528
  # Oracle does not have a TIME datatype.
480
- unless current_adapter?(:OracleAdapter)
529
+ unless current_adapter?(:OracleAdapter,:IBM_DBAdapter)
481
530
  def test_utc_as_time_zone
531
+ puts "In base_test test_utc_as_time_zone"
482
532
  with_timezone_config default: :utc do
483
533
  attributes = { "bonus_time" => "5:42:00AM" }
484
534
  topic = Topic.find(1)
485
535
  topic.attributes = attributes
486
536
  assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
487
537
  end
488
- end
538
+ end
539
+ end
489
540
 
490
541
  def test_utc_as_time_zone_and_new
542
+ puts "In base_test test_utc_as_time_zone_and_new"
491
543
  with_timezone_config default: :utc do
492
544
  attributes = { "bonus_time(1i)"=>"2000",
493
545
  "bonus_time(2i)"=>"1",
@@ -502,6 +554,7 @@ class BasicsTest < ActiveRecord::TestCase
502
554
  end
503
555
 
504
556
  def test_default_values_on_empty_strings
557
+ puts "In base_test test_default_values_on_empty_strings"
505
558
  topic = Topic.new
506
559
  topic.approved = nil
507
560
  topic.last_read = nil
@@ -515,27 +568,34 @@ class BasicsTest < ActiveRecord::TestCase
515
568
  end
516
569
 
517
570
  def test_equality
571
+ puts "In base_test test_equality"
518
572
  assert_equal Topic.find(1), Topic.find(2).topic
519
573
  end
520
574
 
521
575
  def test_find_by_slug
576
+ puts "In base_test test_find_by_slug"
522
577
  assert_equal Topic.find('1-meowmeow'), Topic.find(1)
523
578
  end
524
579
 
525
580
  def test_find_by_slug_with_array
526
- assert_equal Topic.find(['1-meowmeow', '2-hello']), Topic.find([1, 2])
581
+ puts "In base_test test_find_by_slug_with_array"
582
+ assert_equal Topic.find([1, 2]), Topic.find(['1-meowmeow', '2-hello'])
583
+ assert_equal 'The Second Topic of the day', Topic.find(['2-hello', '1-meowmeow']).first.title
527
584
  end
528
585
 
529
586
  def test_find_by_slug_with_range
587
+ puts "In base_test test_find_by_slug_with_range"
530
588
  assert_equal Topic.where(id: '1-meowmeow'..'2-hello'), Topic.where(id: 1..2)
531
589
  end
532
590
 
533
591
  def test_equality_of_new_records
592
+ puts "In base_test test_equality_of_new_records"
534
593
  assert_not_equal Topic.new, Topic.new
535
594
  assert_equal false, Topic.new == Topic.new
536
595
  end
537
596
 
538
597
  def test_equality_of_destroyed_records
598
+ puts "In base_test test_equality_of_destroyed_records"
539
599
  topic_1 = Topic.new(:title => 'test_1')
540
600
  topic_1.save
541
601
  topic_2 = Topic.find(topic_1.id)
@@ -545,12 +605,14 @@ class BasicsTest < ActiveRecord::TestCase
545
605
  end
546
606
 
547
607
  def test_equality_with_blank_ids
608
+ puts "In base_test test_equality_with_blank_ids"
548
609
  one = Subscriber.new(:id => '')
549
610
  two = Subscriber.new(:id => '')
550
611
  assert_equal one, two
551
612
  end
552
613
 
553
614
  def test_equality_of_relation_and_collection_proxy
615
+ puts "In base_test test_equality_of_relation_and_collection_proxy"
554
616
  car = Car.create!
555
617
  car.bulbs.build
556
618
  car.save
@@ -560,6 +622,7 @@ class BasicsTest < ActiveRecord::TestCase
560
622
  end
561
623
 
562
624
  def test_equality_of_relation_and_array
625
+ puts "In base_test test_equality_of_relation_and_array"
563
626
  car = Car.create!
564
627
  car.bulbs.build
565
628
  car.save
@@ -568,6 +631,7 @@ class BasicsTest < ActiveRecord::TestCase
568
631
  end
569
632
 
570
633
  def test_equality_of_relation_and_association_relation
634
+ puts "In base_test test_equality_of_relation_and_association_relation"
571
635
  car = Car.create!
572
636
  car.bulbs.build
573
637
  car.save
@@ -577,6 +641,7 @@ class BasicsTest < ActiveRecord::TestCase
577
641
  end
578
642
 
579
643
  def test_equality_of_collection_proxy_and_association_relation
644
+ puts "In base_test test_equality_of_collection_proxy_and_association_relation"
580
645
  car = Car.create!
581
646
  car.bulbs.build
582
647
  car.save
@@ -586,10 +651,12 @@ class BasicsTest < ActiveRecord::TestCase
586
651
  end
587
652
 
588
653
  def test_hashing
654
+ puts "In base_test test_hashing"
589
655
  assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
590
656
  end
591
657
 
592
658
  def test_successful_comparison_of_like_class_records
659
+ puts "In base_test test_successful_comparison_of_like_class_records"
593
660
  topic_1 = Topic.create!
594
661
  topic_2 = Topic.create!
595
662
 
@@ -597,12 +664,14 @@ class BasicsTest < ActiveRecord::TestCase
597
664
  end
598
665
 
599
666
  def test_failed_comparison_of_unlike_class_records
667
+ puts "In base_test test_failed_comparison_of_unlike_class_records"
600
668
  assert_raises ArgumentError do
601
669
  [ topics(:first), posts(:welcome) ].sort
602
670
  end
603
671
  end
604
672
 
605
673
  def test_create_without_prepared_statement
674
+ puts "In base_test test_create_without_prepared_statement"
606
675
  topic = Topic.connection.unprepared_statement do
607
676
  Topic.create(:title => 'foo')
608
677
  end
@@ -611,6 +680,7 @@ class BasicsTest < ActiveRecord::TestCase
611
680
  end
612
681
 
613
682
  def test_destroy_without_prepared_statement
683
+ puts "In base_test test_destroy_without_prepared_statement"
614
684
  topic = Topic.create(title: 'foo')
615
685
  Topic.connection.unprepared_statement do
616
686
  Topic.find(topic.id).destroy
@@ -620,12 +690,14 @@ class BasicsTest < ActiveRecord::TestCase
620
690
  end
621
691
 
622
692
  def test_comparison_with_different_objects
693
+ puts "In base_test test_comparison_with_different_objects"
623
694
  topic = Topic.create
624
695
  category = Category.create(:name => "comparison")
625
696
  assert_nil topic <=> category
626
697
  end
627
698
 
628
699
  def test_comparison_with_different_objects_in_array
700
+ puts "In base_test test_comparison_with_different_objects_in_array"
629
701
  topic = Topic.create
630
702
  assert_raises(ArgumentError) do
631
703
  [1, topic].sort
@@ -633,6 +705,7 @@ class BasicsTest < ActiveRecord::TestCase
633
705
  end
634
706
 
635
707
  def test_readonly_attributes
708
+ puts "In base_test test_readonly_attributes"
636
709
  assert_equal Set.new([ 'title' , 'comments_count' ]), ReadonlyTitlePost.readonly_attributes
637
710
 
638
711
  post = ReadonlyTitlePost.create(:title => "cannot change this", :body => "changeable")
@@ -646,6 +719,7 @@ class BasicsTest < ActiveRecord::TestCase
646
719
  end
647
720
 
648
721
  def test_unicode_column_name
722
+ puts "In base_test test_unicode_column_name"
649
723
  Weird.reset_column_information
650
724
  weird = Weird.create(:なまえ => 'たこ焼き仮面')
651
725
  assert_equal 'たこ焼き仮面', weird.なまえ
@@ -653,6 +727,7 @@ class BasicsTest < ActiveRecord::TestCase
653
727
 
654
728
  unless current_adapter?(:PostgreSQLAdapter)
655
729
  def test_respect_internal_encoding
730
+ puts "In base_test test_respect_internal_encoding"
656
731
  old_default_internal = Encoding.default_internal
657
732
  silence_warnings { Encoding.default_internal = "EUC-JP" }
658
733
 
@@ -666,6 +741,7 @@ class BasicsTest < ActiveRecord::TestCase
666
741
  end
667
742
 
668
743
  def test_non_valid_identifier_column_name
744
+ puts "In base_test test_non_valid_identifier_column_name"
669
745
  weird = Weird.create('a$b' => 'value')
670
746
  weird.reload
671
747
  assert_equal 'value', weird.send('a$b')
@@ -678,12 +754,14 @@ class BasicsTest < ActiveRecord::TestCase
678
754
  end
679
755
 
680
756
  def test_group_weirds_by_from
757
+ puts "In base_test test_group_weirds_by_from"
681
758
  Weird.create('a$b' => 'value', :from => 'aaron')
682
759
  count = Weird.group(Weird.arel_table[:from]).count
683
760
  assert_equal 1, count['aaron']
684
761
  end
685
762
 
686
763
  def test_attributes_on_dummy_time
764
+ puts "In base_test test_attributes_on_dummy_time"
687
765
  # Oracle does not have a TIME datatype.
688
766
  return true if current_adapter?(:OracleAdapter)
689
767
 
@@ -698,6 +776,7 @@ class BasicsTest < ActiveRecord::TestCase
698
776
  end
699
777
 
700
778
  def test_attributes_on_dummy_time_with_invalid_time
779
+ puts "In base_test test_attributes_on_dummy_time_with_invalid_time"
701
780
  # Oracle does not have a TIME datatype.
702
781
  return true if current_adapter?(:OracleAdapter)
703
782
 
@@ -710,6 +789,7 @@ class BasicsTest < ActiveRecord::TestCase
710
789
  end
711
790
 
712
791
  def test_boolean
792
+ puts "In base_test test_boolean"
713
793
  b_nil = Boolean.create({ "value" => nil })
714
794
  nil_id = b_nil.id
715
795
  b_false = Boolean.create({ "value" => false })
@@ -726,6 +806,7 @@ class BasicsTest < ActiveRecord::TestCase
726
806
  end
727
807
 
728
808
  def test_boolean_without_questionmark
809
+ puts "In base_test test_boolean_without_questionmark"
729
810
  b_true = Boolean.create({ "value" => true })
730
811
  true_id = b_true.id
731
812
 
@@ -736,6 +817,7 @@ class BasicsTest < ActiveRecord::TestCase
736
817
  end
737
818
 
738
819
  def test_boolean_cast_from_string
820
+ puts "In base_test test_boolean_cast_from_string"
739
821
  b_blank = Boolean.create({ "value" => "" })
740
822
  blank_id = b_blank.id
741
823
  b_false = Boolean.create({ "value" => "0" })
@@ -752,11 +834,13 @@ class BasicsTest < ActiveRecord::TestCase
752
834
  end
753
835
 
754
836
  def test_new_record_returns_boolean
837
+ puts "In base_test test_new_record_returns_boolean"
755
838
  assert_equal false, Topic.new.persisted?
756
839
  assert_equal true, Topic.find(1).persisted?
757
840
  end
758
841
 
759
842
  def test_dup
843
+ puts "In base_test test_dup"
760
844
  topic = Topic.find(1)
761
845
  duped_topic = nil
762
846
  assert_nothing_raised { duped_topic = topic.dup }
@@ -788,6 +872,7 @@ class BasicsTest < ActiveRecord::TestCase
788
872
 
789
873
  DeveloperSalary = Struct.new(:amount)
790
874
  def test_dup_with_aggregate_of_same_name_as_attribute
875
+ puts "In base_test test_dup_with_aggregate_of_same_name_as_attribute"
791
876
  developer_with_aggregate = Class.new(ActiveRecord::Base) do
792
877
  self.table_name = 'developers'
793
878
  composed_of :salary, :class_name => 'BasicsTest::DeveloperSalary', :mapping => [%w(salary amount)]
@@ -802,7 +887,7 @@ class BasicsTest < ActiveRecord::TestCase
802
887
  assert_equal dev.salary.amount, dup.salary.amount
803
888
  assert !dup.persisted?
804
889
 
805
- # test if the attributes have been dupd
890
+ # test if the attributes have been duped
806
891
  original_amount = dup.salary.amount
807
892
  dev.salary.amount = 1
808
893
  assert_equal original_amount, dup.salary.amount
@@ -813,21 +898,23 @@ class BasicsTest < ActiveRecord::TestCase
813
898
  end
814
899
 
815
900
  def test_dup_does_not_copy_associations
901
+ puts "In base_test test_dup_does_not_copy_associations"
816
902
  author = authors(:david)
817
903
  assert_not_equal [], author.posts
818
- author.send(:clear_association_cache)
819
904
 
820
905
  author_dup = author.dup
821
906
  assert_equal [], author_dup.posts
822
907
  end
823
908
 
824
909
  def test_clone_preserves_subtype
910
+ puts "In base_test test_clone_preserves_subtype"
825
911
  clone = nil
826
912
  assert_nothing_raised { clone = Company.find(3).clone }
827
913
  assert_kind_of Client, clone
828
914
  end
829
915
 
830
916
  def test_clone_of_new_object_with_defaults
917
+ puts "In base_test test_clone_of_new_object_with_defaults"
831
918
  developer = Developer.new
832
919
  assert !developer.name_changed?
833
920
  assert !developer.salary_changed?
@@ -838,6 +925,7 @@ class BasicsTest < ActiveRecord::TestCase
838
925
  end
839
926
 
840
927
  def test_clone_of_new_object_marks_attributes_as_dirty
928
+ puts "In base_test test_clone_of_new_object_marks_attributes_as_dirty"
841
929
  developer = Developer.new :name => 'Bjorn', :salary => 100000
842
930
  assert developer.name_changed?
843
931
  assert developer.salary_changed?
@@ -848,6 +936,7 @@ class BasicsTest < ActiveRecord::TestCase
848
936
  end
849
937
 
850
938
  def test_clone_of_new_object_marks_as_dirty_only_changed_attributes
939
+ puts "In base_test test_clone_of_new_object_marks_as_dirty_only_changed_attributes"
851
940
  developer = Developer.new :name => 'Bjorn'
852
941
  assert developer.name_changed? # obviously
853
942
  assert !developer.salary_changed? # attribute has non-nil default value, so treated as not changed
@@ -858,6 +947,7 @@ class BasicsTest < ActiveRecord::TestCase
858
947
  end
859
948
 
860
949
  def test_dup_of_saved_object_marks_attributes_as_dirty
950
+ puts "In base_test test_dup_of_saved_object_marks_attributes_as_dirty"
861
951
  developer = Developer.create! :name => 'Bjorn', :salary => 100000
862
952
  assert !developer.name_changed?
863
953
  assert !developer.salary_changed?
@@ -868,6 +958,7 @@ class BasicsTest < ActiveRecord::TestCase
868
958
  end
869
959
 
870
960
  def test_dup_of_saved_object_marks_as_dirty_only_changed_attributes
961
+ puts "In base_test test_dup_of_saved_object_marks_as_dirty_only_changed_attributes"
871
962
  developer = Developer.create! :name => 'Bjorn'
872
963
  assert !developer.name_changed? # both attributes of saved object should be treated as not changed
873
964
  assert !developer.salary_changed?
@@ -878,6 +969,7 @@ class BasicsTest < ActiveRecord::TestCase
878
969
  end
879
970
 
880
971
  def test_bignum
972
+ puts "In base_test test_bignum"
881
973
  company = Company.find(1)
882
974
  company.rating = 2147483647
883
975
  company.save
@@ -888,6 +980,7 @@ class BasicsTest < ActiveRecord::TestCase
888
980
  # TODO: extend defaults tests to other databases!
889
981
  if current_adapter?(:PostgreSQLAdapter)
890
982
  def test_default
983
+ puts "In base_test test_default"
891
984
  with_timezone_config default: :local do
892
985
  default = Default.new
893
986
 
@@ -901,103 +994,17 @@ class BasicsTest < ActiveRecord::TestCase
901
994
  assert_equal 'a text field', default.char3
902
995
  end
903
996
  end
904
-
905
- class Geometric < ActiveRecord::Base; end
906
- def test_geometric_content
907
-
908
- # accepted format notes:
909
- # ()'s aren't required
910
- # values can be a mix of float or integer
911
-
912
- g = Geometric.new(
913
- :a_point => '(5.0, 6.1)',
914
- #:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
915
- :a_line_segment => '(2.0, 3), (5.5, 7.0)',
916
- :a_box => '2.0, 3, 5.5, 7.0',
917
- :a_path => '[(2.0, 3), (5.5, 7.0), (8.5, 11.0)]', # [ ] is an open path
918
- :a_polygon => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))',
919
- :a_circle => '<(5.3, 10.4), 2>'
920
- )
921
-
922
- assert g.save
923
-
924
- # Reload and check that we have all the geometric attributes.
925
- h = Geometric.find(g.id)
926
-
927
- assert_equal [5.0, 6.1], h.a_point
928
- assert_equal '[(2,3),(5.5,7)]', h.a_line_segment
929
- assert_equal '(5.5,7),(2,3)', h.a_box # reordered to store upper right corner then bottom left corner
930
- assert_equal '[(2,3),(5.5,7),(8.5,11)]', h.a_path
931
- assert_equal '((2,3),(5.5,7),(8.5,11))', h.a_polygon
932
- assert_equal '<(5.3,10.4),2>', h.a_circle
933
-
934
- # use a geometric function to test for an open path
935
- objs = Geometric.find_by_sql ["select isopen(a_path) from geometrics where id = ?", g.id]
936
-
937
- assert_equal true, objs[0].isopen
938
-
939
- # test alternate formats when defining the geometric types
940
-
941
- g = Geometric.new(
942
- :a_point => '5.0, 6.1',
943
- #:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
944
- :a_line_segment => '((2.0, 3), (5.5, 7.0))',
945
- :a_box => '(2.0, 3), (5.5, 7.0)',
946
- :a_path => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))', # ( ) is a closed path
947
- :a_polygon => '2.0, 3, 5.5, 7.0, 8.5, 11.0',
948
- :a_circle => '((5.3, 10.4), 2)'
949
- )
950
-
951
- assert g.save
952
-
953
- # Reload and check that we have all the geometric attributes.
954
- h = Geometric.find(g.id)
955
-
956
- assert_equal [5.0, 6.1], h.a_point
957
- assert_equal '[(2,3),(5.5,7)]', h.a_line_segment
958
- assert_equal '(5.5,7),(2,3)', h.a_box # reordered to store upper right corner then bottom left corner
959
- assert_equal '((2,3),(5.5,7),(8.5,11))', h.a_path
960
- assert_equal '((2,3),(5.5,7),(8.5,11))', h.a_polygon
961
- assert_equal '<(5.3,10.4),2>', h.a_circle
962
-
963
- # use a geometric function to test for an closed path
964
- objs = Geometric.find_by_sql ["select isclosed(a_path) from geometrics where id = ?", g.id]
965
-
966
- assert_equal true, objs[0].isclosed
967
-
968
- # test native ruby formats when defining the geometric types
969
- g = Geometric.new(
970
- :a_point => [5.0, 6.1],
971
- #:a_line => '((2.0, 3), (5.5, 7.0))' # line type is currently unsupported in postgresql
972
- :a_line_segment => '((2.0, 3), (5.5, 7.0))',
973
- :a_box => '(2.0, 3), (5.5, 7.0)',
974
- :a_path => '((2.0, 3), (5.5, 7.0), (8.5, 11.0))', # ( ) is a closed path
975
- :a_polygon => '2.0, 3, 5.5, 7.0, 8.5, 11.0',
976
- :a_circle => '((5.3, 10.4), 2)'
977
- )
978
-
979
- assert g.save
980
-
981
- # Reload and check that we have all the geometric attributes.
982
- h = Geometric.find(g.id)
983
-
984
- assert_equal [5.0, 6.1], h.a_point
985
- assert_equal '[(2,3),(5.5,7)]', h.a_line_segment
986
- assert_equal '(5.5,7),(2,3)', h.a_box # reordered to store upper right corner then bottom left corner
987
- assert_equal '((2,3),(5.5,7),(8.5,11))', h.a_path
988
- assert_equal '((2,3),(5.5,7),(8.5,11))', h.a_polygon
989
- assert_equal '<(5.3,10.4),2>', h.a_circle
990
- end
991
997
  end
992
998
 
993
999
  class NumericData < ActiveRecord::Base
994
1000
  self.table_name = 'numeric_data'
995
1001
 
996
- attribute :my_house_population, Type::Integer.new
997
- attribute :atoms_in_universe, Type::Integer.new
1002
+ attribute :my_house_population, :integer
1003
+ attribute :atoms_in_universe, :integer
998
1004
  end
999
1005
 
1000
1006
  def test_big_decimal_conditions
1007
+ puts "In base_test test_big_decimal_conditions"
1001
1008
  m = NumericData.new(
1002
1009
  :bank_balance => 1586.43,
1003
1010
  :big_bank_balance => BigDecimal("1000234000567.95"),
@@ -1009,6 +1016,7 @@ class BasicsTest < ActiveRecord::TestCase
1009
1016
  end
1010
1017
 
1011
1018
  def test_numeric_fields
1019
+ puts "In base_test test_numeric_fields"
1012
1020
  m = NumericData.new(
1013
1021
  :bank_balance => 1586.43,
1014
1022
  :big_bank_balance => BigDecimal("1000234000567.95"),
@@ -1024,17 +1032,11 @@ class BasicsTest < ActiveRecord::TestCase
1024
1032
  # to cover 64-bit platforms and test it is a Bignum, but the main thing
1025
1033
  # is that it's an Integer.
1026
1034
  unless current_adapter?(:IBM_DBAdapter)
1027
- assert_kind_of Integer, m1.world_population
1035
+ assert_kind_of Integer, m1.world_population
1028
1036
  else
1029
- assert_kind_of BigDecimal, m1.world_population
1030
- end
1031
- assert_equal 6000000000, m1.world_population
1037
+ assert_equal 6000000000, m1.world_population
1032
1038
 
1033
- unless current_adapter?(:IBM_DBAdapter)
1034
- assert_kind_of Fixnum, m1.my_house_population
1035
- else
1036
- assert_kind_of BigDecimal, m1.my_house_population
1037
- end
1039
+ assert_kind_of Integer, m1.my_house_population
1038
1040
  assert_equal 3, m1.my_house_population
1039
1041
 
1040
1042
  assert_kind_of BigDecimal, m1.bank_balance
@@ -1044,19 +1046,51 @@ class BasicsTest < ActiveRecord::TestCase
1044
1046
  assert_equal BigDecimal("1000234000567.95"), m1.big_bank_balance
1045
1047
  end
1046
1048
 
1049
+ def test_numeric_fields_with_scale
1050
+ puts "In base_test test_numeric_fields_with_scale"
1051
+ m = NumericData.new(
1052
+ :bank_balance => 1586.43122334,
1053
+ :big_bank_balance => BigDecimal("234000567.952344"),
1054
+ :world_population => 6000000000,
1055
+ :my_house_population => 3
1056
+ )
1057
+ assert m.save
1058
+
1059
+ m1 = NumericData.find(m.id)
1060
+ assert_not_nil m1
1061
+
1062
+ # As with migration_test.rb, we should make world_population >= 2**62
1063
+ # to cover 64-bit platforms and test it is a Bignum, but the main thing
1064
+ # is that it's an Integer.
1065
+ assert_kind_of Integer, m1.world_population
1066
+ assert_equal 6000000000, m1.world_population
1067
+
1068
+ assert_kind_of Integer, m1.my_house_population
1069
+ assert_equal 3, m1.my_house_population
1070
+
1071
+ assert_kind_of BigDecimal, m1.bank_balance
1072
+ assert_equal BigDecimal("1586.43"), m1.bank_balance
1073
+
1074
+ assert_kind_of BigDecimal, m1.big_bank_balance
1075
+ assert_equal BigDecimal("234000567.95"), m1.big_bank_balance
1076
+ end
1077
+
1047
1078
  def test_auto_id
1079
+ puts "In base_test test_auto_id"
1048
1080
  auto = AutoId.new
1049
1081
  auto.save
1050
1082
  assert(auto.id > 0)
1051
1083
  end
1052
1084
 
1053
1085
  def test_sql_injection_via_find
1086
+ puts "In base_test test_sql_injection_via_find"
1054
1087
  assert_raise(ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid) do
1055
1088
  Topic.find("123456 OR id > 0")
1056
1089
  end
1057
1090
  end
1058
1091
 
1059
1092
  def test_column_name_properly_quoted
1093
+ puts "In base_test test_column_name_properly_quoted"
1060
1094
  col_record = ColumnName.new
1061
1095
  col_record.references = 40
1062
1096
  assert col_record.save
@@ -1067,6 +1101,7 @@ class BasicsTest < ActiveRecord::TestCase
1067
1101
  end
1068
1102
 
1069
1103
  def test_quoting_arrays
1104
+ puts "In base_test test_quoting_arrays"
1070
1105
  replies = Reply.all.merge!(:where => [ "id IN (?)", topics(:first).replies.collect(&:id) ]).to_a
1071
1106
  assert_equal topics(:first).replies.size, replies.size
1072
1107
 
@@ -1075,12 +1110,14 @@ class BasicsTest < ActiveRecord::TestCase
1075
1110
  end
1076
1111
 
1077
1112
  def test_quote
1113
+ puts "In base_test test_quote"
1078
1114
  author_name = "\\ \001 ' \n \\n \""
1079
1115
  topic = Topic.create('author_name' => author_name)
1080
1116
  assert_equal author_name, Topic.find(topic.id).author_name
1081
1117
  end
1082
1118
 
1083
1119
  def test_toggle_attribute
1120
+ puts "In base_test test_toggle_attribute"
1084
1121
  assert !topics(:first).approved?
1085
1122
  topics(:first).toggle!(:approved)
1086
1123
  assert topics(:first).approved?
@@ -1092,6 +1129,7 @@ class BasicsTest < ActiveRecord::TestCase
1092
1129
  end
1093
1130
 
1094
1131
  def test_reload
1132
+ puts "In base_test test_reload"
1095
1133
  t1 = Topic.find(1)
1096
1134
  t2 = Topic.find(1)
1097
1135
  t1.title = "something else"
@@ -1101,63 +1139,77 @@ class BasicsTest < ActiveRecord::TestCase
1101
1139
  end
1102
1140
 
1103
1141
  def test_reload_with_exclusive_scope
1142
+ puts "In base_test test_reload_with_exclusive_scope"
1104
1143
  dev = DeveloperCalledDavid.first
1105
1144
  dev.update!(name: "NotDavid" )
1106
1145
  assert_equal dev, dev.reload
1107
1146
  end
1108
1147
 
1109
1148
  def test_switching_between_table_name
1149
+ puts "In base_test test_switching_between_table_name"
1150
+ k = Class.new(Joke)
1151
+
1110
1152
  assert_difference("GoodJoke.count") do
1111
- Joke.table_name = "cold_jokes"
1112
- Joke.create
1153
+ k.table_name = "cold_jokes"
1154
+ k.create
1113
1155
 
1114
- Joke.table_name = "funny_jokes"
1115
- Joke.create
1156
+ k.table_name = "funny_jokes"
1157
+ k.create
1116
1158
  end
1117
1159
  end
1118
1160
 
1119
1161
  def test_clear_cash_when_setting_table_name
1120
- Joke.table_name = "cold_jokes"
1121
- before_columns = Joke.columns
1122
- before_seq = Joke.sequence_name
1162
+ puts "In base_test test_clear_cash_when_setting_table_name"
1163
+ original_table_name = Joke.table_name
1123
1164
 
1124
1165
  Joke.table_name = "funny_jokes"
1166
+ before_columns = Joke.columns
1167
+ before_seq = Joke.sequence_name
1168
+
1169
+ Joke.table_name = "cold_jokes"
1125
1170
  after_columns = Joke.columns
1126
- after_seq = Joke.sequence_name
1171
+ after_seq = Joke.sequence_name
1127
1172
 
1128
1173
  assert_not_equal before_columns, after_columns
1129
1174
  assert_not_equal before_seq, after_seq unless before_seq.nil? && after_seq.nil?
1175
+ ensure
1176
+ Joke.table_name = original_table_name
1130
1177
  end
1131
1178
 
1132
1179
  def test_dont_clear_sequence_name_when_setting_explicitly
1133
- Joke.sequence_name = "black_jokes_seq"
1134
- Joke.table_name = "cold_jokes"
1135
- before_seq = Joke.sequence_name
1180
+ puts "In base_test test_dont_clear_sequence_name_when_setting_explicitly"
1181
+ k = Class.new(Joke)
1182
+ k.sequence_name = "black_jokes_seq"
1183
+ k.table_name = "cold_jokes"
1184
+ before_seq = k.sequence_name
1136
1185
 
1137
- Joke.table_name = "funny_jokes"
1138
- after_seq = Joke.sequence_name
1186
+ k.table_name = "funny_jokes"
1187
+ after_seq = k.sequence_name
1139
1188
 
1140
1189
  assert_equal before_seq, after_seq unless before_seq.nil? && after_seq.nil?
1141
- ensure
1142
- Joke.reset_sequence_name
1143
1190
  end
1144
1191
 
1145
1192
  def test_dont_clear_inheritance_column_when_setting_explicitly
1146
- Joke.inheritance_column = "my_type"
1147
- before_inherit = Joke.inheritance_column
1193
+ puts "In base_test test_dont_clear_inheritance_column_when_setting_explicitly"
1194
+ k = Class.new(Joke)
1195
+ k.inheritance_column = "my_type"
1196
+ before_inherit = k.inheritance_column
1148
1197
 
1149
- Joke.reset_column_information
1150
- after_inherit = Joke.inheritance_column
1198
+ k.reset_column_information
1199
+ after_inherit = k.inheritance_column
1151
1200
 
1152
1201
  assert_equal before_inherit, after_inherit unless before_inherit.blank? && after_inherit.blank?
1153
1202
  end
1154
1203
 
1155
1204
  def test_set_table_name_symbol_converted_to_string
1156
- Joke.table_name = :cold_jokes
1157
- assert_equal 'cold_jokes', Joke.table_name
1205
+ puts "In base_test test_set_table_name_symbol_converted_to_string"
1206
+ k = Class.new(Joke)
1207
+ k.table_name = :cold_jokes
1208
+ assert_equal 'cold_jokes', k.table_name
1158
1209
  end
1159
1210
 
1160
1211
  def test_quoted_table_name_after_set_table_name
1212
+ puts "In base_test test_quoted_table_name_after_set_table_name"
1161
1213
  klass = Class.new(ActiveRecord::Base)
1162
1214
 
1163
1215
  klass.table_name = "foo"
@@ -1170,6 +1222,7 @@ class BasicsTest < ActiveRecord::TestCase
1170
1222
  end
1171
1223
 
1172
1224
  def test_set_table_name_with_inheritance
1225
+ puts "In base_test test_set_table_name_with_inheritance"
1173
1226
  k = Class.new( ActiveRecord::Base )
1174
1227
  def k.name; "Foo"; end
1175
1228
  def k.table_name; super + "ks"; end
@@ -1177,6 +1230,7 @@ class BasicsTest < ActiveRecord::TestCase
1177
1230
  end
1178
1231
 
1179
1232
  def test_sequence_name_with_abstract_class
1233
+ puts "In base_test test_sequence_name_with_abstract_class"
1180
1234
  ak = Class.new(ActiveRecord::Base)
1181
1235
  ak.abstract_class = true
1182
1236
  k = Class.new(ak)
@@ -1187,6 +1241,7 @@ class BasicsTest < ActiveRecord::TestCase
1187
1241
  end
1188
1242
 
1189
1243
  def test_count_with_join
1244
+ puts "In base_test test_count_with_join"
1190
1245
  res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'"
1191
1246
 
1192
1247
  res2 = Post.where("posts.#{QUOTED_TYPE} = 'Post'").joins("LEFT JOIN comments ON posts.id=comments.post_id").count
@@ -1215,97 +1270,78 @@ class BasicsTest < ActiveRecord::TestCase
1215
1270
  end
1216
1271
 
1217
1272
  def test_no_limit_offset
1273
+ puts "In base_test test_no_limit_offset"
1218
1274
  assert_nothing_raised do
1219
1275
  Developer.all.merge!(:offset => 2).to_a
1220
1276
  end
1221
1277
  end
1222
1278
 
1223
1279
  def test_find_last
1280
+ puts "In base_test test_find_last"
1224
1281
  last = Developer.last
1225
1282
  assert_equal last, Developer.all.merge!(:order => 'id desc').first
1226
1283
  end
1227
1284
 
1228
1285
  def test_last
1286
+ puts "In base_test test_last"
1229
1287
  assert_equal Developer.all.merge!(:order => 'id desc').first, Developer.last
1230
1288
  end
1231
1289
 
1232
1290
  def test_all
1291
+ puts "In base_test test_all"
1233
1292
  developers = Developer.all
1234
1293
  assert_kind_of ActiveRecord::Relation, developers
1235
1294
  assert_equal Developer.all, developers
1236
1295
  end
1237
1296
 
1238
1297
  def test_all_with_conditions
1298
+ puts "In base_test test_all_with_conditions"
1239
1299
  assert_equal Developer.all.merge!(:order => 'id desc').to_a, Developer.order('id desc').to_a
1240
1300
  end
1241
1301
 
1242
1302
  def test_find_ordered_last
1303
+ puts "In base_test test_find_ordered_last"
1243
1304
  last = Developer.all.merge!(:order => 'developers.salary ASC').last
1244
1305
  assert_equal last, Developer.all.merge!(:order => 'developers.salary ASC').to_a.last
1245
1306
  end
1246
1307
 
1247
1308
  def test_find_reverse_ordered_last
1309
+ puts "In base_test test_find_reverse_ordered_last"
1248
1310
  last = Developer.all.merge!(:order => 'developers.salary DESC').last
1249
1311
  assert_equal last, Developer.all.merge!(:order => 'developers.salary DESC').to_a.last
1250
1312
  end
1251
1313
 
1252
1314
  def test_find_multiple_ordered_last
1315
+ puts "In base_test test_find_multiple_ordered_last"
1253
1316
  last = Developer.all.merge!(:order => 'developers.name, developers.salary DESC').last
1254
1317
  assert_equal last, Developer.all.merge!(:order => 'developers.name, developers.salary DESC').to_a.last
1255
1318
  end
1256
1319
 
1257
1320
  def test_find_keeps_multiple_order_values
1321
+ puts "In base_test test_find_keeps_multiple_order_values"
1258
1322
  combined = Developer.all.merge!(:order => 'developers.name, developers.salary').to_a
1259
1323
  assert_equal combined, Developer.all.merge!(:order => ['developers.name', 'developers.salary']).to_a
1260
1324
  end
1261
1325
 
1262
1326
  def test_find_keeps_multiple_group_values
1327
+ puts "In base_test test_find_keeps_multiple_group_values"
1263
1328
  combined = Developer.all.merge!(:group => 'developers.name, developers.salary, developers.id, developers.created_at, developers.updated_at, developers.created_on, developers.updated_on').to_a
1264
1329
  assert_equal combined, Developer.all.merge!(:group => ['developers.name', 'developers.salary', 'developers.id', 'developers.created_at', 'developers.updated_at', 'developers.created_on', 'developers.updated_on']).to_a
1265
1330
  end
1266
1331
 
1267
1332
  def test_find_symbol_ordered_last
1333
+ puts "In base_test test_find_symbol_ordered_last"
1268
1334
  last = Developer.all.merge!(:order => :salary).last
1269
1335
  assert_equal last, Developer.all.merge!(:order => :salary).to_a.last
1270
1336
  end
1271
1337
 
1272
- def test_abstract_class
1273
- assert !ActiveRecord::Base.abstract_class?
1274
- assert LoosePerson.abstract_class?
1275
- assert !LooseDescendant.abstract_class?
1276
- end
1277
-
1278
1338
  def test_abstract_class_table_name
1339
+ puts "In base_test test_abstract_class_table_name"
1279
1340
  assert_nil AbstractCompany.table_name
1280
1341
  end
1281
1342
 
1282
- def test_descends_from_active_record
1283
- assert !ActiveRecord::Base.descends_from_active_record?
1284
-
1285
- # Abstract subclass of AR::Base.
1286
- assert LoosePerson.descends_from_active_record?
1287
-
1288
- # Concrete subclass of an abstract class.
1289
- assert LooseDescendant.descends_from_active_record?
1290
-
1291
- # Concrete subclass of AR::Base.
1292
- assert TightPerson.descends_from_active_record?
1293
-
1294
- # Concrete subclass of a concrete class but has no type column.
1295
- assert TightDescendant.descends_from_active_record?
1296
-
1297
- # Concrete subclass of AR::Base.
1298
- assert Post.descends_from_active_record?
1299
-
1300
- # Abstract subclass of a concrete class which has a type column.
1301
- # This is pathological, as you'll never have Sub < Abstract < Concrete.
1302
- assert !StiPost.descends_from_active_record?
1303
-
1304
- # Concrete subclasses an abstract class which has a type column.
1305
- assert !SubStiPost.descends_from_active_record?
1306
- end
1307
-
1308
1343
  def test_find_on_abstract_base_class_doesnt_use_type_condition
1344
+ puts "In base_test test_find_on_abstract_base_class_doesnt_use_type_condition"
1309
1345
  old_class = LooseDescendant
1310
1346
  Object.send :remove_const, :LooseDescendant
1311
1347
 
@@ -1318,6 +1354,7 @@ class BasicsTest < ActiveRecord::TestCase
1318
1354
  end
1319
1355
 
1320
1356
  def test_assert_queries
1357
+ puts "In base_test test_assert_queries"
1321
1358
  query = lambda { ActiveRecord::Base.connection.execute 'select count(*) from developers' }
1322
1359
  assert_queries(2) { 2.times { query.call } }
1323
1360
  assert_queries 1, &query
@@ -1325,6 +1362,7 @@ class BasicsTest < ActiveRecord::TestCase
1325
1362
  end
1326
1363
 
1327
1364
  def test_benchmark_with_log_level
1365
+ puts "In base_test test_benchmark_with_log_level"
1328
1366
  original_logger = ActiveRecord::Base.logger
1329
1367
  log = StringIO.new
1330
1368
  ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
@@ -1340,60 +1378,19 @@ class BasicsTest < ActiveRecord::TestCase
1340
1378
  end
1341
1379
 
1342
1380
  def test_benchmark_with_use_silence
1381
+ puts "In base_test test_benchmark_with_use_silence"
1343
1382
  original_logger = ActiveRecord::Base.logger
1344
1383
  log = StringIO.new
1345
1384
  ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
1385
+ ActiveRecord::Base.logger.level = Logger::DEBUG
1346
1386
  ActiveRecord::Base.benchmark("Logging", :level => :debug, :silence => false) { ActiveRecord::Base.logger.debug "Quiet" }
1347
1387
  assert_match(/Quiet/, log.string)
1348
1388
  ensure
1349
1389
  ActiveRecord::Base.logger = original_logger
1350
1390
  end
1351
1391
 
1352
- def test_compute_type_success
1353
- assert_equal Author, ActiveRecord::Base.send(:compute_type, 'Author')
1354
- end
1355
-
1356
- def test_compute_type_nonexistent_constant
1357
- e = assert_raises NameError do
1358
- ActiveRecord::Base.send :compute_type, 'NonexistentModel'
1359
- end
1360
- assert_equal 'uninitialized constant ActiveRecord::Base::NonexistentModel', e.message
1361
- assert_equal 'ActiveRecord::Base::NonexistentModel', e.name
1362
- end
1363
-
1364
- def test_compute_type_no_method_error
1365
- ActiveSupport::Dependencies.stubs(:safe_constantize).raises(NoMethodError)
1366
- assert_raises NoMethodError do
1367
- ActiveRecord::Base.send :compute_type, 'InvalidModel'
1368
- end
1369
- end
1370
-
1371
- def test_compute_type_on_undefined_method
1372
- error = nil
1373
- begin
1374
- Class.new(Author) do
1375
- alias_method :foo, :bar
1376
- end
1377
- rescue => e
1378
- error = e
1379
- end
1380
-
1381
- ActiveSupport::Dependencies.stubs(:safe_constantize).raises(e)
1382
-
1383
- exception = assert_raises NameError do
1384
- ActiveRecord::Base.send :compute_type, 'InvalidModel'
1385
- end
1386
- assert_equal error.message, exception.message
1387
- end
1388
-
1389
- def test_compute_type_argument_error
1390
- ActiveSupport::Dependencies.stubs(:safe_constantize).raises(ArgumentError)
1391
- assert_raises ArgumentError do
1392
- ActiveRecord::Base.send :compute_type, 'InvalidModel'
1393
- end
1394
- end
1395
-
1396
1392
  def test_clear_cache!
1393
+ puts "In base_test test_clear_cache"
1397
1394
  # preheat cache
1398
1395
  c1 = Post.connection.schema_cache.columns('posts')
1399
1396
  ActiveRecord::Base.clear_cache!
@@ -1405,18 +1402,21 @@ class BasicsTest < ActiveRecord::TestCase
1405
1402
  end
1406
1403
 
1407
1404
  def test_current_scope_is_reset
1405
+ puts "In base_test test_current_scope_is_reset"
1408
1406
  Object.const_set :UnloadablePost, Class.new(ActiveRecord::Base)
1409
1407
  UnloadablePost.send(:current_scope=, UnloadablePost.all)
1410
1408
 
1411
1409
  UnloadablePost.unloadable
1412
- assert_not_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, "UnloadablePost")
1410
+ klass = UnloadablePost
1411
+ assert_not_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, klass)
1413
1412
  ActiveSupport::Dependencies.remove_unloadable_constants!
1414
- assert_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, "UnloadablePost")
1413
+ assert_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, klass)
1415
1414
  ensure
1416
1415
  Object.class_eval{ remove_const :UnloadablePost } if defined?(UnloadablePost)
1417
1416
  end
1418
1417
 
1419
1418
  def test_marshal_round_trip
1419
+ puts "In base_test test_marshal_round_trip"
1420
1420
  expected = posts(:welcome)
1421
1421
  marshalled = Marshal.dump(expected)
1422
1422
  actual = Marshal.load(marshalled)
@@ -1425,6 +1425,7 @@ class BasicsTest < ActiveRecord::TestCase
1425
1425
  end
1426
1426
 
1427
1427
  def test_marshal_new_record_round_trip
1428
+ puts "In base_test test_marshal_new_record_round_trip"
1428
1429
  marshalled = Marshal.dump(Post.new)
1429
1430
  post = Marshal.load(marshalled)
1430
1431
 
@@ -1432,6 +1433,7 @@ class BasicsTest < ActiveRecord::TestCase
1432
1433
  end
1433
1434
 
1434
1435
  def test_marshalling_with_associations
1436
+ puts "In base_test test_marshalling_with_associations"
1435
1437
  post = Post.new
1436
1438
  post.comments.build
1437
1439
 
@@ -1443,6 +1445,7 @@ class BasicsTest < ActiveRecord::TestCase
1443
1445
 
1444
1446
  if Process.respond_to?(:fork) && !in_memory_db?
1445
1447
  def test_marshal_between_processes
1448
+ puts "In base_test test_marshal_between_processes"
1446
1449
  # Define a new model to ensure there are no caches
1447
1450
  if self.class.const_defined?("Post", false)
1448
1451
  flunk "there should be no post constant"
@@ -1473,6 +1476,7 @@ class BasicsTest < ActiveRecord::TestCase
1473
1476
  end
1474
1477
 
1475
1478
  def test_marshalling_new_record_round_trip_with_associations
1479
+ puts "In base_test test_marshalling_new_record_round_trip_with_associations"
1476
1480
  post = Post.new
1477
1481
  post.comments.build
1478
1482
 
@@ -1482,19 +1486,38 @@ class BasicsTest < ActiveRecord::TestCase
1482
1486
  end
1483
1487
 
1484
1488
  def test_attribute_names
1489
+ puts "In base_test test_attribute_names"
1485
1490
  assert_equal ["id", "type", "firm_id", "firm_name", "name", "client_of", "rating", "account_id", "description"],
1486
1491
  Company.attribute_names
1487
1492
  end
1488
1493
 
1494
+ def test_has_attribute
1495
+ puts "In base_test test_has_attribute"
1496
+ assert Company.has_attribute?('id')
1497
+ assert Company.has_attribute?('type')
1498
+ assert Company.has_attribute?('name')
1499
+ assert_not Company.has_attribute?('lastname')
1500
+ assert_not Company.has_attribute?('age')
1501
+ end
1502
+
1503
+ def test_has_attribute_with_symbol
1504
+ puts "In base_test test_has_attribute_with_symbol"
1505
+ assert Company.has_attribute?(:id)
1506
+ assert_not Company.has_attribute?(:age)
1507
+ end
1508
+
1489
1509
  def test_attribute_names_on_table_not_exists
1510
+ puts "In base_test test_attribute_names_on_table_not_exists"
1490
1511
  assert_equal [], NonExistentTable.attribute_names
1491
1512
  end
1492
1513
 
1493
1514
  def test_attribute_names_on_abstract_class
1515
+ puts "In base_test test_attribute_names_on_abstract_class"
1494
1516
  assert_equal [], AbstractCompany.attribute_names
1495
1517
  end
1496
1518
 
1497
1519
  def test_touch_should_raise_error_on_a_new_object
1520
+ puts "In base_test test_touch_should_raise_error_on_a_new_object"
1498
1521
  company = Company.new(:rating => 1, :name => "37signals", :firm_name => "37signals")
1499
1522
  assert_raises(ActiveRecord::ActiveRecordError) do
1500
1523
  company.touch :updated_at
@@ -1502,22 +1525,24 @@ class BasicsTest < ActiveRecord::TestCase
1502
1525
  end
1503
1526
 
1504
1527
  def test_uniq_delegates_to_scoped
1505
- scope = stub
1506
- Bird.stubs(:all).returns(mock(:uniq => scope))
1507
- assert_equal scope, Bird.uniq
1528
+ puts "In base_test test_uniq_delegates_to_scoped"
1529
+ assert_deprecated do
1530
+ assert_equal Bird.all.distinct, Bird.uniq
1531
+ end
1508
1532
  end
1509
1533
 
1510
1534
  def test_distinct_delegates_to_scoped
1511
- scope = stub
1512
- Bird.stubs(:all).returns(mock(:distinct => scope))
1513
- assert_equal scope, Bird.distinct
1535
+ puts "In base_test test_distinct_delegates_to_scoped"
1536
+ assert_equal Bird.all.distinct, Bird.distinct
1514
1537
  end
1515
1538
 
1516
1539
  def test_table_name_with_2_abstract_subclasses
1540
+ puts "In base_test test_table_name_with_2_abstract_subclasses"
1517
1541
  assert_equal "photos", Photo.table_name
1518
1542
  end
1519
1543
 
1520
1544
  def test_column_types_typecast
1545
+ puts "In base_test test_column_types_typecast"
1521
1546
  topic = Topic.first
1522
1547
  assert_not_equal 't.lo', topic.author_name
1523
1548
 
@@ -1525,7 +1550,7 @@ class BasicsTest < ActiveRecord::TestCase
1525
1550
  attrs.delete 'id'
1526
1551
 
1527
1552
  typecast = Class.new(ActiveRecord::Type::Value) {
1528
- def type_cast value
1553
+ def cast value
1529
1554
  "t.lo"
1530
1555
  end
1531
1556
  }
@@ -1537,10 +1562,12 @@ class BasicsTest < ActiveRecord::TestCase
1537
1562
  end
1538
1563
 
1539
1564
  def test_typecasting_aliases
1565
+ puts "In base_test test_typecasting_aliases"
1540
1566
  assert_equal 10, Topic.select('10 as tenderlove').first.tenderlove
1541
1567
  end
1542
1568
 
1543
1569
  def test_slice
1570
+ puts "In base_test test_slice"
1544
1571
  company = Company.new(:rating => 1, :name => "37signals", :firm_name => "37signals")
1545
1572
  hash = company.slice(:name, :rating, "arbitrary_method")
1546
1573
  assert_equal hash[:name], company.name
@@ -1553,17 +1580,20 @@ class BasicsTest < ActiveRecord::TestCase
1553
1580
  end
1554
1581
 
1555
1582
  def test_default_values_are_deeply_dupped
1583
+ puts "In base_test test_default_values_are_deeply_dupped"
1556
1584
  company = Company.new
1557
1585
  company.description << "foo"
1558
1586
  assert_equal "", Company.new.description
1559
1587
  end
1560
1588
 
1561
1589
  test "scoped can take a values hash" do
1590
+ puts "In base_test scoped can take a values hash"
1562
1591
  klass = Class.new(ActiveRecord::Base)
1563
1592
  assert_equal ['foo'], klass.all.merge!(select: 'foo').select_values
1564
1593
  end
1565
1594
 
1566
1595
  test "connection_handler can be overridden" do
1596
+ puts "In base_test connection_handler can be overridden"
1567
1597
  klass = Class.new(ActiveRecord::Base)
1568
1598
  orig_handler = klass.connection_handler
1569
1599
  new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
@@ -1580,6 +1610,7 @@ class BasicsTest < ActiveRecord::TestCase
1580
1610
  end
1581
1611
 
1582
1612
  test "new threads get default the default connection handler" do
1613
+ puts "In base_test new threads get default the default connection handler"
1583
1614
  klass = Class.new(ActiveRecord::Base)
1584
1615
  orig_handler = klass.connection_handler
1585
1616
  handler = nil
@@ -1595,24 +1626,25 @@ class BasicsTest < ActiveRecord::TestCase
1595
1626
  end
1596
1627
 
1597
1628
  test "changing a connection handler in a main thread does not poison the other threads" do
1629
+ puts "In base_test changing a connection handler in a main thread does not poison the other threads"
1598
1630
  klass = Class.new(ActiveRecord::Base)
1599
1631
  orig_handler = klass.connection_handler
1600
1632
  new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
1601
1633
  after_handler = nil
1602
- latch1 = ActiveSupport::Concurrency::Latch.new
1603
- latch2 = ActiveSupport::Concurrency::Latch.new
1634
+ latch1 = Concurrent::CountDownLatch.new
1635
+ latch2 = Concurrent::CountDownLatch.new
1604
1636
 
1605
1637
  t = Thread.new do
1606
1638
  klass.connection_handler = new_handler
1607
- latch1.release
1608
- latch2.await
1639
+ latch1.count_down
1640
+ latch2.wait
1609
1641
  after_handler = klass.connection_handler
1610
1642
  end
1611
1643
 
1612
- latch1.await
1644
+ latch1.wait
1613
1645
 
1614
1646
  klass.connection_handler = orig_handler
1615
- latch2.release
1647
+ latch2.count_down
1616
1648
  t.join
1617
1649
 
1618
1650
  assert_equal after_handler, new_handler
@@ -1623,10 +1655,12 @@ class BasicsTest < ActiveRecord::TestCase
1623
1655
  # AR::Base objects. If the future has made this irrelevant, feel free to
1624
1656
  # delete this.
1625
1657
  test "records without an id have unique hashes" do
1658
+ puts "In base_test records without an id have unique hashes"
1626
1659
  assert_not_equal Post.new.hash, Post.new.hash
1627
1660
  end
1628
1661
 
1629
1662
  test "resetting column information doesn't remove attribute methods" do
1663
+ puts "In base_test changing a connection handler in a main thread does not poison the other threads"
1630
1664
  topic = topics(:first)
1631
1665
 
1632
1666
  assert_not topic.id_changed?
@@ -1635,4 +1669,45 @@ class BasicsTest < ActiveRecord::TestCase
1635
1669
 
1636
1670
  assert_not topic.id_changed?
1637
1671
  end
1672
+
1673
+ test "ignored columns are not present in columns_hash" do
1674
+ puts "In base_test ignored columns are not present in columns_hash"
1675
+ cache_columns = Developer.connection.schema_cache.columns_hash(Developer.table_name)
1676
+ assert_includes cache_columns.keys, "first_name"
1677
+ assert_not_includes Developer.columns_hash.keys, "first_name"
1678
+ assert_not_includes SubDeveloper.columns_hash.keys, "first_name"
1679
+ assert_not_includes SymbolIgnoredDeveloper.columns_hash.keys, "first_name"
1680
+ end
1681
+
1682
+ test "ignored columns have no attribute methods" do
1683
+ puts "In base_test ignored columns have no attribute methods"
1684
+ refute Developer.new.respond_to?(:first_name)
1685
+ refute Developer.new.respond_to?(:first_name=)
1686
+ refute Developer.new.respond_to?(:first_name?)
1687
+ refute SubDeveloper.new.respond_to?(:first_name)
1688
+ refute SubDeveloper.new.respond_to?(:first_name=)
1689
+ refute SubDeveloper.new.respond_to?(:first_name?)
1690
+ refute SymbolIgnoredDeveloper.new.respond_to?(:first_name)
1691
+ refute SymbolIgnoredDeveloper.new.respond_to?(:first_name=)
1692
+ refute SymbolIgnoredDeveloper.new.respond_to?(:first_name?)
1693
+ end
1694
+
1695
+ test "ignored columns don't prevent explicit declaration of attribute methods" do
1696
+ puts "In base_test ignored columns don't prevent explicit declaration of attribute methods"
1697
+ assert Developer.new.respond_to?(:last_name)
1698
+ assert Developer.new.respond_to?(:last_name=)
1699
+ assert Developer.new.respond_to?(:last_name?)
1700
+ assert SubDeveloper.new.respond_to?(:last_name)
1701
+ assert SubDeveloper.new.respond_to?(:last_name=)
1702
+ assert SubDeveloper.new.respond_to?(:last_name?)
1703
+ assert SymbolIgnoredDeveloper.new.respond_to?(:last_name)
1704
+ assert SymbolIgnoredDeveloper.new.respond_to?(:last_name=)
1705
+ assert SymbolIgnoredDeveloper.new.respond_to?(:last_name?)
1706
+ end
1707
+
1708
+ test "ignored columns are stored as an array of string" do
1709
+ puts "In base_test ignored columns are stored as an array of string"
1710
+ assert_equal(%w(first_name last_name), Developer.ignored_columns)
1711
+ assert_equal(%w(first_name last_name), SymbolIgnoredDeveloper.ignored_columns)
1712
+ end
1638
1713
  end