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.
- checksums.yaml +4 -4
- data/CHANGES +9 -0
- data/LICENSE +55 -18
- data/README +1 -1
- data/debug.log +1 -0
- data/ext/Makefile +28 -24
- data/ext/ibm_db.c +66 -65
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +26 -24
- data/ext/ruby_ibm_db_cli.c +1 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +1520 -1282
- data/lib/ibm_db.so +1 -0
- data/lib/mswin32/ibm_db.rb +3 -1
- data/lib/mswin32/rb3x/i386/ruby30/ibm_db.so +0 -0
- data/lib/mswin32/rb3x/i386/ruby31/ibm_db.so +0 -0
- data/test/active_record/connection_adapters/fake_adapter.rb +5 -2
- data/test/activejob/destroy_association_async_test.rb +305 -0
- data/test/activejob/destroy_async_job_not_present_test.rb +31 -0
- data/test/activejob/helper.rb +15 -0
- data/test/assets/schema_dump_5_1.yml +345 -0
- data/test/cases/adapter_prevent_writes_test.rb +334 -0
- data/test/cases/adapter_test.rb +432 -218
- data/test/cases/adapters/mysql2/active_schema_test.rb +85 -75
- data/test/cases/adapters/mysql2/auto_increment_test.rb +34 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +5 -3
- data/test/cases/adapters/mysql2/boolean_test.rb +6 -4
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +26 -24
- data/test/cases/adapters/mysql2/charset_collation_test.rb +20 -17
- data/test/cases/adapters/mysql2/connection_test.rb +48 -50
- data/test/cases/adapters/mysql2/count_deleted_rows_with_lock_test.rb +28 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +23 -19
- data/test/cases/adapters/mysql2/enum_test.rb +32 -11
- data/test/cases/adapters/mysql2/explain_test.rb +13 -11
- data/test/cases/adapters/mysql2/json_test.rb +17 -188
- data/test/cases/adapters/mysql2/mysql2_adapter_prevent_writes_test.rb +208 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +183 -28
- data/test/cases/adapters/mysql2/nested_deadlock_test.rb +75 -0
- data/test/cases/adapters/mysql2/optimizer_hints_test.rb +69 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +26 -21
- data/test/cases/adapters/mysql2/schema_test.rb +24 -22
- data/test/cases/adapters/mysql2/set_test.rb +32 -0
- data/test/cases/adapters/mysql2/sp_test.rb +10 -8
- data/test/cases/adapters/mysql2/sql_types_test.rb +8 -6
- data/test/cases/adapters/mysql2/table_options_test.rb +93 -10
- data/test/cases/adapters/mysql2/transaction_test.rb +151 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +11 -9
- data/test/cases/adapters/mysql2/virtual_column_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +40 -25
- data/test/cases/adapters/postgresql/array_test.rb +118 -63
- data/test/cases/adapters/postgresql/bit_string_test.rb +12 -10
- data/test/cases/adapters/postgresql/bytea_test.rb +26 -25
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +10 -9
- data/test/cases/adapters/postgresql/change_schema_test.rb +7 -5
- data/test/cases/adapters/postgresql/cidr_test.rb +2 -0
- data/test/cases/adapters/postgresql/citext_test.rb +58 -58
- data/test/cases/adapters/postgresql/collation_test.rb +17 -15
- data/test/cases/adapters/postgresql/composite_test.rb +25 -23
- data/test/cases/adapters/postgresql/connection_test.rb +73 -85
- data/test/cases/adapters/postgresql/create_unlogged_tables_test.rb +74 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +19 -22
- data/test/cases/adapters/postgresql/date_test.rb +42 -0
- data/test/cases/adapters/postgresql/domain_test.rb +9 -7
- data/test/cases/adapters/postgresql/enum_test.rb +12 -10
- data/test/cases/adapters/postgresql/explain_test.rb +10 -8
- data/test/cases/adapters/postgresql/extension_migration_test.rb +13 -12
- data/test/cases/adapters/postgresql/foreign_table_test.rb +109 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +8 -6
- data/test/cases/adapters/postgresql/geometric_test.rb +57 -63
- data/test/cases/adapters/postgresql/hstore_test.rb +288 -280
- data/test/cases/adapters/postgresql/infinity_test.rb +54 -15
- data/test/cases/adapters/postgresql/integer_test.rb +2 -0
- data/test/cases/adapters/postgresql/interval_test.rb +99 -0
- data/test/cases/adapters/postgresql/json_test.rb +16 -201
- data/test/cases/adapters/postgresql/ltree_test.rb +14 -16
- data/test/cases/adapters/postgresql/money_test.rb +47 -16
- data/test/cases/adapters/postgresql/network_test.rb +36 -28
- data/test/cases/adapters/postgresql/numbers_test.rb +7 -5
- data/test/cases/adapters/postgresql/optimizer_hints_test.rb +71 -0
- data/test/cases/adapters/postgresql/partitions_test.rb +22 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_prevent_writes_test.rb +205 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +178 -136
- data/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb +27 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +12 -6
- data/test/cases/adapters/postgresql/range_test.rb +406 -292
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +16 -15
- data/test/cases/adapters/postgresql/rename_table_test.rb +9 -8
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +14 -23
- data/test/cases/adapters/postgresql/schema_test.rb +207 -91
- data/test/cases/adapters/postgresql/serial_test.rb +9 -7
- data/test/cases/adapters/postgresql/statement_pool_test.rb +26 -6
- data/test/cases/adapters/postgresql/timestamp_test.rb +17 -15
- data/test/cases/adapters/postgresql/transaction_nested_test.rb +114 -0
- data/test/cases/adapters/postgresql/transaction_test.rb +189 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +12 -10
- data/test/cases/adapters/postgresql/utils_test.rb +11 -9
- data/test/cases/adapters/postgresql/uuid_test.rb +226 -109
- data/test/cases/adapters/postgresql/xml_test.rb +10 -14
- data/test/cases/adapters/sqlite3/collation_test.rb +26 -15
- data/test/cases/adapters/sqlite3/copy_table_test.rb +31 -28
- data/test/cases/adapters/sqlite3/explain_test.rb +13 -11
- data/test/cases/adapters/sqlite3/json_test.rb +29 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +35 -57
- data/test/cases/adapters/sqlite3/sqlite3_adapter_prevent_writes_test.rb +186 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +318 -131
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +11 -11
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +7 -6
- data/test/cases/adapters/sqlite3/transaction_test.rb +123 -0
- data/test/cases/aggregations_test.rb +14 -12
- data/test/cases/annotate_test.rb +46 -0
- data/test/cases/ar_schema_test.rb +153 -86
- data/test/cases/arel/attributes/attribute_test.rb +1145 -0
- data/test/cases/arel/attributes/math_test.rb +83 -0
- data/test/cases/arel/attributes_test.rb +27 -0
- data/test/cases/arel/collectors/bind_test.rb +40 -0
- data/test/cases/arel/collectors/composite_test.rb +47 -0
- data/test/cases/arel/collectors/sql_string_test.rb +41 -0
- data/test/cases/arel/collectors/substitute_bind_collector_test.rb +48 -0
- data/test/cases/arel/crud_test.rb +65 -0
- data/test/cases/arel/delete_manager_test.rb +53 -0
- data/test/cases/arel/factory_methods_test.rb +46 -0
- data/test/cases/arel/helper.rb +45 -0
- data/test/cases/arel/insert_manager_test.rb +241 -0
- data/test/cases/arel/nodes/and_test.rb +30 -0
- data/test/cases/arel/nodes/as_test.rb +36 -0
- data/test/cases/arel/nodes/ascending_test.rb +46 -0
- data/test/cases/arel/nodes/bin_test.rb +35 -0
- data/test/cases/arel/nodes/binary_test.rb +29 -0
- data/test/cases/arel/nodes/bind_param_test.rb +22 -0
- data/test/cases/arel/nodes/case_test.rb +96 -0
- data/test/cases/arel/nodes/casted_test.rb +18 -0
- data/test/cases/arel/nodes/comment_test.rb +22 -0
- data/test/cases/arel/nodes/count_test.rb +35 -0
- data/test/cases/arel/nodes/delete_statement_test.rb +36 -0
- data/test/cases/arel/nodes/descending_test.rb +46 -0
- data/test/cases/arel/nodes/distinct_test.rb +21 -0
- data/test/cases/arel/nodes/equality_test.rb +62 -0
- data/test/cases/arel/nodes/extract_test.rb +43 -0
- data/test/cases/arel/nodes/false_test.rb +21 -0
- data/test/cases/arel/nodes/grouping_test.rb +26 -0
- data/test/cases/arel/nodes/infix_operation_test.rb +42 -0
- data/test/cases/arel/nodes/insert_statement_test.rb +44 -0
- data/test/cases/arel/nodes/named_function_test.rb +48 -0
- data/test/cases/arel/nodes/node_test.rb +22 -0
- data/test/cases/arel/nodes/not_test.rb +31 -0
- data/test/cases/arel/nodes/or_test.rb +36 -0
- data/test/cases/arel/nodes/over_test.rb +69 -0
- data/test/cases/arel/nodes/select_core_test.rb +79 -0
- data/test/cases/arel/nodes/select_statement_test.rb +51 -0
- data/test/cases/arel/nodes/sql_literal_test.rb +75 -0
- data/test/cases/arel/nodes/sum_test.rb +35 -0
- data/test/cases/arel/nodes/table_alias_test.rb +29 -0
- data/test/cases/arel/nodes/true_test.rb +21 -0
- data/test/cases/arel/nodes/unary_operation_test.rb +41 -0
- data/test/cases/arel/nodes/update_statement_test.rb +60 -0
- data/test/cases/arel/nodes/window_test.rb +81 -0
- data/test/cases/arel/nodes_test.rb +34 -0
- data/test/cases/arel/select_manager_test.rb +1238 -0
- data/test/cases/arel/support/fake_record.rb +135 -0
- data/test/cases/arel/table_test.rb +216 -0
- data/test/cases/arel/update_manager_test.rb +126 -0
- data/test/cases/arel/visitors/dispatch_contamination_test.rb +78 -0
- data/test/cases/arel/visitors/dot_test.rb +90 -0
- data/test/cases/arel/visitors/mysql_test.rb +157 -0
- data/test/cases/arel/visitors/postgres_test.rb +366 -0
- data/test/cases/arel/visitors/sqlite_test.rb +75 -0
- data/test/cases/arel/visitors/to_sql_test.rb +750 -0
- data/test/cases/associations/belongs_to_associations_test.rb +510 -158
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +4 -2
- data/test/cases/associations/callbacks_test.rb +56 -38
- data/test/cases/associations/cascaded_eager_loading_test.rb +118 -61
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +138 -18
- data/test/cases/associations/eager_load_nested_include_test.rb +38 -37
- data/test/cases/associations/eager_singularization_test.rb +21 -21
- data/test/cases/associations/eager_test.rb +559 -415
- data/test/cases/associations/extension_test.rb +18 -12
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +234 -213
- data/test/cases/associations/has_many_associations_test.rb +1038 -465
- data/test/cases/associations/has_many_through_associations_test.rb +558 -249
- data/test/cases/associations/has_one_associations_test.rb +294 -129
- data/test/cases/associations/has_one_through_associations_test.rb +121 -75
- data/test/cases/associations/inner_join_association_test.rb +114 -38
- data/test/cases/associations/inverse_associations_test.rb +606 -398
- data/test/cases/associations/join_model_test.rb +158 -148
- data/test/cases/associations/left_outer_join_association_test.rb +59 -24
- data/test/cases/associations/nested_through_associations_test.rb +166 -109
- data/test/cases/associations/required_test.rb +35 -10
- data/test/cases/associations_test.rb +241 -110
- data/test/cases/attribute_methods/read_test.rb +11 -11
- data/test/cases/attribute_methods_test.rb +413 -298
- data/test/cases/attributes_test.rb +145 -27
- data/test/cases/autosave_association_test.rb +681 -436
- data/test/cases/base_prevent_writes_test.rb +229 -0
- data/test/cases/base_test.rb +599 -542
- data/test/cases/batches_test.rb +288 -82
- data/test/cases/binary_test.rb +26 -31
- data/test/cases/bind_parameter_test.rb +194 -21
- data/test/cases/boolean_test.rb +52 -0
- data/test/cases/cache_key_test.rb +110 -5
- data/test/cases/calculations_test.rb +740 -177
- data/test/cases/callbacks_test.rb +74 -207
- data/test/cases/clone_test.rb +15 -10
- data/test/cases/coders/json_test.rb +2 -0
- data/test/cases/coders/yaml_column_test.rb +16 -13
- data/test/cases/collection_cache_key_test.rb +177 -20
- data/test/cases/column_alias_test.rb +9 -7
- data/test/cases/column_definition_test.rb +10 -68
- data/test/cases/comment_test.rb +166 -107
- data/test/cases/connection_adapters/adapter_leasing_test.rb +14 -10
- data/test/cases/connection_adapters/connection_handler_test.rb +358 -51
- data/test/cases/connection_adapters/connection_handlers_multi_db_test.rb +400 -0
- data/test/cases/connection_adapters/connection_handlers_multi_pool_config_test.rb +103 -0
- data/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb +499 -0
- data/test/cases/connection_adapters/connection_swapping_nested_test.rb +457 -0
- data/test/cases/connection_adapters/legacy_connection_handlers_multi_db_test.rb +486 -0
- data/test/cases/connection_adapters/legacy_connection_handlers_sharding_db_test.rb +586 -0
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +319 -138
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +62 -50
- data/test/cases/connection_adapters/schema_cache_test.rb +259 -26
- data/test/cases/connection_adapters/type_lookup_test.rb +96 -95
- data/test/cases/connection_management_test.rb +13 -11
- data/test/cases/connection_pool_test.rb +316 -83
- data/test/cases/core_test.rb +82 -58
- data/test/cases/counter_cache_test.rb +204 -50
- data/test/cases/custom_locking_test.rb +5 -3
- data/test/cases/database_configurations/hash_config_test.rb +74 -0
- data/test/cases/database_configurations/resolver_test.rb +150 -0
- data/test/cases/database_configurations_test.rb +145 -0
- data/test/cases/database_selector_test.rb +296 -0
- data/test/cases/database_statements_test.rb +18 -16
- data/test/cases/date_test.rb +8 -16
- data/test/cases/date_time_precision_test.rb +100 -78
- data/test/cases/date_time_test.rb +23 -8
- data/test/cases/defaults_test.rb +106 -71
- data/test/cases/delegated_type_test.rb +57 -0
- data/test/cases/dirty_test.rb +419 -223
- data/test/cases/disconnected_test.rb +6 -6
- data/test/cases/dup_test.rb +54 -27
- data/test/cases/enum_test.rb +461 -82
- data/test/cases/errors_test.rb +7 -7
- data/test/cases/explain_subscriber_test.rb +17 -15
- data/test/cases/explain_test.rb +11 -19
- data/test/cases/filter_attributes_test.rb +153 -0
- data/test/cases/finder_respond_to_test.rb +14 -14
- data/test/cases/finder_test.rb +669 -287
- data/test/cases/fixture_set/file_test.rb +34 -38
- data/test/cases/fixtures_test.rb +833 -176
- data/test/cases/forbidden_attributes_protection_test.rb +32 -67
- data/test/cases/habtm_destroy_order_test.rb +25 -25
- data/test/cases/helper.rb +78 -49
- data/test/cases/hot_compatibility_test.rb +33 -32
- data/test/cases/i18n_test.rb +18 -17
- data/test/cases/inheritance_test.rb +180 -115
- data/test/cases/insert_all_test.rb +489 -0
- data/test/cases/instrumentation_test.rb +101 -0
- data/test/cases/integration_test.rb +119 -31
- data/test/cases/invalid_connection_test.rb +18 -16
- data/test/cases/invertible_migration_test.rb +183 -43
- data/test/cases/json_attribute_test.rb +35 -0
- data/test/cases/json_serialization_test.rb +57 -58
- data/test/cases/json_shared_test_cases.rb +290 -0
- data/test/cases/locking_test.rb +413 -119
- data/test/cases/log_subscriber_test.rb +68 -26
- data/test/cases/marshal_serialization_test.rb +39 -0
- data/test/cases/migration/change_schema_test.rb +118 -72
- data/test/cases/migration/change_table_test.rb +138 -30
- data/test/cases/migration/check_constraint_test.rb +162 -0
- data/test/cases/migration/column_attributes_test.rb +45 -35
- data/test/cases/migration/column_positioning_test.rb +18 -6
- data/test/cases/migration/columns_test.rb +93 -77
- data/test/cases/migration/command_recorder_test.rb +121 -34
- data/test/cases/migration/compatibility_test.rb +578 -23
- data/test/cases/migration/create_join_table_test.rb +35 -25
- data/test/cases/migration/foreign_key_test.rb +503 -284
- data/test/cases/migration/helper.rb +4 -3
- data/test/cases/migration/index_test.rb +119 -70
- data/test/cases/migration/logger_test.rb +9 -6
- data/test/cases/migration/pending_migrations_test.rb +88 -34
- data/test/cases/migration/references_foreign_key_test.rb +164 -150
- data/test/cases/migration/references_index_test.rb +38 -19
- data/test/cases/migration/references_statements_test.rb +15 -14
- data/test/cases/migration/rename_table_test.rb +53 -30
- data/test/cases/migration_test.rb +637 -269
- data/test/cases/migrator_test.rb +191 -135
- data/test/cases/mixin_test.rb +7 -11
- data/test/cases/modules_test.rb +36 -34
- data/test/cases/multi_db_migrator_test.rb +223 -0
- data/test/cases/multiparameter_attributes_test.rb +60 -33
- data/test/cases/multiple_db_test.rb +16 -22
- data/test/cases/nested_attributes_test.rb +341 -320
- data/test/cases/nested_attributes_with_callbacks_test.rb +26 -24
- data/test/cases/null_relation_test.rb +84 -0
- data/test/cases/numeric_data_test.rb +93 -0
- data/test/cases/persistence_test.rb +361 -269
- data/test/cases/pooled_connections_test.rb +18 -26
- data/test/cases/prepared_statement_status_test.rb +48 -0
- data/test/cases/primary_keys_test.rb +210 -104
- data/test/cases/query_cache_test.rb +610 -141
- data/test/cases/quoting_test.rb +132 -31
- data/test/cases/readonly_test.rb +49 -48
- data/test/cases/reaper_test.rb +146 -32
- data/test/cases/reflection_test.rb +167 -156
- data/test/cases/relation/delegation_test.rb +49 -36
- data/test/cases/relation/delete_all_test.rb +117 -0
- data/test/cases/relation/merging_test.rb +319 -42
- data/test/cases/relation/mutation_test.rb +55 -93
- data/test/cases/relation/or_test.rb +129 -29
- data/test/cases/relation/predicate_builder_test.rb +21 -6
- data/test/cases/relation/record_fetch_warning_test.rb +5 -3
- data/test/cases/relation/select_test.rb +67 -0
- data/test/cases/relation/update_all_test.rb +317 -0
- data/test/cases/relation/where_chain_test.rb +68 -32
- data/test/cases/relation/where_clause_test.rb +136 -61
- data/test/cases/relation/where_test.rb +155 -48
- data/test/cases/relation_test.rb +266 -112
- data/test/cases/relations_test.rb +969 -744
- data/test/cases/reload_models_test.rb +13 -9
- data/test/cases/reserved_word_test.rb +141 -0
- data/test/cases/result_test.rb +68 -17
- data/test/cases/sanitize_test.rb +87 -71
- data/test/cases/schema_dumper_test.rb +221 -128
- data/test/cases/schema_loading_test.rb +3 -2
- data/test/cases/scoping/default_scoping_test.rb +185 -144
- data/test/cases/scoping/named_scoping_test.rb +177 -89
- data/test/cases/scoping/relation_scoping_test.rb +197 -75
- data/test/cases/secure_token_test.rb +18 -3
- data/test/cases/serialization_test.rb +30 -28
- data/test/cases/serialized_attribute_test.rb +133 -42
- data/test/cases/signed_id_test.rb +168 -0
- data/test/cases/statement_cache_test.rb +41 -24
- data/test/cases/statement_invalid_test.rb +42 -0
- data/test/cases/store_test.rb +180 -55
- data/test/cases/strict_loading_test.rb +473 -0
- data/test/cases/suppressor_test.rb +26 -12
- data/test/cases/tasks/database_tasks_test.rb +1258 -194
- data/test/cases/tasks/mysql_rake_test.rb +370 -298
- data/test/cases/tasks/postgresql_rake_test.rb +481 -251
- data/test/cases/tasks/sqlite_rake_test.rb +225 -178
- data/test/cases/test_case.rb +51 -40
- data/test/cases/test_databases_test.rb +79 -0
- data/test/cases/test_fixtures_test.rb +79 -19
- data/test/cases/time_precision_test.rb +98 -76
- data/test/cases/timestamp_test.rb +102 -99
- data/test/cases/touch_later_test.rb +12 -10
- data/test/cases/transaction_callbacks_test.rb +344 -90
- data/test/cases/transaction_isolation_test.rb +12 -12
- data/test/cases/transactions_test.rb +612 -162
- data/test/cases/type/adapter_specific_registry_test.rb +14 -2
- data/test/cases/type/date_time_test.rb +4 -2
- data/test/cases/type/integer_test.rb +4 -2
- data/test/cases/type/string_test.rb +10 -8
- data/test/cases/type/time_test.rb +28 -0
- data/test/cases/type/type_map_test.rb +29 -28
- data/test/cases/type/unsigned_integer_test.rb +19 -0
- data/test/cases/type_test.rb +2 -0
- data/test/cases/types_test.rb +3 -1
- data/test/cases/unconnected_test.rb +14 -1
- data/test/cases/unsafe_raw_sql_test.rb +274 -0
- data/test/cases/validations/absence_validation_test.rb +19 -17
- data/test/cases/validations/association_validation_test.rb +30 -28
- data/test/cases/validations/i18n_generate_message_validation_test.rb +34 -16
- data/test/cases/validations/i18n_validation_test.rb +22 -21
- data/test/cases/validations/length_validation_test.rb +34 -33
- data/test/cases/validations/numericality_validation_test.rb +181 -0
- data/test/cases/validations/presence_validation_test.rb +21 -19
- data/test/cases/validations/uniqueness_validation_test.rb +156 -86
- data/test/cases/validations_repair_helper.rb +2 -0
- data/test/cases/validations_test.rb +61 -26
- data/test/cases/view_test.rb +122 -116
- data/test/cases/yaml_serialization_test.rb +79 -34
- data/test/config.example.yml +19 -19
- data/test/config.rb +3 -1
- data/test/config.yml +16 -6
- data/test/fixtures/all/namespaced/accounts.yml +2 -0
- data/test/fixtures/author_addresses.yml +1 -8
- data/test/fixtures/authors.yml +1 -7
- data/test/fixtures/binaries.yml +4 -0
- data/test/fixtures/books.yml +9 -2
- data/test/fixtures/categories_posts.yml +3 -0
- data/test/fixtures/citations.yml +5 -0
- data/test/fixtures/comments.yml +7 -0
- data/test/fixtures/companies.yml +5 -0
- data/test/fixtures/computers.yml +2 -0
- data/test/fixtures/customers.yml +10 -1
- data/test/fixtures/developers.yml +1 -1
- data/test/fixtures/essays.yml +10 -0
- data/test/fixtures/faces.yml +3 -3
- data/test/fixtures/humans.yml +5 -0
- data/test/fixtures/interests.yml +7 -7
- data/test/fixtures/memberships.yml +7 -0
- data/test/fixtures/minimalistics.yml +3 -0
- data/test/fixtures/mixed_case_monkeys.yml +2 -2
- data/test/fixtures/naked/yml/courses_with_invalid_key.yml +3 -0
- data/test/fixtures/naked/yml/parrots.yml +1 -0
- data/test/fixtures/other_books.yml +26 -0
- data/test/fixtures/other_posts.yml +1 -0
- data/test/fixtures/parrots.yml +7 -1
- data/test/fixtures/pirates.yml +3 -0
- data/test/fixtures/posts.yml +11 -3
- data/test/fixtures/readers.yml +6 -0
- data/test/fixtures/reserved_words/values.yml +2 -2
- data/test/fixtures/sponsors.yml +3 -0
- data/test/fixtures/strict_zines.yml +2 -0
- data/test/fixtures/subscribers.yml +1 -1
- data/test/fixtures/tasks.yml +1 -1
- data/test/fixtures/warehouse-things.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +2 -0
- data/test/migrations/decimal/1_give_me_big_numbers.rb +6 -4
- data/test/migrations/magic/1_currencies_have_symbols.rb +3 -2
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -0
- data/test/migrations/missing/1_people_have_last_names.rb +2 -0
- data/test/migrations/missing/3_we_need_reminders.rb +2 -0
- data/test/migrations/missing/4_innocent_jointable.rb +3 -1
- data/test/migrations/rename/1_we_need_things.rb +2 -0
- data/test/migrations/rename/2_rename_things.rb +2 -0
- data/test/migrations/to_copy/1_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +3 -1
- data/test/migrations/to_copy2/1_create_articles.rb +2 -0
- data/test/migrations/to_copy2/2_create_comments.rb +3 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +3 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +2 -0
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +2 -0
- data/test/migrations/valid/1_valid_people_have_last_names.rb +2 -0
- data/test/migrations/valid/2_we_need_reminders.rb +2 -0
- data/test/migrations/valid/3_innocent_jointable.rb +3 -1
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +2 -0
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -0
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +3 -1
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +2 -0
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +2 -0
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +3 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +2 -0
- data/test/models/account.rb +46 -0
- data/test/models/admin/account.rb +3 -1
- data/test/models/admin/randomly_named_c1.rb +2 -0
- data/test/models/admin/user.rb +16 -8
- data/test/models/admin.rb +4 -2
- data/test/models/aircraft.rb +3 -1
- data/test/models/arunit2_model.rb +2 -0
- data/test/models/author.rb +153 -102
- data/test/models/auto_id.rb +2 -0
- data/test/models/autoloadable/extra_firm.rb +2 -0
- data/test/models/binary.rb +3 -1
- data/test/models/binary_field.rb +6 -0
- data/test/models/bird.rb +13 -1
- data/test/models/book.rb +14 -4
- data/test/models/book_destroy_async.rb +24 -0
- data/test/models/boolean.rb +5 -0
- data/test/models/bulb.rb +13 -4
- data/test/models/cake_designer.rb +2 -0
- data/test/models/car.rb +17 -10
- data/test/models/carrier.rb +2 -0
- data/test/models/cart.rb +5 -0
- data/test/models/cat.rb +2 -0
- data/test/models/categorization.rb +8 -6
- data/test/models/category.rb +28 -16
- data/test/models/chef.rb +2 -0
- data/test/models/citation.rb +5 -1
- data/test/models/club.rb +13 -10
- data/test/models/college.rb +4 -2
- data/test/models/column.rb +2 -0
- data/test/models/column_name.rb +2 -0
- data/test/models/comment.rb +32 -10
- data/test/models/company.rb +102 -106
- data/test/models/company_in_module.rb +27 -26
- data/test/models/computer.rb +3 -1
- data/test/models/contact.rb +15 -13
- data/test/models/content.rb +5 -3
- data/test/models/contract.rb +21 -3
- data/test/models/country.rb +2 -4
- data/test/models/course.rb +3 -1
- data/test/models/customer.rb +10 -8
- data/test/models/customer_carrier.rb +2 -0
- data/test/models/dashboard.rb +2 -0
- data/test/models/default.rb +2 -0
- data/test/models/department.rb +2 -0
- data/test/models/destroy_async_parent.rb +15 -0
- data/test/models/destroy_async_parent_soft_delete.rb +20 -0
- data/test/models/developer.rb +152 -85
- data/test/models/dl_keyed_belongs_to.rb +13 -0
- data/test/models/dl_keyed_belongs_to_soft_delete.rb +19 -0
- data/test/models/dl_keyed_has_many.rb +5 -0
- data/test/models/dl_keyed_has_many_through.rb +5 -0
- data/test/models/dl_keyed_has_one.rb +5 -0
- data/test/models/dl_keyed_join.rb +10 -0
- data/test/models/dog.rb +2 -0
- data/test/models/dog_lover.rb +2 -0
- data/test/models/doubloon.rb +3 -1
- data/test/models/drink_designer.rb +17 -0
- data/test/models/edge.rb +4 -2
- data/test/models/electron.rb +2 -0
- data/test/models/engine.rb +3 -2
- data/test/models/entrant.rb +2 -0
- data/test/models/entry.rb +5 -0
- data/test/models/essay.rb +6 -3
- data/test/models/essay_destroy_async.rb +12 -0
- data/test/models/event.rb +3 -1
- data/test/models/eye.rb +5 -3
- data/test/models/face.rb +14 -6
- data/test/models/family.rb +6 -0
- data/test/models/family_tree.rb +6 -0
- data/test/models/friendship.rb +5 -3
- data/test/models/frog.rb +8 -0
- data/test/models/guid.rb +3 -1
- data/test/models/guitar.rb +2 -0
- data/test/models/hotel.rb +5 -3
- data/test/models/human.rb +39 -0
- data/test/models/image.rb +3 -1
- data/test/models/interest.rb +14 -3
- data/test/models/invoice.rb +4 -2
- data/test/models/item.rb +3 -1
- data/test/models/job.rb +5 -3
- data/test/models/joke.rb +4 -2
- data/test/models/keyboard.rb +3 -1
- data/test/models/legacy_thing.rb +2 -0
- data/test/models/lesson.rb +2 -0
- data/test/models/line_item.rb +3 -1
- data/test/models/liquid.rb +2 -0
- data/test/models/matey.rb +3 -1
- data/test/models/measurement.rb +4 -0
- data/test/models/member.rb +23 -20
- data/test/models/member_detail.rb +3 -0
- data/test/models/member_type.rb +2 -0
- data/test/models/membership.rb +4 -1
- data/test/models/mentor.rb +3 -1
- data/test/models/message.rb +5 -0
- data/test/models/minimalistic.rb +2 -0
- data/test/models/minivan.rb +3 -2
- data/test/models/mixed_case_monkey.rb +3 -1
- data/test/models/molecule.rb +2 -0
- data/test/models/mouse.rb +6 -0
- data/test/models/movie.rb +2 -0
- data/test/models/node.rb +4 -2
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +2 -0
- data/test/models/numeric_data.rb +12 -0
- data/test/models/order.rb +4 -2
- data/test/models/organization.rb +9 -7
- data/test/models/other_dog.rb +3 -1
- data/test/models/owner.rb +6 -4
- data/test/models/parrot.rb +12 -4
- data/test/models/person.rb +59 -54
- data/test/models/personal_legacy_thing.rb +3 -1
- data/test/models/pet.rb +4 -2
- data/test/models/pet_treasure.rb +2 -0
- data/test/models/pirate.rb +67 -43
- data/test/models/possession.rb +3 -1
- data/test/models/post.rb +184 -86
- data/test/models/price_estimate.rb +11 -1
- data/test/models/professor.rb +3 -1
- data/test/models/project.rb +14 -12
- data/test/models/publisher/article.rb +2 -0
- data/test/models/publisher/magazine.rb +2 -0
- data/test/models/publisher.rb +2 -0
- data/test/models/randomly_named_c1.rb +2 -0
- data/test/models/rating.rb +5 -1
- data/test/models/reader.rb +7 -5
- data/test/models/recipe.rb +2 -0
- data/test/models/record.rb +2 -0
- data/test/models/reference.rb +6 -3
- data/test/models/reply.rb +39 -21
- data/test/models/room.rb +6 -0
- data/test/models/section.rb +6 -0
- data/test/models/seminar.rb +6 -0
- data/test/models/session.rb +6 -0
- data/test/models/ship.rb +12 -9
- data/test/models/ship_part.rb +5 -3
- data/test/models/shop.rb +4 -2
- data/test/models/shop_account.rb +2 -0
- data/test/models/speedometer.rb +2 -0
- data/test/models/sponsor.rb +8 -5
- data/test/models/squeak.rb +6 -0
- data/test/models/strict_zine.rb +7 -0
- data/test/models/string_key_object.rb +2 -0
- data/test/models/student.rb +2 -0
- data/test/models/subscriber.rb +4 -2
- data/test/models/subscription.rb +5 -1
- data/test/models/tag.rb +6 -3
- data/test/models/tagging.rb +13 -6
- data/test/models/task.rb +2 -0
- data/test/models/topic.rb +54 -19
- data/test/models/toy.rb +4 -0
- data/test/models/traffic_light.rb +2 -0
- data/test/models/treasure.rb +5 -3
- data/test/models/treaty.rb +2 -4
- data/test/models/tree.rb +2 -0
- data/test/models/tuning_peg.rb +2 -0
- data/test/models/tyre.rb +2 -0
- data/test/models/user.rb +12 -4
- data/test/models/uuid_child.rb +2 -0
- data/test/models/uuid_item.rb +2 -0
- data/test/models/uuid_parent.rb +2 -0
- data/test/models/vegetables.rb +12 -3
- data/test/models/vertex.rb +6 -4
- data/test/models/warehouse_thing.rb +2 -0
- data/test/models/wheel.rb +3 -1
- data/test/models/without_table.rb +3 -1
- data/test/models/zine.rb +3 -1
- data/test/schema/mysql2_specific_schema.rb +49 -35
- data/test/schema/oracle_specific_schema.rb +13 -15
- data/test/schema/postgresql_specific_schema.rb +51 -40
- data/test/schema/schema.rb +334 -154
- data/test/schema/sqlite_specific_schema.rb +9 -16
- data/test/support/config.rb +26 -26
- data/test/support/connection.rb +14 -8
- data/test/support/connection_helper.rb +3 -1
- data/test/support/ddl_helper.rb +2 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/legacy_relation.dump +0 -0
- data/test/support/schema_dumping_helper.rb +2 -0
- data/test/support/stubs/strong_parameters.rb +40 -0
- data/test/support/yaml_compatibility_fixtures/rails_v1_mysql.yml +206 -0
- data/test/support/yaml_compatibility_fixtures/rails_v2.yml +55 -0
- metadata +192 -14
@@ -1,15 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "cases/helper"
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
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 =
|
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
|
-
|
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
|
-
|
41
|
+
test "attribute_for_inspect with a date" do
|
38
42
|
t = topics(:first)
|
39
43
|
|
40
|
-
assert_equal %("#{t.written_on.to_s(:
|
44
|
+
assert_equal %("#{t.written_on.to_s(:inspect)}"), t.attribute_for_inspect(:written_on)
|
41
45
|
end
|
42
46
|
|
43
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
65
|
-
|
76
|
+
assert_not t.attribute_present?("content")
|
77
|
+
assert_not t.attribute_present?("author_name")
|
66
78
|
end
|
67
79
|
|
68
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
105
|
+
test "attribute keys on a new instance" do
|
94
106
|
t = Topic.new
|
95
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
116
|
+
test "set attributes" do
|
105
117
|
topic = Topic.find(1)
|
106
|
-
topic.attributes = {
|
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
|
-
|
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
|
-
|
119
|
-
test = AutoId.create(
|
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
|
-
|
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
|
-
|
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
|
-
|
144
|
-
|
155
|
+
assert_not_respond_to topic, "nothingness"
|
156
|
+
assert_not_respond_to topic, :nothingness
|
145
157
|
end
|
146
158
|
|
147
|
-
|
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
|
-
|
152
|
-
|
163
|
+
assert_respond_to keyboard, "key_number"
|
164
|
+
assert_respond_to keyboard, "id"
|
153
165
|
end
|
154
166
|
|
155
|
-
|
167
|
+
test "id_before_type_cast with a custom primary key" do
|
156
168
|
keyboard = Keyboard.create
|
157
|
-
keyboard.key_number =
|
158
|
-
assert_equal
|
159
|
-
|
160
|
-
assert_equal
|
161
|
-
assert_equal
|
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
|
-
#
|
165
|
-
|
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
|
-
|
182
|
+
test "array content" do
|
183
|
+
content = %w( one two three )
|
184
184
|
topic = Topic.new
|
185
|
-
topic.content =
|
185
|
+
topic.content = content
|
186
186
|
topic.save
|
187
187
|
|
188
|
-
assert_equal
|
188
|
+
assert_equal content, Topic.find(topic.id).content
|
189
189
|
end
|
190
190
|
|
191
|
-
|
192
|
-
category = Category.new(
|
193
|
-
category_attrs = {"name"=>"Test category", "id" => nil, "type" => nil, "categorizations_count" => nil}
|
194
|
-
assert_equal category_attrs
|
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
|
-
|
199
|
-
bool = Boolean.create!(
|
200
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
274
|
-
|
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
|
-
|
272
|
+
test "attributes without primary key" do
|
281
273
|
klass = Class.new(ActiveRecord::Base) do
|
282
|
-
self.table_name =
|
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?(
|
278
|
+
assert_not klass.new.has_attribute?("id")
|
287
279
|
end
|
288
280
|
|
289
|
-
|
290
|
-
new_topic = { :
|
291
|
-
new_topic_values = { :
|
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
|
-
|
301
|
-
topic = Topic.create(
|
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
|
-
|
300
|
+
test "write_attribute" do
|
307
301
|
topic = Topic.new
|
308
|
-
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.
|
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
|
-
|
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
|
-
|
332
|
-
|
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[:
|
335
|
-
assert_raises(ActiveModel::MissingAttributeError) { computer[:no_column_exists] =
|
336
|
-
assert_nothing_raised { computer[:developer] =
|
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
|
-
|
362
|
+
test "read_attribute when false" do
|
340
363
|
topic = topics(:first)
|
341
364
|
topic.approved = false
|
342
|
-
|
365
|
+
assert_not topic.approved?, "approved should be false"
|
343
366
|
topic.approved = "false"
|
344
|
-
|
367
|
+
assert_not topic.approved?, "approved should be false"
|
345
368
|
end
|
346
369
|
|
347
|
-
|
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
|
-
|
378
|
+
test "boolean attributes writing and reading" do
|
356
379
|
topic = Topic.new
|
357
380
|
topic.approved = "false"
|
358
|
-
|
381
|
+
assert_not topic.approved?, "approved should be false"
|
359
382
|
|
360
383
|
topic.approved = "false"
|
361
|
-
|
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
|
-
|
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.
|
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.
|
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
|
-
|
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
|
-
|
404
|
-
topic = Topic.new(:
|
405
|
-
def topic.title()
|
406
|
-
assert_equal
|
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
|
-
|
432
|
+
test "string attribute predicate" do
|
410
433
|
[nil, "", " "].each do |value|
|
411
|
-
assert_equal false, Topic.new(:
|
434
|
+
assert_equal false, Topic.new(author_name: value).author_name?
|
412
435
|
end
|
413
436
|
|
414
|
-
assert_equal true, Topic.new(:
|
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
|
-
|
444
|
+
test "number attribute predicate" do
|
418
445
|
[nil, 0, "0"].each do |value|
|
419
|
-
assert_equal false, Developer.new(:
|
446
|
+
assert_equal false, Developer.new(salary: value).salary?
|
420
447
|
end
|
421
448
|
|
422
|
-
assert_equal true, Developer.new(:
|
423
|
-
assert_equal true, Developer.new(:
|
449
|
+
assert_equal true, Developer.new(salary: 1).salary?
|
450
|
+
assert_equal true, Developer.new(salary: "1").salary?
|
424
451
|
end
|
425
452
|
|
426
|
-
|
453
|
+
test "boolean attribute predicate" do
|
427
454
|
[nil, "", false, "false", "f", 0].each do |value|
|
428
|
-
assert_equal false, Topic.new(:
|
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(:
|
459
|
+
assert_equal true, Topic.new(approved: value).approved?
|
433
460
|
end
|
434
461
|
end
|
435
462
|
|
436
|
-
|
437
|
-
|
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
|
-
|
535
|
+
assert_predicate object, :string_value?
|
446
536
|
|
447
537
|
object.string_value = " "
|
448
|
-
|
538
|
+
assert_not_predicate object, :string_value?
|
449
539
|
|
450
540
|
assert_equal 1, object.int_value.to_i
|
451
|
-
|
541
|
+
assert_predicate object, :int_value?
|
452
542
|
|
453
543
|
object.int_value = "0"
|
454
|
-
|
544
|
+
assert_not_predicate object, :int_value?
|
455
545
|
end
|
456
546
|
|
457
|
-
|
547
|
+
test "non-attribute read and write" do
|
458
548
|
topic = Topic.new
|
459
|
-
|
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
|
-
|
465
|
-
topic = @target.new(:
|
466
|
-
|
467
|
-
assert_equal
|
468
|
-
|
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
|
-
|
473
|
-
topic = @target.new(:
|
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
|
-
|
480
|
-
assert_equal [
|
481
|
-
assert_equal [
|
482
|
-
assert_equal [
|
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
|
-
|
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(:
|
580
|
+
topic = @target.new(title: "Budget")
|
491
581
|
|
492
582
|
meth = "title#{suffix}"
|
493
|
-
|
494
|
-
assert_equal [
|
495
|
-
assert_equal [
|
496
|
-
assert_equal [
|
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
|
-
|
501
|
-
[[
|
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(
|
504
|
-
topic = @target.new(:
|
593
|
+
@target.attribute_method_affix(prefix: prefix, suffix: suffix)
|
594
|
+
topic = @target.new(title: "Budget")
|
505
595
|
|
506
596
|
meth = "#{prefix}title#{suffix}"
|
507
|
-
|
508
|
-
assert_equal [
|
509
|
-
assert_equal [
|
510
|
-
assert_equal [
|
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
|
-
|
515
|
-
myobj = {:
|
516
|
-
topic = Topic.create(
|
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
|
-
|
522
|
-
Topic.create(:
|
523
|
-
# Oracle does not support boolean expressions in SELECT
|
524
|
-
if current_adapter?(:OracleAdapter
|
525
|
-
topic = Topic.all.merge!(:
|
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!(:
|
617
|
+
topic = Topic.all.merge!(select: "topics.*, 1=2 as is_test").first
|
528
618
|
end
|
529
|
-
|
619
|
+
assert_not_predicate topic, :is_test?
|
530
620
|
end
|
531
621
|
|
532
|
-
|
533
|
-
Topic.create(:
|
534
|
-
# Oracle does not support boolean expressions in SELECT
|
535
|
-
if current_adapter?(:OracleAdapter
|
536
|
-
topic = Topic.all.merge!(:
|
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!(:
|
628
|
+
topic = Topic.all.merge!(select: "topics.*, 2=2 as is_test").first
|
539
629
|
end
|
540
|
-
|
630
|
+
assert_predicate topic, :is_test?
|
541
631
|
end
|
542
632
|
|
543
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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(:
|
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
|
-
|
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
|
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
|
-
|
734
|
+
test "time zone-aware attribute saved" do
|
645
735
|
in_time_zone 1 do
|
646
|
-
record = @target.create(:
|
736
|
+
record = @target.create(written_on: "2012-02-20 10:00")
|
647
737
|
|
648
|
-
record.written_on =
|
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
|
-
|
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
|
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
|
-
|
664
|
-
time_string =
|
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
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
836
|
+
assert_predicate record.bonus_time, :utc?
|
732
837
|
end
|
733
838
|
end
|
734
839
|
end
|
735
840
|
|
736
|
-
|
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
|
-
|
844
|
+
assert_nil record.bonus_time
|
740
845
|
end
|
741
846
|
end
|
742
847
|
|
743
|
-
|
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
|
-
|
856
|
+
test "attribute readers respect access control" do
|
752
857
|
privatize("title")
|
753
858
|
|
754
|
-
topic = @target.new(:
|
755
|
-
|
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
|
-
|
862
|
+
assert_includes exception.message, "private method"
|
758
863
|
assert_equal "I'm private", topic.send(:title)
|
759
864
|
end
|
760
865
|
|
761
|
-
|
866
|
+
test "attribute writers respect access control" do
|
762
867
|
privatize("title=(value)")
|
763
868
|
|
764
869
|
topic = @target.new
|
765
|
-
|
766
|
-
exception = assert_raise(NoMethodError) { topic.title = "Pants"}
|
767
|
-
|
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
|
-
|
876
|
+
test "attribute predicates respect access control" do
|
772
877
|
privatize("title?")
|
773
878
|
|
774
|
-
topic = @target.new(:
|
775
|
-
|
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
|
-
|
882
|
+
assert_includes exception.message, "private method"
|
778
883
|
assert topic.send(:title?)
|
779
884
|
end
|
780
885
|
|
781
|
-
|
886
|
+
test "bulk updates respect access control" do
|
782
887
|
privatize("title=(value)")
|
783
888
|
|
784
|
-
assert_raise(ActiveRecord::UnknownAttributeError) { @target.new(:
|
785
|
-
assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { :
|
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
|
-
|
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
|
-
|
899
|
+
assert_match "unknown attribute 'hello' for Topic.", error.message
|
795
900
|
end
|
796
901
|
|
797
|
-
|
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
|
805
|
-
dev = klass.new(name:
|
909
|
+
2.times { klass = Class.new(klass) }
|
910
|
+
dev = klass.new(name: "arthurnn")
|
806
911
|
dev.save!
|
807
|
-
assert_equal
|
912
|
+
assert_equal "dev:arthurnn", dev.reload.name
|
808
913
|
end
|
809
914
|
|
810
|
-
|
915
|
+
test "global methods are overwritten" do
|
811
916
|
klass = Class.new(ActiveRecord::Base) do
|
812
|
-
self.table_name =
|
917
|
+
self.table_name = "computers"
|
813
918
|
end
|
814
919
|
|
815
|
-
|
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
|
-
|
821
|
-
klass = Class.new(ActiveRecord::Base)
|
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 =
|
931
|
+
self.table_name = "computers"
|
825
932
|
end
|
826
933
|
|
827
|
-
|
828
|
-
|
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
|
-
|
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
|
-
|
850
|
-
|
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
|
-
|
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
|
-
|
986
|
+
test "inherited custom accessors with reserved names" do
|
873
987
|
klass = Class.new(ActiveRecord::Base) do
|
874
|
-
self.table_name =
|
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
|
-
|
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 +
|
1012
|
+
assert_equal real_topic.title + "!", klass.find(real_topic.id).title
|
899
1013
|
end
|
900
1014
|
|
901
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
931
|
-
@target.table_name =
|
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
|
-
|
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
|
-
|
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
|
-
|
948
|
-
model = @target.select(
|
1061
|
+
test "attribute_names with a custom select" do
|
1062
|
+
model = @target.select("id").last!
|
949
1063
|
|
950
|
-
assert_equal [
|
951
|
-
# Sanity check, make sure other columns exist
|
952
|
-
assert_not_equal [
|
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
|
-
|
1069
|
+
test "came_from_user?" do
|
956
1070
|
model = @target.first
|
957
1071
|
|
958
|
-
|
1072
|
+
assert_not_predicate model, :id_came_from_user?
|
959
1073
|
model.id = "omg"
|
960
|
-
|
1074
|
+
assert_predicate model, :id_came_from_user?
|
961
1075
|
end
|
962
1076
|
|
963
|
-
|
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
|
-
|
974
|
-
|
975
|
-
|
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
|
-
|
986
|
-
|
987
|
-
|
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
|
-
|
994
|
-
|
995
|
-
|
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
|
-
|
998
|
-
|
999
|
-
|
1104
|
+
assert_empty klass.send(:generated_attribute_methods).instance_methods(false)
|
1105
|
+
klass
|
1106
|
+
end
|
1000
1107
|
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
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
|