ibm_db 5.2.0-x86-mingw32 → 5.4.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (625) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +9 -0
  3. data/LICENSE +55 -18
  4. data/README +1 -1
  5. data/debug.log +1 -0
  6. data/ext/Makefile +28 -24
  7. data/ext/ibm_db.c +66 -65
  8. data/ext/ibm_db.o +0 -0
  9. data/ext/ibm_db.so +0 -0
  10. data/ext/mkmf.log +26 -24
  11. data/ext/ruby_ibm_db_cli.c +1 -0
  12. data/ext/ruby_ibm_db_cli.o +0 -0
  13. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +1520 -1282
  14. data/lib/ibm_db.so +1 -0
  15. data/lib/mswin32/ibm_db.rb +3 -1
  16. data/lib/mswin32/rb3x/i386/ruby30/ibm_db.so +0 -0
  17. data/lib/mswin32/rb3x/i386/ruby31/ibm_db.so +0 -0
  18. data/test/active_record/connection_adapters/fake_adapter.rb +5 -2
  19. data/test/activejob/destroy_association_async_test.rb +305 -0
  20. data/test/activejob/destroy_async_job_not_present_test.rb +31 -0
  21. data/test/activejob/helper.rb +15 -0
  22. data/test/assets/schema_dump_5_1.yml +345 -0
  23. data/test/cases/adapter_prevent_writes_test.rb +334 -0
  24. data/test/cases/adapter_test.rb +432 -218
  25. data/test/cases/adapters/mysql2/active_schema_test.rb +85 -75
  26. data/test/cases/adapters/mysql2/auto_increment_test.rb +34 -0
  27. data/test/cases/adapters/mysql2/bind_parameter_test.rb +5 -3
  28. data/test/cases/adapters/mysql2/boolean_test.rb +6 -4
  29. data/test/cases/adapters/mysql2/case_sensitivity_test.rb +26 -24
  30. data/test/cases/adapters/mysql2/charset_collation_test.rb +20 -17
  31. data/test/cases/adapters/mysql2/connection_test.rb +48 -50
  32. data/test/cases/adapters/mysql2/count_deleted_rows_with_lock_test.rb +28 -0
  33. data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +23 -19
  34. data/test/cases/adapters/mysql2/enum_test.rb +32 -11
  35. data/test/cases/adapters/mysql2/explain_test.rb +13 -11
  36. data/test/cases/adapters/mysql2/json_test.rb +17 -188
  37. data/test/cases/adapters/mysql2/mysql2_adapter_prevent_writes_test.rb +208 -0
  38. data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +183 -28
  39. data/test/cases/adapters/mysql2/nested_deadlock_test.rb +75 -0
  40. data/test/cases/adapters/mysql2/optimizer_hints_test.rb +69 -0
  41. data/test/cases/adapters/mysql2/schema_migrations_test.rb +26 -21
  42. data/test/cases/adapters/mysql2/schema_test.rb +24 -22
  43. data/test/cases/adapters/mysql2/set_test.rb +32 -0
  44. data/test/cases/adapters/mysql2/sp_test.rb +10 -8
  45. data/test/cases/adapters/mysql2/sql_types_test.rb +8 -6
  46. data/test/cases/adapters/mysql2/table_options_test.rb +93 -10
  47. data/test/cases/adapters/mysql2/transaction_test.rb +151 -0
  48. data/test/cases/adapters/mysql2/unsigned_type_test.rb +11 -9
  49. data/test/cases/adapters/mysql2/virtual_column_test.rb +66 -0
  50. data/test/cases/adapters/postgresql/active_schema_test.rb +40 -25
  51. data/test/cases/adapters/postgresql/array_test.rb +118 -63
  52. data/test/cases/adapters/postgresql/bit_string_test.rb +12 -10
  53. data/test/cases/adapters/postgresql/bytea_test.rb +26 -25
  54. data/test/cases/adapters/postgresql/case_insensitive_test.rb +10 -9
  55. data/test/cases/adapters/postgresql/change_schema_test.rb +7 -5
  56. data/test/cases/adapters/postgresql/cidr_test.rb +2 -0
  57. data/test/cases/adapters/postgresql/citext_test.rb +58 -58
  58. data/test/cases/adapters/postgresql/collation_test.rb +17 -15
  59. data/test/cases/adapters/postgresql/composite_test.rb +25 -23
  60. data/test/cases/adapters/postgresql/connection_test.rb +73 -85
  61. data/test/cases/adapters/postgresql/create_unlogged_tables_test.rb +74 -0
  62. data/test/cases/adapters/postgresql/datatype_test.rb +19 -22
  63. data/test/cases/adapters/postgresql/date_test.rb +42 -0
  64. data/test/cases/adapters/postgresql/domain_test.rb +9 -7
  65. data/test/cases/adapters/postgresql/enum_test.rb +12 -10
  66. data/test/cases/adapters/postgresql/explain_test.rb +10 -8
  67. data/test/cases/adapters/postgresql/extension_migration_test.rb +13 -12
  68. data/test/cases/adapters/postgresql/foreign_table_test.rb +109 -0
  69. data/test/cases/adapters/postgresql/full_text_test.rb +8 -6
  70. data/test/cases/adapters/postgresql/geometric_test.rb +57 -63
  71. data/test/cases/adapters/postgresql/hstore_test.rb +288 -280
  72. data/test/cases/adapters/postgresql/infinity_test.rb +54 -15
  73. data/test/cases/adapters/postgresql/integer_test.rb +2 -0
  74. data/test/cases/adapters/postgresql/interval_test.rb +99 -0
  75. data/test/cases/adapters/postgresql/json_test.rb +16 -201
  76. data/test/cases/adapters/postgresql/ltree_test.rb +14 -16
  77. data/test/cases/adapters/postgresql/money_test.rb +47 -16
  78. data/test/cases/adapters/postgresql/network_test.rb +36 -28
  79. data/test/cases/adapters/postgresql/numbers_test.rb +7 -5
  80. data/test/cases/adapters/postgresql/optimizer_hints_test.rb +71 -0
  81. data/test/cases/adapters/postgresql/partitions_test.rb +22 -0
  82. data/test/cases/adapters/postgresql/postgresql_adapter_prevent_writes_test.rb +205 -0
  83. data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +178 -136
  84. data/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb +27 -0
  85. data/test/cases/adapters/postgresql/quoting_test.rb +12 -6
  86. data/test/cases/adapters/postgresql/range_test.rb +406 -292
  87. data/test/cases/adapters/postgresql/referential_integrity_test.rb +16 -15
  88. data/test/cases/adapters/postgresql/rename_table_test.rb +9 -8
  89. data/test/cases/adapters/postgresql/schema_authorization_test.rb +14 -23
  90. data/test/cases/adapters/postgresql/schema_test.rb +207 -91
  91. data/test/cases/adapters/postgresql/serial_test.rb +9 -7
  92. data/test/cases/adapters/postgresql/statement_pool_test.rb +26 -6
  93. data/test/cases/adapters/postgresql/timestamp_test.rb +17 -15
  94. data/test/cases/adapters/postgresql/transaction_nested_test.rb +114 -0
  95. data/test/cases/adapters/postgresql/transaction_test.rb +189 -0
  96. data/test/cases/adapters/postgresql/type_lookup_test.rb +12 -10
  97. data/test/cases/adapters/postgresql/utils_test.rb +11 -9
  98. data/test/cases/adapters/postgresql/uuid_test.rb +226 -109
  99. data/test/cases/adapters/postgresql/xml_test.rb +10 -14
  100. data/test/cases/adapters/sqlite3/collation_test.rb +26 -15
  101. data/test/cases/adapters/sqlite3/copy_table_test.rb +31 -28
  102. data/test/cases/adapters/sqlite3/explain_test.rb +13 -11
  103. data/test/cases/adapters/sqlite3/json_test.rb +29 -0
  104. data/test/cases/adapters/sqlite3/quoting_test.rb +35 -57
  105. data/test/cases/adapters/sqlite3/sqlite3_adapter_prevent_writes_test.rb +186 -0
  106. data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +318 -131
  107. data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +11 -11
  108. data/test/cases/adapters/sqlite3/statement_pool_test.rb +7 -6
  109. data/test/cases/adapters/sqlite3/transaction_test.rb +123 -0
  110. data/test/cases/aggregations_test.rb +14 -12
  111. data/test/cases/annotate_test.rb +46 -0
  112. data/test/cases/ar_schema_test.rb +153 -86
  113. data/test/cases/arel/attributes/attribute_test.rb +1145 -0
  114. data/test/cases/arel/attributes/math_test.rb +83 -0
  115. data/test/cases/arel/attributes_test.rb +27 -0
  116. data/test/cases/arel/collectors/bind_test.rb +40 -0
  117. data/test/cases/arel/collectors/composite_test.rb +47 -0
  118. data/test/cases/arel/collectors/sql_string_test.rb +41 -0
  119. data/test/cases/arel/collectors/substitute_bind_collector_test.rb +48 -0
  120. data/test/cases/arel/crud_test.rb +65 -0
  121. data/test/cases/arel/delete_manager_test.rb +53 -0
  122. data/test/cases/arel/factory_methods_test.rb +46 -0
  123. data/test/cases/arel/helper.rb +45 -0
  124. data/test/cases/arel/insert_manager_test.rb +241 -0
  125. data/test/cases/arel/nodes/and_test.rb +30 -0
  126. data/test/cases/arel/nodes/as_test.rb +36 -0
  127. data/test/cases/arel/nodes/ascending_test.rb +46 -0
  128. data/test/cases/arel/nodes/bin_test.rb +35 -0
  129. data/test/cases/arel/nodes/binary_test.rb +29 -0
  130. data/test/cases/arel/nodes/bind_param_test.rb +22 -0
  131. data/test/cases/arel/nodes/case_test.rb +96 -0
  132. data/test/cases/arel/nodes/casted_test.rb +18 -0
  133. data/test/cases/arel/nodes/comment_test.rb +22 -0
  134. data/test/cases/arel/nodes/count_test.rb +35 -0
  135. data/test/cases/arel/nodes/delete_statement_test.rb +36 -0
  136. data/test/cases/arel/nodes/descending_test.rb +46 -0
  137. data/test/cases/arel/nodes/distinct_test.rb +21 -0
  138. data/test/cases/arel/nodes/equality_test.rb +62 -0
  139. data/test/cases/arel/nodes/extract_test.rb +43 -0
  140. data/test/cases/arel/nodes/false_test.rb +21 -0
  141. data/test/cases/arel/nodes/grouping_test.rb +26 -0
  142. data/test/cases/arel/nodes/infix_operation_test.rb +42 -0
  143. data/test/cases/arel/nodes/insert_statement_test.rb +44 -0
  144. data/test/cases/arel/nodes/named_function_test.rb +48 -0
  145. data/test/cases/arel/nodes/node_test.rb +22 -0
  146. data/test/cases/arel/nodes/not_test.rb +31 -0
  147. data/test/cases/arel/nodes/or_test.rb +36 -0
  148. data/test/cases/arel/nodes/over_test.rb +69 -0
  149. data/test/cases/arel/nodes/select_core_test.rb +79 -0
  150. data/test/cases/arel/nodes/select_statement_test.rb +51 -0
  151. data/test/cases/arel/nodes/sql_literal_test.rb +75 -0
  152. data/test/cases/arel/nodes/sum_test.rb +35 -0
  153. data/test/cases/arel/nodes/table_alias_test.rb +29 -0
  154. data/test/cases/arel/nodes/true_test.rb +21 -0
  155. data/test/cases/arel/nodes/unary_operation_test.rb +41 -0
  156. data/test/cases/arel/nodes/update_statement_test.rb +60 -0
  157. data/test/cases/arel/nodes/window_test.rb +81 -0
  158. data/test/cases/arel/nodes_test.rb +34 -0
  159. data/test/cases/arel/select_manager_test.rb +1238 -0
  160. data/test/cases/arel/support/fake_record.rb +135 -0
  161. data/test/cases/arel/table_test.rb +216 -0
  162. data/test/cases/arel/update_manager_test.rb +126 -0
  163. data/test/cases/arel/visitors/dispatch_contamination_test.rb +78 -0
  164. data/test/cases/arel/visitors/dot_test.rb +90 -0
  165. data/test/cases/arel/visitors/mysql_test.rb +157 -0
  166. data/test/cases/arel/visitors/postgres_test.rb +366 -0
  167. data/test/cases/arel/visitors/sqlite_test.rb +75 -0
  168. data/test/cases/arel/visitors/to_sql_test.rb +750 -0
  169. data/test/cases/associations/belongs_to_associations_test.rb +510 -158
  170. data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +4 -2
  171. data/test/cases/associations/callbacks_test.rb +56 -38
  172. data/test/cases/associations/cascaded_eager_loading_test.rb +118 -61
  173. data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +138 -18
  174. data/test/cases/associations/eager_load_nested_include_test.rb +38 -37
  175. data/test/cases/associations/eager_singularization_test.rb +21 -21
  176. data/test/cases/associations/eager_test.rb +559 -415
  177. data/test/cases/associations/extension_test.rb +18 -12
  178. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +234 -213
  179. data/test/cases/associations/has_many_associations_test.rb +1038 -465
  180. data/test/cases/associations/has_many_through_associations_test.rb +558 -249
  181. data/test/cases/associations/has_one_associations_test.rb +294 -129
  182. data/test/cases/associations/has_one_through_associations_test.rb +121 -75
  183. data/test/cases/associations/inner_join_association_test.rb +114 -38
  184. data/test/cases/associations/inverse_associations_test.rb +606 -398
  185. data/test/cases/associations/join_model_test.rb +158 -148
  186. data/test/cases/associations/left_outer_join_association_test.rb +59 -24
  187. data/test/cases/associations/nested_through_associations_test.rb +166 -109
  188. data/test/cases/associations/required_test.rb +35 -10
  189. data/test/cases/associations_test.rb +241 -110
  190. data/test/cases/attribute_methods/read_test.rb +11 -11
  191. data/test/cases/attribute_methods_test.rb +413 -298
  192. data/test/cases/attributes_test.rb +145 -27
  193. data/test/cases/autosave_association_test.rb +681 -436
  194. data/test/cases/base_prevent_writes_test.rb +229 -0
  195. data/test/cases/base_test.rb +599 -542
  196. data/test/cases/batches_test.rb +288 -82
  197. data/test/cases/binary_test.rb +26 -31
  198. data/test/cases/bind_parameter_test.rb +194 -21
  199. data/test/cases/boolean_test.rb +52 -0
  200. data/test/cases/cache_key_test.rb +110 -5
  201. data/test/cases/calculations_test.rb +740 -177
  202. data/test/cases/callbacks_test.rb +74 -207
  203. data/test/cases/clone_test.rb +15 -10
  204. data/test/cases/coders/json_test.rb +2 -0
  205. data/test/cases/coders/yaml_column_test.rb +16 -13
  206. data/test/cases/collection_cache_key_test.rb +177 -20
  207. data/test/cases/column_alias_test.rb +9 -7
  208. data/test/cases/column_definition_test.rb +10 -68
  209. data/test/cases/comment_test.rb +166 -107
  210. data/test/cases/connection_adapters/adapter_leasing_test.rb +14 -10
  211. data/test/cases/connection_adapters/connection_handler_test.rb +358 -51
  212. data/test/cases/connection_adapters/connection_handlers_multi_db_test.rb +400 -0
  213. data/test/cases/connection_adapters/connection_handlers_multi_pool_config_test.rb +103 -0
  214. data/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb +499 -0
  215. data/test/cases/connection_adapters/connection_swapping_nested_test.rb +457 -0
  216. data/test/cases/connection_adapters/legacy_connection_handlers_multi_db_test.rb +486 -0
  217. data/test/cases/connection_adapters/legacy_connection_handlers_sharding_db_test.rb +586 -0
  218. data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +319 -138
  219. data/test/cases/connection_adapters/mysql_type_lookup_test.rb +62 -50
  220. data/test/cases/connection_adapters/schema_cache_test.rb +259 -26
  221. data/test/cases/connection_adapters/type_lookup_test.rb +96 -95
  222. data/test/cases/connection_management_test.rb +13 -11
  223. data/test/cases/connection_pool_test.rb +316 -83
  224. data/test/cases/core_test.rb +82 -58
  225. data/test/cases/counter_cache_test.rb +204 -50
  226. data/test/cases/custom_locking_test.rb +5 -3
  227. data/test/cases/database_configurations/hash_config_test.rb +74 -0
  228. data/test/cases/database_configurations/resolver_test.rb +150 -0
  229. data/test/cases/database_configurations_test.rb +145 -0
  230. data/test/cases/database_selector_test.rb +296 -0
  231. data/test/cases/database_statements_test.rb +18 -16
  232. data/test/cases/date_test.rb +8 -16
  233. data/test/cases/date_time_precision_test.rb +100 -78
  234. data/test/cases/date_time_test.rb +23 -8
  235. data/test/cases/defaults_test.rb +106 -71
  236. data/test/cases/delegated_type_test.rb +57 -0
  237. data/test/cases/dirty_test.rb +419 -223
  238. data/test/cases/disconnected_test.rb +6 -6
  239. data/test/cases/dup_test.rb +54 -27
  240. data/test/cases/enum_test.rb +461 -82
  241. data/test/cases/errors_test.rb +7 -7
  242. data/test/cases/explain_subscriber_test.rb +17 -15
  243. data/test/cases/explain_test.rb +11 -19
  244. data/test/cases/filter_attributes_test.rb +153 -0
  245. data/test/cases/finder_respond_to_test.rb +14 -14
  246. data/test/cases/finder_test.rb +669 -287
  247. data/test/cases/fixture_set/file_test.rb +34 -38
  248. data/test/cases/fixtures_test.rb +833 -176
  249. data/test/cases/forbidden_attributes_protection_test.rb +32 -67
  250. data/test/cases/habtm_destroy_order_test.rb +25 -25
  251. data/test/cases/helper.rb +78 -49
  252. data/test/cases/hot_compatibility_test.rb +33 -32
  253. data/test/cases/i18n_test.rb +18 -17
  254. data/test/cases/inheritance_test.rb +180 -115
  255. data/test/cases/insert_all_test.rb +489 -0
  256. data/test/cases/instrumentation_test.rb +101 -0
  257. data/test/cases/integration_test.rb +119 -31
  258. data/test/cases/invalid_connection_test.rb +18 -16
  259. data/test/cases/invertible_migration_test.rb +183 -43
  260. data/test/cases/json_attribute_test.rb +35 -0
  261. data/test/cases/json_serialization_test.rb +57 -58
  262. data/test/cases/json_shared_test_cases.rb +290 -0
  263. data/test/cases/locking_test.rb +413 -119
  264. data/test/cases/log_subscriber_test.rb +68 -26
  265. data/test/cases/marshal_serialization_test.rb +39 -0
  266. data/test/cases/migration/change_schema_test.rb +118 -72
  267. data/test/cases/migration/change_table_test.rb +138 -30
  268. data/test/cases/migration/check_constraint_test.rb +162 -0
  269. data/test/cases/migration/column_attributes_test.rb +45 -35
  270. data/test/cases/migration/column_positioning_test.rb +18 -6
  271. data/test/cases/migration/columns_test.rb +93 -77
  272. data/test/cases/migration/command_recorder_test.rb +121 -34
  273. data/test/cases/migration/compatibility_test.rb +578 -23
  274. data/test/cases/migration/create_join_table_test.rb +35 -25
  275. data/test/cases/migration/foreign_key_test.rb +503 -284
  276. data/test/cases/migration/helper.rb +4 -3
  277. data/test/cases/migration/index_test.rb +119 -70
  278. data/test/cases/migration/logger_test.rb +9 -6
  279. data/test/cases/migration/pending_migrations_test.rb +88 -34
  280. data/test/cases/migration/references_foreign_key_test.rb +164 -150
  281. data/test/cases/migration/references_index_test.rb +38 -19
  282. data/test/cases/migration/references_statements_test.rb +15 -14
  283. data/test/cases/migration/rename_table_test.rb +53 -30
  284. data/test/cases/migration_test.rb +637 -269
  285. data/test/cases/migrator_test.rb +191 -135
  286. data/test/cases/mixin_test.rb +7 -11
  287. data/test/cases/modules_test.rb +36 -34
  288. data/test/cases/multi_db_migrator_test.rb +223 -0
  289. data/test/cases/multiparameter_attributes_test.rb +60 -33
  290. data/test/cases/multiple_db_test.rb +16 -22
  291. data/test/cases/nested_attributes_test.rb +341 -320
  292. data/test/cases/nested_attributes_with_callbacks_test.rb +26 -24
  293. data/test/cases/null_relation_test.rb +84 -0
  294. data/test/cases/numeric_data_test.rb +93 -0
  295. data/test/cases/persistence_test.rb +361 -269
  296. data/test/cases/pooled_connections_test.rb +18 -26
  297. data/test/cases/prepared_statement_status_test.rb +48 -0
  298. data/test/cases/primary_keys_test.rb +210 -104
  299. data/test/cases/query_cache_test.rb +610 -141
  300. data/test/cases/quoting_test.rb +132 -31
  301. data/test/cases/readonly_test.rb +49 -48
  302. data/test/cases/reaper_test.rb +146 -32
  303. data/test/cases/reflection_test.rb +167 -156
  304. data/test/cases/relation/delegation_test.rb +49 -36
  305. data/test/cases/relation/delete_all_test.rb +117 -0
  306. data/test/cases/relation/merging_test.rb +319 -42
  307. data/test/cases/relation/mutation_test.rb +55 -93
  308. data/test/cases/relation/or_test.rb +129 -29
  309. data/test/cases/relation/predicate_builder_test.rb +21 -6
  310. data/test/cases/relation/record_fetch_warning_test.rb +5 -3
  311. data/test/cases/relation/select_test.rb +67 -0
  312. data/test/cases/relation/update_all_test.rb +317 -0
  313. data/test/cases/relation/where_chain_test.rb +68 -32
  314. data/test/cases/relation/where_clause_test.rb +136 -61
  315. data/test/cases/relation/where_test.rb +155 -48
  316. data/test/cases/relation_test.rb +266 -112
  317. data/test/cases/relations_test.rb +969 -744
  318. data/test/cases/reload_models_test.rb +13 -9
  319. data/test/cases/reserved_word_test.rb +141 -0
  320. data/test/cases/result_test.rb +68 -17
  321. data/test/cases/sanitize_test.rb +87 -71
  322. data/test/cases/schema_dumper_test.rb +221 -128
  323. data/test/cases/schema_loading_test.rb +3 -2
  324. data/test/cases/scoping/default_scoping_test.rb +185 -144
  325. data/test/cases/scoping/named_scoping_test.rb +177 -89
  326. data/test/cases/scoping/relation_scoping_test.rb +197 -75
  327. data/test/cases/secure_token_test.rb +18 -3
  328. data/test/cases/serialization_test.rb +30 -28
  329. data/test/cases/serialized_attribute_test.rb +133 -42
  330. data/test/cases/signed_id_test.rb +168 -0
  331. data/test/cases/statement_cache_test.rb +41 -24
  332. data/test/cases/statement_invalid_test.rb +42 -0
  333. data/test/cases/store_test.rb +180 -55
  334. data/test/cases/strict_loading_test.rb +473 -0
  335. data/test/cases/suppressor_test.rb +26 -12
  336. data/test/cases/tasks/database_tasks_test.rb +1258 -194
  337. data/test/cases/tasks/mysql_rake_test.rb +370 -298
  338. data/test/cases/tasks/postgresql_rake_test.rb +481 -251
  339. data/test/cases/tasks/sqlite_rake_test.rb +225 -178
  340. data/test/cases/test_case.rb +51 -40
  341. data/test/cases/test_databases_test.rb +79 -0
  342. data/test/cases/test_fixtures_test.rb +79 -19
  343. data/test/cases/time_precision_test.rb +98 -76
  344. data/test/cases/timestamp_test.rb +102 -99
  345. data/test/cases/touch_later_test.rb +12 -10
  346. data/test/cases/transaction_callbacks_test.rb +344 -90
  347. data/test/cases/transaction_isolation_test.rb +12 -12
  348. data/test/cases/transactions_test.rb +612 -162
  349. data/test/cases/type/adapter_specific_registry_test.rb +14 -2
  350. data/test/cases/type/date_time_test.rb +4 -2
  351. data/test/cases/type/integer_test.rb +4 -2
  352. data/test/cases/type/string_test.rb +10 -8
  353. data/test/cases/type/time_test.rb +28 -0
  354. data/test/cases/type/type_map_test.rb +29 -28
  355. data/test/cases/type/unsigned_integer_test.rb +19 -0
  356. data/test/cases/type_test.rb +2 -0
  357. data/test/cases/types_test.rb +3 -1
  358. data/test/cases/unconnected_test.rb +14 -1
  359. data/test/cases/unsafe_raw_sql_test.rb +274 -0
  360. data/test/cases/validations/absence_validation_test.rb +19 -17
  361. data/test/cases/validations/association_validation_test.rb +30 -28
  362. data/test/cases/validations/i18n_generate_message_validation_test.rb +34 -16
  363. data/test/cases/validations/i18n_validation_test.rb +22 -21
  364. data/test/cases/validations/length_validation_test.rb +34 -33
  365. data/test/cases/validations/numericality_validation_test.rb +181 -0
  366. data/test/cases/validations/presence_validation_test.rb +21 -19
  367. data/test/cases/validations/uniqueness_validation_test.rb +156 -86
  368. data/test/cases/validations_repair_helper.rb +2 -0
  369. data/test/cases/validations_test.rb +61 -26
  370. data/test/cases/view_test.rb +122 -116
  371. data/test/cases/yaml_serialization_test.rb +79 -34
  372. data/test/config.example.yml +19 -19
  373. data/test/config.rb +3 -1
  374. data/test/config.yml +16 -6
  375. data/test/fixtures/all/namespaced/accounts.yml +2 -0
  376. data/test/fixtures/author_addresses.yml +1 -8
  377. data/test/fixtures/authors.yml +1 -7
  378. data/test/fixtures/binaries.yml +4 -0
  379. data/test/fixtures/books.yml +9 -2
  380. data/test/fixtures/categories_posts.yml +3 -0
  381. data/test/fixtures/citations.yml +5 -0
  382. data/test/fixtures/comments.yml +7 -0
  383. data/test/fixtures/companies.yml +5 -0
  384. data/test/fixtures/computers.yml +2 -0
  385. data/test/fixtures/customers.yml +10 -1
  386. data/test/fixtures/developers.yml +1 -1
  387. data/test/fixtures/essays.yml +10 -0
  388. data/test/fixtures/faces.yml +3 -3
  389. data/test/fixtures/humans.yml +5 -0
  390. data/test/fixtures/interests.yml +7 -7
  391. data/test/fixtures/memberships.yml +7 -0
  392. data/test/fixtures/minimalistics.yml +3 -0
  393. data/test/fixtures/mixed_case_monkeys.yml +2 -2
  394. data/test/fixtures/naked/yml/courses_with_invalid_key.yml +3 -0
  395. data/test/fixtures/naked/yml/parrots.yml +1 -0
  396. data/test/fixtures/other_books.yml +26 -0
  397. data/test/fixtures/other_posts.yml +1 -0
  398. data/test/fixtures/parrots.yml +7 -1
  399. data/test/fixtures/pirates.yml +3 -0
  400. data/test/fixtures/posts.yml +11 -3
  401. data/test/fixtures/readers.yml +6 -0
  402. data/test/fixtures/reserved_words/values.yml +2 -2
  403. data/test/fixtures/sponsors.yml +3 -0
  404. data/test/fixtures/strict_zines.yml +2 -0
  405. data/test/fixtures/subscribers.yml +1 -1
  406. data/test/fixtures/tasks.yml +1 -1
  407. data/test/fixtures/warehouse-things.yml +3 -0
  408. data/test/migrations/10_urban/9_add_expressions.rb +2 -0
  409. data/test/migrations/decimal/1_give_me_big_numbers.rb +6 -4
  410. data/test/migrations/magic/1_currencies_have_symbols.rb +3 -2
  411. data/test/migrations/missing/1000_people_have_middle_names.rb +2 -0
  412. data/test/migrations/missing/1_people_have_last_names.rb +2 -0
  413. data/test/migrations/missing/3_we_need_reminders.rb +2 -0
  414. data/test/migrations/missing/4_innocent_jointable.rb +3 -1
  415. data/test/migrations/rename/1_we_need_things.rb +2 -0
  416. data/test/migrations/rename/2_rename_things.rb +2 -0
  417. data/test/migrations/to_copy/1_people_have_hobbies.rb +3 -1
  418. data/test/migrations/to_copy/2_people_have_descriptions.rb +3 -1
  419. data/test/migrations/to_copy2/1_create_articles.rb +2 -0
  420. data/test/migrations/to_copy2/2_create_comments.rb +3 -1
  421. data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +3 -1
  422. data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +3 -1
  423. data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +3 -1
  424. data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +2 -0
  425. data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +2 -0
  426. data/test/migrations/valid/1_valid_people_have_last_names.rb +2 -0
  427. data/test/migrations/valid/2_we_need_reminders.rb +2 -0
  428. data/test/migrations/valid/3_innocent_jointable.rb +3 -1
  429. data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +2 -0
  430. data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -0
  431. data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +3 -1
  432. data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +2 -0
  433. data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +2 -0
  434. data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +3 -1
  435. data/test/migrations/version_check/20131219224947_migration_version_check.rb +2 -0
  436. data/test/models/account.rb +46 -0
  437. data/test/models/admin/account.rb +3 -1
  438. data/test/models/admin/randomly_named_c1.rb +2 -0
  439. data/test/models/admin/user.rb +16 -8
  440. data/test/models/admin.rb +4 -2
  441. data/test/models/aircraft.rb +3 -1
  442. data/test/models/arunit2_model.rb +2 -0
  443. data/test/models/author.rb +153 -102
  444. data/test/models/auto_id.rb +2 -0
  445. data/test/models/autoloadable/extra_firm.rb +2 -0
  446. data/test/models/binary.rb +3 -1
  447. data/test/models/binary_field.rb +6 -0
  448. data/test/models/bird.rb +13 -1
  449. data/test/models/book.rb +14 -4
  450. data/test/models/book_destroy_async.rb +24 -0
  451. data/test/models/boolean.rb +5 -0
  452. data/test/models/bulb.rb +13 -4
  453. data/test/models/cake_designer.rb +2 -0
  454. data/test/models/car.rb +17 -10
  455. data/test/models/carrier.rb +2 -0
  456. data/test/models/cart.rb +5 -0
  457. data/test/models/cat.rb +2 -0
  458. data/test/models/categorization.rb +8 -6
  459. data/test/models/category.rb +28 -16
  460. data/test/models/chef.rb +2 -0
  461. data/test/models/citation.rb +5 -1
  462. data/test/models/club.rb +13 -10
  463. data/test/models/college.rb +4 -2
  464. data/test/models/column.rb +2 -0
  465. data/test/models/column_name.rb +2 -0
  466. data/test/models/comment.rb +32 -10
  467. data/test/models/company.rb +102 -106
  468. data/test/models/company_in_module.rb +27 -26
  469. data/test/models/computer.rb +3 -1
  470. data/test/models/contact.rb +15 -13
  471. data/test/models/content.rb +5 -3
  472. data/test/models/contract.rb +21 -3
  473. data/test/models/country.rb +2 -4
  474. data/test/models/course.rb +3 -1
  475. data/test/models/customer.rb +10 -8
  476. data/test/models/customer_carrier.rb +2 -0
  477. data/test/models/dashboard.rb +2 -0
  478. data/test/models/default.rb +2 -0
  479. data/test/models/department.rb +2 -0
  480. data/test/models/destroy_async_parent.rb +15 -0
  481. data/test/models/destroy_async_parent_soft_delete.rb +20 -0
  482. data/test/models/developer.rb +152 -85
  483. data/test/models/dl_keyed_belongs_to.rb +13 -0
  484. data/test/models/dl_keyed_belongs_to_soft_delete.rb +19 -0
  485. data/test/models/dl_keyed_has_many.rb +5 -0
  486. data/test/models/dl_keyed_has_many_through.rb +5 -0
  487. data/test/models/dl_keyed_has_one.rb +5 -0
  488. data/test/models/dl_keyed_join.rb +10 -0
  489. data/test/models/dog.rb +2 -0
  490. data/test/models/dog_lover.rb +2 -0
  491. data/test/models/doubloon.rb +3 -1
  492. data/test/models/drink_designer.rb +17 -0
  493. data/test/models/edge.rb +4 -2
  494. data/test/models/electron.rb +2 -0
  495. data/test/models/engine.rb +3 -2
  496. data/test/models/entrant.rb +2 -0
  497. data/test/models/entry.rb +5 -0
  498. data/test/models/essay.rb +6 -3
  499. data/test/models/essay_destroy_async.rb +12 -0
  500. data/test/models/event.rb +3 -1
  501. data/test/models/eye.rb +5 -3
  502. data/test/models/face.rb +14 -6
  503. data/test/models/family.rb +6 -0
  504. data/test/models/family_tree.rb +6 -0
  505. data/test/models/friendship.rb +5 -3
  506. data/test/models/frog.rb +8 -0
  507. data/test/models/guid.rb +3 -1
  508. data/test/models/guitar.rb +2 -0
  509. data/test/models/hotel.rb +5 -3
  510. data/test/models/human.rb +39 -0
  511. data/test/models/image.rb +3 -1
  512. data/test/models/interest.rb +14 -3
  513. data/test/models/invoice.rb +4 -2
  514. data/test/models/item.rb +3 -1
  515. data/test/models/job.rb +5 -3
  516. data/test/models/joke.rb +4 -2
  517. data/test/models/keyboard.rb +3 -1
  518. data/test/models/legacy_thing.rb +2 -0
  519. data/test/models/lesson.rb +2 -0
  520. data/test/models/line_item.rb +3 -1
  521. data/test/models/liquid.rb +2 -0
  522. data/test/models/matey.rb +3 -1
  523. data/test/models/measurement.rb +4 -0
  524. data/test/models/member.rb +23 -20
  525. data/test/models/member_detail.rb +3 -0
  526. data/test/models/member_type.rb +2 -0
  527. data/test/models/membership.rb +4 -1
  528. data/test/models/mentor.rb +3 -1
  529. data/test/models/message.rb +5 -0
  530. data/test/models/minimalistic.rb +2 -0
  531. data/test/models/minivan.rb +3 -2
  532. data/test/models/mixed_case_monkey.rb +3 -1
  533. data/test/models/molecule.rb +2 -0
  534. data/test/models/mouse.rb +6 -0
  535. data/test/models/movie.rb +2 -0
  536. data/test/models/node.rb +4 -2
  537. data/test/models/non_primary_key.rb +2 -0
  538. data/test/models/notification.rb +2 -0
  539. data/test/models/numeric_data.rb +12 -0
  540. data/test/models/order.rb +4 -2
  541. data/test/models/organization.rb +9 -7
  542. data/test/models/other_dog.rb +3 -1
  543. data/test/models/owner.rb +6 -4
  544. data/test/models/parrot.rb +12 -4
  545. data/test/models/person.rb +59 -54
  546. data/test/models/personal_legacy_thing.rb +3 -1
  547. data/test/models/pet.rb +4 -2
  548. data/test/models/pet_treasure.rb +2 -0
  549. data/test/models/pirate.rb +67 -43
  550. data/test/models/possession.rb +3 -1
  551. data/test/models/post.rb +184 -86
  552. data/test/models/price_estimate.rb +11 -1
  553. data/test/models/professor.rb +3 -1
  554. data/test/models/project.rb +14 -12
  555. data/test/models/publisher/article.rb +2 -0
  556. data/test/models/publisher/magazine.rb +2 -0
  557. data/test/models/publisher.rb +2 -0
  558. data/test/models/randomly_named_c1.rb +2 -0
  559. data/test/models/rating.rb +5 -1
  560. data/test/models/reader.rb +7 -5
  561. data/test/models/recipe.rb +2 -0
  562. data/test/models/record.rb +2 -0
  563. data/test/models/reference.rb +6 -3
  564. data/test/models/reply.rb +39 -21
  565. data/test/models/room.rb +6 -0
  566. data/test/models/section.rb +6 -0
  567. data/test/models/seminar.rb +6 -0
  568. data/test/models/session.rb +6 -0
  569. data/test/models/ship.rb +12 -9
  570. data/test/models/ship_part.rb +5 -3
  571. data/test/models/shop.rb +4 -2
  572. data/test/models/shop_account.rb +2 -0
  573. data/test/models/speedometer.rb +2 -0
  574. data/test/models/sponsor.rb +8 -5
  575. data/test/models/squeak.rb +6 -0
  576. data/test/models/strict_zine.rb +7 -0
  577. data/test/models/string_key_object.rb +2 -0
  578. data/test/models/student.rb +2 -0
  579. data/test/models/subscriber.rb +4 -2
  580. data/test/models/subscription.rb +5 -1
  581. data/test/models/tag.rb +6 -3
  582. data/test/models/tagging.rb +13 -6
  583. data/test/models/task.rb +2 -0
  584. data/test/models/topic.rb +54 -19
  585. data/test/models/toy.rb +4 -0
  586. data/test/models/traffic_light.rb +2 -0
  587. data/test/models/treasure.rb +5 -3
  588. data/test/models/treaty.rb +2 -4
  589. data/test/models/tree.rb +2 -0
  590. data/test/models/tuning_peg.rb +2 -0
  591. data/test/models/tyre.rb +2 -0
  592. data/test/models/user.rb +12 -4
  593. data/test/models/uuid_child.rb +2 -0
  594. data/test/models/uuid_item.rb +2 -0
  595. data/test/models/uuid_parent.rb +2 -0
  596. data/test/models/vegetables.rb +12 -3
  597. data/test/models/vertex.rb +6 -4
  598. data/test/models/warehouse_thing.rb +2 -0
  599. data/test/models/wheel.rb +3 -1
  600. data/test/models/without_table.rb +3 -1
  601. data/test/models/zine.rb +3 -1
  602. data/test/schema/mysql2_specific_schema.rb +49 -35
  603. data/test/schema/oracle_specific_schema.rb +13 -15
  604. data/test/schema/postgresql_specific_schema.rb +51 -40
  605. data/test/schema/schema.rb +334 -154
  606. data/test/schema/sqlite_specific_schema.rb +9 -16
  607. data/test/support/config.rb +26 -26
  608. data/test/support/connection.rb +14 -8
  609. data/test/support/connection_helper.rb +3 -1
  610. data/test/support/ddl_helper.rb +2 -0
  611. data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic.dump +0 -0
  612. data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic_associations.dump +0 -0
  613. data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic.dump +0 -0
  614. data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic_associations.dump +0 -0
  615. data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic.dump +0 -0
  616. data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic_associations.dump +0 -0
  617. data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic.dump +0 -0
  618. data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic_associations.dump +0 -0
  619. data/test/support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump +0 -0
  620. data/test/support/marshal_compatibility_fixtures/legacy_relation.dump +0 -0
  621. data/test/support/schema_dumping_helper.rb +2 -0
  622. data/test/support/stubs/strong_parameters.rb +40 -0
  623. data/test/support/yaml_compatibility_fixtures/rails_v1_mysql.yml +206 -0
  624. data/test/support/yaml_compatibility_fixtures/rails_v2.yml +55 -0
  625. metadata +192 -14
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "cases/helper"
2
- require 'models/minimalistic'
3
- require 'models/developer'
4
- require 'models/auto_id'
5
- require 'models/boolean'
6
- require 'models/computer'
7
- require 'models/topic'
8
- require 'models/company'
9
- require 'models/category'
10
- require 'models/reply'
11
- require 'models/contact'
12
- require 'models/keyboard'
4
+ require "models/minimalistic"
5
+ require "models/developer"
6
+ require "models/auto_id"
7
+ require "models/boolean"
8
+ require "models/computer"
9
+ require "models/topic"
10
+ require "models/company"
11
+ require "models/category"
12
+ require "models/reply"
13
+ require "models/contact"
14
+ require "models/keyboard"
15
+ require "models/numeric_data"
13
16
 
14
17
  class AttributeMethodsTest < ActiveRecord::TestCase
15
18
  include InTimeZone
@@ -19,7 +22,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
19
22
  def setup
20
23
  @old_matchers = ActiveRecord::Base.send(:attribute_method_matchers).dup
21
24
  @target = Class.new(ActiveRecord::Base)
22
- @target.table_name = 'topics'
25
+ @target.table_name = "topics"
23
26
  end
24
27
 
25
28
  teardown do
@@ -27,45 +30,54 @@ class AttributeMethodsTest < ActiveRecord::TestCase
27
30
  ActiveRecord::Base.send(:attribute_method_matchers).concat(@old_matchers)
28
31
  end
29
32
 
30
- def test_attribute_for_inspect_string
33
+ test "attribute_for_inspect with a string" do
31
34
  t = topics(:first)
32
35
  t.title = "The First Topic Now Has A Title With\nNewlines And More Than 50 Characters"
33
36
 
34
37
  assert_equal '"The First Topic Now Has A Title With\nNewlines And ..."', t.attribute_for_inspect(:title)
38
+ assert_equal '"The First Topic Now Has A Title With\nNewlines And ..."', t.attribute_for_inspect(:heading)
35
39
  end
36
40
 
37
- def test_attribute_for_inspect_date
41
+ test "attribute_for_inspect with a date" do
38
42
  t = topics(:first)
39
43
 
40
- assert_equal %("#{t.written_on.to_s(:db)}"), t.attribute_for_inspect(:written_on)
44
+ assert_equal %("#{t.written_on.to_s(:inspect)}"), t.attribute_for_inspect(:written_on)
41
45
  end
42
46
 
43
- def test_attribute_for_inspect_array
47
+ test "attribute_for_inspect with an array" do
44
48
  t = topics(:first)
45
49
  t.content = [Object.new]
46
50
 
47
51
  assert_match %r(\[#<Object:0x[0-9a-f]+>\]), t.attribute_for_inspect(:content)
48
52
  end
49
53
 
50
- def test_attribute_for_inspect_long_array
54
+ test "attribute_for_inspect with a long array" do
51
55
  t = topics(:first)
52
56
  t.content = (1..11).to_a
53
57
 
54
58
  assert_equal "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]", t.attribute_for_inspect(:content)
55
59
  end
56
60
 
57
- def test_attribute_present
61
+ test "attribute_for_inspect with a non-primary key id attribute" do
62
+ t = topics(:first).becomes(TitlePrimaryKeyTopic)
63
+ t.title = "The First Topic Now Has A Title With\nNewlines And More Than 50 Characters"
64
+
65
+ assert_equal "1", t.attribute_for_inspect(:id)
66
+ end
67
+
68
+ test "attribute_present" do
58
69
  t = Topic.new
59
70
  t.title = "hello there!"
60
71
  t.written_on = Time.now
61
72
  t.author_name = ""
62
73
  assert t.attribute_present?("title")
74
+ assert t.attribute_present?("heading")
63
75
  assert t.attribute_present?("written_on")
64
- assert !t.attribute_present?("content")
65
- assert !t.attribute_present?("author_name")
76
+ assert_not t.attribute_present?("content")
77
+ assert_not t.attribute_present?("author_name")
66
78
  end
67
79
 
68
- def test_attribute_present_with_booleans
80
+ test "attribute_present with booleans" do
69
81
  b1 = Boolean.new
70
82
  b1.value = false
71
83
  assert b1.attribute_present?(:value)
@@ -75,7 +87,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
75
87
  assert b2.attribute_present?(:value)
76
88
 
77
89
  b3 = Boolean.new
78
- assert !b3.attribute_present?(:value)
90
+ assert_not b3.attribute_present?(:value)
79
91
 
80
92
  b4 = Boolean.new
81
93
  b4.value = false
@@ -83,44 +95,44 @@ class AttributeMethodsTest < ActiveRecord::TestCase
83
95
  assert Boolean.find(b4.id).attribute_present?(:value)
84
96
  end
85
97
 
86
- def test_caching_nil_primary_key
98
+ test "caching a nil primary key" do
87
99
  klass = Class.new(Minimalistic)
88
100
  assert_called(klass, :reset_primary_key, returns: nil) do
89
101
  2.times { klass.primary_key }
90
102
  end
91
103
  end
92
104
 
93
- def test_attribute_keys_on_new_instance
105
+ test "attribute keys on a new instance" do
94
106
  t = Topic.new
95
- assert_equal nil, t.title, "The topics table has a title column, so it should be nil"
107
+ assert_nil t.title, "The topics table has a title column, so it should be nil"
96
108
  assert_raise(NoMethodError) { t.title2 }
97
109
  end
98
110
 
99
- def test_boolean_attributes
100
- assert !Topic.find(1).approved?
101
- assert Topic.find(2).approved?
111
+ test "boolean attributes" do
112
+ assert_not_predicate Topic.find(1), :approved?
113
+ assert_predicate Topic.find(2), :approved?
102
114
  end
103
115
 
104
- def test_set_attributes
116
+ test "set attributes" do
105
117
  topic = Topic.find(1)
106
- topic.attributes = { "title" => "Budget", "author_name" => "Jason" }
118
+ topic.attributes = { title: "Budget", author_name: "Jason" }
107
119
  topic.save
108
120
  assert_equal("Budget", topic.title)
109
121
  assert_equal("Jason", topic.author_name)
110
122
  assert_equal(topics(:first).author_email_address, Topic.find(1).author_email_address)
111
123
  end
112
124
 
113
- def test_set_attributes_without_hash
125
+ test "set attributes without a hash" do
114
126
  topic = Topic.new
115
- assert_raise(ArgumentError) { topic.attributes = '' }
127
+ assert_raise(ArgumentError) { topic.attributes = "" }
116
128
  end
117
129
 
118
- def test_integers_as_nil
119
- test = AutoId.create('value' => '')
130
+ test "integers as nil" do
131
+ test = AutoId.create(value: "")
120
132
  assert_nil AutoId.find(test.id).value
121
133
  end
122
134
 
123
- def test_set_attributes_with_block
135
+ test "set attributes with a block" do
124
136
  topic = Topic.new do |t|
125
137
  t.title = "Budget"
126
138
  t.author_name = "Jason"
@@ -130,7 +142,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
130
142
  assert_equal("Jason", topic.author_name)
131
143
  end
132
144
 
133
- def test_respond_to?
145
+ test "respond_to?" do
134
146
  topic = Topic.find(1)
135
147
  assert_respond_to topic, "title"
136
148
  assert_respond_to topic, "title?"
@@ -140,79 +152,62 @@ class AttributeMethodsTest < ActiveRecord::TestCase
140
152
  assert_respond_to topic, :title=
141
153
  assert_respond_to topic, "author_name"
142
154
  assert_respond_to topic, "attribute_names"
143
- assert !topic.respond_to?("nothingness")
144
- assert !topic.respond_to?(:nothingness)
155
+ assert_not_respond_to topic, "nothingness"
156
+ assert_not_respond_to topic, :nothingness
145
157
  end
146
158
 
147
- def test_respond_to_with_custom_primary_key
159
+ test "respond_to? with a custom primary key" do
148
160
  keyboard = Keyboard.create
149
161
  assert_not_nil keyboard.key_number
150
162
  assert_equal keyboard.key_number, keyboard.id
151
- assert keyboard.respond_to?('key_number')
152
- assert keyboard.respond_to?('id')
163
+ assert_respond_to keyboard, "key_number"
164
+ assert_respond_to keyboard, "id"
153
165
  end
154
166
 
155
- def test_id_before_type_cast_with_custom_primary_key
167
+ test "id_before_type_cast with a custom primary key" do
156
168
  keyboard = Keyboard.create
157
- keyboard.key_number = '10'
158
- assert_equal '10', keyboard.id_before_type_cast
159
- assert_equal nil, keyboard.read_attribute_before_type_cast('id')
160
- assert_equal '10', keyboard.read_attribute_before_type_cast('key_number')
161
- assert_equal '10', keyboard.read_attribute_before_type_cast(:key_number)
169
+ keyboard.key_number = "10"
170
+ assert_equal "10", keyboard.id_before_type_cast
171
+ assert_nil keyboard.read_attribute_before_type_cast("id")
172
+ assert_equal "10", keyboard.read_attribute_before_type_cast("key_number")
173
+ assert_equal "10", keyboard.read_attribute_before_type_cast(:key_number)
162
174
  end
163
175
 
164
- # Syck calls respond_to? before actually calling initialize
165
- def test_respond_to_with_allocated_object
166
- klass = Class.new(ActiveRecord::Base) do
167
- self.table_name = 'topics'
168
- end
169
-
170
- topic = klass.allocate
171
- assert !topic.respond_to?("nothingness")
172
- assert !topic.respond_to?(:nothingness)
173
- assert_respond_to topic, "title"
174
- assert_respond_to topic, :title
175
- end
176
-
177
- # IRB inspects the return value of "MyModel.allocate".
178
- def test_allocated_object_can_be_inspected
176
+ # IRB inspects the return value of MyModel.allocate.
177
+ test "allocated objects can be inspected" do
179
178
  topic = Topic.allocate
180
179
  assert_equal "#<Topic not initialized>", topic.inspect
181
180
  end
182
181
 
183
- def test_array_content
182
+ test "array content" do
183
+ content = %w( one two three )
184
184
  topic = Topic.new
185
- topic.content = %w( one two three )
185
+ topic.content = content
186
186
  topic.save
187
187
 
188
- assert_equal(%w( one two three ), Topic.find(topic.id).content)
188
+ assert_equal content, Topic.find(topic.id).content
189
189
  end
190
190
 
191
- def test_read_attributes_before_type_cast
192
- category = Category.new({:name=>"Test category", :type => nil})
193
- category_attrs = {"name"=>"Test category", "id" => nil, "type" => nil, "categorizations_count" => nil}
194
- assert_equal category_attrs , category.attributes_before_type_cast
191
+ test "read attributes_before_type_cast" do
192
+ category = Category.new(name: "Test category", type: nil)
193
+ category_attrs = { "name" => "Test category", "id" => nil, "type" => nil, "categorizations_count" => nil }
194
+ assert_equal category_attrs, category.attributes_before_type_cast
195
195
  end
196
196
 
197
197
  if current_adapter?(:Mysql2Adapter)
198
- def test_read_attributes_before_type_cast_on_boolean
199
- bool = Boolean.create!({ "value" => false })
200
- if RUBY_PLATFORM =~ /java/
201
- # JRuby will return the value before typecast as string
202
- assert_equal "0", bool.reload.attributes_before_type_cast["value"]
203
- else
204
- assert_equal 0, bool.reload.attributes_before_type_cast["value"]
205
- end
198
+ test "read attributes_before_type_cast on a boolean" do
199
+ bool = Boolean.create!("value" => false)
200
+ assert_equal 0, bool.reload.attributes_before_type_cast["value"]
206
201
  end
207
202
  end
208
203
 
209
- def test_read_attributes_before_type_cast_on_datetime
204
+ test "read attributes_before_type_cast on a datetime" do
210
205
  in_time_zone "Pacific Time (US & Canada)" do
211
206
  record = @target.new
212
207
 
213
208
  record.written_on = "345643456"
214
209
  assert_equal "345643456", record.written_on_before_type_cast
215
- assert_equal nil, record.written_on
210
+ assert_nil record.written_on
216
211
 
217
212
  record.written_on = "2009-10-11 12:13:14"
218
213
  assert_equal "2009-10-11 12:13:14", record.written_on_before_type_cast
@@ -221,7 +216,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
221
216
  end
222
217
  end
223
218
 
224
- def test_read_attributes_after_type_cast_on_datetime
219
+ test "read attributes_after_type_cast on a date" do
225
220
  tz = "Pacific Time (US & Canada)"
226
221
 
227
222
  in_time_zone tz do
@@ -242,7 +237,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
242
237
  end
243
238
  end
244
239
 
245
- def test_hash_content
240
+ test "hash content" do
246
241
  topic = Topic.new
247
242
  topic.content = { "one" => 1, "two" => 2 }
248
243
  topic.save
@@ -256,7 +251,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
256
251
  assert_equal 3, Topic.find(topic.id).content["three"]
257
252
  end
258
253
 
259
- def test_update_array_content
254
+ test "update array content" do
260
255
  topic = Topic.new
261
256
  topic.content = %w( one two three )
262
257
 
@@ -270,55 +265,73 @@ class AttributeMethodsTest < ActiveRecord::TestCase
270
265
  assert_equal(%w( one two three four five ), topic.content)
271
266
  end
272
267
 
273
- def test_case_sensitive_attributes_hash
274
- # DB2 is not case-sensitive
275
- return true if current_adapter?(:DB2Adapter)
276
-
277
- assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.first.attributes
268
+ test "case-sensitive attributes hash" do
269
+ assert_equal @loaded_fixtures["computers"]["workstation"].to_hash, Computer.first.attributes
278
270
  end
279
271
 
280
- def test_attributes_without_primary_key
272
+ test "attributes without primary key" do
281
273
  klass = Class.new(ActiveRecord::Base) do
282
- self.table_name = 'developers_projects'
274
+ self.table_name = "developers_projects"
283
275
  end
284
276
 
285
277
  assert_equal klass.column_names, klass.new.attributes.keys
286
- assert_not klass.new.has_attribute?('id')
278
+ assert_not klass.new.has_attribute?("id")
287
279
  end
288
280
 
289
- def test_hashes_not_mangled
290
- new_topic = { :title => "New Topic" }
291
- new_topic_values = { :title => "AnotherTopic" }
281
+ test "hashes are not mangled" do
282
+ new_topic = { title: "New Topic", content: { key: "First value" } }
283
+ new_topic_values = { title: "AnotherTopic", content: { key: "Second value" } }
292
284
 
293
285
  topic = Topic.new(new_topic)
294
286
  assert_equal new_topic[:title], topic.title
287
+ assert_equal new_topic[:content], topic.content
295
288
 
296
- topic.attributes= new_topic_values
289
+ topic.attributes = new_topic_values
297
290
  assert_equal new_topic_values[:title], topic.title
291
+ assert_equal new_topic_values[:content], topic.content
298
292
  end
299
293
 
300
- def test_create_through_factory
301
- topic = Topic.create("title" => "New Topic")
294
+ test "create through factory" do
295
+ topic = Topic.create(title: "New Topic")
302
296
  topicReloaded = Topic.find(topic.id)
303
297
  assert_equal(topic, topicReloaded)
304
298
  end
305
299
 
306
- def test_write_attribute
300
+ test "write_attribute" do
307
301
  topic = Topic.new
308
- topic.send(:write_attribute, :title, "Still another topic")
302
+ topic.write_attribute :title, "Still another topic"
309
303
  assert_equal "Still another topic", topic.title
310
304
 
311
305
  topic[:title] = "Still another topic: part 2"
312
306
  assert_equal "Still another topic: part 2", topic.title
313
307
 
314
- topic.send(:write_attribute, "title", "Still another topic: part 3")
308
+ topic.write_attribute "title", "Still another topic: part 3"
315
309
  assert_equal "Still another topic: part 3", topic.title
316
310
 
317
311
  topic["title"] = "Still another topic: part 4"
318
312
  assert_equal "Still another topic: part 4", topic.title
319
313
  end
320
314
 
321
- def test_read_attribute
315
+ test "write_attribute can write aliased attributes as well" do
316
+ topic = Topic.new(title: "Don't change the topic")
317
+ topic.write_attribute :heading, "New topic"
318
+
319
+ assert_equal "New topic", topic.title
320
+ end
321
+
322
+ test "write_attribute raises ActiveModel::MissingAttributeError when the attribute does not exist" do
323
+ topic = Topic.first
324
+ assert_raises(ActiveModel::MissingAttributeError) { topic.update_columns(no_column_exists: "Hello!") }
325
+ assert_raises(ActiveModel::UnknownAttributeError) { topic.update(no_column_exists: "Hello!") }
326
+ end
327
+
328
+ test "write_attribute allows writing to aliased attributes" do
329
+ topic = Topic.first
330
+ assert_nothing_raised { topic.update_columns(heading: "Hello!") }
331
+ assert_nothing_raised { topic.update(heading: "Hello!") }
332
+ end
333
+
334
+ test "read_attribute" do
322
335
  topic = Topic.new
323
336
  topic.title = "Don't change the topic"
324
337
  assert_equal "Don't change the topic", topic.read_attribute("title")
@@ -328,23 +341,33 @@ class AttributeMethodsTest < ActiveRecord::TestCase
328
341
  assert_equal "Don't change the topic", topic[:title]
329
342
  end
330
343
 
331
- def test_read_attribute_raises_missing_attribute_error_when_not_exists
332
- computer = Computer.select('id').first
344
+ test "read_attribute can read aliased attributes as well" do
345
+ topic = Topic.new(title: "Don't change the topic")
346
+
347
+ assert_equal "Don't change the topic", topic.read_attribute("heading")
348
+ assert_equal "Don't change the topic", topic["heading"]
349
+
350
+ assert_equal "Don't change the topic", topic.read_attribute(:heading)
351
+ assert_equal "Don't change the topic", topic[:heading]
352
+ end
353
+
354
+ test "read_attribute raises ActiveModel::MissingAttributeError when the attribute does not exist" do
355
+ computer = Computer.select("id").first
333
356
  assert_raises(ActiveModel::MissingAttributeError) { computer[:developer] }
334
- assert_raises(ActiveModel::MissingAttributeError) { computer[:extendedWarranty] }
335
- assert_raises(ActiveModel::MissingAttributeError) { computer[:no_column_exists] = 'Hello!' }
336
- assert_nothing_raised { computer[:developer] = 'Hello!' }
357
+ assert_raises(ActiveModel::MissingAttributeError) { computer[:extendedwarranty] }
358
+ assert_raises(ActiveModel::MissingAttributeError) { computer[:no_column_exists] = "Hello!" }
359
+ assert_nothing_raised { computer[:developer] = "Hello!" }
337
360
  end
338
361
 
339
- def test_read_attribute_when_false
362
+ test "read_attribute when false" do
340
363
  topic = topics(:first)
341
364
  topic.approved = false
342
- assert !topic.approved?, "approved should be false"
365
+ assert_not topic.approved?, "approved should be false"
343
366
  topic.approved = "false"
344
- assert !topic.approved?, "approved should be false"
367
+ assert_not topic.approved?, "approved should be false"
345
368
  end
346
369
 
347
- def test_read_attribute_when_true
370
+ test "read_attribute when true" do
348
371
  topic = topics(:first)
349
372
  topic.approved = true
350
373
  assert topic.approved?, "approved should be true"
@@ -352,13 +375,13 @@ class AttributeMethodsTest < ActiveRecord::TestCase
352
375
  assert topic.approved?, "approved should be true"
353
376
  end
354
377
 
355
- def test_read_write_boolean_attribute
378
+ test "boolean attributes writing and reading" do
356
379
  topic = Topic.new
357
380
  topic.approved = "false"
358
- assert !topic.approved?, "approved should be false"
381
+ assert_not topic.approved?, "approved should be false"
359
382
 
360
383
  topic.approved = "false"
361
- assert !topic.approved?, "approved should be false"
384
+ assert_not topic.approved?, "approved should be false"
362
385
 
363
386
  topic.approved = "true"
364
387
  assert topic.approved?, "approved should be true"
@@ -367,26 +390,26 @@ class AttributeMethodsTest < ActiveRecord::TestCase
367
390
  assert topic.approved?, "approved should be true"
368
391
  end
369
392
 
370
- def test_overridden_write_attribute
393
+ test "overridden write_attribute" do
371
394
  topic = Topic.new
372
395
  def topic.write_attribute(attr_name, value)
373
396
  super(attr_name, value.downcase)
374
397
  end
375
398
 
376
- topic.send(:write_attribute, :title, "Yet another topic")
399
+ topic.write_attribute :title, "Yet another topic"
377
400
  assert_equal "yet another topic", topic.title
378
401
 
379
402
  topic[:title] = "Yet another topic: part 2"
380
403
  assert_equal "yet another topic: part 2", topic.title
381
404
 
382
- topic.send(:write_attribute, "title", "Yet another topic: part 3")
405
+ topic.write_attribute "title", "Yet another topic: part 3"
383
406
  assert_equal "yet another topic: part 3", topic.title
384
407
 
385
408
  topic["title"] = "Yet another topic: part 4"
386
409
  assert_equal "yet another topic: part 4", topic.title
387
410
  end
388
411
 
389
- def test_overridden_read_attribute
412
+ test "overridden read_attribute" do
390
413
  topic = Topic.new
391
414
  topic.title = "Stop changing the topic"
392
415
  def topic.read_attribute(attr_name)
@@ -400,41 +423,108 @@ class AttributeMethodsTest < ActiveRecord::TestCase
400
423
  assert_equal "STOP CHANGING THE TOPIC", topic[:title]
401
424
  end
402
425
 
403
- def test_read_overridden_attribute
404
- topic = Topic.new(:title => 'a')
405
- def topic.title() 'b' end
406
- assert_equal 'a', topic[:title]
426
+ test "read overridden attribute" do
427
+ topic = Topic.new(title: "a")
428
+ def topic.title() "b" end
429
+ assert_equal "a", topic[:title]
407
430
  end
408
431
 
409
- def test_query_attribute_string
432
+ test "string attribute predicate" do
410
433
  [nil, "", " "].each do |value|
411
- assert_equal false, Topic.new(:author_name => value).author_name?
434
+ assert_equal false, Topic.new(author_name: value).author_name?
412
435
  end
413
436
 
414
- assert_equal true, Topic.new(:author_name => "Name").author_name?
437
+ assert_equal true, Topic.new(author_name: "Name").author_name?
438
+
439
+ ActiveModel::Type::Boolean::FALSE_VALUES.each do |value|
440
+ assert_predicate Topic.new(author_name: value), :author_name?
441
+ end
415
442
  end
416
443
 
417
- def test_query_attribute_number
444
+ test "number attribute predicate" do
418
445
  [nil, 0, "0"].each do |value|
419
- assert_equal false, Developer.new(:salary => value).salary?
446
+ assert_equal false, Developer.new(salary: value).salary?
420
447
  end
421
448
 
422
- assert_equal true, Developer.new(:salary => 1).salary?
423
- assert_equal true, Developer.new(:salary => "1").salary?
449
+ assert_equal true, Developer.new(salary: 1).salary?
450
+ assert_equal true, Developer.new(salary: "1").salary?
424
451
  end
425
452
 
426
- def test_query_attribute_boolean
453
+ test "boolean attribute predicate" do
427
454
  [nil, "", false, "false", "f", 0].each do |value|
428
- assert_equal false, Topic.new(:approved => value).approved?
455
+ assert_equal false, Topic.new(approved: value).approved?
429
456
  end
430
457
 
431
458
  [true, "true", "1", 1].each do |value|
432
- assert_equal true, Topic.new(:approved => value).approved?
459
+ assert_equal true, Topic.new(approved: value).approved?
433
460
  end
434
461
  end
435
462
 
436
- def test_query_attribute_with_custom_fields
437
- object = Company.find_by_sql(<<-SQL).first
463
+ test "user-defined text attribute predicate" do
464
+ klass = Class.new(ActiveRecord::Base) do
465
+ self.table_name = Topic.table_name
466
+
467
+ attribute :user_defined_text, :text
468
+ end
469
+
470
+ topic = klass.new(user_defined_text: "text")
471
+ assert_predicate topic, :user_defined_text?
472
+
473
+ ActiveModel::Type::Boolean::FALSE_VALUES.each do |value|
474
+ topic = klass.new(user_defined_text: value)
475
+ assert_predicate topic, :user_defined_text?
476
+ end
477
+ end
478
+
479
+ test "user-defined date attribute predicate" do
480
+ klass = Class.new(ActiveRecord::Base) do
481
+ self.table_name = Topic.table_name
482
+
483
+ attribute :user_defined_date, :date
484
+ end
485
+
486
+ topic = klass.new(user_defined_date: Date.current)
487
+ assert_predicate topic, :user_defined_date?
488
+ end
489
+
490
+ test "user-defined datetime attribute predicate" do
491
+ klass = Class.new(ActiveRecord::Base) do
492
+ self.table_name = Topic.table_name
493
+
494
+ attribute :user_defined_datetime, :datetime
495
+ end
496
+
497
+ topic = klass.new(user_defined_datetime: Time.current)
498
+ assert_predicate topic, :user_defined_datetime?
499
+ end
500
+
501
+ test "user-defined time attribute predicate" do
502
+ klass = Class.new(ActiveRecord::Base) do
503
+ self.table_name = Topic.table_name
504
+
505
+ attribute :user_defined_time, :time
506
+ end
507
+
508
+ topic = klass.new(user_defined_time: Time.current)
509
+ assert_predicate topic, :user_defined_time?
510
+ end
511
+
512
+ test "user-defined json attribute predicate" do
513
+ klass = Class.new(ActiveRecord::Base) do
514
+ self.table_name = Topic.table_name
515
+
516
+ attribute :user_defined_json, :json
517
+ end
518
+
519
+ topic = klass.new(user_defined_json: { key: "value" })
520
+ assert_predicate topic, :user_defined_json?
521
+
522
+ topic = klass.new(user_defined_json: {})
523
+ assert_not_predicate topic, :user_defined_json?
524
+ end
525
+
526
+ test "custom field attribute predicate" do
527
+ object = Company.find_by_sql(<<~SQL).first
438
528
  SELECT c1.*, c2.type as string_value, c2.rating as int_value
439
529
  FROM companies c1, companies c2
440
530
  WHERE c1.firm_id = c2.id
@@ -442,107 +532,107 @@ class AttributeMethodsTest < ActiveRecord::TestCase
442
532
  SQL
443
533
 
444
534
  assert_equal "Firm", object.string_value
445
- assert object.string_value?
535
+ assert_predicate object, :string_value?
446
536
 
447
537
  object.string_value = " "
448
- assert !object.string_value?
538
+ assert_not_predicate object, :string_value?
449
539
 
450
540
  assert_equal 1, object.int_value.to_i
451
- assert object.int_value?
541
+ assert_predicate object, :int_value?
452
542
 
453
543
  object.int_value = "0"
454
- assert !object.int_value?
544
+ assert_not_predicate object, :int_value?
455
545
  end
456
546
 
457
- def test_non_attribute_access_and_assignment
547
+ test "non-attribute read and write" do
458
548
  topic = Topic.new
459
- assert !topic.respond_to?("mumbo")
549
+ assert_not_respond_to topic, "mumbo"
460
550
  assert_raise(NoMethodError) { topic.mumbo }
461
551
  assert_raise(NoMethodError) { topic.mumbo = 5 }
462
552
  end
463
553
 
464
- def test_undeclared_attribute_method_does_not_affect_respond_to_and_method_missing
465
- topic = @target.new(:title => 'Budget')
466
- assert topic.respond_to?('title')
467
- assert_equal 'Budget', topic.title
468
- assert !topic.respond_to?('title_hello_world')
554
+ test "undeclared attribute method does not affect respond_to? and method_missing" do
555
+ topic = @target.new(title: "Budget")
556
+ assert_respond_to topic, "title"
557
+ assert_equal "Budget", topic.title
558
+ assert_not_respond_to topic, "title_hello_world"
469
559
  assert_raise(NoMethodError) { topic.title_hello_world }
470
560
  end
471
561
 
472
- def test_declared_prefixed_attribute_method_affects_respond_to_and_method_missing
473
- topic = @target.new(:title => 'Budget')
562
+ test "declared prefixed attribute method affects respond_to? and method_missing" do
563
+ topic = @target.new(title: "Budget")
474
564
  %w(default_ title_).each do |prefix|
475
565
  @target.class_eval "def #{prefix}attribute(*args) args end"
476
566
  @target.attribute_method_prefix prefix
477
567
 
478
568
  meth = "#{prefix}title"
479
- assert topic.respond_to?(meth)
480
- assert_equal ['title'], topic.send(meth)
481
- assert_equal ['title', 'a'], topic.send(meth, 'a')
482
- assert_equal ['title', 1, 2, 3], topic.send(meth, 1, 2, 3)
569
+ assert_respond_to topic, meth
570
+ assert_equal ["title"], topic.public_send(meth)
571
+ assert_equal ["title", "a"], topic.public_send(meth, "a")
572
+ assert_equal ["title", 1, 2, 3], topic.public_send(meth, 1, 2, 3)
483
573
  end
484
574
  end
485
575
 
486
- def test_declared_suffixed_attribute_method_affects_respond_to_and_method_missing
576
+ test "declared suffixed attribute method affects respond_to? and method_missing" do
487
577
  %w(_default _title_default _it! _candidate= able?).each do |suffix|
488
578
  @target.class_eval "def attribute#{suffix}(*args) args end"
489
579
  @target.attribute_method_suffix suffix
490
- topic = @target.new(:title => 'Budget')
580
+ topic = @target.new(title: "Budget")
491
581
 
492
582
  meth = "title#{suffix}"
493
- assert topic.respond_to?(meth)
494
- assert_equal ['title'], topic.send(meth)
495
- assert_equal ['title', 'a'], topic.send(meth, 'a')
496
- assert_equal ['title', 1, 2, 3], topic.send(meth, 1, 2, 3)
583
+ assert_respond_to topic, meth
584
+ assert_equal ["title"], topic.public_send(meth)
585
+ assert_equal ["title", "a"], topic.public_send(meth, "a")
586
+ assert_equal ["title", 1, 2, 3], topic.public_send(meth, 1, 2, 3)
497
587
  end
498
588
  end
499
589
 
500
- def test_declared_affixed_attribute_method_affects_respond_to_and_method_missing
501
- [['mark_', '_for_update'], ['reset_', '!'], ['default_', '_value?']].each do |prefix, suffix|
590
+ test "declared affixed attribute method affects respond_to? and method_missing" do
591
+ [["mark_", "_for_update"], ["reset_", "!"], ["default_", "_value?"]].each do |prefix, suffix|
502
592
  @target.class_eval "def #{prefix}attribute#{suffix}(*args) args end"
503
- @target.attribute_method_affix({ :prefix => prefix, :suffix => suffix })
504
- topic = @target.new(:title => 'Budget')
593
+ @target.attribute_method_affix(prefix: prefix, suffix: suffix)
594
+ topic = @target.new(title: "Budget")
505
595
 
506
596
  meth = "#{prefix}title#{suffix}"
507
- assert topic.respond_to?(meth)
508
- assert_equal ['title'], topic.send(meth)
509
- assert_equal ['title', 'a'], topic.send(meth, 'a')
510
- assert_equal ['title', 1, 2, 3], topic.send(meth, 1, 2, 3)
597
+ assert_respond_to topic, meth
598
+ assert_equal ["title"], topic.public_send(meth)
599
+ assert_equal ["title", "a"], topic.public_send(meth, "a")
600
+ assert_equal ["title", 1, 2, 3], topic.public_send(meth, 1, 2, 3)
511
601
  end
512
602
  end
513
603
 
514
- def test_should_unserialize_attributes_for_frozen_records
515
- myobj = {:value1 => :value2}
516
- topic = Topic.create("content" => myobj)
604
+ test "should unserialize attributes for frozen records" do
605
+ myobj = { value1: :value2 }
606
+ topic = Topic.create(content: myobj)
517
607
  topic.freeze
518
608
  assert_equal myobj, topic.content
519
609
  end
520
610
 
521
- def test_typecast_attribute_from_select_to_false
522
- Topic.create(:title => 'Budget')
523
- # Oracle does not support boolean expressions in SELECT
524
- if current_adapter?(:OracleAdapter, :FbAdapter)
525
- topic = Topic.all.merge!(:select => "topics.*, 0 as is_test").first
611
+ test "typecast attribute from select to false" do
612
+ Topic.create(title: "Budget")
613
+ # Oracle does not support boolean expressions in SELECT.
614
+ if current_adapter?(:OracleAdapter) or current_adapter?(:IBM_DBAdapter)
615
+ topic = Topic.all.merge!(select: "topics.*, 0 as is_test").first
526
616
  else
527
- topic = Topic.all.merge!(:select => "topics.*, 1=2 as is_test").first
617
+ topic = Topic.all.merge!(select: "topics.*, 1=2 as is_test").first
528
618
  end
529
- assert !topic.is_test?
619
+ assert_not_predicate topic, :is_test?
530
620
  end
531
621
 
532
- def test_typecast_attribute_from_select_to_true
533
- Topic.create(:title => 'Budget')
534
- # Oracle does not support boolean expressions in SELECT
535
- if current_adapter?(:OracleAdapter, :FbAdapter)
536
- topic = Topic.all.merge!(:select => "topics.*, 1 as is_test").first
622
+ test "typecast attribute from select to true" do
623
+ Topic.create(title: "Budget")
624
+ # Oracle does not support boolean expressions in SELECT.
625
+ if current_adapter?(:OracleAdapter) or current_adapter?(:IBM_DBAdapter)
626
+ topic = Topic.all.merge!(select: "topics.*, 1 as is_test").first
537
627
  else
538
- topic = Topic.all.merge!(:select => "topics.*, 2=2 as is_test").first
628
+ topic = Topic.all.merge!(select: "topics.*, 2=2 as is_test").first
539
629
  end
540
- assert topic.is_test?
630
+ assert_predicate topic, :is_test?
541
631
  end
542
632
 
543
- def test_raises_dangerous_attribute_error_when_defining_activerecord_method_in_model
633
+ test "raises ActiveRecord::DangerousAttributeError when defining an AR method in a model" do
544
634
  %w(save create_or_update).each do |method|
545
- klass = Class.new ActiveRecord::Base
635
+ klass = Class.new(ActiveRecord::Base)
546
636
  klass.class_eval "def #{method}() 'defined #{method}' end"
547
637
  assert_raise ActiveRecord::DangerousAttributeError do
548
638
  klass.instance_method_already_implemented?(method)
@@ -550,7 +640,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
550
640
  end
551
641
  end
552
642
 
553
- def test_converted_values_are_returned_after_assignment
643
+ test "converted values are returned after assignment" do
554
644
  developer = Developer.new(name: 1337, salary: "50000")
555
645
 
556
646
  assert_equal "50000", developer.salary_before_type_cast
@@ -565,7 +655,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
565
655
  assert_equal "1337", developer.name
566
656
  end
567
657
 
568
- def test_write_nil_to_time_attributes
658
+ test "write nil to time attribute" do
569
659
  in_time_zone "Pacific Time (US & Canada)" do
570
660
  record = @target.new
571
661
  record.written_on = nil
@@ -573,7 +663,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
573
663
  end
574
664
  end
575
665
 
576
- def test_write_time_to_date_attributes
666
+ test "write time to date attribute" do
577
667
  in_time_zone "Pacific Time (US & Canada)" do
578
668
  record = @target.new
579
669
  record.last_read = Time.utc(2010, 1, 1, 10)
@@ -581,7 +671,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
581
671
  end
582
672
  end
583
673
 
584
- def test_time_attributes_are_retrieved_in_current_time_zone
674
+ test "time attributes are retrieved in the current time zone" do
585
675
  in_time_zone "Pacific Time (US & Canada)" do
586
676
  utc_time = Time.utc(2008, 1, 1)
587
677
  record = @target.new
@@ -593,7 +683,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
593
683
  end
594
684
  end
595
685
 
596
- def test_setting_time_zone_aware_attribute_to_utc
686
+ test "setting a time zone-aware attribute to UTC" do
597
687
  in_time_zone "Pacific Time (US & Canada)" do
598
688
  utc_time = Time.utc(2008, 1, 1)
599
689
  record = @target.new
@@ -604,11 +694,11 @@ class AttributeMethodsTest < ActiveRecord::TestCase
604
694
  end
605
695
  end
606
696
 
607
- def test_setting_time_zone_aware_attribute_in_other_time_zone
697
+ test "setting time zone-aware attribute in other time zone" do
608
698
  utc_time = Time.utc(2008, 1, 1)
609
699
  cst_time = utc_time.in_time_zone("Central Time (US & Canada)")
610
700
  in_time_zone "Pacific Time (US & Canada)" do
611
- record = @target.new
701
+ record = @target.new
612
702
  record.written_on = cst_time
613
703
  assert_equal utc_time, record.written_on
614
704
  assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
@@ -616,23 +706,23 @@ class AttributeMethodsTest < ActiveRecord::TestCase
616
706
  end
617
707
  end
618
708
 
619
- def test_setting_time_zone_aware_read_attribute
709
+ test "setting time zone-aware read attribute" do
620
710
  utc_time = Time.utc(2008, 1, 1)
621
711
  cst_time = utc_time.in_time_zone("Central Time (US & Canada)")
622
712
  in_time_zone "Pacific Time (US & Canada)" do
623
- record = @target.create(:written_on => cst_time).reload
713
+ record = @target.create(written_on: cst_time).reload
624
714
  assert_equal utc_time, record[:written_on]
625
715
  assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record[:written_on].time_zone
626
716
  assert_equal Time.utc(2007, 12, 31, 16), record[:written_on].time
627
717
  end
628
718
  end
629
719
 
630
- def test_setting_time_zone_aware_attribute_with_string
720
+ test "setting time zone-aware attribute with a string" do
631
721
  utc_time = Time.utc(2008, 1, 1)
632
722
  (-11..13).each do |timezone_offset|
633
723
  time_string = utc_time.in_time_zone(timezone_offset).to_s
634
724
  in_time_zone "Pacific Time (US & Canada)" do
635
- record = @target.new
725
+ record = @target.new
636
726
  record.written_on = time_string
637
727
  assert_equal Time.zone.parse(time_string), record.written_on
638
728
  assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
@@ -641,30 +731,30 @@ class AttributeMethodsTest < ActiveRecord::TestCase
641
731
  end
642
732
  end
643
733
 
644
- def test_time_zone_aware_attribute_saved
734
+ test "time zone-aware attribute saved" do
645
735
  in_time_zone 1 do
646
- record = @target.create(:written_on => '2012-02-20 10:00')
736
+ record = @target.create(written_on: "2012-02-20 10:00")
647
737
 
648
- record.written_on = '2012-02-20 09:00'
738
+ record.written_on = "2012-02-20 09:00"
649
739
  record.save
650
740
  assert_equal Time.zone.local(2012, 02, 20, 9), record.reload.written_on
651
741
  end
652
742
  end
653
743
 
654
- def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
744
+ test "setting a time zone-aware attribute to a blank string returns nil" do
655
745
  in_time_zone "Pacific Time (US & Canada)" do
656
- record = @target.new
657
- record.written_on = ' '
746
+ record = @target.new
747
+ record.written_on = " "
658
748
  assert_nil record.written_on
659
749
  assert_nil record[:written_on]
660
750
  end
661
751
  end
662
752
 
663
- def test_setting_time_zone_aware_attribute_interprets_time_zone_unaware_string_in_time_zone
664
- time_string = 'Tue Jan 01 00:00:00 2008'
753
+ test "setting a time zone-aware attribute interprets time zone-unaware string in time zone" do
754
+ time_string = "Tue Jan 01 00:00:00 2008"
665
755
  (-11..13).each do |timezone_offset|
666
756
  in_time_zone timezone_offset do
667
- record = @target.new
757
+ record = @target.new
668
758
  record.written_on = time_string
669
759
  assert_equal Time.zone.parse(time_string), record.written_on
670
760
  assert_equal ActiveSupport::TimeZone[timezone_offset], record.written_on.time_zone
@@ -673,10 +763,10 @@ class AttributeMethodsTest < ActiveRecord::TestCase
673
763
  end
674
764
  end
675
765
 
676
- def test_setting_time_zone_aware_datetime_in_current_time_zone
766
+ test "setting a time zone-aware datetime in the current time zone" do
677
767
  utc_time = Time.utc(2008, 1, 1)
678
768
  in_time_zone "Pacific Time (US & Canada)" do
679
- record = @target.new
769
+ record = @target.new
680
770
  record.written_on = utc_time.in_time_zone
681
771
  assert_equal utc_time, record.written_on
682
772
  assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
@@ -684,15 +774,20 @@ class AttributeMethodsTest < ActiveRecord::TestCase
684
774
  end
685
775
  end
686
776
 
687
- def test_yaml_dumping_record_with_time_zone_aware_attribute
777
+ test "YAML dumping a record with time zone-aware attribute" do
688
778
  in_time_zone "Pacific Time (US & Canada)" do
689
779
  record = Topic.new(id: 1)
690
780
  record.written_on = "Jan 01 00:00:00 2014"
691
- assert_equal record, YAML.load(YAML.dump(record))
781
+ payload = YAML.dump(record)
782
+ assert_equal record, YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(payload) : YAML.load(payload)
692
783
  end
784
+ ensure
785
+ # NOTE: Reset column info because global topics
786
+ # don't have tz-aware attributes by default.
787
+ Topic.reset_column_information
693
788
  end
694
789
 
695
- def test_setting_time_zone_aware_time_in_current_time_zone
790
+ test "setting a time zone-aware time in the current time zone" do
696
791
  in_time_zone "Pacific Time (US & Canada)" do
697
792
  record = @target.new
698
793
  time_string = "10:00:00"
@@ -702,12 +797,12 @@ class AttributeMethodsTest < ActiveRecord::TestCase
702
797
  assert_equal expected_time, record.bonus_time
703
798
  assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.bonus_time.time_zone
704
799
 
705
- record.bonus_time = ''
800
+ record.bonus_time = ""
706
801
  assert_nil record.bonus_time
707
802
  end
708
803
  end
709
804
 
710
- def test_setting_time_zone_aware_time_with_dst
805
+ test "setting a time zone-aware time with DST" do
711
806
  in_time_zone "Pacific Time (US & Canada)" do
712
807
  current_time = Time.zone.local(2014, 06, 15, 10)
713
808
  record = @target.new(bonus_time: current_time)
@@ -721,26 +816,36 @@ class AttributeMethodsTest < ActiveRecord::TestCase
721
816
  end
722
817
  end
723
818
 
724
- def test_removing_time_zone_aware_types
819
+ test "setting invalid string to a zone-aware time attribute" do
820
+ in_time_zone "Pacific Time (US & Canada)" do
821
+ record = @target.new
822
+ time_string = "ABC"
823
+
824
+ record.bonus_time = time_string
825
+ assert_nil record.bonus_time
826
+ end
827
+ end
828
+
829
+ test "removing time zone-aware types" do
725
830
  with_time_zone_aware_types(:datetime) do
726
831
  in_time_zone "Pacific Time (US & Canada)" do
727
832
  record = @target.new(bonus_time: "10:00:00")
728
833
  expected_time = Time.utc(2000, 01, 01, 10)
729
834
 
730
835
  assert_equal expected_time, record.bonus_time
731
- assert record.bonus_time.utc?
836
+ assert_predicate record.bonus_time, :utc?
732
837
  end
733
838
  end
734
839
  end
735
840
 
736
- def test_time_zone_aware_attributes_dont_recurse_infinitely_on_invalid_values
841
+ test "time zone-aware attributes do not recurse infinitely on invalid values" do
737
842
  in_time_zone "Pacific Time (US & Canada)" do
738
843
  record = @target.new(bonus_time: [])
739
- assert_equal nil, record.bonus_time
844
+ assert_nil record.bonus_time
740
845
  end
741
846
  end
742
847
 
743
- def test_setting_time_zone_conversion_for_attributes_should_write_value_on_class_variable
848
+ test "setting a time_zone_conversion_for_attributes should write the value on a class variable" do
744
849
  Topic.skip_time_zone_conversion_for_attributes = [:field_a]
745
850
  Minimalistic.skip_time_zone_conversion_for_attributes = [:field_b]
746
851
 
@@ -748,89 +853,91 @@ class AttributeMethodsTest < ActiveRecord::TestCase
748
853
  assert_equal [:field_b], Minimalistic.skip_time_zone_conversion_for_attributes
749
854
  end
750
855
 
751
- def test_read_attributes_respect_access_control
856
+ test "attribute readers respect access control" do
752
857
  privatize("title")
753
858
 
754
- topic = @target.new(:title => "The pros and cons of programming naked.")
755
- assert !topic.respond_to?(:title)
859
+ topic = @target.new(title: "The pros and cons of programming naked.")
860
+ assert_not_respond_to topic, :title
756
861
  exception = assert_raise(NoMethodError) { topic.title }
757
- assert exception.message.include?("private method")
862
+ assert_includes exception.message, "private method"
758
863
  assert_equal "I'm private", topic.send(:title)
759
864
  end
760
865
 
761
- def test_write_attributes_respect_access_control
866
+ test "attribute writers respect access control" do
762
867
  privatize("title=(value)")
763
868
 
764
869
  topic = @target.new
765
- assert !topic.respond_to?(:title=)
766
- exception = assert_raise(NoMethodError) { topic.title = "Pants"}
767
- assert exception.message.include?("private method")
870
+ assert_not_respond_to topic, :title=
871
+ exception = assert_raise(NoMethodError) { topic.title = "Pants" }
872
+ assert_includes exception.message, "private method"
768
873
  topic.send(:title=, "Very large pants")
769
874
  end
770
875
 
771
- def test_question_attributes_respect_access_control
876
+ test "attribute predicates respect access control" do
772
877
  privatize("title?")
773
878
 
774
- topic = @target.new(:title => "Isaac Newton's pants")
775
- assert !topic.respond_to?(:title?)
879
+ topic = @target.new(title: "Isaac Newton's pants")
880
+ assert_not_respond_to topic, :title?
776
881
  exception = assert_raise(NoMethodError) { topic.title? }
777
- assert exception.message.include?("private method")
882
+ assert_includes exception.message, "private method"
778
883
  assert topic.send(:title?)
779
884
  end
780
885
 
781
- def test_bulk_update_respects_access_control
886
+ test "bulk updates respect access control" do
782
887
  privatize("title=(value)")
783
888
 
784
- assert_raise(ActiveRecord::UnknownAttributeError) { @target.new(:title => "Rants about pants") }
785
- assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { :title => "Ants in pants" } }
889
+ assert_raise(ActiveRecord::UnknownAttributeError) { @target.new(title: "Rants about pants") }
890
+ assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { title: "Ants in pants" } }
786
891
  end
787
892
 
788
- def test_bulk_update_raise_unknown_attribute_error
893
+ test "bulk update raises ActiveRecord::UnknownAttributeError" do
789
894
  error = assert_raises(ActiveRecord::UnknownAttributeError) {
790
895
  Topic.new(hello: "world")
791
896
  }
792
897
  assert_instance_of Topic, error.record
793
898
  assert_equal "hello", error.attribute
794
- assert_equal "unknown attribute 'hello' for Topic.", error.message
899
+ assert_match "unknown attribute 'hello' for Topic.", error.message
795
900
  end
796
901
 
797
- def test_methods_override_in_multi_level_subclass
902
+ test "method overrides in multi-level subclasses" do
798
903
  klass = Class.new(Developer) do
799
904
  def name
800
905
  "dev:#{read_attribute(:name)}"
801
906
  end
802
907
  end
803
908
 
804
- 2.times { klass = Class.new klass }
805
- dev = klass.new(name: 'arthurnn')
909
+ 2.times { klass = Class.new(klass) }
910
+ dev = klass.new(name: "arthurnn")
806
911
  dev.save!
807
- assert_equal 'dev:arthurnn', dev.reload.name
912
+ assert_equal "dev:arthurnn", dev.reload.name
808
913
  end
809
914
 
810
- def test_global_methods_are_overwritten
915
+ test "global methods are overwritten" do
811
916
  klass = Class.new(ActiveRecord::Base) do
812
- self.table_name = 'computers'
917
+ self.table_name = "computers"
813
918
  end
814
919
 
815
- assert !klass.instance_method_already_implemented?(:system)
920
+ assert_not klass.instance_method_already_implemented?(:system)
816
921
  computer = klass.new
817
922
  assert_nil computer.system
818
923
  end
819
924
 
820
- def test_global_methods_are_overwritten_when_subclassing
821
- klass = Class.new(ActiveRecord::Base) { self.abstract_class = true }
925
+ test "global methods are overwritten when subclassing" do
926
+ klass = Class.new(ActiveRecord::Base) do
927
+ self.abstract_class = true
928
+ end
822
929
 
823
930
  subklass = Class.new(klass) do
824
- self.table_name = 'computers'
931
+ self.table_name = "computers"
825
932
  end
826
933
 
827
- assert !klass.instance_method_already_implemented?(:system)
828
- assert !subklass.instance_method_already_implemented?(:system)
934
+ assert_not klass.instance_method_already_implemented?(:system)
935
+ assert_not subklass.instance_method_already_implemented?(:system)
829
936
  computer = subklass.new
830
937
  assert_nil computer.system
831
938
  end
832
939
 
833
- def test_instance_method_should_be_defined_on_the_base_class
940
+ test "instance methods should be defined on the base class" do
834
941
  subklass = Class.new(Topic)
835
942
 
836
943
  Topic.define_attribute_methods
@@ -846,14 +953,21 @@ class AttributeMethodsTest < ActiveRecord::TestCase
846
953
  assert subklass.method_defined?(:id), "subklass is missing id method"
847
954
  end
848
955
 
849
- def test_read_attribute_with_nil_should_not_asplode
850
- assert_equal nil, Topic.new.read_attribute(nil)
956
+ test "define_attribute_method works with both symbol and string" do
957
+ klass = Class.new(ActiveRecord::Base)
958
+
959
+ assert_nothing_raised { klass.define_attribute_method(:foo) }
960
+ assert_nothing_raised { klass.define_attribute_method("bar") }
961
+ end
962
+
963
+ test "read_attribute with nil should not asplode" do
964
+ assert_nil Topic.new.read_attribute(nil)
851
965
  end
852
966
 
853
967
  # If B < A, and A defines an accessor for 'foo', we don't want to override
854
968
  # that by defining a 'foo' method in the generated methods module for B.
855
969
  # (That module will be inserted between the two, e.g. [B, <GeneratedAttributes>, A].)
856
- def test_inherited_custom_accessors
970
+ test "inherited custom accessors" do
857
971
  klass = new_topic_like_ar_class do
858
972
  self.abstract_class = true
859
973
  def title; "omg"; end
@@ -869,9 +983,9 @@ class AttributeMethodsTest < ActiveRecord::TestCase
869
983
  assert_equal "lol", topic.author_name
870
984
  end
871
985
 
872
- def test_inherited_custom_accessors_with_reserved_names
986
+ test "inherited custom accessors with reserved names" do
873
987
  klass = Class.new(ActiveRecord::Base) do
874
- self.table_name = 'computers'
988
+ self.table_name = "computers"
875
989
  self.abstract_class = true
876
990
  def system; "omg"; end
877
991
  def system=(val); self.developer = val; end
@@ -887,18 +1001,18 @@ class AttributeMethodsTest < ActiveRecord::TestCase
887
1001
  assert_equal 99, computer.developer
888
1002
  end
889
1003
 
890
- def test_on_the_fly_super_invokable_generated_attribute_methods_via_method_missing
1004
+ test "on_the_fly_super_invokable_generated_attribute_methods_via_method_missing" do
891
1005
  klass = new_topic_like_ar_class do
892
1006
  def title
893
- super + '!'
1007
+ super + "!"
894
1008
  end
895
1009
  end
896
1010
 
897
1011
  real_topic = topics(:first)
898
- assert_equal real_topic.title + '!', klass.find(real_topic.id).title
1012
+ assert_equal real_topic.title + "!", klass.find(real_topic.id).title
899
1013
  end
900
1014
 
901
- def test_on_the_fly_super_invokable_generated_predicate_attribute_methods_via_method_missing
1015
+ test "on-the-fly super-invokable generated attribute predicates via method_missing" do
902
1016
  klass = new_topic_like_ar_class do
903
1017
  def title?
904
1018
  !super
@@ -909,7 +1023,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
909
1023
  assert_equal !real_topic.title?, klass.find(real_topic.id).title?
910
1024
  end
911
1025
 
912
- def test_calling_super_when_parent_does_not_define_method_raises_error
1026
+ test "calling super when the parent does not define method raises NoMethodError" do
913
1027
  klass = new_topic_like_ar_class do
914
1028
  def some_method_that_is_not_on_super
915
1029
  super
@@ -921,46 +1035,46 @@ class AttributeMethodsTest < ActiveRecord::TestCase
921
1035
  end
922
1036
  end
923
1037
 
924
- def test_attribute_method?
1038
+ test "attribute_method?" do
925
1039
  assert @target.attribute_method?(:title)
926
1040
  assert @target.attribute_method?(:title=)
927
1041
  assert_not @target.attribute_method?(:wibble)
928
1042
  end
929
1043
 
930
- def test_attribute_method_returns_false_if_table_does_not_exist
931
- @target.table_name = 'wibble'
1044
+ test "attribute_method? returns false if the table does not exist" do
1045
+ @target.table_name = "wibble"
932
1046
  assert_not @target.attribute_method?(:title)
933
1047
  end
934
1048
 
935
- def test_attribute_names_on_new_record
1049
+ test "attribute_names on a new record" do
936
1050
  model = @target.new
937
1051
 
938
1052
  assert_equal @target.column_names, model.attribute_names
939
1053
  end
940
1054
 
941
- def test_attribute_names_on_queried_record
1055
+ test "attribute_names on a queried record" do
942
1056
  model = @target.last!
943
1057
 
944
1058
  assert_equal @target.column_names, model.attribute_names
945
1059
  end
946
1060
 
947
- def test_attribute_names_with_custom_select
948
- model = @target.select('id').last!
1061
+ test "attribute_names with a custom select" do
1062
+ model = @target.select("id").last!
949
1063
 
950
- assert_equal ['id'], model.attribute_names
951
- # Sanity check, make sure other columns exist
952
- assert_not_equal ['id'], @target.column_names
1064
+ assert_equal ["id"], model.attribute_names
1065
+ # Sanity check, make sure other columns exist.
1066
+ assert_not_equal ["id"], @target.column_names
953
1067
  end
954
1068
 
955
- def test_came_from_user
1069
+ test "came_from_user?" do
956
1070
  model = @target.first
957
1071
 
958
- assert_not model.id_came_from_user?
1072
+ assert_not_predicate model, :id_came_from_user?
959
1073
  model.id = "omg"
960
- assert model.id_came_from_user?
1074
+ assert_predicate model, :id_came_from_user?
961
1075
  end
962
1076
 
963
- def test_accessed_fields
1077
+ test "accessed_fields" do
964
1078
  model = @target.first
965
1079
 
966
1080
  assert_equal [], model.accessed_fields
@@ -970,40 +1084,41 @@ class AttributeMethodsTest < ActiveRecord::TestCase
970
1084
  assert_equal ["title"], model.accessed_fields
971
1085
  end
972
1086
 
973
- private
974
-
975
- def new_topic_like_ar_class(&block)
976
- klass = Class.new(ActiveRecord::Base) do
977
- self.table_name = 'topics'
978
- class_eval(&block)
979
- end
980
-
981
- assert_empty klass.generated_attribute_methods.instance_methods(false)
982
- klass
1087
+ test "generated attribute methods ancestors have correct module" do
1088
+ mod = Topic.send(:generated_attribute_methods)
1089
+ assert_equal "Topic::GeneratedAttributeMethods", mod.inspect
983
1090
  end
984
1091
 
985
- def with_time_zone_aware_types(*types)
986
- old_types = ActiveRecord::Base.time_zone_aware_types
987
- ActiveRecord::Base.time_zone_aware_types = types
988
- yield
989
- ensure
990
- ActiveRecord::Base.time_zone_aware_types = old_types
1092
+ test "read_attribute_before_type_cast with aliased attribute" do
1093
+ model = NumericData.new(new_bank_balance: "abcd")
1094
+ assert_equal "abcd", model.read_attribute_before_type_cast("new_bank_balance")
991
1095
  end
992
1096
 
993
- def cached_columns
994
- Topic.columns.map(&:name)
995
- end
1097
+ private
1098
+ def new_topic_like_ar_class(&block)
1099
+ klass = Class.new(ActiveRecord::Base) do
1100
+ self.table_name = "topics"
1101
+ class_eval(&block)
1102
+ end
996
1103
 
997
- def time_related_columns_on_topic
998
- Topic.columns.select { |c| [:time, :date, :datetime, :timestamp].include?(c.type) }
999
- end
1104
+ assert_empty klass.send(:generated_attribute_methods).instance_methods(false)
1105
+ klass
1106
+ end
1000
1107
 
1001
- def privatize(method_signature)
1002
- @target.class_eval(<<-private_method, __FILE__, __LINE__ + 1)
1003
- private
1004
- def #{method_signature}
1005
- "I'm private"
1006
- end
1007
- private_method
1008
- end
1108
+ def with_time_zone_aware_types(*types)
1109
+ old_types = ActiveRecord::Base.time_zone_aware_types
1110
+ ActiveRecord::Base.time_zone_aware_types = types
1111
+ yield
1112
+ ensure
1113
+ ActiveRecord::Base.time_zone_aware_types = old_types
1114
+ end
1115
+
1116
+ def privatize(method_signature)
1117
+ @target.class_eval(<<-private_method, __FILE__, __LINE__ + 1)
1118
+ private
1119
+ def #{method_signature}
1120
+ "I'm private"
1121
+ end
1122
+ private_method
1123
+ end
1009
1124
  end