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
|
@@ -7,10 +7,16 @@ module ActiveRecord
|
|
|
7
7
|
module Type
|
|
8
8
|
class DateTimeTest < ActiveRecord::TestCase
|
|
9
9
|
def test_datetime_seconds_precision_applied_to_timestamp
|
|
10
|
-
skip "This test is invalid if subsecond precision isn't supported" unless supports_datetime_with_precision?
|
|
11
10
|
p = Task.create!(starting: ::Time.now)
|
|
12
11
|
assert_equal p.starting.usec, p.reload.starting.usec
|
|
13
12
|
end
|
|
13
|
+
|
|
14
|
+
test "serialize_cast_value is equivalent to serialize after cast" do
|
|
15
|
+
type = Type::DateTime.new(precision: 1)
|
|
16
|
+
value = type.cast("1999-12-31 12:34:56.789 -1000")
|
|
17
|
+
|
|
18
|
+
assert_equal type.serialize(value), type.serialize_cast_value(value)
|
|
19
|
+
end
|
|
14
20
|
end
|
|
15
21
|
end
|
|
16
22
|
end
|
|
@@ -23,6 +23,15 @@ module ActiveRecord
|
|
|
23
23
|
assert_equal expected_time, topic.bonus_time
|
|
24
24
|
assert_instance_of ::Time, topic.bonus_time
|
|
25
25
|
end
|
|
26
|
+
|
|
27
|
+
test "serialize_cast_value is equivalent to serialize after cast" do
|
|
28
|
+
type = Type::Time.new(precision: 1)
|
|
29
|
+
value = type.cast("1999-12-31T12:34:56.789-10:00")
|
|
30
|
+
|
|
31
|
+
assert_equal type.serialize(value), type.serialize_cast_value(value)
|
|
32
|
+
assert_instance_of type.serialize(value).class, type.serialize_cast_value(value)
|
|
33
|
+
assert_instance_of type.serialize(nil).class, type.serialize_cast_value(nil)
|
|
34
|
+
end
|
|
26
35
|
end
|
|
27
36
|
end
|
|
28
37
|
end
|
|
@@ -4,16 +4,60 @@ require "cases/helper"
|
|
|
4
4
|
|
|
5
5
|
module ActiveRecord
|
|
6
6
|
module Type
|
|
7
|
-
|
|
7
|
+
module TypeMapSharedTests
|
|
8
8
|
def test_default_type
|
|
9
|
-
mapping =
|
|
9
|
+
mapping = klass.new
|
|
10
10
|
|
|
11
11
|
assert_kind_of Value, mapping.lookup(:undefined)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
+
def test_requires_value_or_block
|
|
15
|
+
mapping = klass.new
|
|
16
|
+
|
|
17
|
+
assert_raises(ArgumentError) do
|
|
18
|
+
mapping.register_type(/only key/i)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_fetch
|
|
23
|
+
mapping = klass.new
|
|
24
|
+
mapping.register_type(1, "string")
|
|
25
|
+
|
|
26
|
+
assert_equal "string", mapping.fetch(1) { "int" }
|
|
27
|
+
assert_equal "int", mapping.fetch(2) { "int" }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_fetch_memoizes
|
|
31
|
+
mapping = klass.new
|
|
32
|
+
|
|
33
|
+
looked_up = false
|
|
34
|
+
mapping.register_type(1) do
|
|
35
|
+
fail if looked_up
|
|
36
|
+
looked_up = true
|
|
37
|
+
"string"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
assert_equal "string", mapping.fetch(1)
|
|
41
|
+
assert_equal "string", mapping.fetch(1)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_register_clears_cache
|
|
45
|
+
mapping = klass.new
|
|
46
|
+
|
|
47
|
+
mapping.register_type(1, "string")
|
|
48
|
+
mapping.lookup(1)
|
|
49
|
+
mapping.register_type(1, "int")
|
|
50
|
+
|
|
51
|
+
assert_equal "int", mapping.lookup(1)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class TypeMapTest < ActiveRecord::TestCase
|
|
56
|
+
include TypeMapSharedTests
|
|
57
|
+
|
|
14
58
|
def test_registering_types
|
|
15
59
|
boolean = Boolean.new
|
|
16
|
-
mapping =
|
|
60
|
+
mapping = klass.new
|
|
17
61
|
|
|
18
62
|
mapping.register_type(/boolean/i, boolean)
|
|
19
63
|
|
|
@@ -23,7 +67,7 @@ module ActiveRecord
|
|
|
23
67
|
def test_overriding_registered_types
|
|
24
68
|
time = Time.new
|
|
25
69
|
timestamp = DateTime.new
|
|
26
|
-
mapping =
|
|
70
|
+
mapping = klass.new
|
|
27
71
|
|
|
28
72
|
mapping.register_type(/time/i, time)
|
|
29
73
|
mapping.register_type(/time/i, timestamp)
|
|
@@ -31,18 +75,9 @@ module ActiveRecord
|
|
|
31
75
|
assert_equal mapping.lookup("time"), timestamp
|
|
32
76
|
end
|
|
33
77
|
|
|
34
|
-
def test_fuzzy_lookup
|
|
35
|
-
string = +""
|
|
36
|
-
mapping = TypeMap.new
|
|
37
|
-
|
|
38
|
-
mapping.register_type(/varchar/i, string)
|
|
39
|
-
|
|
40
|
-
assert_equal mapping.lookup("varchar(20)"), string
|
|
41
|
-
end
|
|
42
|
-
|
|
43
78
|
def test_aliasing_types
|
|
44
79
|
string = +""
|
|
45
|
-
mapping =
|
|
80
|
+
mapping = klass.new
|
|
46
81
|
|
|
47
82
|
mapping.register_type(/string/i, string)
|
|
48
83
|
mapping.alias_type(/varchar/i, "string")
|
|
@@ -53,29 +88,38 @@ module ActiveRecord
|
|
|
53
88
|
def test_changing_type_changes_aliases
|
|
54
89
|
time = Time.new
|
|
55
90
|
timestamp = DateTime.new
|
|
56
|
-
mapping =
|
|
91
|
+
mapping = klass.new
|
|
57
92
|
|
|
58
93
|
mapping.register_type(/timestamp/i, time)
|
|
59
94
|
mapping.alias_type(/datetime/i, "timestamp")
|
|
60
95
|
mapping.register_type(/timestamp/i, timestamp)
|
|
61
96
|
|
|
62
|
-
assert_equal mapping.lookup("datetime")
|
|
97
|
+
assert_equal timestamp, mapping.lookup("datetime")
|
|
63
98
|
end
|
|
64
99
|
|
|
65
100
|
def test_aliases_keep_metadata
|
|
66
|
-
mapping =
|
|
101
|
+
mapping = klass.new
|
|
67
102
|
|
|
68
103
|
mapping.register_type(/decimal/i) { |sql_type| sql_type }
|
|
69
104
|
mapping.alias_type(/number/i, "decimal")
|
|
70
105
|
|
|
71
|
-
assert_equal
|
|
72
|
-
assert_equal mapping.lookup("number")
|
|
106
|
+
assert_equal "decimal(20)", mapping.lookup("number(20)")
|
|
107
|
+
assert_equal "decimal", mapping.lookup("number")
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_fuzzy_lookup
|
|
111
|
+
string = +""
|
|
112
|
+
mapping = klass.new
|
|
113
|
+
|
|
114
|
+
mapping.register_type(/varchar/i, string)
|
|
115
|
+
|
|
116
|
+
assert_equal mapping.lookup("varchar(20)"), string
|
|
73
117
|
end
|
|
74
118
|
|
|
75
119
|
def test_register_proc
|
|
76
120
|
string = +""
|
|
77
121
|
binary = Binary.new
|
|
78
|
-
mapping =
|
|
122
|
+
mapping = klass.new
|
|
79
123
|
|
|
80
124
|
mapping.register_type(/varchar/i) do |type|
|
|
81
125
|
if type.include?("(")
|
|
@@ -89,29 +133,47 @@ module ActiveRecord
|
|
|
89
133
|
assert_equal mapping.lookup("varchar"), binary
|
|
90
134
|
end
|
|
91
135
|
|
|
136
|
+
def test_parent_fallback
|
|
137
|
+
boolean = Boolean.new
|
|
138
|
+
|
|
139
|
+
parent = klass.new
|
|
140
|
+
parent.register_type(/boolean/i, boolean)
|
|
141
|
+
|
|
142
|
+
mapping = klass.new(parent)
|
|
143
|
+
assert_equal boolean, mapping.lookup("boolean")
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_parent_fallback_for_default_type
|
|
147
|
+
parent = klass.new
|
|
148
|
+
mapping = klass.new(parent)
|
|
149
|
+
|
|
150
|
+
assert_kind_of Value, mapping.lookup(:undefined)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
private
|
|
154
|
+
def klass
|
|
155
|
+
TypeMap
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
class HashLookupTypeMapTest < ActiveRecord::TestCase
|
|
160
|
+
include TypeMapSharedTests
|
|
161
|
+
|
|
92
162
|
def test_additional_lookup_args
|
|
93
|
-
mapping =
|
|
163
|
+
mapping = HashLookupTypeMap.new
|
|
94
164
|
|
|
95
|
-
mapping.register_type(
|
|
165
|
+
mapping.register_type("varchar") do |type, limit|
|
|
96
166
|
if limit > 255
|
|
97
167
|
"text"
|
|
98
168
|
else
|
|
99
169
|
"string"
|
|
100
170
|
end
|
|
101
171
|
end
|
|
102
|
-
mapping.alias_type(
|
|
103
|
-
|
|
104
|
-
assert_equal mapping.lookup("varchar", 200), "string"
|
|
105
|
-
assert_equal mapping.lookup("varchar", 400), "text"
|
|
106
|
-
assert_equal mapping.lookup("string", 400), "text"
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_requires_value_or_block
|
|
110
|
-
mapping = TypeMap.new
|
|
172
|
+
mapping.alias_type("string", "varchar")
|
|
111
173
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
174
|
+
assert_equal "string", mapping.lookup("varchar", 200)
|
|
175
|
+
assert_equal "text", mapping.lookup("varchar", 400)
|
|
176
|
+
assert_equal "text", mapping.lookup("string", 400)
|
|
115
177
|
end
|
|
116
178
|
|
|
117
179
|
def test_lookup_non_strings
|
|
@@ -121,58 +183,31 @@ module ActiveRecord
|
|
|
121
183
|
mapping.register_type(2, "int")
|
|
122
184
|
mapping.alias_type(3, 1)
|
|
123
185
|
|
|
124
|
-
assert_equal mapping.lookup(1)
|
|
125
|
-
assert_equal mapping.lookup(2)
|
|
126
|
-
assert_equal mapping.lookup(3)
|
|
186
|
+
assert_equal "string", mapping.lookup(1)
|
|
187
|
+
assert_equal "int", mapping.lookup(2)
|
|
188
|
+
assert_equal "string", mapping.lookup(3)
|
|
127
189
|
assert_kind_of Type::Value, mapping.lookup(4)
|
|
128
190
|
end
|
|
129
191
|
|
|
130
|
-
def
|
|
131
|
-
mapping =
|
|
132
|
-
mapping.register_type(
|
|
192
|
+
def test_fetch_memoizes_on_args
|
|
193
|
+
mapping = HashLookupTypeMap.new
|
|
194
|
+
mapping.register_type("foo") { |*args| args.join("-") }
|
|
133
195
|
|
|
134
|
-
assert_equal "
|
|
135
|
-
assert_equal "
|
|
196
|
+
assert_equal "foo-1-2-3", mapping.fetch("foo", 1, 2, 3) { |*args| args.join("-") }
|
|
197
|
+
assert_equal "foo-2-3-4", mapping.fetch("foo", 2, 3, 4) { |*args| args.join("-") }
|
|
136
198
|
end
|
|
137
199
|
|
|
138
200
|
def test_fetch_yields_args
|
|
139
|
-
mapping =
|
|
201
|
+
mapping = klass.new
|
|
140
202
|
|
|
141
203
|
assert_equal "foo-1-2-3", mapping.fetch("foo", 1, 2, 3) { |*args| args.join("-") }
|
|
142
204
|
assert_equal "bar-1-2-3", mapping.fetch("bar", 1, 2, 3) { |*args| args.join("-") }
|
|
143
205
|
end
|
|
144
206
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
looked_up = false
|
|
149
|
-
mapping.register_type(1) do
|
|
150
|
-
fail if looked_up
|
|
151
|
-
looked_up = true
|
|
152
|
-
"string"
|
|
207
|
+
private
|
|
208
|
+
def klass
|
|
209
|
+
HashLookupTypeMap
|
|
153
210
|
end
|
|
154
|
-
|
|
155
|
-
assert_equal "string", mapping.fetch(1)
|
|
156
|
-
assert_equal "string", mapping.fetch(1)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def test_fetch_memoizes_on_args
|
|
160
|
-
mapping = TypeMap.new
|
|
161
|
-
mapping.register_type("foo") { |*args| args.join("-") }
|
|
162
|
-
|
|
163
|
-
assert_equal "foo-1-2-3", mapping.fetch("foo", 1, 2, 3) { |*args| args.join("-") }
|
|
164
|
-
assert_equal "foo-2-3-4", mapping.fetch("foo", 2, 3, 4) { |*args| args.join("-") }
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def test_register_clears_cache
|
|
168
|
-
mapping = TypeMap.new
|
|
169
|
-
|
|
170
|
-
mapping.register_type(1, "string")
|
|
171
|
-
mapping.lookup(1)
|
|
172
|
-
mapping.register_type(1, "int")
|
|
173
|
-
|
|
174
|
-
assert_equal "int", mapping.lookup(1)
|
|
175
|
-
end
|
|
176
211
|
end
|
|
177
212
|
end
|
|
178
213
|
end
|
|
@@ -14,6 +14,18 @@ module ActiveRecord
|
|
|
14
14
|
UnsignedInteger.new.serialize(-1)
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
|
+
|
|
18
|
+
test "serialize_cast_value enforces range" do
|
|
19
|
+
type = UnsignedInteger.new
|
|
20
|
+
|
|
21
|
+
assert_raises(ActiveModel::RangeError) do
|
|
22
|
+
type.serialize_cast_value(-1)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
assert_raises(ActiveModel::RangeError) do
|
|
26
|
+
type.serialize_cast_value(4294967296)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
17
29
|
end
|
|
18
30
|
end
|
|
19
31
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "cases/helper"
|
|
4
|
+
require "models/developer"
|
|
5
|
+
|
|
6
|
+
module ActiveRecord
|
|
7
|
+
module TypeCaster
|
|
8
|
+
class ConnectionTest < ActiveSupport::TestCase
|
|
9
|
+
test "#type_for_attribute is not aware of custom types" do
|
|
10
|
+
type_caster = Connection.new(AttributedDeveloper, "developers")
|
|
11
|
+
|
|
12
|
+
type = type_caster.type_for_attribute(:name)
|
|
13
|
+
|
|
14
|
+
assert_not_equal DeveloperName, type.class
|
|
15
|
+
assert_equal ActiveRecord::Type::String, type.class
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/test/cases/type_test.rb
CHANGED
|
@@ -30,7 +30,7 @@ class TypeTest < ActiveRecord::TestCase
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
test "lookup defaults to the current adapter" do
|
|
33
|
-
current_adapter = ActiveRecord::Base
|
|
33
|
+
current_adapter = ActiveRecord::Type.adapter_name_from(ActiveRecord::Base)
|
|
34
34
|
type = Struct.new(:args)
|
|
35
35
|
adapter_type = Struct.new(:args)
|
|
36
36
|
ActiveRecord::Type.register(:foo, type, override: false)
|
|
@@ -9,8 +9,8 @@ class TestUnconnectedAdapter < ActiveRecord::TestCase
|
|
|
9
9
|
self.use_transactional_tests = false
|
|
10
10
|
|
|
11
11
|
def setup
|
|
12
|
-
@underlying = ActiveRecord::Base.
|
|
13
|
-
@
|
|
12
|
+
@underlying = ActiveRecord::Base.lease_connection
|
|
13
|
+
@connection_name = ActiveRecord::Base.remove_connection
|
|
14
14
|
|
|
15
15
|
# Clear out connection info from other pids (like a fork parent) too
|
|
16
16
|
ActiveRecord::ConnectionAdapters::PoolConfig.discard_pools!
|
|
@@ -18,26 +18,26 @@ class TestUnconnectedAdapter < ActiveRecord::TestCase
|
|
|
18
18
|
|
|
19
19
|
teardown do
|
|
20
20
|
@underlying = nil
|
|
21
|
-
ActiveRecord::Base.establish_connection(@
|
|
21
|
+
ActiveRecord::Base.establish_connection(@connection_name)
|
|
22
22
|
load_schema if in_memory_db?
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def test_connection_no_longer_established
|
|
26
|
-
assert_raise(ActiveRecord::
|
|
26
|
+
assert_raise(ActiveRecord::ConnectionNotDefined) do
|
|
27
27
|
TestRecord.find(1)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
assert_raise(ActiveRecord::
|
|
30
|
+
assert_raise(ActiveRecord::ConnectionNotDefined) do
|
|
31
31
|
TestRecord.new.save
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def test_error_message_when_connection_not_established
|
|
36
|
-
error = assert_raise(ActiveRecord::
|
|
36
|
+
error = assert_raise(ActiveRecord::ConnectionNotDefined) do
|
|
37
37
|
TestRecord.find(1)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
assert_equal "No connection
|
|
40
|
+
assert_equal "No database connection defined.", error.message
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def test_underlying_adapter_no_longer_active
|
|
@@ -74,8 +74,7 @@ class UnsafeRawSqlTest < ActiveRecord::TestCase
|
|
|
74
74
|
test "order: allows quoted table and column names" do
|
|
75
75
|
ids_expected = Post.order(Arel.sql("title")).pluck(:id)
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
ids = Post.order(quoted_title).pluck(:id)
|
|
77
|
+
ids = Post.order(quote_table_name("posts.title")).pluck(:id)
|
|
79
78
|
|
|
80
79
|
assert_equal ids_expected, ids
|
|
81
80
|
end
|
|
@@ -166,12 +165,37 @@ class UnsafeRawSqlTest < ActiveRecord::TestCase
|
|
|
166
165
|
assert_equal ids_expected, ids
|
|
167
166
|
end
|
|
168
167
|
|
|
169
|
-
test "order:
|
|
168
|
+
test "order: allows valid arguments with COLLATE" do
|
|
169
|
+
skip "IBM DB does not support column-level COLLATE in ORDER BY" if current_adapter?(:IBM_DBAdapter)
|
|
170
|
+
|
|
171
|
+
collation_name = {
|
|
172
|
+
"PostgreSQL" => "C",
|
|
173
|
+
"Mysql2" => "utf8mb4_bin",
|
|
174
|
+
"Trilogy" => "utf8mb4_bin",
|
|
175
|
+
"SQLite" => "binary"
|
|
176
|
+
}[ActiveRecord::Base.lease_connection.adapter_name]
|
|
177
|
+
|
|
178
|
+
ids_expected = Post.order(Arel.sql(%Q'author_id, title COLLATE "#{collation_name}" DESC')).pluck(:id)
|
|
179
|
+
|
|
180
|
+
ids = Post.order(["author_id", %Q'title COLLATE "#{collation_name}" DESC']).pluck(:id)
|
|
181
|
+
|
|
182
|
+
assert_equal ids_expected, ids
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
test "order: allows nested functions" do
|
|
186
|
+
ids_expected = Post.order(Arel.sql("author_id, length(trim(title))")).pluck(:id)
|
|
187
|
+
|
|
188
|
+
ids = Post.order("author_id, length(trim(title))").pluck(:id)
|
|
189
|
+
|
|
190
|
+
assert_equal ids_expected, ids
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
test "order: disallows dangerous query method" do
|
|
170
194
|
e = assert_raises(ActiveRecord::UnknownAttributeReference) do
|
|
171
195
|
Post.order("REPLACE(title, 'misc', 'zzzz')")
|
|
172
196
|
end
|
|
173
197
|
|
|
174
|
-
assert_match(/
|
|
198
|
+
assert_match(/Dangerous query method \(method whose arguments are used as raw SQL\) called with non-attribute argument\(s\):/, e.message)
|
|
175
199
|
end
|
|
176
200
|
|
|
177
201
|
test "pluck: allows string column name" do
|
|
@@ -233,12 +257,19 @@ class UnsafeRawSqlTest < ActiveRecord::TestCase
|
|
|
233
257
|
test "pluck: allows quoted table and column names" do
|
|
234
258
|
titles_expected = Post.pluck(Arel.sql("title"))
|
|
235
259
|
|
|
236
|
-
|
|
237
|
-
titles = Post.pluck(quoted_title)
|
|
260
|
+
titles = Post.pluck(quote_table_name("posts.title"))
|
|
238
261
|
|
|
239
262
|
assert_equal titles_expected, titles
|
|
240
263
|
end
|
|
241
264
|
|
|
265
|
+
test "pluck: allows nested functions" do
|
|
266
|
+
title_lengths_expected = Post.pluck(Arel.sql("length(trim(title))"))
|
|
267
|
+
|
|
268
|
+
title_lengths = Post.pluck("length(trim(title))")
|
|
269
|
+
|
|
270
|
+
assert_equal title_lengths_expected, title_lengths
|
|
271
|
+
end
|
|
272
|
+
|
|
242
273
|
test "pluck: disallows invalid column name" do
|
|
243
274
|
assert_raises(ActiveRecord::UnknownAttributeReference) do
|
|
244
275
|
Post.pluck("REPLACE(title, 'misc', 'zzzz')")
|
|
@@ -264,11 +295,11 @@ class UnsafeRawSqlTest < ActiveRecord::TestCase
|
|
|
264
295
|
assert_equal excepted_values, values
|
|
265
296
|
end
|
|
266
297
|
|
|
267
|
-
test "pluck:
|
|
298
|
+
test "pluck: disallows dangerous query method" do
|
|
268
299
|
e = assert_raises(ActiveRecord::UnknownAttributeReference) do
|
|
269
300
|
Post.includes(:comments).pluck(:title, "REPLACE(title, 'misc', 'zzzz')")
|
|
270
301
|
end
|
|
271
302
|
|
|
272
|
-
assert_match(/
|
|
303
|
+
assert_match(/Dangerous query method \(method whose arguments are used as raw SQL\) called with non-attribute argument\(s\):/, e.message)
|
|
273
304
|
end
|
|
274
305
|
end
|
|
@@ -28,7 +28,7 @@ class AbsenceValidationTest < ActiveRecord::TestCase
|
|
|
28
28
|
assert_equal 1, boy.errors[:face].size, "should only add one error"
|
|
29
29
|
|
|
30
30
|
boy.face.mark_for_destruction
|
|
31
|
-
|
|
31
|
+
assert_predicate boy, :valid?, "should be valid if association is marked for destruction"
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def test_has_many_marked_for_destruction
|
|
@@ -49,7 +49,7 @@ class AssociationValidationTest < ActiveRecord::TestCase
|
|
|
49
49
|
|
|
50
50
|
def test_validates_associated_without_marked_for_destruction
|
|
51
51
|
reply = Class.new do
|
|
52
|
-
def valid?
|
|
52
|
+
def valid?(context = nil)
|
|
53
53
|
true
|
|
54
54
|
end
|
|
55
55
|
end
|
|
@@ -84,7 +84,7 @@ class AssociationValidationTest < ActiveRecord::TestCase
|
|
|
84
84
|
Interest.validates_presence_of(:human)
|
|
85
85
|
human = Human.new(name: "John")
|
|
86
86
|
interest = human.interests.build(topic: "Airplanes")
|
|
87
|
-
|
|
87
|
+
assert_predicate interest, :valid?, "Expected interest to be valid, but was not. Interest should have a human object associated"
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
@@ -93,7 +93,29 @@ class AssociationValidationTest < ActiveRecord::TestCase
|
|
|
93
93
|
Interest.validates_presence_of(:human)
|
|
94
94
|
human = Human.create!(name: "John")
|
|
95
95
|
interest = human.interests.build(topic: "Airplanes")
|
|
96
|
-
|
|
96
|
+
assert_predicate interest, :valid?, "Expected interest to be valid, but was not. Interest should have a human object associated"
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
|
+
|
|
100
|
+
def test_validates_associated_with_custom_context
|
|
101
|
+
Reply.validates_associated :topic, on: :custom
|
|
102
|
+
Topic.validates_presence_of :content, on: :custom
|
|
103
|
+
r = Reply.create("title" => "A reply", "content" => "with content!")
|
|
104
|
+
r.topic = Topic.create("title" => "uhohuhoh")
|
|
105
|
+
assert_predicate r, :valid?
|
|
106
|
+
assert_not r.valid?(:custom)
|
|
107
|
+
assert_equal ["is invalid"], r.errors[:topic]
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_validates_associated_with_create_context
|
|
111
|
+
Reply.validates_associated :topic, on: :create
|
|
112
|
+
Topic.validates_presence_of :content, on: :create
|
|
113
|
+
t = Topic.create(title: "uhoh", content: "stuff")
|
|
114
|
+
t.update!(content: nil)
|
|
115
|
+
# NOTE: Does not pass along :create context from reply to Topic validation.
|
|
116
|
+
r = t.replies.create(title: "A reply", content: "with content!")
|
|
117
|
+
|
|
118
|
+
assert_predicate t, :valid?
|
|
119
|
+
assert_predicate r, :valid?
|
|
120
|
+
end
|
|
99
121
|
end
|
|
@@ -111,14 +111,9 @@ class NumericalityValidationTest < ActiveRecord::TestCase
|
|
|
111
111
|
|
|
112
112
|
subject = model_class.new(virtual_decimal_number: 123.455)
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
# we just check the behaviour because both versions of BigDecimal report "3.0.0"
|
|
118
|
-
assert_not_predicate subject, :valid?
|
|
119
|
-
else
|
|
120
|
-
assert_predicate subject, :valid?
|
|
121
|
-
end
|
|
114
|
+
# BigDecimal's to_d behavior changed in BigDecimal 3.1.0, see https://github.com/ruby/bigdecimal/issues/70
|
|
115
|
+
# Since BigDecimal 3.1.4 or higher is installed as an Active Support dependency, we just check the behavior of BigDecimal 3.1.0+.
|
|
116
|
+
assert_not_predicate subject, :valid?
|
|
122
117
|
end
|
|
123
118
|
|
|
124
119
|
def test_virtual_attribute_with_precision_round_up
|
|
@@ -152,7 +147,6 @@ class NumericalityValidationTest < ActiveRecord::TestCase
|
|
|
152
147
|
["99.994", 99.994, BigDecimal("99.994")].each do |raw_value|
|
|
153
148
|
subject = model_class.new(virtual_decimal_number: raw_value)
|
|
154
149
|
assert_equal BigDecimal("99.99"), subject.virtual_decimal_number
|
|
155
|
-
puts "subject = #{subject.attributes}"
|
|
156
150
|
assert_predicate subject, :valid?
|
|
157
151
|
end
|
|
158
152
|
|
|
@@ -24,7 +24,7 @@ class PresenceValidationTest < ActiveRecord::TestCase
|
|
|
24
24
|
def test_validates_presence_of_has_one
|
|
25
25
|
Boy.validates_presence_of(:face)
|
|
26
26
|
b = Boy.new
|
|
27
|
-
|
|
27
|
+
assert_predicate b, :invalid?, "should not be valid if has_one association missing"
|
|
28
28
|
assert_equal 1, b.errors[:face].size, "validates_presence_of should only add one error"
|
|
29
29
|
end
|
|
30
30
|
|