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/fixtures_test.rb
CHANGED
|
@@ -6,6 +6,8 @@ require "models/admin"
|
|
|
6
6
|
require "models/admin/account"
|
|
7
7
|
require "models/admin/randomly_named_c1"
|
|
8
8
|
require "models/admin/user"
|
|
9
|
+
require "models/aircraft"
|
|
10
|
+
require "models/author"
|
|
9
11
|
require "models/binary"
|
|
10
12
|
require "models/book"
|
|
11
13
|
require "models/bulb"
|
|
@@ -16,10 +18,13 @@ require "models/company"
|
|
|
16
18
|
require "models/computer"
|
|
17
19
|
require "models/course"
|
|
18
20
|
require "models/developer"
|
|
21
|
+
require "models/dog_lover"
|
|
19
22
|
require "models/dog"
|
|
20
23
|
require "models/doubloon"
|
|
24
|
+
require "models/essay"
|
|
21
25
|
require "models/joke"
|
|
22
26
|
require "models/matey"
|
|
27
|
+
require "models/organization"
|
|
23
28
|
require "models/other_dog"
|
|
24
29
|
require "models/parrot"
|
|
25
30
|
require "models/pirate"
|
|
@@ -30,7 +35,8 @@ require "models/task"
|
|
|
30
35
|
require "models/topic"
|
|
31
36
|
require "models/traffic_light"
|
|
32
37
|
require "models/treasure"
|
|
33
|
-
require "
|
|
38
|
+
require "models/tree"
|
|
39
|
+
require "models/cpk"
|
|
34
40
|
|
|
35
41
|
class FixturesTest < ActiveRecord::TestCase
|
|
36
42
|
include ConnectionHelper
|
|
@@ -39,7 +45,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
39
45
|
self.use_transactional_tests = false
|
|
40
46
|
|
|
41
47
|
# other_topics fixture should not be included here
|
|
42
|
-
fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights, :
|
|
48
|
+
fixtures :topics, :developers, :accounts, :tasks, :categories, :funny_jokes, :binaries, :traffic_lights, :trees
|
|
43
49
|
|
|
44
50
|
FIXTURES = %w( accounts binaries companies customers
|
|
45
51
|
developers developers_projects entrants
|
|
@@ -79,7 +85,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
79
85
|
end
|
|
80
86
|
end
|
|
81
87
|
|
|
82
|
-
if current_adapter?(:Mysql2Adapter, :PostgreSQLAdapter)
|
|
88
|
+
if current_adapter?(:Mysql2Adapter, :TrilogyAdapter, :PostgreSQLAdapter)
|
|
83
89
|
def test_bulk_insert
|
|
84
90
|
subscriber = InsertQuerySubscriber.new
|
|
85
91
|
subscription = ActiveSupport::Notifications.subscribe("sql.active_record", subscriber)
|
|
@@ -93,12 +99,12 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
93
99
|
subscriber = InsertQuerySubscriber.new
|
|
94
100
|
subscription = ActiveSupport::Notifications.subscribe("sql.active_record", subscriber)
|
|
95
101
|
|
|
96
|
-
create_fixtures("bulbs", "
|
|
102
|
+
create_fixtures("bulbs", "movies", "computers")
|
|
97
103
|
|
|
98
104
|
expected_sql = <<~EOS.chop
|
|
99
|
-
INSERT INTO #{
|
|
100
|
-
INSERT INTO #{
|
|
101
|
-
INSERT INTO #{
|
|
105
|
+
INSERT INTO #{quote_table_name("bulbs")} .*
|
|
106
|
+
INSERT INTO #{quote_table_name("movies")} .*
|
|
107
|
+
INSERT INTO #{quote_table_name("computers")} .*
|
|
102
108
|
EOS
|
|
103
109
|
assert_equal 1, subscriber.events.size
|
|
104
110
|
assert_match(/#{expected_sql}/, subscriber.events.first)
|
|
@@ -107,8 +113,6 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
107
113
|
end
|
|
108
114
|
|
|
109
115
|
def test_bulk_insert_with_a_multi_statement_query_raises_an_exception_when_any_insert_fails
|
|
110
|
-
require "models/aircraft"
|
|
111
|
-
|
|
112
116
|
assert_equal false, Aircraft.columns_hash["wheels_count"].null
|
|
113
117
|
fixtures = {
|
|
114
118
|
"aircraft" => [
|
|
@@ -119,7 +123,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
119
123
|
|
|
120
124
|
assert_no_difference "Aircraft.count" do
|
|
121
125
|
assert_raises(ActiveRecord::NotNullViolation) do
|
|
122
|
-
ActiveRecord::Base.
|
|
126
|
+
ActiveRecord::Base.lease_connection.insert_fixtures_set(fixtures)
|
|
123
127
|
end
|
|
124
128
|
end
|
|
125
129
|
end
|
|
@@ -133,7 +137,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
133
137
|
|
|
134
138
|
assert_difference "TrafficLight.count" do
|
|
135
139
|
ActiveRecord::Base.transaction do
|
|
136
|
-
conn = ActiveRecord::Base.
|
|
140
|
+
conn = ActiveRecord::Base.lease_connection
|
|
137
141
|
assert_equal 1, conn.open_transactions
|
|
138
142
|
conn.insert_fixtures_set(fixtures)
|
|
139
143
|
assert_equal 1, conn.open_transactions
|
|
@@ -142,12 +146,20 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
142
146
|
end
|
|
143
147
|
end
|
|
144
148
|
|
|
145
|
-
if current_adapter?(:Mysql2Adapter)
|
|
149
|
+
if current_adapter?(:Mysql2Adapter, :TrilogyAdapter)
|
|
146
150
|
def test_bulk_insert_with_multi_statements_enabled
|
|
151
|
+
adapter_name = ActiveRecord::Base.lease_connection.adapter_name
|
|
147
152
|
run_without_connection do |orig_connection|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
153
|
+
case adapter_name
|
|
154
|
+
when "Trilogy"
|
|
155
|
+
ActiveRecord::Base.establish_connection(
|
|
156
|
+
orig_connection.merge(multi_statement: true)
|
|
157
|
+
)
|
|
158
|
+
else
|
|
159
|
+
ActiveRecord::Base.establish_connection(
|
|
160
|
+
orig_connection.merge(flags: %w[MULTI_STATEMENTS])
|
|
161
|
+
)
|
|
162
|
+
end
|
|
151
163
|
|
|
152
164
|
fixtures = {
|
|
153
165
|
"traffic_lights" => [
|
|
@@ -156,14 +168,19 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
156
168
|
}
|
|
157
169
|
|
|
158
170
|
assert_nothing_raised do
|
|
159
|
-
conn = ActiveRecord::Base.
|
|
171
|
+
conn = ActiveRecord::Base.lease_connection
|
|
160
172
|
conn.execute("SELECT 1; SELECT 2;")
|
|
161
|
-
|
|
173
|
+
case adapter_name
|
|
174
|
+
when "Trilogy"
|
|
175
|
+
conn.raw_connection.next_result while conn.raw_connection.more_results_exist?
|
|
176
|
+
else
|
|
177
|
+
conn.raw_connection.abandon_results!
|
|
178
|
+
end
|
|
162
179
|
end
|
|
163
180
|
|
|
164
181
|
assert_difference "TrafficLight.count" do
|
|
165
182
|
ActiveRecord::Base.transaction do
|
|
166
|
-
conn = ActiveRecord::Base.
|
|
183
|
+
conn = ActiveRecord::Base.lease_connection
|
|
167
184
|
assert_equal 1, conn.open_transactions
|
|
168
185
|
conn.insert_fixtures_set(fixtures)
|
|
169
186
|
assert_equal 1, conn.open_transactions
|
|
@@ -171,18 +188,31 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
171
188
|
end
|
|
172
189
|
|
|
173
190
|
assert_nothing_raised do
|
|
174
|
-
conn = ActiveRecord::Base.
|
|
191
|
+
conn = ActiveRecord::Base.lease_connection
|
|
175
192
|
conn.execute("SELECT 1; SELECT 2;")
|
|
176
|
-
|
|
193
|
+
case adapter_name
|
|
194
|
+
when "Trilogy"
|
|
195
|
+
conn.raw_connection.next_result while conn.raw_connection.more_results_exist?
|
|
196
|
+
else
|
|
197
|
+
conn.raw_connection.abandon_results!
|
|
198
|
+
end
|
|
177
199
|
end
|
|
178
200
|
end
|
|
179
201
|
end
|
|
180
202
|
|
|
181
203
|
def test_bulk_insert_with_multi_statements_disabled
|
|
204
|
+
adapter_name = ActiveRecord::Base.lease_connection.adapter_name
|
|
182
205
|
run_without_connection do |orig_connection|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
206
|
+
case adapter_name
|
|
207
|
+
when "Trilogy"
|
|
208
|
+
ActiveRecord::Base.establish_connection(
|
|
209
|
+
orig_connection.merge(multi_statement: false)
|
|
210
|
+
)
|
|
211
|
+
else
|
|
212
|
+
ActiveRecord::Base.establish_connection(
|
|
213
|
+
orig_connection.merge(flags: [])
|
|
214
|
+
)
|
|
215
|
+
end
|
|
186
216
|
|
|
187
217
|
fixtures = {
|
|
188
218
|
"traffic_lights" => [
|
|
@@ -191,26 +221,36 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
191
221
|
}
|
|
192
222
|
|
|
193
223
|
assert_raises(ActiveRecord::StatementInvalid) do
|
|
194
|
-
conn = ActiveRecord::Base.
|
|
224
|
+
conn = ActiveRecord::Base.lease_connection
|
|
195
225
|
conn.execute("SELECT 1; SELECT 2;")
|
|
196
|
-
|
|
226
|
+
case adapter_name
|
|
227
|
+
when "Trilogy"
|
|
228
|
+
conn.raw_connection.next_result while conn.raw_connection.more_results_exist?
|
|
229
|
+
else
|
|
230
|
+
conn.raw_connection.abandon_results!
|
|
231
|
+
end
|
|
197
232
|
end
|
|
198
233
|
|
|
199
234
|
assert_difference "TrafficLight.count" do
|
|
200
|
-
conn = ActiveRecord::Base.
|
|
235
|
+
conn = ActiveRecord::Base.lease_connection
|
|
201
236
|
conn.insert_fixtures_set(fixtures)
|
|
202
237
|
end
|
|
203
238
|
|
|
204
239
|
assert_raises(ActiveRecord::StatementInvalid) do
|
|
205
|
-
conn = ActiveRecord::Base.
|
|
240
|
+
conn = ActiveRecord::Base.lease_connection
|
|
206
241
|
conn.execute("SELECT 1; SELECT 2;")
|
|
207
|
-
|
|
242
|
+
case adapter_name
|
|
243
|
+
when "Trilogy"
|
|
244
|
+
conn.raw_connection.next_result while conn.raw_connection.more_results_exist?
|
|
245
|
+
else
|
|
246
|
+
conn.raw_connection.abandon_results!
|
|
247
|
+
end
|
|
208
248
|
end
|
|
209
249
|
end
|
|
210
250
|
end
|
|
211
251
|
|
|
212
252
|
def test_insert_fixtures_set_raises_an_error_when_max_allowed_packet_is_smaller_than_fixtures_set_size
|
|
213
|
-
conn = ActiveRecord::Base.
|
|
253
|
+
conn = ActiveRecord::Base.lease_connection
|
|
214
254
|
mysql_margin = 2
|
|
215
255
|
packet_size = 1024
|
|
216
256
|
bytes_needed_to_have_a_1024_bytes_fixture = 906
|
|
@@ -227,7 +267,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
227
267
|
end
|
|
228
268
|
|
|
229
269
|
def test_insert_fixture_set_when_max_allowed_packet_is_bigger_than_fixtures_set_size
|
|
230
|
-
conn = ActiveRecord::Base.
|
|
270
|
+
conn = ActiveRecord::Base.lease_connection
|
|
231
271
|
packet_size = 1024
|
|
232
272
|
fixtures = {
|
|
233
273
|
"traffic_lights" => [
|
|
@@ -245,7 +285,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
245
285
|
def test_insert_fixtures_set_split_the_total_sql_into_two_chunks_smaller_than_max_allowed_packet
|
|
246
286
|
subscriber = InsertQuerySubscriber.new
|
|
247
287
|
subscription = ActiveSupport::Notifications.subscribe("sql.active_record", subscriber)
|
|
248
|
-
conn = ActiveRecord::Base.
|
|
288
|
+
conn = ActiveRecord::Base.lease_connection
|
|
249
289
|
packet_size = 1024
|
|
250
290
|
fixtures = {
|
|
251
291
|
"traffic_lights" => [
|
|
@@ -270,7 +310,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
270
310
|
def test_insert_fixtures_set_concat_total_sql_into_a_single_packet_smaller_than_max_allowed_packet
|
|
271
311
|
subscriber = InsertQuerySubscriber.new
|
|
272
312
|
subscription = ActiveSupport::Notifications.subscribe("sql.active_record", subscriber)
|
|
273
|
-
conn = ActiveRecord::Base.
|
|
313
|
+
conn = ActiveRecord::Base.lease_connection
|
|
274
314
|
packet_size = 1024
|
|
275
315
|
fixtures = {
|
|
276
316
|
"traffic_lights" => [
|
|
@@ -297,7 +337,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
297
337
|
{ "name" => "first", "wheels_count" => 2 },
|
|
298
338
|
{ "name" => "second", "wheels_count" => 3 }
|
|
299
339
|
]
|
|
300
|
-
conn = ActiveRecord::Base.
|
|
340
|
+
conn = ActiveRecord::Base.lease_connection
|
|
301
341
|
assert_nothing_raised do
|
|
302
342
|
conn.insert_fixtures_set({ "aircraft" => fixtures }, ["aircraft"])
|
|
303
343
|
end
|
|
@@ -321,9 +361,9 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
321
361
|
end
|
|
322
362
|
|
|
323
363
|
def test_create_fixtures
|
|
324
|
-
fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, "
|
|
325
|
-
assert
|
|
326
|
-
assert fixtures.detect { |f| f.name == "
|
|
364
|
+
fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, "organizations")
|
|
365
|
+
assert Organization.find_by_name("No Such Agency"), "'No Such Agency' is not in the database"
|
|
366
|
+
assert fixtures.detect { |f| f.name == "organizations" }, "no fixtures named 'organizations' in #{fixtures.map(&:name).inspect}"
|
|
327
367
|
end
|
|
328
368
|
|
|
329
369
|
def test_multiple_clean_fixtures
|
|
@@ -334,7 +374,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
334
374
|
end
|
|
335
375
|
|
|
336
376
|
def test_create_symbol_fixtures
|
|
337
|
-
fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :collections, collections: Course)
|
|
377
|
+
fixtures = ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, :collections, collections: Course)
|
|
338
378
|
|
|
339
379
|
assert Course.find_by_name("Collection"), "course is not in the database"
|
|
340
380
|
assert fixtures.detect { |f| f.name == "collections" }, "no fixtures named 'collections' in #{fixtures.map(&:name).inspect}"
|
|
@@ -366,10 +406,10 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
366
406
|
|
|
367
407
|
def test_inserts
|
|
368
408
|
create_fixtures("topics")
|
|
369
|
-
first_row = ActiveRecord::Base.
|
|
409
|
+
first_row = ActiveRecord::Base.lease_connection.select_one("SELECT * FROM topics WHERE author_name = 'David'")
|
|
370
410
|
assert_equal("The First Topic", first_row["title"])
|
|
371
411
|
|
|
372
|
-
second_row = ActiveRecord::Base.
|
|
412
|
+
second_row = ActiveRecord::Base.lease_connection.select_one("SELECT * FROM topics WHERE author_name = 'Mary'")
|
|
373
413
|
assert_nil(second_row["author_email_address"])
|
|
374
414
|
end
|
|
375
415
|
|
|
@@ -377,7 +417,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
377
417
|
# Reset cache to make finds on the new table work
|
|
378
418
|
ActiveRecord::FixtureSet.reset_cache
|
|
379
419
|
|
|
380
|
-
ActiveRecord::Base.
|
|
420
|
+
ActiveRecord::Base.lease_connection.create_table :prefix_other_topics_suffix do |t|
|
|
381
421
|
t.column :title, :string
|
|
382
422
|
t.column :author_name, :string
|
|
383
423
|
t.column :author_email_address, :string
|
|
@@ -411,11 +451,11 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
411
451
|
# class-level configuration helper.
|
|
412
452
|
assert_not_nil topics, "Fixture data inserted, but fixture objects not returned from create"
|
|
413
453
|
|
|
414
|
-
first_row = ActiveRecord::Base.
|
|
454
|
+
first_row = ActiveRecord::Base.lease_connection.select_one("SELECT * FROM prefix_other_topics_suffix WHERE author_name = 'David'")
|
|
415
455
|
assert_not_nil first_row, "The prefix_other_topics_suffix table appears to be empty despite create_fixtures: the row with author_name = 'David' was not found"
|
|
416
456
|
assert_equal("The First Topic", first_row["title"])
|
|
417
457
|
|
|
418
|
-
second_row = ActiveRecord::Base.
|
|
458
|
+
second_row = ActiveRecord::Base.lease_connection.select_one("SELECT * FROM prefix_other_topics_suffix WHERE author_name = 'Mary'")
|
|
419
459
|
assert_nil(second_row["author_email_address"])
|
|
420
460
|
|
|
421
461
|
assert_equal :prefix_other_topics_suffix, topics.table_name.to_sym
|
|
@@ -428,7 +468,7 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
428
468
|
ActiveRecord::Base.table_name_prefix = old_prefix
|
|
429
469
|
ActiveRecord::Base.table_name_suffix = old_suffix
|
|
430
470
|
|
|
431
|
-
ActiveRecord::Base.
|
|
471
|
+
ActiveRecord::Base.lease_connection.drop_table :prefix_other_topics_suffix rescue nil
|
|
432
472
|
end
|
|
433
473
|
|
|
434
474
|
def test_insert_with_datetime
|
|
@@ -437,10 +477,44 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
437
477
|
assert first
|
|
438
478
|
end
|
|
439
479
|
|
|
480
|
+
def test_insert_with_default_function
|
|
481
|
+
create_fixtures("aircrafts")
|
|
482
|
+
|
|
483
|
+
aircraft = Aircraft.find_by(name: "boeing-with-no-manufactured-at")
|
|
484
|
+
if current_adapter?(:IBM_DBAdapter)
|
|
485
|
+
# DB2 CURRENT TIMESTAMP returns the server's local wall-clock time, but the
|
|
486
|
+
# IBM_DB driver parses it as UTC, producing an epoch 4h off on a UTC-4 host.
|
|
487
|
+
# Reinterpret the stored components as local time so the epoch is correct.
|
|
488
|
+
stored_local = Time.local(
|
|
489
|
+
aircraft.manufactured_at.year,
|
|
490
|
+
aircraft.manufactured_at.month,
|
|
491
|
+
aircraft.manufactured_at.day,
|
|
492
|
+
aircraft.manufactured_at.hour,
|
|
493
|
+
aircraft.manufactured_at.min,
|
|
494
|
+
aircraft.manufactured_at.sec
|
|
495
|
+
)
|
|
496
|
+
assert_in_delta Time.now.to_i, stored_local.to_i, 2
|
|
497
|
+
else
|
|
498
|
+
assert_in_delta Time.now.utc, aircraft.manufactured_at.utc, 1.1
|
|
499
|
+
end
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
def test_insert_with_default_value
|
|
503
|
+
create_fixtures("aircrafts")
|
|
504
|
+
|
|
505
|
+
aircraft = Aircraft.find_by(name: "boeing-with-no-wheels")
|
|
506
|
+
assert_equal 0, aircraft.wheels_count
|
|
507
|
+
end
|
|
508
|
+
|
|
440
509
|
def test_logger_level_invariant
|
|
510
|
+
previous_logger = ActiveRecord::Base.logger
|
|
511
|
+
ActiveRecord::Base.logger = ActiveSupport::Logger.new(nil)
|
|
512
|
+
|
|
441
513
|
level = ActiveRecord::Base.logger.level
|
|
442
514
|
create_fixtures("topics")
|
|
443
515
|
assert_equal level, ActiveRecord::Base.logger.level
|
|
516
|
+
ensure
|
|
517
|
+
ActiveRecord::Base.logger = previous_logger
|
|
444
518
|
end
|
|
445
519
|
|
|
446
520
|
def test_instantiation
|
|
@@ -471,10 +545,10 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
471
545
|
def test_nonexistent_fixture_file
|
|
472
546
|
nonexistent_fixture_path = FIXTURES_ROOT + "/imnothere"
|
|
473
547
|
|
|
474
|
-
#
|
|
548
|
+
# Ensure that this file never exists
|
|
475
549
|
assert_empty Dir[nonexistent_fixture_path + "*"]
|
|
476
550
|
|
|
477
|
-
assert_raise(
|
|
551
|
+
assert_raise(ArgumentError) do
|
|
478
552
|
ActiveRecord::FixtureSet.new(nil, "companies", Company, nonexistent_fixture_path)
|
|
479
553
|
end
|
|
480
554
|
end
|
|
@@ -505,6 +579,8 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
505
579
|
|
|
506
580
|
def test_yaml_file_with_symbol_columns
|
|
507
581
|
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/naked/yml", "trees")
|
|
582
|
+
root = Tree.find(1)
|
|
583
|
+
assert root
|
|
508
584
|
end
|
|
509
585
|
|
|
510
586
|
def test_omap_fixtures
|
|
@@ -519,12 +595,12 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
519
595
|
end
|
|
520
596
|
|
|
521
597
|
def test_yml_file_in_subdirectory
|
|
522
|
-
assert_equal(
|
|
598
|
+
assert_equal("A special category in a subdir file", categories(:sub_special_1).name)
|
|
523
599
|
assert_equal(categories(:sub_special_1).class, SpecialCategory)
|
|
524
600
|
end
|
|
525
601
|
|
|
526
602
|
def test_subsubdir_file_with_arbitrary_name
|
|
527
|
-
assert_equal(
|
|
603
|
+
assert_equal("A special category in an arbitrarily named subsubdir file", categories(:sub_special_3).name)
|
|
528
604
|
assert_equal(categories(:sub_special_3).class, SpecialCategory)
|
|
529
605
|
end
|
|
530
606
|
|
|
@@ -554,11 +630,36 @@ class FixturesTest < ActiveRecord::TestCase
|
|
|
554
630
|
|
|
555
631
|
result = test_case.new(:test_fixtures).run
|
|
556
632
|
|
|
557
|
-
|
|
633
|
+
assert_predicate result, :passed?, "Expected #{result.name} to pass:\n#{result}"
|
|
558
634
|
end
|
|
559
635
|
ensure
|
|
560
636
|
ENV["DATABASE_URL"] = db_url_tmp
|
|
561
637
|
end
|
|
638
|
+
|
|
639
|
+
def test_fixture_method_and_private_alias
|
|
640
|
+
assert_equal "The First Topic", topics(:first).title
|
|
641
|
+
assert_equal "The First Topic", fixture(:topics, :first).title
|
|
642
|
+
assert_equal "The First Topic", active_record_fixture(:topics, :first).title
|
|
643
|
+
end
|
|
644
|
+
|
|
645
|
+
def test_fixture_method_does_not_clash_with_a_test_case_method
|
|
646
|
+
test_case = Class.new(ActiveRecord::TestCase) do
|
|
647
|
+
fixtures :accounts
|
|
648
|
+
|
|
649
|
+
def test_fixtures
|
|
650
|
+
assert accounts(:signals37)
|
|
651
|
+
end
|
|
652
|
+
|
|
653
|
+
private
|
|
654
|
+
def fixture
|
|
655
|
+
Account.new
|
|
656
|
+
end
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
result = test_case.new(:test_fixtures).run
|
|
660
|
+
|
|
661
|
+
assert_predicate result, :passed?, "Expected #{result.name} to pass:\n#{result}"
|
|
662
|
+
end
|
|
562
663
|
end
|
|
563
664
|
|
|
564
665
|
class HasManyThroughFixture < ActiveRecord::TestCase
|
|
@@ -566,7 +667,7 @@ class HasManyThroughFixture < ActiveRecord::TestCase
|
|
|
566
667
|
Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } }
|
|
567
668
|
end
|
|
568
669
|
|
|
569
|
-
def
|
|
670
|
+
def test_has_many_through_with_join_table_name_changed_to_match_habtm_table_name
|
|
570
671
|
pt = make_model "ParrotTreasure"
|
|
571
672
|
parrot = make_model "Parrot"
|
|
572
673
|
treasure = make_model "Treasure"
|
|
@@ -585,7 +686,7 @@ class HasManyThroughFixture < ActiveRecord::TestCase
|
|
|
585
686
|
assert_equal load_has_and_belongs_to_many["parrots_treasures"], rows["parrots_treasures"]
|
|
586
687
|
end
|
|
587
688
|
|
|
588
|
-
def
|
|
689
|
+
def test_has_many_through_with_default_table_name_on_join_table
|
|
589
690
|
pt = make_model "ParrotTreasure"
|
|
590
691
|
parrot = make_model "Parrot"
|
|
591
692
|
treasure = make_model "Treasure"
|
|
@@ -618,7 +719,7 @@ class HasManyThroughFixture < ActiveRecord::TestCase
|
|
|
618
719
|
end
|
|
619
720
|
end
|
|
620
721
|
|
|
621
|
-
if Account.
|
|
722
|
+
if Account.lease_connection.respond_to?(:reset_pk_sequence!)
|
|
622
723
|
class FixturesResetPkSequenceTest < ActiveRecord::TestCase
|
|
623
724
|
fixtures :accounts
|
|
624
725
|
fixtures :companies
|
|
@@ -633,7 +734,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
|
|
|
633
734
|
@instances.each do |instance|
|
|
634
735
|
model = instance.class
|
|
635
736
|
model.delete_all
|
|
636
|
-
model.
|
|
737
|
+
model.lease_connection.reset_pk_sequence!(model.table_name, model.primary_key, model.sequence_name)
|
|
637
738
|
|
|
638
739
|
instance.save!
|
|
639
740
|
assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed."
|
|
@@ -644,7 +745,7 @@ if Account.connection.respond_to?(:reset_pk_sequence!)
|
|
|
644
745
|
@instances.each do |instance|
|
|
645
746
|
model = instance.class
|
|
646
747
|
model.delete_all
|
|
647
|
-
model.
|
|
748
|
+
model.lease_connection.reset_pk_sequence!(model.table_name)
|
|
648
749
|
|
|
649
750
|
instance.save!
|
|
650
751
|
assert_equal 1, instance.id, "Sequence reset for #{model.table_name} failed."
|
|
@@ -738,7 +839,7 @@ class MultipleFixturesTest < ActiveRecord::TestCase
|
|
|
738
839
|
fixtures :developers, :accounts
|
|
739
840
|
|
|
740
841
|
def test_fixture_table_names
|
|
741
|
-
assert_equal %w(
|
|
842
|
+
assert_equal %w(accounts developers topics), fixture_table_names
|
|
742
843
|
end
|
|
743
844
|
end
|
|
744
845
|
|
|
@@ -750,6 +851,7 @@ class SetupTest < ActiveRecord::TestCase
|
|
|
750
851
|
end
|
|
751
852
|
|
|
752
853
|
def test_nothing
|
|
854
|
+
pass
|
|
753
855
|
end
|
|
754
856
|
end
|
|
755
857
|
|
|
@@ -770,7 +872,7 @@ class OverlappingFixturesTest < ActiveRecord::TestCase
|
|
|
770
872
|
fixtures :developers, :accounts
|
|
771
873
|
|
|
772
874
|
def test_fixture_table_names
|
|
773
|
-
assert_equal %w(
|
|
875
|
+
assert_equal %w(accounts developers topics), fixture_table_names
|
|
774
876
|
end
|
|
775
877
|
end
|
|
776
878
|
|
|
@@ -790,6 +892,80 @@ class ForeignKeyFixturesTest < ActiveRecord::TestCase
|
|
|
790
892
|
end
|
|
791
893
|
end
|
|
792
894
|
|
|
895
|
+
class FkObjectToPointTo < ActiveRecord::Base
|
|
896
|
+
has_many :fk_pointing_to_non_existent_objects
|
|
897
|
+
end
|
|
898
|
+
class FkPointingToNonExistentObject < ActiveRecord::Base
|
|
899
|
+
belongs_to :fk_object_to_point_to
|
|
900
|
+
end
|
|
901
|
+
|
|
902
|
+
class FixturesWithForeignKeyViolationsTest < ActiveRecord::TestCase
|
|
903
|
+
fixtures :fk_object_to_point_to
|
|
904
|
+
|
|
905
|
+
def setup
|
|
906
|
+
# other tests in this file load the parrots fixture but not the treasure one (see `test_create_fixtures`).
|
|
907
|
+
# this creates FK violations since Parrot and ParrotTreasure records are created.
|
|
908
|
+
# those violations can cause false positives in these tests. since they aren't related to these tests we
|
|
909
|
+
# delete the irrelevant records here (this test is transactional so it's fine).
|
|
910
|
+
Parrot.all.each(&:destroy)
|
|
911
|
+
|
|
912
|
+
@path = "/fk_pointing_to_non_existent_object.yml"
|
|
913
|
+
end
|
|
914
|
+
|
|
915
|
+
def test_raises_fk_violations
|
|
916
|
+
fk_pointing_to_non_existent_object = <<~FIXTURE
|
|
917
|
+
first:
|
|
918
|
+
fk_object_to_point_to: one
|
|
919
|
+
FIXTURE
|
|
920
|
+
File.write(FIXTURES_ROOT + @path, fk_pointing_to_non_existent_object)
|
|
921
|
+
|
|
922
|
+
with_verify_foreign_keys_for_fixtures do
|
|
923
|
+
if current_adapter?(:SQLite3Adapter, :PostgreSQLAdapter)
|
|
924
|
+
error = assert_raise RuntimeError do
|
|
925
|
+
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, ["fk_pointing_to_non_existent_object"])
|
|
926
|
+
end
|
|
927
|
+
assert_includes error.message, "Foreign key violations found in your fixture data. Ensure you aren't referring to labels that don't exist on associations."
|
|
928
|
+
assert_includes error.message, "fk_pointing_to_non_existent_objects"
|
|
929
|
+
else
|
|
930
|
+
assert_nothing_raised do
|
|
931
|
+
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, ["fk_pointing_to_non_existent_object"])
|
|
932
|
+
end
|
|
933
|
+
end
|
|
934
|
+
end
|
|
935
|
+
|
|
936
|
+
ensure
|
|
937
|
+
File.delete(FIXTURES_ROOT + @path)
|
|
938
|
+
ActiveRecord::FixtureSet.reset_cache
|
|
939
|
+
end
|
|
940
|
+
|
|
941
|
+
def test_does_not_raise_if_no_fk_violations
|
|
942
|
+
fk_pointing_to_valid_object = <<~FIXTURE
|
|
943
|
+
first:
|
|
944
|
+
fk_object_to_point_to_id: 1
|
|
945
|
+
FIXTURE
|
|
946
|
+
File.write(FIXTURES_ROOT + @path, fk_pointing_to_valid_object)
|
|
947
|
+
|
|
948
|
+
with_verify_foreign_keys_for_fixtures do
|
|
949
|
+
assert_nothing_raised do
|
|
950
|
+
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT, ["fk_pointing_to_non_existent_object"])
|
|
951
|
+
end
|
|
952
|
+
end
|
|
953
|
+
|
|
954
|
+
ensure
|
|
955
|
+
File.delete(FIXTURES_ROOT + @path)
|
|
956
|
+
ActiveRecord::FixtureSet.reset_cache
|
|
957
|
+
end
|
|
958
|
+
|
|
959
|
+
private
|
|
960
|
+
def with_verify_foreign_keys_for_fixtures
|
|
961
|
+
setting_was = ActiveRecord.verify_foreign_keys_for_fixtures
|
|
962
|
+
ActiveRecord.verify_foreign_keys_for_fixtures = true
|
|
963
|
+
yield
|
|
964
|
+
ensure
|
|
965
|
+
ActiveRecord.verify_foreign_keys_for_fixtures = setting_was
|
|
966
|
+
end
|
|
967
|
+
end
|
|
968
|
+
|
|
793
969
|
class OverRideFixtureMethodTest < ActiveRecord::TestCase
|
|
794
970
|
fixtures :topics
|
|
795
971
|
|
|
@@ -837,6 +1013,16 @@ class SetFixtureClassPrevailsTest < ActiveRecord::TestCase
|
|
|
837
1013
|
end
|
|
838
1014
|
end
|
|
839
1015
|
|
|
1016
|
+
class FixtureWithSetModelClassPrevailsOverNamingConventionTest < ActiveRecord::TestCase
|
|
1017
|
+
def test_model_class_in_fixture_file_is_respected
|
|
1018
|
+
Object.const_set(:OtherPost, Class.new(ActiveRecord::Base))
|
|
1019
|
+
other_posts = create_fixtures("other_posts").first
|
|
1020
|
+
assert_kind_of Post, other_posts["second_welcome"].find
|
|
1021
|
+
ensure
|
|
1022
|
+
Object.send(:remove_const, :OtherPost)
|
|
1023
|
+
end
|
|
1024
|
+
end
|
|
1025
|
+
|
|
840
1026
|
class CheckSetTableNameFixturesTest < ActiveRecord::TestCase
|
|
841
1027
|
set_fixture_class funny_jokes: Joke
|
|
842
1028
|
fixtures :funny_jokes
|
|
@@ -918,14 +1104,19 @@ class TransactionalFixturesOnConnectionNotification < ActiveRecord::TestCase
|
|
|
918
1104
|
def transaction_open?; end
|
|
919
1105
|
def begin_transaction(*args); end
|
|
920
1106
|
def rollback_transaction(*args); end
|
|
1107
|
+
def connect!; end
|
|
921
1108
|
end.new
|
|
922
1109
|
|
|
923
|
-
connection.pool = Class.new do
|
|
924
|
-
def
|
|
925
|
-
|
|
1110
|
+
pool = connection.pool = Class.new do
|
|
1111
|
+
def initialize(connection); @connection = connection; end
|
|
1112
|
+
def lease_connection; @connection; end
|
|
1113
|
+
def release_connection; end
|
|
1114
|
+
def pin_connection!(_); end
|
|
1115
|
+
def unpin_connection!; @connection.rollback_transaction; true; end
|
|
1116
|
+
end.new(connection)
|
|
926
1117
|
|
|
927
|
-
assert_called_with(
|
|
928
|
-
fire_connection_notification(connection)
|
|
1118
|
+
assert_called_with(pool, :pin_connection!, [true]) do
|
|
1119
|
+
fire_connection_notification(connection.pool)
|
|
929
1120
|
end
|
|
930
1121
|
end
|
|
931
1122
|
|
|
@@ -939,13 +1130,19 @@ class TransactionalFixturesOnConnectionNotification < ActiveRecord::TestCase
|
|
|
939
1130
|
def rollback_transaction(*args)
|
|
940
1131
|
@rollback_transaction_called = true
|
|
941
1132
|
end
|
|
942
|
-
end.new
|
|
943
|
-
|
|
944
|
-
connection.pool = Class.new do
|
|
945
1133
|
def lock_thread=(lock_thread); end
|
|
1134
|
+
def connect!; end
|
|
946
1135
|
end.new
|
|
947
1136
|
|
|
948
|
-
|
|
1137
|
+
connection.pool = Class.new do
|
|
1138
|
+
def initialize(connection); @connection = connection; end
|
|
1139
|
+
def lease_connection; @connection; end
|
|
1140
|
+
def release_connection; end
|
|
1141
|
+
def pin_connection!(_); end
|
|
1142
|
+
def unpin_connection!; @connection.rollback_transaction; true; end
|
|
1143
|
+
end.new(connection)
|
|
1144
|
+
|
|
1145
|
+
fire_connection_notification(connection.pool)
|
|
949
1146
|
teardown_fixtures
|
|
950
1147
|
|
|
951
1148
|
assert(connection.rollback_transaction_called, "Expected <mock connection>#rollback_transaction to be called but was not")
|
|
@@ -958,25 +1155,30 @@ class TransactionalFixturesOnConnectionNotification < ActiveRecord::TestCase
|
|
|
958
1155
|
def transaction_open?; end
|
|
959
1156
|
def begin_transaction(*args); end
|
|
960
1157
|
def rollback_transaction(*args); end
|
|
1158
|
+
def connect!; end
|
|
961
1159
|
end.new
|
|
962
1160
|
|
|
963
1161
|
connection.pool = Class.new do
|
|
964
|
-
def
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1162
|
+
def initialize(connection); @connection = connection; end
|
|
1163
|
+
def lease_connection; @connection; end
|
|
1164
|
+
def release_connection; end
|
|
1165
|
+
def pin_connection!(_); end
|
|
1166
|
+
def unpin_connection!; @connection.rollback_transaction; true; end
|
|
1167
|
+
end.new(connection)
|
|
1168
|
+
|
|
1169
|
+
assert_called_with(connection.pool, :pin_connection!, [true]) do
|
|
1170
|
+
fire_connection_notification(connection.pool, shard: :shard_two)
|
|
969
1171
|
end
|
|
970
1172
|
end
|
|
971
1173
|
|
|
972
1174
|
private
|
|
973
|
-
def fire_connection_notification(
|
|
974
|
-
assert_called_with(ActiveRecord::Base.connection_handler, :
|
|
1175
|
+
def fire_connection_notification(pool, shard: ActiveRecord::Base.default_shard)
|
|
1176
|
+
assert_called_with(ActiveRecord::Base.connection_handler, :retrieve_connection_pool, ["book"], returns: pool, shard: shard) do
|
|
975
1177
|
message_bus = ActiveSupport::Notifications.instrumenter
|
|
976
1178
|
payload = {
|
|
977
|
-
|
|
1179
|
+
connection_name: "book",
|
|
978
1180
|
shard: shard,
|
|
979
|
-
config: nil
|
|
1181
|
+
config: nil
|
|
980
1182
|
}
|
|
981
1183
|
|
|
982
1184
|
message_bus.instrument("!connection.active_record", payload) { }
|
|
@@ -1020,7 +1222,7 @@ end
|
|
|
1020
1222
|
|
|
1021
1223
|
class FixturesBrokenRollbackTest < ActiveRecord::TestCase
|
|
1022
1224
|
def blank_setup
|
|
1023
|
-
@
|
|
1225
|
+
@fixture_connection_pools = [ActiveRecord::Base.connection_pool]
|
|
1024
1226
|
end
|
|
1025
1227
|
alias_method :ar_setup_fixtures, :setup_fixtures
|
|
1026
1228
|
alias_method :setup_fixtures, :blank_setup
|
|
@@ -1031,12 +1233,14 @@ class FixturesBrokenRollbackTest < ActiveRecord::TestCase
|
|
|
1031
1233
|
alias_method :teardown_fixtures, :blank_teardown
|
|
1032
1234
|
alias_method :teardown, :blank_teardown
|
|
1033
1235
|
|
|
1236
|
+
fixtures rand.to_s # bypass fixtures cache
|
|
1237
|
+
|
|
1034
1238
|
def test_no_rollback_in_teardown_unless_transaction_active
|
|
1035
|
-
assert_equal 0, ActiveRecord::Base.
|
|
1239
|
+
assert_equal 0, ActiveRecord::Base.lease_connection.open_transactions
|
|
1036
1240
|
assert_raise(RuntimeError) { ar_setup_fixtures }
|
|
1037
|
-
assert_equal 0, ActiveRecord::Base.
|
|
1241
|
+
assert_equal 0, ActiveRecord::Base.lease_connection.open_transactions
|
|
1038
1242
|
assert_nothing_raised { ar_teardown_fixtures }
|
|
1039
|
-
assert_equal 0, ActiveRecord::Base.
|
|
1243
|
+
assert_equal 0, ActiveRecord::Base.lease_connection.open_transactions
|
|
1040
1244
|
end
|
|
1041
1245
|
|
|
1042
1246
|
private
|
|
@@ -1047,7 +1251,7 @@ end
|
|
|
1047
1251
|
|
|
1048
1252
|
class LoadAllFixturesTest < ActiveRecord::TestCase
|
|
1049
1253
|
def test_all_there
|
|
1050
|
-
self.class.
|
|
1254
|
+
self.class.fixture_paths = [FIXTURES_ROOT + "/all"]
|
|
1051
1255
|
self.class.fixtures :all
|
|
1052
1256
|
|
|
1053
1257
|
if File.symlink? FIXTURES_ROOT + "/all/admin"
|
|
@@ -1058,9 +1262,22 @@ class LoadAllFixturesTest < ActiveRecord::TestCase
|
|
|
1058
1262
|
end
|
|
1059
1263
|
end
|
|
1060
1264
|
|
|
1265
|
+
class LoadAllFixturesWithArrayTest < ActiveRecord::TestCase
|
|
1266
|
+
def test_all_there
|
|
1267
|
+
self.class.fixture_paths = [FIXTURES_ROOT + "/all", FIXTURES_ROOT + "/categories"]
|
|
1268
|
+
self.class.fixtures :all
|
|
1269
|
+
|
|
1270
|
+
if File.symlink? FIXTURES_ROOT + "/all/admin"
|
|
1271
|
+
assert_equal %w(admin/accounts admin/users developers namespaced/accounts people special_categories subsubdir/arbitrary_filename tasks), fixture_table_names.sort
|
|
1272
|
+
end
|
|
1273
|
+
ensure
|
|
1274
|
+
ActiveRecord::FixtureSet.reset_cache
|
|
1275
|
+
end
|
|
1276
|
+
end
|
|
1277
|
+
|
|
1061
1278
|
class LoadAllFixturesWithPathnameTest < ActiveRecord::TestCase
|
|
1062
1279
|
def test_all_there
|
|
1063
|
-
self.class.
|
|
1280
|
+
self.class.fixture_paths = [Pathname.new(FIXTURES_ROOT).join("all")]
|
|
1064
1281
|
self.class.fixtures :all
|
|
1065
1282
|
|
|
1066
1283
|
if File.symlink? FIXTURES_ROOT + "/all/admin"
|
|
@@ -1082,8 +1299,8 @@ class FasterFixturesTest < ActiveRecord::TestCase
|
|
|
1082
1299
|
end
|
|
1083
1300
|
|
|
1084
1301
|
def test_cache
|
|
1085
|
-
assert ActiveRecord::FixtureSet.fixture_is_cached?(ActiveRecord::Base.
|
|
1086
|
-
assert ActiveRecord::FixtureSet.fixture_is_cached?(ActiveRecord::Base.
|
|
1302
|
+
assert ActiveRecord::FixtureSet.fixture_is_cached?(ActiveRecord::Base.connection_pool, "categories")
|
|
1303
|
+
assert ActiveRecord::FixtureSet.fixture_is_cached?(ActiveRecord::Base.connection_pool, "authors")
|
|
1087
1304
|
|
|
1088
1305
|
assert_no_queries do
|
|
1089
1306
|
create_fixtures("categories")
|
|
@@ -1091,7 +1308,7 @@ class FasterFixturesTest < ActiveRecord::TestCase
|
|
|
1091
1308
|
end
|
|
1092
1309
|
|
|
1093
1310
|
load_extra_fixture("posts")
|
|
1094
|
-
assert ActiveRecord::FixtureSet.fixture_is_cached?(ActiveRecord::Base.
|
|
1311
|
+
assert ActiveRecord::FixtureSet.fixture_is_cached?(ActiveRecord::Base.connection_pool, "posts")
|
|
1095
1312
|
self.class.setup_fixture_accessors :posts
|
|
1096
1313
|
assert_equal "Welcome to the weblog", posts(:welcome).title
|
|
1097
1314
|
end
|
|
@@ -1103,7 +1320,7 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|
|
1103
1320
|
fixtures :parrots, :parrots_pirates, :pirates, :treasures, :mateys, :ships, :computers,
|
|
1104
1321
|
:developers, :"admin/accounts", :"admin/users", :live_parrots, :dead_parrots, :books
|
|
1105
1322
|
|
|
1106
|
-
if
|
|
1323
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
1107
1324
|
require "models/uuid_parent"
|
|
1108
1325
|
require "models/uuid_child"
|
|
1109
1326
|
fixtures :uuid_parents, :uuid_children
|
|
@@ -1189,6 +1406,18 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|
|
1189
1406
|
assert(parrots(:george).pirates.include?(pirates(:blackbeard)))
|
|
1190
1407
|
end
|
|
1191
1408
|
|
|
1409
|
+
def test_supports_timestamps_in_join_tables
|
|
1410
|
+
assert_not_nil developers(:david).created_at
|
|
1411
|
+
assert_not_nil computers(:laptop).created_at
|
|
1412
|
+
|
|
1413
|
+
klass = Class.new(ActiveRecord::Base) do
|
|
1414
|
+
self.table_name = "computers_developers"
|
|
1415
|
+
end
|
|
1416
|
+
|
|
1417
|
+
computers_developers = klass.find_by(developer_id: developers(:david), computer_id: computers(:laptop))
|
|
1418
|
+
assert_not_nil computers_developers.created_at
|
|
1419
|
+
end
|
|
1420
|
+
|
|
1192
1421
|
def test_supports_inline_habtm
|
|
1193
1422
|
assert(parrots(:george).treasures.include?(treasures(:diamond)))
|
|
1194
1423
|
assert(parrots(:george).treasures.include?(treasures(:sapphire)))
|
|
@@ -1231,9 +1460,11 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|
|
1231
1460
|
end
|
|
1232
1461
|
|
|
1233
1462
|
def test_only_generates_a_pk_if_necessary
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1463
|
+
assert_nothing_raised do
|
|
1464
|
+
m = Matey.first
|
|
1465
|
+
m.pirate = pirates(:blackbeard)
|
|
1466
|
+
m.target = pirates(:redbeard)
|
|
1467
|
+
end
|
|
1237
1468
|
end
|
|
1238
1469
|
|
|
1239
1470
|
def test_supports_sti
|
|
@@ -1247,6 +1478,12 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|
|
1247
1478
|
assert_equal pirates(:blackbeard), dead_parrots(:deadbird).killer
|
|
1248
1479
|
end
|
|
1249
1480
|
|
|
1481
|
+
def test_resolves_enums_in_sti_subclasses
|
|
1482
|
+
assert_predicate parrots(:george), :australian?
|
|
1483
|
+
assert_predicate parrots(:louis), :african?
|
|
1484
|
+
assert_predicate parrots(:frederick), :african?
|
|
1485
|
+
end
|
|
1486
|
+
|
|
1250
1487
|
def test_namespaced_models
|
|
1251
1488
|
assert_includes admin_accounts(:signals37).users, admin_users(:david)
|
|
1252
1489
|
assert_equal 2, admin_accounts(:signals37).users.size
|
|
@@ -1261,12 +1498,12 @@ class FoxyFixturesTest < ActiveRecord::TestCase
|
|
|
1261
1498
|
end
|
|
1262
1499
|
|
|
1263
1500
|
class ActiveSupportSubclassWithFixturesTest < ActiveRecord::TestCase
|
|
1264
|
-
fixtures :
|
|
1501
|
+
fixtures :organizations
|
|
1265
1502
|
|
|
1266
1503
|
# This seemingly useless assertion catches a bug that caused the fixtures
|
|
1267
1504
|
# setup code call nil[]
|
|
1268
1505
|
def test_foo
|
|
1269
|
-
assert_equal
|
|
1506
|
+
assert_equal organizations(:nsa), Organization.find_by_name("No Such Agency")
|
|
1270
1507
|
end
|
|
1271
1508
|
end
|
|
1272
1509
|
|
|
@@ -1302,12 +1539,21 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
|
|
|
1302
1539
|
end
|
|
1303
1540
|
|
|
1304
1541
|
class IgnoreFixturesTest < ActiveRecord::TestCase
|
|
1305
|
-
fixtures :other_books, :parrots
|
|
1542
|
+
fixtures :other_books, :parrots, :parrots_pirates, :pirates, :treasures
|
|
1306
1543
|
|
|
1307
1544
|
# Set to false to blow away fixtures cache and ensure our fixtures are loaded
|
|
1308
1545
|
# without interfering with other tests that use the same `model_class`.
|
|
1309
1546
|
self.use_transactional_tests = false
|
|
1310
1547
|
|
|
1548
|
+
def before_setup
|
|
1549
|
+
if ActiveRecord::Base.lease_connection.is_a?(ActiveRecord::ConnectionAdapters::IBM_DBAdapter) &&
|
|
1550
|
+
name.end_with?("ignores_books_fixtures", "ignores_parrots_fixtures")
|
|
1551
|
+
skip
|
|
1552
|
+
end
|
|
1553
|
+
|
|
1554
|
+
super
|
|
1555
|
+
end
|
|
1556
|
+
|
|
1311
1557
|
test "ignores books fixtures" do
|
|
1312
1558
|
assert_raise(StandardError) { other_books(:published) }
|
|
1313
1559
|
assert_raise(StandardError) { other_books(:published_paperback) }
|
|
@@ -1386,13 +1632,13 @@ class NilFixturePathTest < ActiveRecord::TestCase
|
|
|
1386
1632
|
error = assert_raises(StandardError) do
|
|
1387
1633
|
TestCase = Class.new(ActiveRecord::TestCase)
|
|
1388
1634
|
TestCase.class_eval do
|
|
1389
|
-
self.
|
|
1635
|
+
self.fixture_paths = nil
|
|
1390
1636
|
fixtures :all
|
|
1391
1637
|
end
|
|
1392
1638
|
end
|
|
1393
1639
|
assert_equal <<~MSG.squish, error.message
|
|
1394
1640
|
No fixture path found.
|
|
1395
|
-
Please set `NilFixturePathTest::TestCase.
|
|
1641
|
+
Please set `NilFixturePathTest::TestCase.fixture_paths`.
|
|
1396
1642
|
MSG
|
|
1397
1643
|
end
|
|
1398
1644
|
end
|
|
@@ -1403,15 +1649,25 @@ class FileFixtureConflictTest < ActiveRecord::TestCase
|
|
|
1403
1649
|
end
|
|
1404
1650
|
|
|
1405
1651
|
test "ignores file fixtures" do
|
|
1406
|
-
self.class.
|
|
1652
|
+
self.class.fixture_paths = [FIXTURES_ROOT + "/all"]
|
|
1407
1653
|
self.class.fixtures :all
|
|
1408
1654
|
|
|
1409
1655
|
assert_equal %w(developers namespaced/accounts people tasks), fixture_table_names.sort
|
|
1410
1656
|
end
|
|
1411
1657
|
end
|
|
1412
1658
|
|
|
1413
|
-
|
|
1414
|
-
|
|
1659
|
+
class PrimaryKeyErrorTest < ActiveRecord::TestCase
|
|
1660
|
+
test "generates the correct value" do
|
|
1661
|
+
e = assert_raise(ActiveRecord::FixtureSet::TableRow::PrimaryKeyError) do
|
|
1662
|
+
ActiveRecord::FixtureSet.create_fixtures(FIXTURES_ROOT + "/primary_key_error", "primary_key_error")
|
|
1663
|
+
end
|
|
1664
|
+
|
|
1665
|
+
assert_includes e.message, "Unable to set"
|
|
1666
|
+
end
|
|
1667
|
+
end
|
|
1668
|
+
|
|
1669
|
+
class MultipleFixtureConnectionsTest < ActiveRecord::TestCase
|
|
1670
|
+
if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
|
1415
1671
|
include ActiveRecord::TestFixtures
|
|
1416
1672
|
|
|
1417
1673
|
fixtures :dogs
|
|
@@ -1450,15 +1706,15 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
|
|
1450
1706
|
|
|
1451
1707
|
def test_writing_and_reading_connections_are_the_same
|
|
1452
1708
|
handler = ActiveRecord::Base.connection_handler
|
|
1453
|
-
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing).
|
|
1454
|
-
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading).
|
|
1709
|
+
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing).lease_connection
|
|
1710
|
+
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading).lease_connection
|
|
1455
1711
|
|
|
1456
1712
|
assert_equal rw_conn, ro_conn
|
|
1457
1713
|
|
|
1458
1714
|
teardown_shared_connection_pool
|
|
1459
1715
|
|
|
1460
|
-
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing).
|
|
1461
|
-
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading).
|
|
1716
|
+
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing).lease_connection
|
|
1717
|
+
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading).lease_connection
|
|
1462
1718
|
|
|
1463
1719
|
assert_not_equal rw_conn, ro_conn
|
|
1464
1720
|
end
|
|
@@ -1470,15 +1726,15 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
|
|
1470
1726
|
}
|
|
1471
1727
|
|
|
1472
1728
|
handler = ActiveRecord::Base.connection_handler
|
|
1473
|
-
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing, shard: :two).
|
|
1474
|
-
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading, shard: :two).
|
|
1729
|
+
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing, shard: :two).lease_connection
|
|
1730
|
+
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading, shard: :two).lease_connection
|
|
1475
1731
|
|
|
1476
1732
|
assert_equal rw_conn, ro_conn
|
|
1477
1733
|
|
|
1478
1734
|
teardown_shared_connection_pool
|
|
1479
1735
|
|
|
1480
|
-
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing, shard: :two).
|
|
1481
|
-
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading, shard: :two).
|
|
1736
|
+
rw_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :writing, shard: :two).lease_connection
|
|
1737
|
+
ro_conn = handler.retrieve_connection_pool("ActiveRecord::Base", role: :reading, shard: :two).lease_connection
|
|
1482
1738
|
|
|
1483
1739
|
assert_not_equal rw_conn, ro_conn
|
|
1484
1740
|
end
|
|
@@ -1491,7 +1747,7 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
|
|
1491
1747
|
|
|
1492
1748
|
setup_shared_connection_pool
|
|
1493
1749
|
|
|
1494
|
-
assert_raises(ActiveRecord::
|
|
1750
|
+
assert_raises(ActiveRecord::ConnectionNotDefined) do
|
|
1495
1751
|
ActiveRecord::Base.connected_to(role: :reading, shard: :two) do
|
|
1496
1752
|
ActiveRecord::Base.retrieve_connection
|
|
1497
1753
|
end
|
|
@@ -1502,7 +1758,7 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
|
|
1502
1758
|
clean_up_connection_handler
|
|
1503
1759
|
teardown_shared_connection_pool
|
|
1504
1760
|
|
|
1505
|
-
assert_raises(ActiveRecord::
|
|
1761
|
+
assert_raises(ActiveRecord::ConnectionNotDefined) do
|
|
1506
1762
|
ActiveRecord::Base.connected_to(role: :reading) do
|
|
1507
1763
|
ActiveRecord::Base.retrieve_connection
|
|
1508
1764
|
end
|
|
@@ -1523,123 +1779,103 @@ if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
|
|
1523
1779
|
end
|
|
1524
1780
|
end
|
|
1525
1781
|
|
|
1526
|
-
class
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
fixtures :dogs
|
|
1530
|
-
|
|
1531
|
-
def setup
|
|
1532
|
-
@old_value = ActiveRecord::Base.legacy_connection_handling
|
|
1533
|
-
ActiveRecord::Base.legacy_connection_handling = true
|
|
1534
|
-
|
|
1535
|
-
@old_handler = ActiveRecord::Base.connection_handler
|
|
1536
|
-
@prev_configs, ActiveRecord::Base.configurations = ActiveRecord::Base.configurations, config
|
|
1537
|
-
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(ENV["RAILS_ENV"], "readonly", readonly_config)
|
|
1782
|
+
class CompositePkFixturesTest < ActiveRecord::TestCase
|
|
1783
|
+
fixtures :cpk_orders, :cpk_books, :cpk_posts, :cpk_tags, :cpk_authors, :cpk_reviews, :cpk_order_agreements
|
|
1538
1784
|
|
|
1539
|
-
|
|
1785
|
+
def test_supports_inline_habtm
|
|
1786
|
+
skip if current_adapter?(:IBM_DBAdapter)
|
|
1540
1787
|
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
ActiveRecord::Base.connection_handlers = {}
|
|
1545
|
-
ActiveRecord::Base.connects_to(database: { writing: :default, reading: :readonly })
|
|
1788
|
+
assert_includes cpk_posts(:welcome).tags, cpk_tags(:cpk_tag_ruby_on_rails)
|
|
1789
|
+
assert_includes cpk_posts(:welcome).tags, cpk_tags(:cpk_tag_digital_product)
|
|
1790
|
+
assert_not_includes cpk_posts(:welcome).tags, cpk_tags(:cpk_tag_loyal_customer)
|
|
1546
1791
|
|
|
1547
|
-
|
|
1792
|
+
assert_equal [cpk_tags(:cpk_tag_digital_product)], cpk_posts(:thinking).tags
|
|
1548
1793
|
end
|
|
1549
1794
|
|
|
1550
|
-
def
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1795
|
+
def test_generates_composite_primary_key_for_partially_filled_fixtures
|
|
1796
|
+
alice = cpk_authors(:cpk_great_author)
|
|
1797
|
+
alice_cpk_book = cpk_books(:cpk_great_author_first_book)
|
|
1798
|
+
|
|
1799
|
+
assert_not_empty(alice_cpk_book.id.compact)
|
|
1800
|
+
assert_equal alice_cpk_book.id.first, alice.id
|
|
1801
|
+
assert_not_nil alice_cpk_book.id.last
|
|
1555
1802
|
end
|
|
1556
1803
|
|
|
1557
|
-
def
|
|
1558
|
-
|
|
1559
|
-
Dog.first
|
|
1804
|
+
def test_generates_composite_primary_key_ids
|
|
1805
|
+
assert_not_empty(cpk_orders(:cpk_groceries_order_1).id.compact)
|
|
1560
1806
|
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
end
|
|
1807
|
+
cpk_books(:cpk_great_author_first_book).id.each do |id_column|
|
|
1808
|
+
assert_not_nil(id_column)
|
|
1564
1809
|
end
|
|
1565
1810
|
end
|
|
1566
1811
|
|
|
1567
|
-
def
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
rw_conn = writing.retrieve_connection_pool("ActiveRecord::Base").connection
|
|
1572
|
-
ro_conn = reading.retrieve_connection_pool("ActiveRecord::Base").connection
|
|
1812
|
+
def test_generates_composite_primary_key_with_unique_components
|
|
1813
|
+
assert_equal 2, cpk_orders(:cpk_groceries_order_1).id.uniq.size
|
|
1814
|
+
end
|
|
1573
1815
|
|
|
1574
|
-
|
|
1816
|
+
def test_resolves_associations_using_composite_primary_keys
|
|
1817
|
+
review = cpk_reviews(:first_book_review)
|
|
1818
|
+
generated_book = cpk_books(:cpk_book_with_generated_pk)
|
|
1575
1819
|
|
|
1576
|
-
|
|
1820
|
+
assert_equal generated_book.id, [review.author_id, review.number]
|
|
1821
|
+
assert_equal generated_book, review.book
|
|
1822
|
+
end
|
|
1577
1823
|
|
|
1578
|
-
|
|
1579
|
-
|
|
1824
|
+
def test_resolves_associations_using_composite_primary_keys_with_partially_filled_values
|
|
1825
|
+
review = cpk_reviews(:second_book_review_for_book_with_partial_pk_defined)
|
|
1826
|
+
book_with_partially_filled_cpk = cpk_books(:cpk_great_author_first_book)
|
|
1580
1827
|
|
|
1581
|
-
|
|
1828
|
+
assert_equal book_with_partially_filled_cpk.id, [review.author_id, review.number]
|
|
1829
|
+
assert_equal book_with_partially_filled_cpk, review.book
|
|
1582
1830
|
end
|
|
1583
1831
|
|
|
1584
|
-
def
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
two: { writing: :default, reading: :readonly }
|
|
1588
|
-
}
|
|
1832
|
+
def test_association_with_custom_primary_key
|
|
1833
|
+
order = cpk_orders(:cpk_groceries_order_2)
|
|
1834
|
+
order_agreement = cpk_order_agreements(:order_agreement_three)
|
|
1589
1835
|
|
|
1590
|
-
|
|
1591
|
-
reading = ActiveRecord::Base.connection_handlers[:reading]
|
|
1836
|
+
_, order_id = order.id
|
|
1592
1837
|
|
|
1593
|
-
|
|
1594
|
-
|
|
1838
|
+
assert_equal order_id, order_agreement.order_id
|
|
1839
|
+
assert_equal order, order_agreement.order
|
|
1840
|
+
end
|
|
1595
1841
|
|
|
1596
|
-
|
|
1842
|
+
def test_composite_identify_resolves_to_same_values
|
|
1843
|
+
identify_one = ActiveRecord::FixtureSet.composite_identify("label", [:a, :b, :c])
|
|
1844
|
+
identify_two = ActiveRecord::FixtureSet.composite_identify("label", [:a, :b, :c])
|
|
1597
1845
|
|
|
1598
|
-
|
|
1846
|
+
assert_equal identify_one, identify_two
|
|
1847
|
+
end
|
|
1599
1848
|
|
|
1600
|
-
|
|
1601
|
-
|
|
1849
|
+
def test_composite_identify_returns_hash_with_key_names
|
|
1850
|
+
id = ActiveRecord::FixtureSet.composite_identify("order", Cpk::Order.primary_key)
|
|
1602
1851
|
|
|
1603
|
-
|
|
1852
|
+
assert_equal ["shop_id", "id"], id.keys
|
|
1604
1853
|
end
|
|
1605
1854
|
|
|
1606
|
-
def
|
|
1607
|
-
ActiveRecord::
|
|
1608
|
-
|
|
1609
|
-
two: { writing: :default }
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
setup_shared_connection_pool
|
|
1855
|
+
def test_composite_identify_uses_same_hashing_algorithm_as_identify_for_first_attribute
|
|
1856
|
+
id_hash = ActiveRecord::FixtureSet.composite_identify("order", [:first_attribute, :second_attribute])
|
|
1857
|
+
id = ActiveRecord::FixtureSet.identify("order")
|
|
1613
1858
|
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
ActiveRecord::Base.retrieve_connection
|
|
1617
|
-
end
|
|
1618
|
-
end
|
|
1859
|
+
assert_equal id, id_hash[:first_attribute]
|
|
1860
|
+
assert_not_equal id, id_hash[:second_attribute]
|
|
1619
1861
|
end
|
|
1620
1862
|
|
|
1621
|
-
def
|
|
1622
|
-
|
|
1623
|
-
|
|
1863
|
+
def test_composite_identify_hashes_one_label_to_same_values_irrespective_of_column_names
|
|
1864
|
+
id_hash_one = ActiveRecord::FixtureSet.composite_identify("order", [:first_attribute, :second_attribute])
|
|
1865
|
+
id_hash_two = ActiveRecord::FixtureSet.composite_identify("order", [:shop_id, :id])
|
|
1624
1866
|
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
ActiveRecord::Base.retrieve_connection
|
|
1628
|
-
end
|
|
1629
|
-
end
|
|
1867
|
+
assert_equal id_hash_one.values, id_hash_two.values
|
|
1868
|
+
assert_not_equal id_hash_one.keys, id_hash_two.keys
|
|
1630
1869
|
end
|
|
1631
1870
|
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
def default_config
|
|
1638
|
-
{ "adapter" => "sqlite3", "database" => "test/fixtures/fixture_database.sqlite3" }
|
|
1639
|
-
end
|
|
1871
|
+
def test_composite_identify_hashes_to_same_values_based_on_position_in_key
|
|
1872
|
+
id = ActiveRecord::FixtureSet.identify("order")
|
|
1873
|
+
id_hash_two = ActiveRecord::FixtureSet.composite_identify("order", [:one, :two])
|
|
1874
|
+
id_hash_three = ActiveRecord::FixtureSet.composite_identify("order", [:one, :two, :three])
|
|
1640
1875
|
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1876
|
+
assert_equal id, id_hash_two.values.first
|
|
1877
|
+
assert_equal id, id_hash_three.values.first
|
|
1878
|
+
assert_equal id_hash_two.values, id_hash_three.values.slice(0, 2)
|
|
1879
|
+
end
|
|
1644
1880
|
end
|
|
1645
1881
|
end
|