ibm_db 5.6.1 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/Makefile +13 -9
- data/ext/extconf.rb +176 -110
- data/ext/ibm_db.c +60 -0
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +6 -6
- data/ext/ruby_ibm_db_cli.c +14 -10
- data/ext/ruby_ibm_db_cli.h +4 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/lib/IBM_DB.rb +2 -2
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +1254 -277
- data/test/active_record/connection_adapters/fake_legacy_adapter.rb +17 -0
- data/test/active_record/connection_adapters/fake_misleading_legacy_adapter.rb +8 -0
- data/test/activejob/destroy_association_async_job_test.rb +62 -0
- data/test/activejob/destroy_association_async_test.rb +147 -11
- data/test/activejob/job_runtime_test.rb +41 -0
- data/test/activejob/unloadable_base_job.rb +3 -0
- data/test/cases/active_record_schema_test.rb +196 -0
- data/test/cases/active_record_test.rb +21 -0
- data/test/cases/adapter_prevent_writes_test.rb +26 -202
- data/test/cases/adapter_test.rb +592 -82
- data/test/cases/adapters/abstract_mysql_adapter/active_schema_test.rb +210 -0
- data/test/cases/adapters/abstract_mysql_adapter/adapter_prevent_writes_test.rb +111 -0
- data/test/cases/adapters/abstract_mysql_adapter/auto_increment_test.rb +48 -0
- data/test/cases/adapters/abstract_mysql_adapter/bind_parameter_test.rb +91 -0
- data/test/cases/adapters/abstract_mysql_adapter/case_sensitivity_test.rb +65 -0
- data/test/cases/adapters/abstract_mysql_adapter/charset_collation_test.rb +85 -0
- data/test/cases/adapters/abstract_mysql_adapter/connection_test.rb +267 -0
- data/test/cases/adapters/abstract_mysql_adapter/count_deleted_rows_with_lock_test.rb +29 -0
- data/test/cases/adapters/abstract_mysql_adapter/json_test.rb +24 -0
- data/test/cases/adapters/abstract_mysql_adapter/mysql_boolean_test.rb +102 -0
- data/test/cases/adapters/abstract_mysql_adapter/mysql_enum_test.rb +47 -0
- data/test/cases/adapters/abstract_mysql_adapter/mysql_explain_test.rb +71 -0
- data/test/cases/adapters/abstract_mysql_adapter/nested_deadlock_test.rb +191 -0
- data/test/cases/adapters/abstract_mysql_adapter/optimizer_hints_test.rb +69 -0
- data/test/cases/adapters/abstract_mysql_adapter/quoting_test.rb +49 -0
- data/test/cases/adapters/abstract_mysql_adapter/schema_migrations_test.rb +68 -0
- data/test/cases/adapters/abstract_mysql_adapter/schema_test.rb +130 -0
- data/test/cases/adapters/abstract_mysql_adapter/set_test.rb +32 -0
- data/test/cases/adapters/abstract_mysql_adapter/sp_test.rb +39 -0
- data/test/cases/adapters/abstract_mysql_adapter/sql_types_test.rb +16 -0
- data/test/cases/adapters/abstract_mysql_adapter/table_options_test.rb +125 -0
- data/test/cases/adapters/abstract_mysql_adapter/transaction_test.rb +204 -0
- data/test/cases/adapters/abstract_mysql_adapter/unsigned_type_test.rb +77 -0
- data/test/cases/adapters/abstract_mysql_adapter/virtual_column_test.rb +69 -0
- data/test/cases/adapters/abstract_mysql_adapter/warnings_test.rb +109 -0
- data/test/cases/adapters/mysql2/check_constraint_quoting_test.rb +35 -0
- data/test/cases/adapters/mysql2/dbconsole_test.rb +87 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +136 -10
- data/test/cases/adapters/mysql2/mysql2_rake_test.rb +433 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +8 -4
- data/test/cases/adapters/postgresql/array_test.rb +6 -6
- data/test/cases/adapters/postgresql/bind_parameter_test.rb +52 -0
- data/test/cases/adapters/postgresql/bit_string_test.rb +2 -2
- data/test/cases/adapters/postgresql/bytea_test.rb +3 -3
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +1 -1
- data/test/cases/adapters/postgresql/change_schema_test.rb +32 -1
- data/test/cases/adapters/postgresql/cidr_test.rb +17 -0
- data/test/cases/adapters/postgresql/citext_test.rb +7 -1
- data/test/cases/adapters/postgresql/collation_test.rb +1 -1
- data/test/cases/adapters/postgresql/composite_test.rb +1 -1
- data/test/cases/adapters/postgresql/connection_test.rb +43 -36
- data/test/cases/adapters/postgresql/create_unlogged_tables_test.rb +3 -2
- data/test/cases/adapters/postgresql/datatype_test.rb +9 -4
- data/test/cases/adapters/postgresql/date_test.rb +2 -2
- data/test/cases/adapters/postgresql/dbconsole_test.rb +109 -0
- data/test/cases/adapters/postgresql/deferred_constraints_test.rb +55 -0
- data/test/cases/adapters/postgresql/domain_test.rb +1 -1
- data/test/cases/adapters/postgresql/enum_test.rb +208 -8
- data/test/cases/adapters/postgresql/explain_test.rb +25 -6
- data/test/cases/adapters/postgresql/extension_migration_test.rb +51 -9
- data/test/cases/adapters/postgresql/foreign_table_test.rb +3 -3
- data/test/cases/adapters/postgresql/full_text_test.rb +1 -1
- data/test/cases/adapters/postgresql/geometric_test.rb +13 -6
- data/test/cases/adapters/postgresql/hstore_test.rb +22 -32
- data/test/cases/adapters/postgresql/infinity_test.rb +13 -2
- data/test/cases/adapters/postgresql/integer_test.rb +1 -1
- data/test/cases/adapters/postgresql/interval_test.rb +9 -17
- data/test/cases/adapters/postgresql/invertible_migration_test.rb +139 -0
- data/test/cases/adapters/postgresql/json_test.rb +5 -0
- data/test/cases/adapters/postgresql/ltree_test.rb +1 -1
- data/test/cases/adapters/postgresql/money_test.rb +17 -9
- data/test/cases/adapters/postgresql/network_test.rb +13 -1
- data/test/cases/adapters/postgresql/numbers_test.rb +18 -2
- data/test/cases/adapters/postgresql/optimizer_hints_test.rb +9 -9
- data/test/cases/adapters/postgresql/partitions_test.rb +5 -2
- data/test/cases/adapters/postgresql/postgresql_adapter_prevent_writes_test.rb +7 -110
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +403 -20
- data/test/cases/adapters/postgresql/postgresql_rake_test.rb +637 -0
- data/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb +1 -1
- data/test/cases/adapters/postgresql/quoting_test.rb +60 -1
- data/test/cases/adapters/postgresql/range_test.rb +185 -21
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +29 -5
- data/test/cases/adapters/postgresql/rename_table_test.rb +35 -8
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +2 -2
- data/test/cases/adapters/postgresql/schema_test.rb +270 -20
- data/test/cases/adapters/postgresql/serial_test.rb +5 -5
- data/test/cases/adapters/postgresql/statement_pool_test.rb +6 -2
- data/test/cases/adapters/postgresql/timestamp_test.rb +122 -5
- data/test/cases/adapters/postgresql/transaction_nested_test.rb +130 -6
- data/test/cases/adapters/postgresql/transaction_test.rb +37 -11
- data/test/cases/adapters/postgresql/type_lookup_test.rb +1 -1
- data/test/cases/adapters/postgresql/uuid_test.rb +77 -9
- data/test/cases/adapters/postgresql/virtual_column_test.rb +114 -0
- data/test/cases/adapters/postgresql/xml_test.rb +1 -1
- data/test/cases/adapters/sqlite3/bind_parameter_test.rb +52 -0
- data/test/cases/adapters/sqlite3/collation_test.rb +1 -1
- data/test/cases/adapters/sqlite3/copy_table_test.rb +28 -7
- data/test/cases/adapters/sqlite3/dbconsole_test.rb +81 -0
- data/test/cases/adapters/sqlite3/explain_test.rb +3 -3
- data/test/cases/adapters/sqlite3/quoting_test.rb +34 -3
- data/test/cases/adapters/sqlite3/sqlite3_adapter_prevent_writes_test.rb +9 -102
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +727 -72
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +6 -3
- data/test/cases/adapters/sqlite3/sqlite_rake_test.rb +264 -0
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +1 -1
- data/test/cases/adapters/sqlite3/transaction_test.rb +6 -3
- data/test/cases/adapters/sqlite3/virtual_column_test.rb +138 -0
- data/test/cases/adapters/sqlite3/virtual_table_test.rb +51 -0
- data/test/cases/adapters/trilogy/dbconsole_test.rb +76 -0
- data/test/cases/adapters/trilogy/trilogy_adapter_test.rb +473 -0
- data/test/cases/adapters/trilogy/trilogy_rake_test.rb +433 -0
- data/test/cases/aggregations_test.rb +16 -0
- data/test/cases/annotate_test.rb +14 -12
- data/test/cases/arel/attributes/attribute_test.rb +86 -47
- data/test/cases/arel/collectors/bind_test.rb +1 -1
- data/test/cases/arel/collectors/composite_test.rb +11 -1
- data/test/cases/arel/collectors/sql_string_test.rb +1 -1
- data/test/cases/arel/collectors/substitute_bind_collector_test.rb +1 -1
- data/test/cases/arel/delete_manager_test.rb +0 -6
- data/test/cases/arel/factory_methods_test.rb +45 -0
- data/test/cases/arel/insert_manager_test.rb +1 -7
- data/test/cases/arel/nodes/as_test.rb +12 -0
- data/test/cases/arel/nodes/ascending_test.rb +1 -1
- data/test/cases/arel/nodes/bin_test.rb +1 -1
- data/test/cases/arel/nodes/bound_sql_literal_test.rb +31 -0
- data/test/cases/arel/nodes/cte_test.rb +46 -0
- data/test/cases/arel/nodes/descending_test.rb +1 -1
- data/test/cases/arel/nodes/equality_test.rb +3 -3
- data/test/cases/arel/nodes/filter_test.rb +37 -0
- data/test/cases/arel/nodes/fragments_test.rb +38 -0
- data/test/cases/arel/nodes/homogeneous_in_test.rb +52 -0
- data/test/cases/arel/nodes/infix_operation_test.rb +1 -1
- data/test/cases/arel/nodes/node_test.rb +1 -1
- data/test/cases/arel/nodes/or_test.rb +2 -2
- data/test/cases/arel/nodes/sql_literal_test.rb +18 -1
- data/test/cases/arel/nodes/table_alias_test.rb +12 -0
- data/test/cases/arel/nodes/unary_operation_test.rb +1 -1
- data/test/cases/arel/nodes/update_statement_test.rb +4 -0
- data/test/cases/arel/nodes_test.rb +3 -2
- data/test/cases/arel/select_manager_test.rb +12 -12
- data/test/cases/arel/support/fake_record.rb +22 -17
- data/test/cases/arel/table_test.rb +15 -25
- data/test/cases/arel/update_manager_test.rb +51 -6
- data/test/cases/arel/visitors/dispatch_contamination_test.rb +1 -1
- data/test/cases/arel/visitors/dot_test.rb +177 -2
- data/test/cases/arel/visitors/mysql_test.rb +49 -1
- data/test/cases/arel/visitors/postgres_test.rb +1 -31
- data/test/cases/arel/visitors/sqlite_test.rb +1 -1
- data/test/cases/arel/visitors/to_sql_test.rb +330 -20
- data/test/cases/assertions/query_assertions_test.rb +136 -0
- data/test/cases/associations/belongs_to_associations_test.rb +502 -41
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +1 -1
- data/test/cases/associations/cascaded_eager_loading_test.rb +26 -15
- data/test/cases/associations/eager_load_nested_include_test.rb +1 -1
- data/test/cases/associations/eager_singularization_test.rb +1 -1
- data/test/cases/associations/eager_test.rb +255 -93
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +25 -53
- data/test/cases/associations/has_many_associations_test.rb +282 -72
- data/test/cases/associations/has_many_through_associations_test.rb +172 -45
- data/test/cases/associations/has_many_through_disable_joins_associations_test.rb +197 -0
- data/test/cases/associations/has_one_associations_test.rb +160 -29
- data/test/cases/associations/has_one_through_associations_test.rb +64 -15
- data/test/cases/associations/has_one_through_disable_joins_associations_test.rb +82 -0
- data/test/cases/associations/inner_join_association_test.rb +36 -6
- data/test/cases/associations/inverse_associations_test.rb +177 -40
- data/test/cases/associations/join_model_test.rb +17 -12
- data/test/cases/associations/left_outer_join_association_test.rb +14 -3
- data/test/cases/associations/nested_error_test.rb +116 -0
- data/test/cases/associations/nested_through_associations_test.rb +54 -19
- data/test/cases/associations/required_test.rb +1 -1
- data/test/cases/associations_test.rb +1278 -21
- data/test/cases/asynchronous_queries_test.rb +310 -0
- data/test/cases/attribute_methods/read_test.rb +6 -0
- data/test/cases/attribute_methods/time_zone_converter_test.rb +21 -0
- data/test/cases/attribute_methods_test.rb +565 -46
- data/test/cases/attributes_test.rb +42 -1
- data/test/cases/autosave_association_test.rb +645 -92
- data/test/cases/base_prevent_writes_test.rb +28 -159
- data/test/cases/base_test.rb +434 -209
- data/test/cases/batches_test.rb +441 -57
- data/test/cases/binary_test.rb +31 -0
- data/test/cases/bind_parameter_test.rb +107 -16
- data/test/cases/cache_key_test.rb +7 -7
- data/test/cases/calculations_test.rb +541 -110
- data/test/cases/callbacks_test.rb +0 -1
- data/test/cases/clone_test.rb +5 -4
- data/test/cases/coders/yaml_column_test.rb +97 -2
- data/test/cases/collection_cache_key_test.rb +24 -16
- data/test/cases/column_alias_test.rb +2 -8
- data/test/cases/column_definition_test.rb +12 -3
- data/test/cases/comment_test.rb +23 -26
- data/test/cases/connection_adapters/adapter_leasing_test.rb +9 -9
- data/test/cases/connection_adapters/connection_handler_test.rb +145 -99
- data/test/cases/connection_adapters/connection_handlers_multi_db_test.rb +79 -55
- data/test/cases/connection_adapters/connection_handlers_multi_pool_config_test.rb +17 -20
- data/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb +146 -55
- data/test/cases/connection_adapters/connection_swapping_nested_test.rb +136 -23
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +96 -27
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -5
- data/test/cases/connection_adapters/registration_test.rb +98 -0
- data/test/cases/connection_adapters/schema_cache_test.rb +288 -135
- data/test/cases/connection_adapters/standalone_connection_test.rb +38 -0
- data/test/cases/connection_adapters/statement_pool_test.rb +29 -0
- data/test/cases/connection_adapters/type_lookup_test.rb +12 -24
- data/test/cases/connection_handling_test.rb +210 -0
- data/test/cases/connection_management_test.rb +44 -7
- data/test/cases/connection_pool_test.rb +466 -99
- data/test/cases/core_test.rb +167 -9
- data/test/cases/counter_cache_test.rb +129 -2
- data/test/cases/custom_locking_test.rb +3 -3
- data/test/cases/database_configurations/hash_config_test.rb +149 -13
- data/test/cases/database_configurations/resolver_test.rb +14 -10
- data/test/cases/database_configurations/url_config_test.rb +53 -0
- data/test/cases/database_configurations_test.rb +86 -43
- data/test/cases/database_selector_test.rb +30 -8
- data/test/cases/database_statements_test.rb +10 -14
- data/test/cases/date_time_precision_test.rb +141 -11
- data/test/cases/date_time_test.rb +19 -1
- data/test/cases/defaults_test.rb +107 -41
- data/test/cases/delegated_type_test.rb +69 -9
- data/test/cases/dirty_test.rb +82 -25
- data/test/cases/disconnected_test.rb +10 -9
- data/test/cases/dup_test.rb +26 -6
- data/test/cases/encryption/cipher/aes256_gcm_test.rb +50 -0
- data/test/cases/encryption/cipher_test.rb +65 -0
- data/test/cases/encryption/concurrency_test.rb +27 -0
- data/test/cases/encryption/config_test.rb +21 -0
- data/test/cases/encryption/configurable_test.rb +93 -0
- data/test/cases/encryption/contexts_test.rb +105 -0
- data/test/cases/encryption/derived_secret_key_provider_test.rb +31 -0
- data/test/cases/encryption/deterministic_key_provider_test.rb +11 -0
- data/test/cases/encryption/encryptable_record_api_test.rb +175 -0
- data/test/cases/encryption/encryptable_record_message_pack_serialized_test.rb +42 -0
- data/test/cases/encryption/encryptable_record_test.rb +470 -0
- data/test/cases/encryption/encrypted_fixtures_test.rb +22 -0
- data/test/cases/encryption/encrypting_only_encryptor_test.rb +20 -0
- data/test/cases/encryption/encryption_schemes_test.rb +240 -0
- data/test/cases/encryption/encryptor_test.rb +113 -0
- data/test/cases/encryption/envelope_encryption_key_provider_test.rb +49 -0
- data/test/cases/encryption/extended_deterministic_queries_test.rb +81 -0
- data/test/cases/encryption/helper.rb +152 -0
- data/test/cases/encryption/key_generator_test.rb +55 -0
- data/test/cases/encryption/key_provider_test.rb +57 -0
- data/test/cases/encryption/key_test.rb +17 -0
- data/test/cases/encryption/message_pack_message_serializer_test.rb +70 -0
- data/test/cases/encryption/message_serializer_test.rb +82 -0
- data/test/cases/encryption/message_test.rb +43 -0
- data/test/cases/encryption/null_encryptor_test.rb +21 -0
- data/test/cases/encryption/properties_test.rb +69 -0
- data/test/cases/encryption/read_only_null_encryptor_test.rb +19 -0
- data/test/cases/encryption/scheme_test.rb +58 -0
- data/test/cases/encryption/unencrypted_attributes_test.rb +27 -0
- data/test/cases/encryption/uniqueness_validations_test.rb +65 -0
- data/test/cases/enum_test.rb +374 -72
- data/test/cases/errors_test.rb +7 -4
- data/test/cases/excluding_test.rb +116 -0
- data/test/cases/explain_subscriber_test.rb +6 -1
- data/test/cases/explain_test.rb +119 -10
- data/test/cases/filter_attributes_test.rb +7 -14
- data/test/cases/finder_respond_to_test.rb +3 -3
- data/test/cases/finder_test.rb +357 -72
- data/test/cases/fixture_set/file_test.rb +9 -0
- data/test/cases/fixtures_test.rb +426 -190
- data/test/cases/helper.rb +66 -192
- data/test/cases/hot_compatibility_test.rb +10 -10
- data/test/cases/inheritance_test.rb +51 -61
- data/test/cases/inherited_test.rb +40 -0
- data/test/cases/insert_all_test.rb +419 -9
- data/test/cases/instrumentation_test.rb +202 -30
- data/test/cases/integration_test.rb +25 -7
- data/test/cases/invalid_connection_test.rb +5 -5
- data/test/cases/invertible_migration_test.rb +108 -24
- data/test/cases/json_attribute_test.rb +1 -0
- data/test/cases/json_serialization_test.rb +5 -5
- data/test/cases/json_shared_test_cases.rb +5 -9
- data/test/cases/locking_test.rb +67 -31
- data/test/cases/log_subscriber_test.rb +17 -15
- data/test/cases/marshal_serialization_test.rb +78 -5
- data/test/cases/message_pack_test.rb +91 -0
- data/test/cases/migration/change_schema_test.rb +77 -46
- data/test/cases/migration/change_table_test.rb +129 -114
- data/test/cases/migration/check_constraint_test.rb +192 -10
- data/test/cases/migration/column_attributes_test.rb +4 -9
- data/test/cases/migration/column_positioning_test.rb +2 -2
- data/test/cases/migration/columns_test.rb +118 -4
- data/test/cases/migration/command_recorder_test.rb +181 -14
- data/test/cases/migration/compatibility_test.rb +883 -196
- data/test/cases/migration/create_join_table_test.rb +8 -1
- data/test/cases/migration/exclusion_constraint_test.rb +192 -0
- data/test/cases/migration/foreign_key_test.rb +356 -14
- data/test/cases/migration/helper.rb +4 -1
- data/test/cases/migration/index_test.rb +67 -2
- data/test/cases/migration/invalid_options_test.rb +129 -0
- data/test/cases/migration/logger_test.rb +7 -4
- data/test/cases/migration/pending_migrations_test.rb +103 -60
- data/test/cases/migration/references_foreign_key_test.rb +73 -4
- data/test/cases/migration/references_index_test.rb +25 -27
- data/test/cases/migration/references_statements_test.rb +27 -3
- data/test/cases/migration/rename_table_test.rb +39 -54
- data/test/cases/migration/schema_definitions_test.rb +109 -0
- data/test/cases/migration/unique_constraint_test.rb +248 -0
- data/test/cases/migration_test.rb +677 -220
- data/test/cases/migrator_test.rb +102 -75
- data/test/cases/multi_db_migrator_test.rb +55 -34
- data/test/cases/multiparameter_attributes_test.rb +26 -29
- data/test/cases/multiple_db_test.rb +42 -19
- data/test/cases/nested_attributes_test.rb +124 -6
- data/test/cases/nested_attributes_with_callbacks_test.rb +2 -2
- data/test/cases/normalized_attribute_test.rb +117 -0
- data/test/cases/null_relation_test.rb +35 -2
- data/test/cases/persistence/reload_association_cache_test.rb +20 -0
- data/test/cases/persistence_test.rb +629 -22
- data/test/cases/pooled_connections_test.rb +57 -56
- data/test/cases/prepared_statement_status_test.rb +8 -3
- data/test/cases/primary_class_test.rb +134 -0
- data/test/cases/primary_keys_test.rb +171 -55
- data/test/cases/query_cache_test.rb +558 -263
- data/test/cases/query_logs_test.rb +293 -0
- data/test/cases/quoting_test.rb +39 -72
- data/test/cases/readonly_test.rb +50 -12
- data/test/cases/reaper_test.rb +22 -6
- data/test/cases/reflection_test.rb +207 -9
- data/test/cases/relation/and_test.rb +43 -0
- data/test/cases/relation/delegation_test.rb +32 -5
- data/test/cases/relation/delete_all_test.rb +27 -6
- data/test/cases/relation/field_ordered_values_test.rb +128 -0
- data/test/cases/relation/load_async_test.rb +650 -0
- data/test/cases/relation/merging_test.rb +80 -109
- data/test/cases/relation/mutation_test.rb +12 -7
- data/test/cases/relation/or_test.rb +11 -8
- data/test/cases/relation/order_test.rb +90 -0
- data/test/cases/relation/predicate_builder_test.rb +21 -6
- data/test/cases/relation/select_test.rb +162 -3
- data/test/cases/relation/structural_compatibility_test.rb +38 -0
- data/test/cases/relation/update_all_test.rb +81 -27
- data/test/cases/relation/where_chain_test.rb +190 -3
- data/test/cases/relation/where_clause_test.rb +43 -1
- data/test/cases/relation/where_test.rb +95 -7
- data/test/cases/relation/with_test.rb +165 -0
- data/test/cases/relation_test.rb +42 -37
- data/test/cases/relations_test.rb +436 -138
- data/test/cases/reload_models_test.rb +18 -14
- data/test/cases/reserved_word_test.rb +2 -1
- data/test/cases/result_test.rb +14 -22
- data/test/cases/sanitize_test.rb +89 -27
- data/test/cases/schema_dumper_test.rb +535 -62
- data/test/cases/scoping/default_scoping_test.rb +219 -35
- data/test/cases/scoping/named_scoping_test.rb +25 -46
- data/test/cases/scoping/relation_scoping_test.rb +112 -4
- data/test/cases/secure_password_test.rb +108 -0
- data/test/cases/secure_token_test.rb +72 -0
- data/test/cases/serialization_test.rb +1 -1
- data/test/cases/serialized_attribute_test.rb +305 -60
- data/test/cases/shard_keys_test.rb +125 -0
- data/test/cases/shard_selector_test.rb +45 -0
- data/test/cases/signed_id_test.rb +57 -5
- data/test/cases/statement_cache_test.rb +31 -30
- data/test/cases/statement_invalid_test.rb +8 -4
- data/test/cases/store_test.rb +73 -9
- data/test/cases/strict_loading_test.rb +327 -13
- data/test/cases/table_metadata_test.rb +16 -0
- data/test/cases/tasks/database_tasks_test.rb +517 -244
- data/test/cases/test_case.rb +254 -60
- data/test/cases/test_case_test.rb +69 -0
- data/test/cases/test_databases_test.rb +7 -3
- data/test/cases/test_fixtures_test.rb +19 -40
- data/test/cases/time_precision_test.rb +17 -5
- data/test/cases/timestamp_test.rb +124 -16
- data/test/cases/token_for_test.rb +165 -0
- data/test/cases/touch_later_test.rb +43 -1
- data/test/cases/transaction_callbacks_test.rb +325 -8
- data/test/cases/transaction_instrumentation_test.rb +453 -0
- data/test/cases/transaction_isolation_test.rb +12 -8
- data/test/cases/transactions_test.rb +629 -112
- data/test/cases/type/date_time_test.rb +7 -1
- data/test/cases/type/time_test.rb +9 -0
- data/test/cases/type/type_map_test.rb +108 -73
- data/test/cases/type/unsigned_integer_test.rb +12 -0
- data/test/cases/type_caster/connection_test.rb +19 -0
- data/test/cases/type_test.rb +1 -1
- data/test/cases/unconnected_test.rb +7 -7
- data/test/cases/unsafe_raw_sql_test.rb +39 -8
- data/test/cases/validations/absence_validation_test.rb +1 -1
- data/test/cases/validations/association_validation_test.rb +25 -3
- data/test/cases/validations/numericality_validation_test.rb +3 -9
- data/test/cases/validations/presence_validation_test.rb +1 -1
- data/test/cases/validations/uniqueness_validation_test.rb +280 -40
- data/test/cases/validations_test.rb +2 -2
- data/test/cases/view_test.rb +33 -22
- data/test/cases/yaml_serialization_test.rb +23 -17
- data/test/config.example.yml +58 -56
- data/test/config.rb +1 -0
- data/test/fixtures/1_need_quoting.yml +2 -0
- data/test/fixtures/accounts.yml +5 -0
- data/test/fixtures/aircrafts.yml +7 -0
- data/test/fixtures/book_identifiers.yml +11 -0
- data/test/fixtures/books.yml +5 -4
- data/test/fixtures/cake_designers.yml +5 -0
- data/test/fixtures/cars.yml +6 -0
- data/test/fixtures/chefs.yml +5 -0
- data/test/fixtures/clothing_items.yml +23 -0
- data/test/fixtures/clubs.yml +1 -1
- data/test/fixtures/comments.yml +2 -1
- data/test/fixtures/cpk_authors.yml +8 -0
- data/test/fixtures/cpk_books.yml +21 -0
- data/test/fixtures/cpk_order_agreements.yml +13 -0
- data/test/fixtures/cpk_order_tags.yml +15 -0
- data/test/fixtures/cpk_orders.yml +11 -0
- data/test/fixtures/cpk_posts.yml +12 -0
- data/test/fixtures/cpk_reviews.yml +13 -0
- data/test/fixtures/cpk_tags.yml +11 -0
- data/test/fixtures/drink_designers.yml +5 -0
- data/test/fixtures/encrypted_book_that_ignores_cases.yml +4 -0
- data/test/fixtures/encrypted_books.yml +4 -0
- data/test/fixtures/fk_object_to_point_to.yml +2 -0
- data/test/fixtures/memberships.yml +15 -15
- data/test/fixtures/paragraphs.yml +5 -0
- data/test/fixtures/parrots.yml +4 -0
- data/test/fixtures/people.yml +2 -0
- data/test/fixtures/pirates.yml +2 -2
- data/test/fixtures/primary_key_error/primary_key_error.yml +6 -0
- data/test/fixtures/references.yml +3 -3
- data/test/fixtures/sharded_blog_posts.yml +14 -0
- data/test/fixtures/sharded_blog_posts_tags.yml +27 -0
- data/test/fixtures/sharded_blogs.yml +8 -0
- data/test/fixtures/sharded_comments.yml +22 -0
- data/test/fixtures/sharded_tags.yml +34 -0
- data/test/fixtures/sponsors.yml +2 -2
- data/test/fixtures/topics.yml +1 -0
- data/test/fixtures/treasures.yml +4 -0
- data/test/fixtures/virtual_columns.yml +5 -0
- data/test/fixtures/warehouse_things.yml +1 -1
- data/test/migrations/old_and_new_versions/20210716122844_add_people_description.rb +5 -0
- data/test/migrations/old_and_new_versions/20210716123013_add_people_number_of_legs.rb +5 -0
- data/test/migrations/old_and_new_versions/230_add_people_hobby.rb +5 -0
- data/test/migrations/old_and_new_versions/231_add_people_last_name.rb +5 -0
- data/test/migrations/scope/1_unscoped.rb +7 -0
- data/test/migrations/scope/2_mysql_only.mysql.rb +7 -0
- data/test/models/admin/user.rb +2 -0
- data/test/models/admin/user_json.rb +48 -0
- data/test/models/attachment.rb +7 -0
- data/test/models/author.rb +70 -3
- data/test/models/author_encrypted.rb +16 -0
- data/test/models/bird.rb +1 -1
- data/test/models/book.rb +18 -11
- data/test/models/book_destroy_async.rb +1 -1
- data/test/models/book_encrypted.rb +106 -0
- data/test/models/book_identifier.rb +5 -0
- data/test/models/branch.rb +11 -0
- data/test/models/bulb.rb +1 -1
- data/test/models/car.rb +8 -1
- data/test/models/cat.rb +1 -1
- data/test/models/category.rb +3 -1
- data/test/models/chat_message.rb +8 -0
- data/test/models/chef.rb +52 -0
- data/test/models/clothing_item.rb +12 -0
- data/test/models/club.rb +4 -1
- data/test/models/comment.rb +7 -4
- data/test/models/comment_overlapping_counter_cache.rb +15 -0
- data/test/models/company.rb +16 -2
- data/test/models/computer.rb +1 -0
- data/test/models/contact.rb +3 -3
- data/test/models/contract.rb +5 -1
- data/test/models/cpk/author.rb +9 -0
- data/test/models/cpk/book.rb +55 -0
- data/test/models/cpk/book_destroy_async.rb +9 -0
- data/test/models/cpk/car.rb +9 -0
- data/test/models/cpk/car_review.rb +9 -0
- data/test/models/cpk/chapter.rb +16 -0
- data/test/models/cpk/chapter_destroy_async.rb +10 -0
- data/test/models/cpk/comment.rb +9 -0
- data/test/models/cpk/order.rb +55 -0
- data/test/models/cpk/order_agreement.rb +10 -0
- data/test/models/cpk/order_tag.rb +10 -0
- data/test/models/cpk/post.rb +10 -0
- data/test/models/cpk/posts_tag.rb +10 -0
- data/test/models/cpk/review.rb +9 -0
- data/test/models/cpk/tag.rb +10 -0
- data/test/models/cpk.rb +15 -0
- data/test/models/customer.rb +3 -1
- data/test/models/destroy_async_parent.rb +1 -1
- data/test/models/developer.rb +44 -3
- data/test/models/discount.rb +4 -0
- data/test/models/drink_designer.rb +1 -0
- data/test/models/editor.rb +8 -0
- data/test/models/editorship.rb +6 -0
- data/test/models/entry.rb +5 -0
- data/test/models/essay.rb +6 -1
- data/test/models/essay_destroy_async.rb +1 -0
- data/test/models/eye.rb +87 -21
- data/test/models/face.rb +1 -1
- data/test/models/friendship.rb +3 -0
- data/test/models/hardback.rb +7 -0
- data/test/models/hotel.rb +2 -0
- data/test/models/human.rb +2 -2
- data/test/models/invoice.rb +2 -1
- data/test/models/invokes_an_undefined_method.rb +5 -0
- data/test/models/line_item.rb +6 -0
- data/test/models/member.rb +9 -4
- data/test/models/membership.rb +2 -2
- data/test/models/message.rb +2 -1
- data/test/models/need_quoting.rb +5 -0
- data/test/models/paragraph.rb +5 -0
- data/test/models/parrot.rb +6 -3
- data/test/models/person.rb +7 -4
- data/test/models/pirate.rb +4 -1
- data/test/models/pk_autopopulated_by_a_trigger_record.rb +5 -0
- data/test/models/post.rb +65 -2
- data/test/models/post_encrypted.rb +15 -0
- data/test/models/post_with_prefetched_pk.rb +15 -0
- data/test/models/project.rb +1 -0
- data/test/models/publication.rb +16 -0
- data/test/models/raises_argument_error.rb +5 -0
- data/test/models/raises_no_method_error.rb +5 -0
- data/test/models/recipient.rb +5 -0
- data/test/models/reference.rb +1 -1
- data/test/models/reply.rb +1 -1
- data/test/models/room.rb +3 -0
- data/test/models/sharded/blog.rb +12 -0
- data/test/models/sharded/blog_post.rb +17 -0
- data/test/models/sharded/blog_post_destroy_async.rb +14 -0
- data/test/models/sharded/blog_post_tag.rb +11 -0
- data/test/models/sharded/blog_post_with_revision.rb +11 -0
- data/test/models/sharded/comment.rb +12 -0
- data/test/models/sharded/comment_destroy_async.rb +12 -0
- data/test/models/sharded/tag.rb +11 -0
- data/test/models/sharded.rb +8 -0
- data/test/models/ship.rb +1 -1
- data/test/models/shipping_line.rb +11 -0
- data/test/models/subscriber.rb +1 -0
- data/test/models/subscription.rb +3 -1
- data/test/models/too_long_table_name.rb +5 -0
- data/test/models/topic.rb +3 -1
- data/test/models/traffic_light.rb +2 -2
- data/test/models/traffic_light_encrypted.rb +21 -0
- data/test/models/translation.rb +9 -0
- data/test/models/treasure.rb +1 -1
- data/test/models/tyre.rb +1 -1
- data/test/models/user.rb +16 -0
- data/test/models/user_with_invalid_relation.rb +28 -0
- data/test/models/uuid_comment.rb +5 -0
- data/test/models/uuid_entry.rb +5 -0
- data/test/models/uuid_message.rb +5 -0
- data/test/models/zine.rb +2 -1
- data/test/schema/mysql2_specific_schema.rb +26 -12
- data/test/schema/postgresql_specific_schema.rb +121 -13
- data/test/schema/schema.rb +361 -103
- data/test/schema/sqlite_specific_schema.rb +17 -6
- data/test/schema/trilogy_specific_schema.rb +96 -0
- data/test/support/adapter_helper.rb +104 -0
- data/test/support/async_helper.rb +15 -0
- data/test/support/config.rb +1 -1
- data/test/support/connection.rb +14 -2
- data/test/support/ddl_helper.rb +1 -1
- data/test/support/fake_adapter.rb +42 -0
- data/test/support/load_schema_helper.rb +22 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_7_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_7_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_7_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_7_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_7_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_7_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_7_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_7_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Trilogy/rails_6_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Trilogy/rails_6_1_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Trilogy/rails_7_1_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Trilogy/rails_7_1_topic_associations.dump +0 -0
- data/test/support/schema_dumping_helper.rb +15 -9
- data/test/support/tools.rb +37 -0
- data/test/support/yaml_compatibility_fixtures/rails_4_1_no_symbol.yml +22 -0
- metadata +247 -15
data/test/cases/base_test.rb
CHANGED
|
@@ -27,8 +27,11 @@ require "models/bird"
|
|
|
27
27
|
require "models/car"
|
|
28
28
|
require "models/bulb"
|
|
29
29
|
require "models/pet"
|
|
30
|
+
require "models/owner"
|
|
31
|
+
require "models/cpk"
|
|
30
32
|
require "concurrent/atomic/count_down_latch"
|
|
31
33
|
require "active_support/core_ext/enumerable"
|
|
34
|
+
require "active_support/core_ext/kernel/reporting"
|
|
32
35
|
|
|
33
36
|
class FirstAbstractClass < ActiveRecord::Base
|
|
34
37
|
self.abstract_class = true
|
|
@@ -64,6 +67,28 @@ class ReadonlyTitlePost < Post
|
|
|
64
67
|
attr_readonly :title
|
|
65
68
|
end
|
|
66
69
|
|
|
70
|
+
class ReadonlyTitleAbstractPost < ActiveRecord::Base
|
|
71
|
+
self.abstract_class = true
|
|
72
|
+
|
|
73
|
+
attr_readonly :title
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class ReadonlyTitlePostWithAbstractParent < ReadonlyTitleAbstractPost
|
|
77
|
+
self.table_name = "posts"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
previous_value, ActiveRecord.raise_on_assign_to_attr_readonly = ActiveRecord.raise_on_assign_to_attr_readonly, false
|
|
81
|
+
|
|
82
|
+
class NonRaisingPost < Post
|
|
83
|
+
attr_readonly :title
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
ActiveRecord.raise_on_assign_to_attr_readonly = previous_value
|
|
87
|
+
|
|
88
|
+
class ReadonlyAuthorPost < Post
|
|
89
|
+
attr_readonly :author_id
|
|
90
|
+
end
|
|
91
|
+
|
|
67
92
|
class Weird < ActiveRecord::Base; end
|
|
68
93
|
|
|
69
94
|
class LintTest < ActiveRecord::TestCase
|
|
@@ -77,7 +102,9 @@ class LintTest < ActiveRecord::TestCase
|
|
|
77
102
|
end
|
|
78
103
|
|
|
79
104
|
class BasicsTest < ActiveRecord::TestCase
|
|
80
|
-
fixtures :topics, :companies, :developers, :projects, :computers, :accounts,
|
|
105
|
+
fixtures :topics, :companies, :developers, :projects, :computers, :accounts,
|
|
106
|
+
:minimalistics, :warehouse_things, :authors, :author_addresses, :categorizations, :categories,
|
|
107
|
+
:posts, :cpk_books
|
|
81
108
|
|
|
82
109
|
def test_generated_association_methods_module_name
|
|
83
110
|
mod = Post.send(:generated_association_methods)
|
|
@@ -94,26 +121,14 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
94
121
|
assert_equal Post.arel_table["body"], Post.arel_table[:text]
|
|
95
122
|
end
|
|
96
123
|
|
|
97
|
-
def test_deprecated_arel_attribute
|
|
98
|
-
assert_deprecated do
|
|
99
|
-
assert_equal Post.arel_table["body"], Post.arel_attribute(:body)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def test_deprecated_arel_attribute_on_relation
|
|
104
|
-
assert_deprecated do
|
|
105
|
-
assert_equal Post.arel_table["body"], Post.all.arel_attribute(:body)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
124
|
def test_incomplete_schema_loading
|
|
110
125
|
topic = Topic.first
|
|
111
|
-
payload = { foo
|
|
126
|
+
payload = { "foo" => 42 }
|
|
112
127
|
topic.update!(content: payload)
|
|
113
128
|
|
|
114
129
|
Topic.reset_column_information
|
|
115
130
|
|
|
116
|
-
Topic.
|
|
131
|
+
Topic.connection_pool.stub(:schema_cache, -> { raise "Some Error" }) do
|
|
117
132
|
assert_raises RuntimeError do
|
|
118
133
|
Topic.columns_hash
|
|
119
134
|
end
|
|
@@ -123,11 +138,12 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
123
138
|
end
|
|
124
139
|
|
|
125
140
|
def test_column_names_are_escaped
|
|
126
|
-
conn = ActiveRecord::Base.
|
|
141
|
+
conn = ActiveRecord::Base.lease_connection
|
|
127
142
|
classname = conn.class.name[/[^:]*$/]
|
|
128
143
|
badchar = {
|
|
129
144
|
"SQLite3Adapter" => '"',
|
|
130
145
|
"Mysql2Adapter" => "`",
|
|
146
|
+
"TrilogyAdapter" => "`",
|
|
131
147
|
"PostgreSQLAdapter" => '"',
|
|
132
148
|
"OracleAdapter" => '"',
|
|
133
149
|
"IBM_DBAdapter" => '"',
|
|
@@ -136,15 +152,12 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
quoted = conn.quote_column_name "foo#{badchar}bar"
|
|
139
|
-
if current_adapter?(:
|
|
140
|
-
|
|
141
|
-
# therefore quoting removes them
|
|
142
|
-
assert_equal("#{badchar}foobar#{badchar}", quoted)
|
|
143
|
-
elsif current_adapter?(:IBM_DBAdapter)
|
|
144
|
-
assert_equal("foobar", quoted)
|
|
155
|
+
expected = if current_adapter?(:IBM_DBAdapter)
|
|
156
|
+
"foobar"
|
|
145
157
|
else
|
|
146
|
-
|
|
158
|
+
"#{badchar}foo#{badchar * 2}bar#{badchar}"
|
|
147
159
|
end
|
|
160
|
+
assert_equal(expected, quoted)
|
|
148
161
|
end
|
|
149
162
|
|
|
150
163
|
def test_columns_should_obey_set_primary_key
|
|
@@ -251,13 +264,10 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
251
264
|
"The written_on attribute should be of the Time class"
|
|
252
265
|
)
|
|
253
266
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
assert_equal 9900, Topic.find(2).written_on.usec
|
|
259
|
-
assert_equal 129346, Topic.find(3).written_on.usec
|
|
260
|
-
end
|
|
267
|
+
assert_equal 11, Topic.find(1).written_on.sec
|
|
268
|
+
assert_equal 223300, Topic.find(1).written_on.usec
|
|
269
|
+
assert_equal 9900, Topic.find(2).written_on.usec
|
|
270
|
+
assert_equal 129346, Topic.find(3).written_on.usec
|
|
261
271
|
end
|
|
262
272
|
|
|
263
273
|
def test_preserving_time_objects_with_local_time_conversion_to_default_timezone_utc
|
|
@@ -507,6 +517,14 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
507
517
|
Post.reset_table_name
|
|
508
518
|
end
|
|
509
519
|
|
|
520
|
+
def test_table_name_based_on_model_name
|
|
521
|
+
assert_equal "posts", PostRecord.table_name
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
def test_table_name_for_base_class
|
|
525
|
+
assert_nil ActiveRecord::Base.table_name
|
|
526
|
+
end
|
|
527
|
+
|
|
510
528
|
def test_null_fields
|
|
511
529
|
assert_nil Topic.find(1).parent_id
|
|
512
530
|
assert_nil Topic.create("title" => "Hey you").parent_id
|
|
@@ -524,39 +542,27 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
524
542
|
topic = Topic.find(topic.id)
|
|
525
543
|
assert_predicate topic, :approved?
|
|
526
544
|
assert_nil topic.last_read
|
|
527
|
-
|
|
528
|
-
# Oracle has some funky default handling, so it requires a bit of
|
|
529
|
-
# extra testing. See ticket #2788.
|
|
530
|
-
if current_adapter?(:OracleAdapter)
|
|
531
|
-
test = TestOracleDefault.new
|
|
532
|
-
assert_equal "X", test.test_char
|
|
533
|
-
assert_equal "hello", test.test_string
|
|
534
|
-
assert_equal 3, test.test_int
|
|
535
|
-
end
|
|
536
545
|
end
|
|
537
546
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
topic.attributes = attributes
|
|
545
|
-
assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
|
|
546
|
-
end
|
|
547
|
+
def test_utc_as_time_zone
|
|
548
|
+
with_timezone_config default: :utc do
|
|
549
|
+
attributes = { "bonus_time" => "5:42:00AM" }
|
|
550
|
+
topic = Topic.find(1)
|
|
551
|
+
topic.attributes = attributes
|
|
552
|
+
assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
|
|
547
553
|
end
|
|
554
|
+
end
|
|
548
555
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
end
|
|
556
|
+
def test_utc_as_time_zone_and_new
|
|
557
|
+
with_timezone_config default: :utc do
|
|
558
|
+
attributes = { "bonus_time(1i)" => "2000",
|
|
559
|
+
"bonus_time(2i)" => "1",
|
|
560
|
+
"bonus_time(3i)" => "1",
|
|
561
|
+
"bonus_time(4i)" => "10",
|
|
562
|
+
"bonus_time(5i)" => "35",
|
|
563
|
+
"bonus_time(6i)" => "50" }
|
|
564
|
+
topic = Topic.new(attributes)
|
|
565
|
+
assert_equal Time.utc(2000, 1, 1, 10, 35, 50), topic.bonus_time
|
|
560
566
|
end
|
|
561
567
|
end
|
|
562
568
|
|
|
@@ -618,26 +624,29 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
618
624
|
car = Car.create!
|
|
619
625
|
car.bulbs.build
|
|
620
626
|
car.save
|
|
627
|
+
bulbs_of_car = Bulb.where(car_id: car.id)
|
|
621
628
|
|
|
622
|
-
|
|
623
|
-
|
|
629
|
+
assert_equal car.bulbs, bulbs_of_car, "CollectionProxy should be comparable with Relation"
|
|
630
|
+
assert_equal bulbs_of_car, car.bulbs, "Relation should be comparable with CollectionProxy"
|
|
624
631
|
end
|
|
625
632
|
|
|
626
633
|
def test_equality_of_relation_and_array
|
|
627
634
|
car = Car.create!
|
|
628
635
|
car.bulbs.build
|
|
629
636
|
car.save
|
|
637
|
+
bulbs_of_car = Bulb.where(car_id: car.id)
|
|
630
638
|
|
|
631
|
-
|
|
639
|
+
assert_equal bulbs_of_car, car.bulbs.to_a, "Relation should be comparable with Array"
|
|
632
640
|
end
|
|
633
641
|
|
|
634
642
|
def test_equality_of_relation_and_association_relation
|
|
635
643
|
car = Car.create!
|
|
636
644
|
car.bulbs.build
|
|
637
645
|
car.save
|
|
646
|
+
bulbs_of_car = Bulb.where(car_id: car.id)
|
|
638
647
|
|
|
639
|
-
assert_equal
|
|
640
|
-
assert_equal car.bulbs.includes(:car),
|
|
648
|
+
assert_equal bulbs_of_car, car.bulbs.includes(:car), "Relation should be comparable with AssociationRelation"
|
|
649
|
+
assert_equal car.bulbs.includes(:car), bulbs_of_car, "AssociationRelation should be comparable with Relation"
|
|
641
650
|
end
|
|
642
651
|
|
|
643
652
|
def test_equality_of_collection_proxy_and_association_relation
|
|
@@ -667,7 +676,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
667
676
|
end
|
|
668
677
|
|
|
669
678
|
def test_create_without_prepared_statement
|
|
670
|
-
topic = Topic.
|
|
679
|
+
topic = Topic.lease_connection.unprepared_statement do
|
|
671
680
|
Topic.create(title: "foo")
|
|
672
681
|
end
|
|
673
682
|
|
|
@@ -676,7 +685,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
676
685
|
|
|
677
686
|
def test_destroy_without_prepared_statement
|
|
678
687
|
topic = Topic.create(title: "foo")
|
|
679
|
-
Topic.
|
|
688
|
+
Topic.lease_connection.unprepared_statement do
|
|
680
689
|
Topic.find(topic.id).destroy
|
|
681
690
|
end
|
|
682
691
|
|
|
@@ -697,16 +706,166 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
697
706
|
end
|
|
698
707
|
|
|
699
708
|
def test_readonly_attributes
|
|
700
|
-
assert_equal
|
|
709
|
+
assert_equal [ "title" ], ReadonlyTitlePost.readonly_attributes
|
|
701
710
|
|
|
702
711
|
post = ReadonlyTitlePost.create(title: "cannot change this", body: "changeable")
|
|
712
|
+
assert_equal "cannot change this", post.title
|
|
713
|
+
assert_equal "changeable", post.body
|
|
714
|
+
|
|
715
|
+
post = Post.find(post.id)
|
|
716
|
+
assert_equal "cannot change this", post.title
|
|
717
|
+
assert_equal "changeable", post.body
|
|
718
|
+
|
|
719
|
+
assert_raises(ActiveRecord::ReadonlyAttributeError) do
|
|
720
|
+
post.title = "changed via assignment"
|
|
721
|
+
end
|
|
722
|
+
post.body = "changed via assignment"
|
|
723
|
+
assert_equal "cannot change this", post.title
|
|
724
|
+
assert_equal "changed via assignment", post.body
|
|
725
|
+
|
|
726
|
+
assert_raises(ActiveRecord::ReadonlyAttributeError) do
|
|
727
|
+
post.write_attribute(:title, "changed via write_attribute")
|
|
728
|
+
end
|
|
729
|
+
post.write_attribute(:body, "changed via write_attribute")
|
|
730
|
+
assert_equal "cannot change this", post.title
|
|
731
|
+
assert_equal "changed via write_attribute", post.body
|
|
732
|
+
|
|
733
|
+
assert_raises(ActiveRecord::ReadonlyAttributeError) do
|
|
734
|
+
post.assign_attributes(body: "changed via assign_attributes", title: "changed via assign_attributes")
|
|
735
|
+
end
|
|
736
|
+
assert_equal "cannot change this", post.title
|
|
737
|
+
assert_equal "changed via assign_attributes", post.body
|
|
738
|
+
|
|
739
|
+
assert_raises(ActiveRecord::ReadonlyAttributeError) do
|
|
740
|
+
post.update(title: "changed via update", body: "changed via update")
|
|
741
|
+
end
|
|
742
|
+
assert_equal "cannot change this", post.title
|
|
743
|
+
assert_equal "changed via assign_attributes", post.body
|
|
744
|
+
|
|
745
|
+
assert_raises(ActiveRecord::ReadonlyAttributeError) do
|
|
746
|
+
post[:title] = "changed via []="
|
|
747
|
+
end
|
|
748
|
+
post[:body] = "changed via []="
|
|
749
|
+
assert_equal "cannot change this", post.title
|
|
750
|
+
assert_equal "changed via []=", post.body
|
|
751
|
+
|
|
752
|
+
post.save!
|
|
753
|
+
|
|
754
|
+
post = Post.find(post.id)
|
|
755
|
+
assert_equal "cannot change this", post.title
|
|
756
|
+
assert_equal "changed via []=", post.body
|
|
757
|
+
end
|
|
758
|
+
|
|
759
|
+
def test_readonly_attributes_on_a_new_record
|
|
760
|
+
assert_equal [ "title" ], ReadonlyTitlePost.readonly_attributes
|
|
761
|
+
|
|
762
|
+
post = ReadonlyTitlePost.new(title: "can change this until you save", body: "changeable")
|
|
763
|
+
assert_equal "can change this until you save", post.title
|
|
764
|
+
assert_equal "changeable", post.body
|
|
765
|
+
|
|
766
|
+
post.title = "changed via assignment"
|
|
767
|
+
post.body = "changed via assignment"
|
|
768
|
+
assert_equal "changed via assignment", post.title
|
|
769
|
+
assert_equal "changed via assignment", post.body
|
|
770
|
+
|
|
771
|
+
post.write_attribute(:title, "changed via write_attribute")
|
|
772
|
+
post.write_attribute(:body, "changed via write_attribute")
|
|
773
|
+
assert_equal "changed via write_attribute", post.title
|
|
774
|
+
assert_equal "changed via write_attribute", post.body
|
|
775
|
+
|
|
776
|
+
post.assign_attributes(body: "changed via assign_attributes", title: "changed via assign_attributes")
|
|
777
|
+
assert_equal "changed via assign_attributes", post.title
|
|
778
|
+
assert_equal "changed via assign_attributes", post.body
|
|
779
|
+
|
|
780
|
+
post[:title] = "changed via []="
|
|
781
|
+
post[:body] = "changed via []="
|
|
782
|
+
assert_equal "changed via []=", post.title
|
|
783
|
+
assert_equal "changed via []=", post.body
|
|
784
|
+
|
|
785
|
+
post.save!
|
|
786
|
+
|
|
787
|
+
post = Post.find(post.id)
|
|
788
|
+
assert_equal "changed via []=", post.title
|
|
789
|
+
assert_equal "changed via []=", post.body
|
|
790
|
+
end
|
|
791
|
+
|
|
792
|
+
def test_readonly_attributes_in_abstract_class_descendant
|
|
793
|
+
assert_equal [ "title" ], ReadonlyTitlePostWithAbstractParent.readonly_attributes
|
|
794
|
+
|
|
795
|
+
assert_nothing_raised do
|
|
796
|
+
ReadonlyTitlePostWithAbstractParent.new(title: "can change this until you save")
|
|
797
|
+
end
|
|
798
|
+
end
|
|
799
|
+
|
|
800
|
+
def test_readonly_attributes_when_configured_to_not_raise
|
|
801
|
+
assert_equal [ "title" ], NonRaisingPost.readonly_attributes
|
|
802
|
+
|
|
803
|
+
post = NonRaisingPost.create(title: "cannot change this", body: "changeable")
|
|
804
|
+
assert_equal "cannot change this", post.title
|
|
805
|
+
assert_equal "changeable", post.body
|
|
806
|
+
|
|
807
|
+
post = Post.find(post.id)
|
|
808
|
+
assert_equal "cannot change this", post.title
|
|
809
|
+
assert_equal "changeable", post.body
|
|
810
|
+
|
|
811
|
+
post.title = "changed via assignment"
|
|
812
|
+
post.body = "changed via assignment"
|
|
813
|
+
post.save!
|
|
703
814
|
post.reload
|
|
704
815
|
assert_equal "cannot change this", post.title
|
|
816
|
+
assert_equal "changed via assignment", post.body
|
|
705
817
|
|
|
706
|
-
post.
|
|
818
|
+
post.write_attribute(:title, "changed via write_attribute")
|
|
819
|
+
post.write_attribute(:body, "changed via write_attribute")
|
|
820
|
+
post.save!
|
|
707
821
|
post.reload
|
|
708
822
|
assert_equal "cannot change this", post.title
|
|
709
|
-
assert_equal "changed", post.body
|
|
823
|
+
assert_equal "changed via write_attribute", post.body
|
|
824
|
+
|
|
825
|
+
post.assign_attributes(body: "changed via assign_attributes", title: "changed via assign_attributes")
|
|
826
|
+
post.save!
|
|
827
|
+
post.reload
|
|
828
|
+
assert_equal "cannot change this", post.title
|
|
829
|
+
assert_equal "changed via assign_attributes", post.body
|
|
830
|
+
|
|
831
|
+
post.update(title: "changed via update", body: "changed via update")
|
|
832
|
+
post.reload
|
|
833
|
+
assert_equal "cannot change this", post.title
|
|
834
|
+
assert_equal "changed via update", post.body
|
|
835
|
+
|
|
836
|
+
post[:title] = "changed via []="
|
|
837
|
+
post[:body] = "changed via []="
|
|
838
|
+
post.save!
|
|
839
|
+
post.reload
|
|
840
|
+
assert_equal "cannot change this", post.title
|
|
841
|
+
assert_equal "changed via []=", post.body
|
|
842
|
+
end
|
|
843
|
+
|
|
844
|
+
def test_readonly_attributes_on_belongs_to_association
|
|
845
|
+
assert_equal [ "author_id" ], ReadonlyAuthorPost.readonly_attributes
|
|
846
|
+
|
|
847
|
+
author1 = Author.create!(name: "Alex")
|
|
848
|
+
author2 = Author.create!(name: "Not Alex")
|
|
849
|
+
|
|
850
|
+
post_with_reload = ReadonlyAuthorPost.create!(author: author1, title: "Hi", body: "there")
|
|
851
|
+
post_with_reload.reload
|
|
852
|
+
post_with_reload.update(title: "Hello", body: "world")
|
|
853
|
+
assert_equal author1, post_with_reload.author
|
|
854
|
+
|
|
855
|
+
post_with_reload2 = ReadonlyAuthorPost.create!(author: author1, title: "Hi", body: "there")
|
|
856
|
+
post_with_reload2.reload
|
|
857
|
+
assert_raises(ActiveRecord::ReadonlyAttributeError) do
|
|
858
|
+
post_with_reload2.update(author: author2)
|
|
859
|
+
end
|
|
860
|
+
|
|
861
|
+
post_without_reload = ReadonlyAuthorPost.create!(author: author1, title: "Hi", body: "there")
|
|
862
|
+
post_without_reload.update(title: "Hello", body: "world")
|
|
863
|
+
assert_equal author1, post_without_reload.author
|
|
864
|
+
|
|
865
|
+
post_without_reload2 = ReadonlyAuthorPost.create!(author: author1, title: "Hi", body: "there")
|
|
866
|
+
assert_raises(ActiveRecord::ReadonlyAttributeError) do
|
|
867
|
+
post_without_reload2.update(author: author2)
|
|
868
|
+
end
|
|
710
869
|
end
|
|
711
870
|
|
|
712
871
|
def test_unicode_column_name
|
|
@@ -715,7 +874,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
715
874
|
assert_equal "たこ焼き仮面", weird.なまえ
|
|
716
875
|
end
|
|
717
876
|
|
|
718
|
-
unless current_adapter?(:PostgreSQLAdapter)
|
|
877
|
+
unless current_adapter?(:PostgreSQLAdapter) || current_adapter?(:TrilogyAdapter) || current_adapter?(:IBM_DBAdapter)
|
|
719
878
|
def test_respect_internal_encoding
|
|
720
879
|
old_default_internal = Encoding.default_internal
|
|
721
880
|
silence_warnings { Encoding.default_internal = "EUC-JP" }
|
|
@@ -748,9 +907,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
748
907
|
end
|
|
749
908
|
|
|
750
909
|
def test_attributes_on_dummy_time
|
|
751
|
-
# Oracle does not have a TIME datatype.
|
|
752
|
-
return true if current_adapter?(:OracleAdapter)
|
|
753
|
-
|
|
754
910
|
with_timezone_config default: :local do
|
|
755
911
|
attributes = {
|
|
756
912
|
"bonus_time" => "5:42:00AM"
|
|
@@ -765,9 +921,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
765
921
|
end
|
|
766
922
|
|
|
767
923
|
def test_attributes_on_dummy_time_with_invalid_time
|
|
768
|
-
# Oracle does not have a TIME datatype.
|
|
769
|
-
return true if current_adapter?(:OracleAdapter)
|
|
770
|
-
|
|
771
924
|
attributes = {
|
|
772
925
|
"bonus_time" => "not a time"
|
|
773
926
|
}
|
|
@@ -798,6 +951,22 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
798
951
|
assert_equal false, Topic.find(1).previously_new_record?
|
|
799
952
|
end
|
|
800
953
|
|
|
954
|
+
def test_previously_new_record_on_destroyed_record
|
|
955
|
+
topic = Topic.create
|
|
956
|
+
assert_predicate topic, :previously_new_record?
|
|
957
|
+
|
|
958
|
+
topic.destroy
|
|
959
|
+
assert_not_predicate topic, :previously_new_record?
|
|
960
|
+
end
|
|
961
|
+
|
|
962
|
+
def test_previously_persisted_returns_boolean
|
|
963
|
+
assert_equal false, Topic.new.previously_persisted?
|
|
964
|
+
assert_equal false, Topic.new.destroy.previously_persisted?
|
|
965
|
+
assert_equal false, Topic.first.previously_persisted?
|
|
966
|
+
assert_equal true, Topic.first.destroy.previously_persisted?
|
|
967
|
+
assert_equal true, Topic.first.delete.previously_persisted?
|
|
968
|
+
end
|
|
969
|
+
|
|
801
970
|
def test_dup
|
|
802
971
|
topic = Topic.find(1)
|
|
803
972
|
duped_topic = nil
|
|
@@ -828,6 +997,14 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
828
997
|
assert_equal("c", duped_topic.title)
|
|
829
998
|
end
|
|
830
999
|
|
|
1000
|
+
def test_dup_for_a_composite_primary_key_model
|
|
1001
|
+
book = cpk_books(:cpk_great_author_first_book)
|
|
1002
|
+
new_book = book.dup
|
|
1003
|
+
|
|
1004
|
+
assert_equal "The first book", new_book.title
|
|
1005
|
+
assert_equal([nil, nil], new_book.id)
|
|
1006
|
+
end
|
|
1007
|
+
|
|
831
1008
|
DeveloperSalary = Struct.new(:amount)
|
|
832
1009
|
def test_dup_with_aggregate_of_same_name_as_attribute
|
|
833
1010
|
developer_with_aggregate = Class.new(ActiveRecord::Base) do
|
|
@@ -845,9 +1022,10 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
845
1022
|
assert_not_predicate dup, :persisted?
|
|
846
1023
|
|
|
847
1024
|
# test if the attributes have been duped
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1025
|
+
salary = DeveloperSalary.new(42)
|
|
1026
|
+
dup.salary = salary
|
|
1027
|
+
salary.amount = 1
|
|
1028
|
+
assert_equal 42, dup.salary.amount
|
|
851
1029
|
|
|
852
1030
|
assert dup.save
|
|
853
1031
|
assert_predicate dup, :persisted?
|
|
@@ -890,7 +1068,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
890
1068
|
|
|
891
1069
|
def test_clone_of_new_object_marks_as_dirty_only_changed_attributes
|
|
892
1070
|
developer = Developer.new name: "Bjorn"
|
|
893
|
-
|
|
1071
|
+
assert_predicate developer, :name_changed? # obviously
|
|
894
1072
|
assert_not developer.salary_changed? # attribute has non-nil default value, so treated as not changed
|
|
895
1073
|
|
|
896
1074
|
cloned_developer = developer.clone
|
|
@@ -904,7 +1082,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
904
1082
|
assert_not_predicate developer, :salary_changed?
|
|
905
1083
|
|
|
906
1084
|
cloned_developer = developer.dup
|
|
907
|
-
|
|
1085
|
+
assert_predicate cloned_developer, :name_changed? # both attributes differ from defaults
|
|
908
1086
|
assert_predicate cloned_developer, :salary_changed?
|
|
909
1087
|
end
|
|
910
1088
|
|
|
@@ -914,11 +1092,13 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
914
1092
|
assert_not_predicate developer, :salary_changed?
|
|
915
1093
|
|
|
916
1094
|
cloned_developer = developer.dup
|
|
917
|
-
|
|
1095
|
+
assert_predicate cloned_developer, :name_changed? # ... but on cloned object should be
|
|
918
1096
|
assert_not cloned_developer.salary_changed? # ... BUT salary has non-nil default which should be treated as not changed on cloned instance
|
|
919
1097
|
end
|
|
920
1098
|
|
|
921
1099
|
def test_bignum
|
|
1100
|
+
skip "IBM DB integer column uses 4-byte range in this schema" if current_adapter?(:IBM_DBAdapter)
|
|
1101
|
+
|
|
922
1102
|
company = Company.find(1)
|
|
923
1103
|
company.rating = 2147483648
|
|
924
1104
|
company.save
|
|
@@ -927,28 +1107,132 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
927
1107
|
end
|
|
928
1108
|
|
|
929
1109
|
def test_bignum_pk
|
|
1110
|
+
skip "IBM DB integer primary key uses 4-byte range in this schema" if current_adapter?(:IBM_DBAdapter)
|
|
1111
|
+
|
|
930
1112
|
company = Company.create!(id: 2147483648, name: "foo")
|
|
931
1113
|
assert_equal company, Company.find(company.id)
|
|
932
1114
|
end
|
|
933
1115
|
|
|
934
|
-
if current_adapter?(:PostgreSQLAdapter, :Mysql2Adapter, :SQLite3Adapter)
|
|
935
|
-
def
|
|
936
|
-
|
|
1116
|
+
if current_adapter?(:PostgreSQLAdapter, :Mysql2Adapter, :TrilogyAdapter, :SQLite3Adapter)
|
|
1117
|
+
def test_default_char_types
|
|
1118
|
+
default = Default.new
|
|
1119
|
+
|
|
1120
|
+
assert_equal "Y", default.char1
|
|
1121
|
+
assert_equal "a varchar field", default.char2
|
|
1122
|
+
|
|
1123
|
+
# Mysql text type can't have default value
|
|
1124
|
+
unless current_adapter?(:Mysql2Adapter, :TrilogyAdapter)
|
|
1125
|
+
assert_equal "a text field", default.char3
|
|
1126
|
+
end
|
|
1127
|
+
end
|
|
1128
|
+
|
|
1129
|
+
def test_default_in_local_time
|
|
1130
|
+
with_env_tz do
|
|
1131
|
+
with_timezone_config default: :local do
|
|
1132
|
+
default = Default.new
|
|
1133
|
+
|
|
1134
|
+
assert_equal Date.new(2004, 1, 1), default.fixed_date
|
|
1135
|
+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
|
|
1136
|
+
|
|
1137
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
1138
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
|
|
1139
|
+
end
|
|
1140
|
+
end
|
|
1141
|
+
end
|
|
1142
|
+
end
|
|
1143
|
+
|
|
1144
|
+
def test_default_in_utc
|
|
1145
|
+
with_timezone_config default: :utc do
|
|
937
1146
|
default = Default.new
|
|
938
1147
|
|
|
939
|
-
# fixed dates / times
|
|
940
1148
|
assert_equal Date.new(2004, 1, 1), default.fixed_date
|
|
941
|
-
assert_equal Time.
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
assert_equal "a varchar field", default.char2
|
|
946
|
-
# Mysql text type can't have default value
|
|
947
|
-
unless current_adapter?(:Mysql2Adapter)
|
|
948
|
-
assert_equal "a text field", default.char3
|
|
1149
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
|
|
1150
|
+
|
|
1151
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
1152
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
|
|
949
1153
|
end
|
|
950
1154
|
end
|
|
951
1155
|
end
|
|
1156
|
+
|
|
1157
|
+
def test_default_in_utc_with_time_zone
|
|
1158
|
+
with_timezone_config default: :utc do
|
|
1159
|
+
Time.use_zone "Central Time (US & Canada)" do
|
|
1160
|
+
default = Default.new
|
|
1161
|
+
|
|
1162
|
+
assert_equal Date.new(2004, 1, 1), default.fixed_date
|
|
1163
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
|
|
1164
|
+
|
|
1165
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
1166
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
|
|
1167
|
+
end
|
|
1168
|
+
end
|
|
1169
|
+
end
|
|
1170
|
+
end
|
|
1171
|
+
|
|
1172
|
+
def test_switching_default_time_zone
|
|
1173
|
+
with_env_tz do
|
|
1174
|
+
2.times do
|
|
1175
|
+
with_timezone_config default: :local do
|
|
1176
|
+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
|
|
1177
|
+
end
|
|
1178
|
+
with_timezone_config default: :utc do
|
|
1179
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
|
|
1180
|
+
end
|
|
1181
|
+
end
|
|
1182
|
+
end
|
|
1183
|
+
end
|
|
1184
|
+
|
|
1185
|
+
def test_mutating_time_objects
|
|
1186
|
+
with_env_tz do
|
|
1187
|
+
with_timezone_config default: :local do
|
|
1188
|
+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
|
|
1189
|
+
assert_equal Time.utc(2004, 1, 1, 5, 0, 0, 0), Default.new.fixed_time.utc
|
|
1190
|
+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), Default.new.fixed_time
|
|
1191
|
+
end
|
|
1192
|
+
end
|
|
1193
|
+
end
|
|
1194
|
+
|
|
1195
|
+
unless in_memory_db?
|
|
1196
|
+
def test_connection_in_local_time
|
|
1197
|
+
with_timezone_config default: :utc do
|
|
1198
|
+
new_config = ActiveRecord::Base.connection_db_config.configuration_hash.merge(default_timezone: "local")
|
|
1199
|
+
ActiveRecord::Base.establish_connection(new_config)
|
|
1200
|
+
Default.reset_column_information
|
|
1201
|
+
|
|
1202
|
+
default = Default.new
|
|
1203
|
+
|
|
1204
|
+
assert_equal Date.new(2004, 1, 1), default.fixed_date
|
|
1205
|
+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
|
|
1206
|
+
|
|
1207
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
1208
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
|
|
1209
|
+
end
|
|
1210
|
+
end
|
|
1211
|
+
ensure
|
|
1212
|
+
ActiveRecord::Base.establish_connection :arunit
|
|
1213
|
+
Default.reset_column_information
|
|
1214
|
+
end
|
|
1215
|
+
|
|
1216
|
+
def test_connection_in_utc_time
|
|
1217
|
+
with_timezone_config default: :local do
|
|
1218
|
+
new_config = ActiveRecord::Base.connection_db_config.configuration_hash.merge(default_timezone: "utc")
|
|
1219
|
+
ActiveRecord::Base.establish_connection(new_config)
|
|
1220
|
+
Default.reset_column_information
|
|
1221
|
+
|
|
1222
|
+
default = Default.new
|
|
1223
|
+
|
|
1224
|
+
assert_equal Date.new(2004, 1, 1), default.fixed_date
|
|
1225
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
|
|
1226
|
+
|
|
1227
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
1228
|
+
assert_equal Time.utc(2004, 1, 1, 0, 0, 0, 0), default.fixed_time_with_time_zone
|
|
1229
|
+
end
|
|
1230
|
+
end
|
|
1231
|
+
ensure
|
|
1232
|
+
ActiveRecord::Base.establish_connection :arunit
|
|
1233
|
+
Default.reset_column_information
|
|
1234
|
+
end
|
|
1235
|
+
end
|
|
952
1236
|
end
|
|
953
1237
|
|
|
954
1238
|
def test_auto_id
|
|
@@ -1070,11 +1354,11 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1070
1354
|
|
|
1071
1355
|
klass.table_name = "foo"
|
|
1072
1356
|
assert_equal "foo", klass.table_name
|
|
1073
|
-
assert_equal klass.
|
|
1357
|
+
assert_equal klass.adapter_class.quote_table_name("foo"), klass.quoted_table_name
|
|
1074
1358
|
|
|
1075
1359
|
klass.table_name = "bar"
|
|
1076
1360
|
assert_equal "bar", klass.table_name
|
|
1077
|
-
assert_equal klass.
|
|
1361
|
+
assert_equal klass.adapter_class.quote_table_name("bar"), klass.quoted_table_name
|
|
1078
1362
|
end
|
|
1079
1363
|
|
|
1080
1364
|
def test_set_table_name_with_inheritance
|
|
@@ -1094,6 +1378,10 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1094
1378
|
assert_equal k.reset_sequence_name, orig_name
|
|
1095
1379
|
end
|
|
1096
1380
|
|
|
1381
|
+
def test_sequence_name_for_cpk_model
|
|
1382
|
+
assert_nil Cpk::Book.sequence_name
|
|
1383
|
+
end
|
|
1384
|
+
|
|
1097
1385
|
def test_count_with_join
|
|
1098
1386
|
res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'"
|
|
1099
1387
|
res2 = Post.where("posts.#{QUOTED_TYPE} = 'Post'").joins("LEFT JOIN comments ON posts.id=comments.post_id").count
|
|
@@ -1149,7 +1437,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1149
1437
|
end
|
|
1150
1438
|
|
|
1151
1439
|
def test_find_keeps_multiple_group_values
|
|
1152
|
-
combined = Developer.merge(group: "developers.name, developers.salary, developers.id, developers.mentor_id, developers.firm_id,
|
|
1440
|
+
combined = Developer.merge(group: "developers.name, developers.salary, developers.id, developers.mentor_id, developers.firm_id, developers.legacy_created_at, developers.legacy_updated_at, developers.legacy_created_on, developers.legacy_updated_on").to_a
|
|
1153
1441
|
assert_equal combined, Developer.merge(group: ["developers.name", "developers.salary", "developers.id", "developers.mentor_id", "developers.firm_id", "developers.created_at", "developers.updated_at", "developers.created_on", "developers.updated_on"]).to_a
|
|
1154
1442
|
end
|
|
1155
1443
|
|
|
@@ -1174,10 +1462,10 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1174
1462
|
end
|
|
1175
1463
|
end
|
|
1176
1464
|
|
|
1177
|
-
def
|
|
1178
|
-
query = lambda { ActiveRecord::Base.
|
|
1179
|
-
|
|
1180
|
-
|
|
1465
|
+
def test_assert_queries_count
|
|
1466
|
+
query = lambda { ActiveRecord::Base.lease_connection.execute "select count(*) from developers" }
|
|
1467
|
+
assert_queries_count(2) { 2.times { query.call } }
|
|
1468
|
+
assert_queries_count 1, &query
|
|
1181
1469
|
assert_no_queries { assert true }
|
|
1182
1470
|
end
|
|
1183
1471
|
|
|
@@ -1209,31 +1497,18 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1209
1497
|
|
|
1210
1498
|
def test_clear_cache!
|
|
1211
1499
|
# preheat cache
|
|
1212
|
-
c1 = Post.
|
|
1213
|
-
assert_not_equal 0, Post.
|
|
1500
|
+
c1 = Post.schema_cache.columns("posts")
|
|
1501
|
+
assert_not_equal 0, Post.schema_cache.size
|
|
1214
1502
|
|
|
1215
1503
|
ActiveRecord::Base.clear_cache!
|
|
1216
|
-
assert_equal 0, Post.
|
|
1504
|
+
assert_equal 0, Post.schema_cache.size
|
|
1217
1505
|
|
|
1218
|
-
c2 = Post.
|
|
1219
|
-
assert_not_equal 0, Post.
|
|
1506
|
+
c2 = Post.schema_cache.columns("posts")
|
|
1507
|
+
assert_not_equal 0, Post.schema_cache.size
|
|
1220
1508
|
|
|
1221
1509
|
assert_equal c1, c2
|
|
1222
1510
|
end
|
|
1223
1511
|
|
|
1224
|
-
def test_current_scope_is_reset
|
|
1225
|
-
Object.const_set :UnloadablePost, Class.new(ActiveRecord::Base)
|
|
1226
|
-
UnloadablePost.current_scope = UnloadablePost.all
|
|
1227
|
-
|
|
1228
|
-
UnloadablePost.unloadable
|
|
1229
|
-
klass = UnloadablePost
|
|
1230
|
-
assert_not_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, klass)
|
|
1231
|
-
ActiveSupport::Dependencies.remove_unloadable_constants!
|
|
1232
|
-
assert_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, klass)
|
|
1233
|
-
ensure
|
|
1234
|
-
Object.class_eval { remove_const :UnloadablePost } if defined?(UnloadablePost)
|
|
1235
|
-
end
|
|
1236
|
-
|
|
1237
1512
|
def test_marshal_round_trip
|
|
1238
1513
|
expected = posts(:welcome)
|
|
1239
1514
|
marshalled = Marshal.dump(expected)
|
|
@@ -1256,10 +1531,10 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1256
1531
|
marshalled = Marshal.dump(Post.new)
|
|
1257
1532
|
post = Marshal.load(marshalled)
|
|
1258
1533
|
|
|
1259
|
-
|
|
1534
|
+
assert_predicate post, :new_record?, "should be a new record"
|
|
1260
1535
|
end
|
|
1261
1536
|
|
|
1262
|
-
def
|
|
1537
|
+
def test_marshalling_with_associations_6_1
|
|
1263
1538
|
post = Post.new
|
|
1264
1539
|
post.comments.build
|
|
1265
1540
|
|
|
@@ -1269,19 +1544,19 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1269
1544
|
assert_equal 1, post.comments.length
|
|
1270
1545
|
end
|
|
1271
1546
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
"support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump",
|
|
1276
|
-
TEST_ROOT
|
|
1277
|
-
)
|
|
1278
|
-
topic = Marshal.load(File.read(path))
|
|
1547
|
+
def test_marshalling_with_associations_7_1
|
|
1548
|
+
previous_format_version = ActiveRecord::Marshalling.format_version
|
|
1549
|
+
ActiveRecord::Marshalling.format_version = 7.1
|
|
1279
1550
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1551
|
+
post = Post.new
|
|
1552
|
+
post.comments.build
|
|
1553
|
+
|
|
1554
|
+
marshalled = Marshal.dump(post)
|
|
1555
|
+
post = Marshal.load(marshalled)
|
|
1556
|
+
|
|
1557
|
+
assert_equal 1, post.comments.length
|
|
1558
|
+
ensure
|
|
1559
|
+
ActiveRecord::Marshalling.format_version = previous_format_version
|
|
1285
1560
|
end
|
|
1286
1561
|
|
|
1287
1562
|
if Process.respond_to?(:fork) && !in_memory_db?
|
|
@@ -1299,7 +1574,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1299
1574
|
rd.binmode
|
|
1300
1575
|
wr.binmode
|
|
1301
1576
|
|
|
1302
|
-
ActiveRecord::Base.connection_handler.clear_all_connections!
|
|
1577
|
+
ActiveRecord::Base.connection_handler.clear_all_connections!(:all)
|
|
1303
1578
|
|
|
1304
1579
|
fork do
|
|
1305
1580
|
rd.close
|
|
@@ -1307,6 +1582,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1307
1582
|
post.comments.build
|
|
1308
1583
|
wr.write Marshal.dump(post)
|
|
1309
1584
|
wr.close
|
|
1585
|
+
exit!(0)
|
|
1310
1586
|
end
|
|
1311
1587
|
|
|
1312
1588
|
wr.close
|
|
@@ -1323,11 +1599,11 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1323
1599
|
|
|
1324
1600
|
post = Marshal.load(Marshal.dump(post))
|
|
1325
1601
|
|
|
1326
|
-
|
|
1602
|
+
assert_predicate post, :new_record?, "should be a new record"
|
|
1327
1603
|
end
|
|
1328
1604
|
|
|
1329
1605
|
def test_attribute_names
|
|
1330
|
-
expected = ["id", "type", "firm_id", "firm_name", "name", "client_of", "rating", "account_id", "description", "metadata"]
|
|
1606
|
+
expected = ["id", "type", "firm_id", "firm_name", "name", "client_of", "rating", "account_id", "description", "status", "metadata"]
|
|
1331
1607
|
assert_equal expected, Company.attribute_names
|
|
1332
1608
|
end
|
|
1333
1609
|
|
|
@@ -1411,45 +1687,15 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1411
1687
|
assert_equal "t.lo", topic.author_name
|
|
1412
1688
|
end
|
|
1413
1689
|
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
company = Company.new(rating: 1, name: "37signals", firm_name: "37signals")
|
|
1420
|
-
hash = company.slice(:name, :rating, "arbitrary_method")
|
|
1421
|
-
assert_equal hash[:name], company.name
|
|
1422
|
-
assert_equal hash["name"], company.name
|
|
1423
|
-
assert_equal hash[:rating], company.rating
|
|
1424
|
-
assert_equal hash["arbitrary_method"], company.arbitrary_method
|
|
1425
|
-
assert_equal hash[:arbitrary_method], company.arbitrary_method
|
|
1426
|
-
assert_nil hash[:firm_name]
|
|
1427
|
-
assert_nil hash["firm_name"]
|
|
1428
|
-
end
|
|
1429
|
-
|
|
1430
|
-
def test_slice_accepts_array_argument
|
|
1431
|
-
attrs = {
|
|
1432
|
-
title: "slice",
|
|
1433
|
-
author_name: "@Cohen-Carlisle",
|
|
1434
|
-
content: "accept arrays so I don't have to splat"
|
|
1435
|
-
}.with_indifferent_access
|
|
1436
|
-
topic = Topic.new(attrs)
|
|
1437
|
-
assert_equal attrs, topic.slice(attrs.keys)
|
|
1438
|
-
end
|
|
1439
|
-
|
|
1440
|
-
def test_values_at
|
|
1441
|
-
company = Company.new(name: "37signals", rating: 1)
|
|
1442
|
-
|
|
1443
|
-
assert_equal [ "37signals", 1, "I am Jack's profound disappointment" ],
|
|
1444
|
-
company.values_at(:name, :rating, :arbitrary_method)
|
|
1445
|
-
assert_equal [ "I am Jack's profound disappointment", 1, "37signals" ],
|
|
1446
|
-
company.values_at(:arbitrary_method, :rating, :name)
|
|
1690
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
1691
|
+
def test_column_types_on_queries_on_postgresql
|
|
1692
|
+
result = ActiveRecord::Base.lease_connection.exec_query("SELECT 1 AS test")
|
|
1693
|
+
assert_equal ActiveModel::Type::Integer, result.column_types["test"].class
|
|
1694
|
+
end
|
|
1447
1695
|
end
|
|
1448
1696
|
|
|
1449
|
-
def
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
assert_equal %w( Budget Jason ), topic.values_at(%w( title author_name ))
|
|
1697
|
+
def test_typecasting_aliases
|
|
1698
|
+
assert_equal 10, Topic.select("10 as tenderlove").first.tenderlove
|
|
1453
1699
|
end
|
|
1454
1700
|
|
|
1455
1701
|
def test_default_values_are_deeply_dupped
|
|
@@ -1460,6 +1706,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1460
1706
|
|
|
1461
1707
|
test "scoped can take a values hash" do
|
|
1462
1708
|
klass = Class.new(ActiveRecord::Base)
|
|
1709
|
+
klass.table_name = "bar"
|
|
1463
1710
|
assert_equal ["foo"], klass.all.merge!(select: "foo").select_values
|
|
1464
1711
|
end
|
|
1465
1712
|
|
|
@@ -1541,7 +1788,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1541
1788
|
end
|
|
1542
1789
|
|
|
1543
1790
|
test "ignored columns are not present in columns_hash" do
|
|
1544
|
-
cache_columns = Developer.
|
|
1791
|
+
cache_columns = Developer.schema_cache.columns_hash(Developer.table_name)
|
|
1545
1792
|
assert_includes cache_columns.keys, "first_name"
|
|
1546
1793
|
assert_not_includes Developer.columns_hash.keys, "first_name"
|
|
1547
1794
|
assert_not_includes SubDeveloper.columns_hash.keys, "first_name"
|
|
@@ -1642,26 +1889,26 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1642
1889
|
ActiveRecord::Base.protected_environments = previous_protected_environments
|
|
1643
1890
|
end
|
|
1644
1891
|
|
|
1645
|
-
test "
|
|
1646
|
-
|
|
1647
|
-
|
|
1892
|
+
test "#present? and #blank? on ActiveRecord::Base classes" do
|
|
1893
|
+
assert_not_empty Topic.all
|
|
1894
|
+
assert_no_queries do
|
|
1895
|
+
assert_predicate Topic, :present?
|
|
1896
|
+
assert_not Topic.blank?
|
|
1648
1897
|
end
|
|
1649
1898
|
|
|
1650
|
-
|
|
1899
|
+
Topic.delete_all
|
|
1900
|
+
assert_no_queries do
|
|
1901
|
+
assert_predicate Topic, :present?
|
|
1902
|
+
assert_not Topic.blank?
|
|
1903
|
+
end
|
|
1651
1904
|
end
|
|
1652
1905
|
|
|
1653
|
-
test "cannot call
|
|
1654
|
-
old_value = ActiveRecord::Base.legacy_connection_handling
|
|
1655
|
-
ActiveRecord::Base.legacy_connection_handling = true
|
|
1656
|
-
|
|
1906
|
+
test "cannot call connects_to on non-abstract or non-ActiveRecord::Base classes" do
|
|
1657
1907
|
error = assert_raises(NotImplementedError) do
|
|
1658
|
-
Bird.
|
|
1908
|
+
Bird.connects_to(database: { writing: :arunit })
|
|
1659
1909
|
end
|
|
1660
1910
|
|
|
1661
|
-
assert_equal "`
|
|
1662
|
-
ensure
|
|
1663
|
-
clean_up_legacy_connection_handlers
|
|
1664
|
-
ActiveRecord::Base.legacy_connection_handling = old_value
|
|
1911
|
+
assert_equal "`connects_to` can only be called on ActiveRecord::Base or abstract classes", error.message
|
|
1665
1912
|
end
|
|
1666
1913
|
|
|
1667
1914
|
test "cannot call connected_to with role and shard on non-abstract classes" do
|
|
@@ -1712,28 +1959,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
1712
1959
|
ActiveRecord::Base.connected_to_stack.pop
|
|
1713
1960
|
end
|
|
1714
1961
|
|
|
1715
|
-
test "#connecting_to doesn't work with legacy connection handling" do
|
|
1716
|
-
old_value = ActiveRecord::Base.legacy_connection_handling
|
|
1717
|
-
ActiveRecord::Base.legacy_connection_handling = true
|
|
1718
|
-
|
|
1719
|
-
assert_raises NotImplementedError do
|
|
1720
|
-
SecondAbstractClass.connecting_to(role: :writing, prevent_writes: true)
|
|
1721
|
-
end
|
|
1722
|
-
ensure
|
|
1723
|
-
ActiveRecord::Base.legacy_connection_handling = old_value
|
|
1724
|
-
end
|
|
1725
|
-
|
|
1726
|
-
test "#connected_to_many doesn't work with legacy connection handling" do
|
|
1727
|
-
old_value = ActiveRecord::Base.legacy_connection_handling
|
|
1728
|
-
ActiveRecord::Base.legacy_connection_handling = true
|
|
1729
|
-
|
|
1730
|
-
assert_raises NotImplementedError do
|
|
1731
|
-
ActiveRecord::Base.connected_to_many([SecondAbstractClass], role: :writing)
|
|
1732
|
-
end
|
|
1733
|
-
ensure
|
|
1734
|
-
ActiveRecord::Base.legacy_connection_handling = old_value
|
|
1735
|
-
end
|
|
1736
|
-
|
|
1737
1962
|
test "#connected_to_many cannot be called on anything but ActiveRecord::Base" do
|
|
1738
1963
|
assert_raises NotImplementedError do
|
|
1739
1964
|
SecondAbstractClass.connected_to_many([SecondAbstractClass], role: :writing)
|