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
|
@@ -11,6 +11,8 @@ require "models/uuid_item"
|
|
|
11
11
|
require "models/author"
|
|
12
12
|
require "models/person"
|
|
13
13
|
require "models/essay"
|
|
14
|
+
require "models/keyboard"
|
|
15
|
+
require "models/cpk"
|
|
14
16
|
|
|
15
17
|
class Wizard < ActiveRecord::Base
|
|
16
18
|
self.abstract_class = true
|
|
@@ -34,6 +36,11 @@ class ReplyWithTitleObject < Reply
|
|
|
34
36
|
validates_uniqueness_of :content, scope: :title
|
|
35
37
|
|
|
36
38
|
def title; ReplyTitle.new; end
|
|
39
|
+
alias heading title
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class TopicWithEvent < Topic
|
|
43
|
+
belongs_to :event, foreign_key: :parent_id
|
|
37
44
|
end
|
|
38
45
|
|
|
39
46
|
class TopicWithUniqEvent < Topic
|
|
@@ -66,10 +73,18 @@ class TopicWithAfterCreate < Topic
|
|
|
66
73
|
end
|
|
67
74
|
end
|
|
68
75
|
|
|
76
|
+
class LessonWithUniqKeyboard < ActiveRecord::Base
|
|
77
|
+
self.table_name = "lessons"
|
|
78
|
+
|
|
79
|
+
belongs_to :keyboard, primary_key: :name, foreign_key: :name
|
|
80
|
+
|
|
81
|
+
validates_uniqueness_of :keyboard
|
|
82
|
+
end
|
|
83
|
+
|
|
69
84
|
class UniquenessValidationTest < ActiveRecord::TestCase
|
|
70
85
|
INT_MAX_VALUE = 2147483647
|
|
71
86
|
|
|
72
|
-
fixtures :topics,
|
|
87
|
+
fixtures :topics, :warehouse_things
|
|
73
88
|
|
|
74
89
|
repair_validations(Topic, Reply)
|
|
75
90
|
|
|
@@ -91,6 +106,16 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
91
106
|
assert t2.save, "Should now save t2 as unique"
|
|
92
107
|
end
|
|
93
108
|
|
|
109
|
+
def test_validate_uniqueness_with_singleton_class
|
|
110
|
+
Topic.create!(title: "abc")
|
|
111
|
+
t2 = Topic.new(title: "abc")
|
|
112
|
+
t2.singleton_class.validates(:title, uniqueness: true)
|
|
113
|
+
assert_not_predicate t2, :valid?
|
|
114
|
+
|
|
115
|
+
t3 = Topic.new(title: "abc")
|
|
116
|
+
assert_predicate t3, :valid?
|
|
117
|
+
end
|
|
118
|
+
|
|
94
119
|
def test_validate_uniqueness_with_alias_attribute
|
|
95
120
|
Topic.alias_attribute :new_title, :title
|
|
96
121
|
Topic.validates_uniqueness_of(:new_title)
|
|
@@ -122,12 +147,12 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
122
147
|
|
|
123
148
|
def test_validate_uniqueness_when_integer_out_of_range
|
|
124
149
|
entry = BigIntTest.create(engines_count: INT_MAX_VALUE + 1)
|
|
125
|
-
assert_equal
|
|
150
|
+
assert_equal ["is not included in the list"], entry.errors[:engines_count]
|
|
126
151
|
end
|
|
127
152
|
|
|
128
153
|
def test_validate_uniqueness_when_integer_out_of_range_show_order_does_not_matter
|
|
129
154
|
entry = BigIntReverseTest.create(engines_count: INT_MAX_VALUE + 1)
|
|
130
|
-
assert_equal
|
|
155
|
+
assert_equal ["is not included in the list"], entry.errors[:engines_count]
|
|
131
156
|
end
|
|
132
157
|
|
|
133
158
|
def test_validates_uniqueness_with_newline_chars
|
|
@@ -143,7 +168,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
143
168
|
t = Topic.create("title" => "I'm unique!")
|
|
144
169
|
|
|
145
170
|
r1 = t.replies.create "title" => "r1", "content" => "hello world"
|
|
146
|
-
|
|
171
|
+
assert_predicate r1, :valid?, "Saving r1"
|
|
147
172
|
|
|
148
173
|
r2 = t.replies.create "title" => "r2", "content" => "hello world"
|
|
149
174
|
assert_not r2.valid?, "Saving r2 first time"
|
|
@@ -153,7 +178,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
153
178
|
|
|
154
179
|
t2 = Topic.create("title" => "I'm unique too!")
|
|
155
180
|
r3 = t2.replies.create "title" => "r3", "content" => "hello world"
|
|
156
|
-
|
|
181
|
+
assert_predicate r3, :valid?, "Saving r3"
|
|
157
182
|
end
|
|
158
183
|
|
|
159
184
|
def test_validate_uniqueness_with_aliases
|
|
@@ -188,28 +213,30 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
188
213
|
t = Topic.create("title" => "I'm unique!")
|
|
189
214
|
|
|
190
215
|
r1 = t.replies.create "title" => "r1", "content" => "hello world"
|
|
191
|
-
|
|
216
|
+
assert_predicate r1, :valid?, "Saving r1"
|
|
192
217
|
|
|
193
218
|
r2 = t.replies.create "title" => "r2", "content" => "hello world"
|
|
194
219
|
assert_not r2.valid?, "Saving r2 first time"
|
|
195
220
|
end
|
|
196
221
|
|
|
197
222
|
def test_validate_uniqueness_with_polymorphic_object_scope
|
|
198
|
-
Essay
|
|
223
|
+
repair_validations(Essay) do
|
|
224
|
+
Essay.validates_uniqueness_of(:name, scope: :writer)
|
|
199
225
|
|
|
200
|
-
|
|
201
|
-
|
|
226
|
+
a = Author.create(name: "Sergey")
|
|
227
|
+
p = Person.create(first_name: "Sergey")
|
|
202
228
|
|
|
203
|
-
|
|
204
|
-
|
|
229
|
+
e1 = a.essays.create(name: "Essay")
|
|
230
|
+
assert_predicate e1, :valid?, "Saving e1"
|
|
205
231
|
|
|
206
|
-
|
|
207
|
-
|
|
232
|
+
e2 = p.essays.create(name: "Essay")
|
|
233
|
+
assert_predicate e2, :valid?, "Saving e2"
|
|
234
|
+
end
|
|
208
235
|
end
|
|
209
236
|
|
|
210
237
|
def test_validate_uniqueness_with_composed_attribute_scope
|
|
211
238
|
r1 = ReplyWithTitleObject.create "title" => "r1", "content" => "hello world"
|
|
212
|
-
|
|
239
|
+
assert_predicate r1, :valid?, "Saving r1"
|
|
213
240
|
|
|
214
241
|
r2 = ReplyWithTitleObject.create "title" => "r1", "content" => "hello world"
|
|
215
242
|
assert_not r2.valid?, "Saving r2 first time"
|
|
@@ -221,7 +248,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
221
248
|
t = Topic.create("title" => "I'm unique!")
|
|
222
249
|
|
|
223
250
|
r1 = t.replies.create "title" => "r1", "content" => "hello world"
|
|
224
|
-
|
|
251
|
+
assert_predicate r1, :valid?, "Saving r1"
|
|
225
252
|
|
|
226
253
|
r2 = t.replies.create "title" => "r2", "content" => "hello world"
|
|
227
254
|
assert_not r2.valid?, "Saving r2 first time"
|
|
@@ -231,7 +258,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
231
258
|
t = Topic.create("title" => "What, me worry?")
|
|
232
259
|
|
|
233
260
|
r1 = t.unique_replies.create "title" => "r1", "content" => "a barrel of fun"
|
|
234
|
-
|
|
261
|
+
assert_predicate r1, :valid?, "Saving r1"
|
|
235
262
|
|
|
236
263
|
r2 = t.silly_unique_replies.create "title" => "r2", "content" => "a barrel of fun"
|
|
237
264
|
assert_not r2.valid?, "Saving r2"
|
|
@@ -239,7 +266,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
239
266
|
# Should succeed as validates_uniqueness_of only applies to
|
|
240
267
|
# UniqueReply and its subclasses
|
|
241
268
|
r3 = t.replies.create "title" => "r2", "content" => "a barrel of fun"
|
|
242
|
-
|
|
269
|
+
assert_predicate r3, :valid?, "Saving r3"
|
|
243
270
|
end
|
|
244
271
|
|
|
245
272
|
def test_validate_uniqueness_with_scope_array
|
|
@@ -247,10 +274,10 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
247
274
|
|
|
248
275
|
t = Topic.create("title" => "The earth is actually flat!")
|
|
249
276
|
|
|
250
|
-
r1 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're
|
|
251
|
-
|
|
277
|
+
r1 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're joking!", "content" => "Silly reply"
|
|
278
|
+
assert_predicate r1, :valid?, "Saving r1"
|
|
252
279
|
|
|
253
|
-
r2 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're
|
|
280
|
+
r2 = t.replies.create "author_name" => "jeremy", "author_email_address" => "jeremy@rubyonrails.com", "title" => "You're joking!", "content" => "Silly reply again..."
|
|
254
281
|
assert_not r2.valid?, "Saving r2. Double reply by same author."
|
|
255
282
|
|
|
256
283
|
r2.author_email_address = "jeremy_alt_email@rubyonrails.com"
|
|
@@ -293,7 +320,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
293
320
|
|
|
294
321
|
t2.parent_id = nil
|
|
295
322
|
t2.title = nil
|
|
296
|
-
|
|
323
|
+
assert_predicate t2, :valid?, "should validate with nil"
|
|
297
324
|
assert t2.save, "should save with nil"
|
|
298
325
|
|
|
299
326
|
t_utf8 = Topic.new("title" => "Я тоже уникальный!")
|
|
@@ -344,13 +371,13 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
344
371
|
assert_not topic1.valid?
|
|
345
372
|
assert_not topic1.save
|
|
346
373
|
|
|
347
|
-
if current_adapter?(:Mysql2Adapter)
|
|
374
|
+
if current_adapter?(:Mysql2Adapter, :TrilogyAdapter)
|
|
348
375
|
# Case insensitive collation (utf8mb4_0900_ai_ci) by default.
|
|
349
376
|
# Should not allow "David" if "david" exists.
|
|
350
377
|
assert_not topic2.valid?
|
|
351
378
|
assert_not topic2.save
|
|
352
379
|
else
|
|
353
|
-
|
|
380
|
+
assert_predicate topic2, :valid?
|
|
354
381
|
assert topic2.save
|
|
355
382
|
end
|
|
356
383
|
|
|
@@ -368,14 +395,14 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
368
395
|
assert t.save, "Should still save t as unique"
|
|
369
396
|
|
|
370
397
|
t2 = Topic.new("title" => "I'M UNIQUE!")
|
|
371
|
-
|
|
398
|
+
assert_predicate t2, :valid?, "Should be valid"
|
|
372
399
|
assert t2.save, "Should save t2 as unique"
|
|
373
400
|
assert_empty t2.errors[:title]
|
|
374
401
|
assert_empty t2.errors[:parent_id]
|
|
375
402
|
assert_not_equal ["has already been taken"], t2.errors[:title]
|
|
376
403
|
|
|
377
404
|
t3 = Topic.new("title" => "I'M uNiQUe!")
|
|
378
|
-
|
|
405
|
+
assert_predicate t3, :valid?, "Should be valid"
|
|
379
406
|
assert t3.save, "Should save t2 as unique"
|
|
380
407
|
assert_empty t3.errors[:title]
|
|
381
408
|
assert_empty t3.errors[:parent_id]
|
|
@@ -394,7 +421,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
394
421
|
def test_validate_uniqueness_with_non_standard_table_names
|
|
395
422
|
i1 = WarehouseThing.create(value: 1000)
|
|
396
423
|
assert_not i1.valid?, "i1 should not be valid"
|
|
397
|
-
|
|
424
|
+
assert_predicate i1.errors[:value], :any?, "Should not be empty"
|
|
398
425
|
end
|
|
399
426
|
|
|
400
427
|
def test_validates_uniqueness_inside_scoping
|
|
@@ -421,11 +448,11 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
421
448
|
if current_adapter?(:SQLite3Adapter)
|
|
422
449
|
# Event.title has limit 5, but SQLite doesn't truncate.
|
|
423
450
|
e1 = Event.create(title: "abcdefgh")
|
|
424
|
-
|
|
451
|
+
assert_predicate e1, :valid?, "Could not create an event with a unique 8 characters title"
|
|
425
452
|
|
|
426
453
|
e2 = Event.create(title: "abcdefgh")
|
|
427
454
|
assert_not e2.valid?, "Created an event whose title is not unique"
|
|
428
|
-
elsif current_adapter?(:Mysql2Adapter, :
|
|
455
|
+
elsif current_adapter?(:Mysql2Adapter, :TrilogyAdapter, :PostgreSQLAdapter)
|
|
429
456
|
assert_raise(ActiveRecord::ValueTooLong) do
|
|
430
457
|
Event.create(title: "abcdefgh")
|
|
431
458
|
end
|
|
@@ -440,11 +467,11 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
440
467
|
if current_adapter?(:SQLite3Adapter)
|
|
441
468
|
# Event.title has limit 5, but SQLite doesn't truncate.
|
|
442
469
|
e1 = Event.create(title: "一二三四五六七八")
|
|
443
|
-
|
|
470
|
+
assert_predicate e1, :valid?, "Could not create an event with a unique 8 characters title"
|
|
444
471
|
|
|
445
472
|
e2 = Event.create(title: "一二三四五六七八")
|
|
446
473
|
assert_not e2.valid?, "Created an event whose title is not unique"
|
|
447
|
-
elsif current_adapter?(:Mysql2Adapter, :
|
|
474
|
+
elsif current_adapter?(:Mysql2Adapter, :TrilogyAdapter, :PostgreSQLAdapter)
|
|
448
475
|
assert_raise(ActiveRecord::ValueTooLong) do
|
|
449
476
|
Event.create(title: "一二三四五六七八")
|
|
450
477
|
end
|
|
@@ -457,30 +484,30 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
457
484
|
|
|
458
485
|
def test_validate_straight_inheritance_uniqueness
|
|
459
486
|
w1 = IneptWizard.create(name: "Rincewind", city: "Ankh-Morpork")
|
|
460
|
-
|
|
487
|
+
assert_predicate w1, :valid?, "Saving w1"
|
|
461
488
|
|
|
462
489
|
# Should use validation from base class (which is abstract)
|
|
463
490
|
w2 = IneptWizard.new(name: "Rincewind", city: "Quirm")
|
|
464
491
|
assert_not w2.valid?, "w2 shouldn't be valid"
|
|
465
|
-
|
|
492
|
+
assert_predicate w2.errors[:name], :any?, "Should have errors for name"
|
|
466
493
|
assert_equal ["has already been taken"], w2.errors[:name], "Should have uniqueness message for name"
|
|
467
494
|
|
|
468
495
|
w3 = Conjurer.new(name: "Rincewind", city: "Quirm")
|
|
469
496
|
assert_not w3.valid?, "w3 shouldn't be valid"
|
|
470
|
-
|
|
497
|
+
assert_predicate w3.errors[:name], :any?, "Should have errors for name"
|
|
471
498
|
assert_equal ["has already been taken"], w3.errors[:name], "Should have uniqueness message for name"
|
|
472
499
|
|
|
473
500
|
w4 = Conjurer.create(name: "The Amazing Bonko", city: "Quirm")
|
|
474
|
-
|
|
501
|
+
assert_predicate w4, :valid?, "Saving w4"
|
|
475
502
|
|
|
476
503
|
w5 = Thaumaturgist.new(name: "The Amazing Bonko", city: "Lancre")
|
|
477
504
|
assert_not w5.valid?, "w5 shouldn't be valid"
|
|
478
|
-
|
|
505
|
+
assert_predicate w5.errors[:name], :any?, "Should have errors for name"
|
|
479
506
|
assert_equal ["has already been taken"], w5.errors[:name], "Should have uniqueness message for name"
|
|
480
507
|
|
|
481
508
|
w6 = Thaumaturgist.new(name: "Mustrum Ridcully", city: "Quirm")
|
|
482
509
|
assert_not w6.valid?, "w6 shouldn't be valid"
|
|
483
|
-
|
|
510
|
+
assert_predicate w6.errors[:city], :any?, "Should have errors for city"
|
|
484
511
|
assert_equal ["has already been taken"], w6.errors[:city], "Should have uniqueness message for city"
|
|
485
512
|
end
|
|
486
513
|
|
|
@@ -493,7 +520,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
493
520
|
assert_not t3.valid?, "t3 shouldn't be valid"
|
|
494
521
|
|
|
495
522
|
t4 = Topic.new("title" => "I'm an unapproved topic", "approved" => false)
|
|
496
|
-
|
|
523
|
+
assert_predicate t4, :valid?, "t4 should be valid"
|
|
497
524
|
end
|
|
498
525
|
|
|
499
526
|
def test_validate_uniqueness_with_non_callable_conditions_is_not_supported
|
|
@@ -513,10 +540,10 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
513
540
|
assert todays_topic.save, "1st topic written today with this title should save"
|
|
514
541
|
|
|
515
542
|
todays_topic_duplicate = Topic.new(title: "Highlights of the Day", written_on: today_midday + 1.minute)
|
|
516
|
-
|
|
543
|
+
assert_predicate todays_topic_duplicate, :invalid?, "2nd topic written today with this title should be invalid"
|
|
517
544
|
|
|
518
545
|
tomorrows_topic = Topic.new(title: "Highlights of the Day", written_on: today_midday + 1.day)
|
|
519
|
-
|
|
546
|
+
assert_predicate tomorrows_topic, :valid?, "1st topic written tomorrow with this title should be valid"
|
|
520
547
|
end
|
|
521
548
|
|
|
522
549
|
def test_validate_uniqueness_on_existing_relation
|
|
@@ -581,7 +608,7 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
581
608
|
assert t.save, "Should save t as unique"
|
|
582
609
|
|
|
583
610
|
t.id += 1
|
|
584
|
-
|
|
611
|
+
assert_predicate t, :valid?, "Should be valid"
|
|
585
612
|
assert t.save, "Should still save t as unique"
|
|
586
613
|
end
|
|
587
614
|
|
|
@@ -616,3 +643,216 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
616
643
|
assert_equal(["has already been taken"], item2.errors[:id])
|
|
617
644
|
end
|
|
618
645
|
end
|
|
646
|
+
|
|
647
|
+
class UniquenessValidationWithIndexTest < ActiveRecord::TestCase
|
|
648
|
+
self.use_transactional_tests = false
|
|
649
|
+
|
|
650
|
+
def setup
|
|
651
|
+
@connection = Topic.lease_connection
|
|
652
|
+
@connection.schema_cache.clear!
|
|
653
|
+
Topic.delete_all
|
|
654
|
+
Event.delete_all
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
def teardown
|
|
658
|
+
Topic.clear_validators!
|
|
659
|
+
@connection.remove_index(:topics, name: :topics_index, if_exists: true)
|
|
660
|
+
end
|
|
661
|
+
|
|
662
|
+
def test_new_record
|
|
663
|
+
Topic.validates_uniqueness_of(:title)
|
|
664
|
+
@connection.add_index(:topics, :title, unique: true, name: :topics_index)
|
|
665
|
+
|
|
666
|
+
t = Topic.new(title: "abc")
|
|
667
|
+
assert_queries_count(1) do
|
|
668
|
+
t.valid?
|
|
669
|
+
end
|
|
670
|
+
end
|
|
671
|
+
|
|
672
|
+
def test_changing_non_unique_attribute
|
|
673
|
+
Topic.validates_uniqueness_of(:title)
|
|
674
|
+
@connection.add_index(:topics, :title, unique: true, name: :topics_index)
|
|
675
|
+
|
|
676
|
+
t = Topic.create!(title: "abc")
|
|
677
|
+
t.author_name = "John"
|
|
678
|
+
assert_no_queries do
|
|
679
|
+
t.valid?
|
|
680
|
+
end
|
|
681
|
+
end
|
|
682
|
+
|
|
683
|
+
def test_changing_unique_attribute
|
|
684
|
+
Topic.validates_uniqueness_of(:title)
|
|
685
|
+
@connection.add_index(:topics, :title, unique: true, name: :topics_index)
|
|
686
|
+
|
|
687
|
+
t = Topic.create!(title: "abc")
|
|
688
|
+
t.title = "abc v2"
|
|
689
|
+
assert_queries_count(1) do
|
|
690
|
+
t.valid?
|
|
691
|
+
end
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
def test_changing_non_unique_attribute_and_unique_attribute_is_nil
|
|
695
|
+
Topic.validates_uniqueness_of(:title)
|
|
696
|
+
@connection.add_index(:topics, :title, unique: true, name: :topics_index)
|
|
697
|
+
|
|
698
|
+
t = Topic.create!
|
|
699
|
+
assert_nil t.title
|
|
700
|
+
t.author_name = "John"
|
|
701
|
+
assert_queries_count(1) do
|
|
702
|
+
t.valid?
|
|
703
|
+
end
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
def test_conditions
|
|
707
|
+
Topic.validates_uniqueness_of(:title, conditions: -> { where.not(author_name: nil) })
|
|
708
|
+
@connection.add_index(:topics, :title, unique: true, name: :topics_index)
|
|
709
|
+
|
|
710
|
+
t = Topic.create!(title: "abc")
|
|
711
|
+
t.title = "abc v2"
|
|
712
|
+
assert_queries_count(1) do
|
|
713
|
+
t.valid?
|
|
714
|
+
end
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
def test_case_sensitive
|
|
718
|
+
Topic.validates_uniqueness_of(:title, case_sensitive: true)
|
|
719
|
+
@connection.add_index(:topics, :title, unique: true, name: :topics_index)
|
|
720
|
+
|
|
721
|
+
t = Topic.create!(title: "abc")
|
|
722
|
+
t.title = "abc v2"
|
|
723
|
+
assert_queries_count(1) do
|
|
724
|
+
t.valid?
|
|
725
|
+
end
|
|
726
|
+
end
|
|
727
|
+
|
|
728
|
+
def test_partial_index
|
|
729
|
+
skip unless @connection.supports_partial_index?
|
|
730
|
+
|
|
731
|
+
Topic.validates_uniqueness_of(:title)
|
|
732
|
+
@connection.add_index(:topics, :title, unique: true, where: "approved", name: :topics_index)
|
|
733
|
+
|
|
734
|
+
t = Topic.create!(title: "abc")
|
|
735
|
+
t.author_name = "John"
|
|
736
|
+
assert_queries_count(1) do
|
|
737
|
+
t.valid?
|
|
738
|
+
end
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
def test_non_unique_index
|
|
742
|
+
Topic.validates_uniqueness_of(:title)
|
|
743
|
+
@connection.add_index(:topics, :title, name: :topics_index)
|
|
744
|
+
|
|
745
|
+
t = Topic.create!(title: "abc")
|
|
746
|
+
t.author_name = "John"
|
|
747
|
+
assert_queries_count(1) do
|
|
748
|
+
t.valid?
|
|
749
|
+
end
|
|
750
|
+
end
|
|
751
|
+
|
|
752
|
+
def test_scope
|
|
753
|
+
Topic.validates_uniqueness_of(:title, scope: :author_name)
|
|
754
|
+
@connection.add_index(:topics, [:author_name, :title], unique: true, name: :topics_index)
|
|
755
|
+
|
|
756
|
+
t = Topic.create!(title: "abc", author_name: "John")
|
|
757
|
+
t.content = "hello world"
|
|
758
|
+
assert_no_queries do
|
|
759
|
+
t.valid?
|
|
760
|
+
end
|
|
761
|
+
|
|
762
|
+
t.author_name = "Amy"
|
|
763
|
+
assert_queries_count(1) do
|
|
764
|
+
t.valid?
|
|
765
|
+
end
|
|
766
|
+
end
|
|
767
|
+
|
|
768
|
+
def test_uniqueness_on_relation
|
|
769
|
+
TopicWithEvent.validates_uniqueness_of(:event)
|
|
770
|
+
@connection.add_index(:topics, :parent_id, unique: true, name: :topics_index)
|
|
771
|
+
|
|
772
|
+
e1 = Event.create!(title: "abc")
|
|
773
|
+
e2 = Event.create!(title: "cde")
|
|
774
|
+
t = TopicWithEvent.create!(event: e1)
|
|
775
|
+
|
|
776
|
+
t.content = "hello world"
|
|
777
|
+
assert_no_queries do
|
|
778
|
+
t.valid?
|
|
779
|
+
end
|
|
780
|
+
|
|
781
|
+
t.event = e2
|
|
782
|
+
assert_queries_count(1) do
|
|
783
|
+
t.valid?
|
|
784
|
+
end
|
|
785
|
+
ensure
|
|
786
|
+
TopicWithEvent.clear_validators!
|
|
787
|
+
Event.delete_all
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
def test_uniqueness_on_custom_relation_primary_key
|
|
791
|
+
Keyboard.create!(name: "Keyboard #1")
|
|
792
|
+
LessonWithUniqKeyboard.create!(name: "Keyboard #1")
|
|
793
|
+
|
|
794
|
+
another = LessonWithUniqKeyboard.new(name: "Keyboard #1")
|
|
795
|
+
assert_not_predicate another, :valid?
|
|
796
|
+
assert_equal ["has already been taken"], another.errors[:keyboard]
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
def test_index_of_sublist_of_columns
|
|
800
|
+
Topic.validates_uniqueness_of(:title, scope: :author_name)
|
|
801
|
+
@connection.add_index(:topics, :author_name, unique: true, name: :topics_index)
|
|
802
|
+
|
|
803
|
+
t = Topic.create!(title: "abc", author_name: "John")
|
|
804
|
+
t.content = "hello world"
|
|
805
|
+
assert_no_queries do
|
|
806
|
+
t.valid?
|
|
807
|
+
end
|
|
808
|
+
|
|
809
|
+
t.author_name = "Amy"
|
|
810
|
+
assert_queries_count(1) do
|
|
811
|
+
t.valid?
|
|
812
|
+
end
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
def test_index_of_columns_list_and_extra_columns
|
|
816
|
+
Topic.validates_uniqueness_of(:title)
|
|
817
|
+
@connection.add_index(:topics, [:title, :author_name], unique: true, name: :topics_index)
|
|
818
|
+
|
|
819
|
+
t = Topic.create!(title: "abc", author_name: "John")
|
|
820
|
+
t.content = "hello world"
|
|
821
|
+
assert_queries_count(1) do
|
|
822
|
+
t.valid?
|
|
823
|
+
end
|
|
824
|
+
end
|
|
825
|
+
|
|
826
|
+
if current_adapter?(:PostgreSQLAdapter)
|
|
827
|
+
def test_expression_index
|
|
828
|
+
Topic.validates_uniqueness_of(:title)
|
|
829
|
+
@connection.add_index(:topics, "LOWER(title)", unique: true, name: :topics_index)
|
|
830
|
+
|
|
831
|
+
t = Topic.create!(title: "abc", author_name: "John")
|
|
832
|
+
t.content = "hello world"
|
|
833
|
+
|
|
834
|
+
assert_queries_count(1) do
|
|
835
|
+
t.valid?
|
|
836
|
+
end
|
|
837
|
+
end
|
|
838
|
+
end
|
|
839
|
+
end
|
|
840
|
+
|
|
841
|
+
class UniquenessWithCompositeKey < ActiveRecord::TestCase
|
|
842
|
+
class BookWithUniqueRevision < Cpk::Book
|
|
843
|
+
validates :revision, uniqueness: true
|
|
844
|
+
end
|
|
845
|
+
|
|
846
|
+
def test_uniqueness_validation_for_model_with_composite_key
|
|
847
|
+
book_one = BookWithUniqueRevision.create!(id: [1, 42], title: "Author 1's book", revision: 36)
|
|
848
|
+
book_two = BookWithUniqueRevision.create!(id: [2, 42], title: "Author 2's book", revision: 37)
|
|
849
|
+
|
|
850
|
+
assert_not_equal book_one.revision, book_two.revision
|
|
851
|
+
|
|
852
|
+
assert_changes("book_two.valid?", from: true, to: false) do
|
|
853
|
+
book_two.revision = book_one.revision
|
|
854
|
+
end
|
|
855
|
+
ensure
|
|
856
|
+
BookWithUniqueRevision.delete_all
|
|
857
|
+
end
|
|
858
|
+
end
|
|
@@ -20,7 +20,7 @@ class ValidationsTest < ActiveRecord::TestCase
|
|
|
20
20
|
r = WrongReply.new
|
|
21
21
|
r.title = "Wrong Create"
|
|
22
22
|
assert_not_predicate r, :valid?
|
|
23
|
-
|
|
23
|
+
assert_predicate r.errors[:title], :any?, "A reply with a bad title should mark that attribute as invalid"
|
|
24
24
|
assert_equal ["is Wrong Create"], r.errors[:title], "A reply with a bad content should contain an error"
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -33,7 +33,7 @@ class ValidationsTest < ActiveRecord::TestCase
|
|
|
33
33
|
r.title = "Wrong Update"
|
|
34
34
|
assert_not r.valid?, "Second validation should fail"
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
assert_predicate r.errors[:title], :any?, "A reply with a bad title should mark that attribute as invalid"
|
|
37
37
|
assert_equal ["is Wrong Update"], r.errors[:title], "A reply with a bad content should contain an error"
|
|
38
38
|
end
|
|
39
39
|
|
data/test/cases/view_test.rb
CHANGED
|
@@ -19,9 +19,9 @@ module ViewBehavior
|
|
|
19
19
|
|
|
20
20
|
def setup
|
|
21
21
|
super
|
|
22
|
-
@connection = ActiveRecord::Base.
|
|
22
|
+
@connection = ActiveRecord::Base.lease_connection
|
|
23
23
|
create_view "ebooks", <<~SQL
|
|
24
|
-
SELECT id, name, status FROM books WHERE format = 'ebook'
|
|
24
|
+
SELECT id, name, cover, status FROM books WHERE format = 'ebook'
|
|
25
25
|
SQL
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -37,7 +37,11 @@ module ViewBehavior
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def test_views
|
|
40
|
-
|
|
40
|
+
if current_adapter?(:IBM_DBAdapter)
|
|
41
|
+
assert_includes @connection.views, Ebook.table_name
|
|
42
|
+
else
|
|
43
|
+
assert_equal [Ebook.table_name], @connection.views
|
|
44
|
+
end
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def test_view_exists
|
|
@@ -58,11 +62,12 @@ module ViewBehavior
|
|
|
58
62
|
def test_column_definitions
|
|
59
63
|
assert_equal([["id", :integer],
|
|
60
64
|
["name", :string],
|
|
65
|
+
["cover", :string],
|
|
61
66
|
["status", :integer]], Ebook.columns.map { |c| [c.name, c.type] })
|
|
62
67
|
end
|
|
63
68
|
|
|
64
69
|
def test_attributes
|
|
65
|
-
assert_equal({ "id" => 2, "name" => "Ruby for Rails", "status" => 0 },
|
|
70
|
+
assert_equal({ "id" => 2, "name" => "Ruby for Rails", "cover" => "hard", "status" => 0 },
|
|
66
71
|
Ebook.first.attributes)
|
|
67
72
|
end
|
|
68
73
|
|
|
@@ -77,14 +82,9 @@ module ViewBehavior
|
|
|
77
82
|
schema = dump_table_schema "ebooks"
|
|
78
83
|
assert_no_match %r{create_table "ebooks"}, schema
|
|
79
84
|
end
|
|
80
|
-
|
|
81
|
-
private
|
|
82
|
-
def quote_table_name(name)
|
|
83
|
-
@connection.quote_table_name(name)
|
|
84
|
-
end
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
if ActiveRecord::Base.
|
|
87
|
+
if ActiveRecord::Base.lease_connection.supports_views?
|
|
88
88
|
class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
|
|
89
89
|
include ViewBehavior
|
|
90
90
|
|
|
@@ -100,12 +100,14 @@ if ActiveRecord::Base.connection.supports_views?
|
|
|
100
100
|
|
|
101
101
|
class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
|
|
102
102
|
include SchemaDumpingHelper
|
|
103
|
+
|
|
104
|
+
self.use_transactional_tests = false
|
|
103
105
|
fixtures :books
|
|
104
106
|
|
|
105
107
|
class Paperback < ActiveRecord::Base; end
|
|
106
108
|
|
|
107
109
|
setup do
|
|
108
|
-
@connection = ActiveRecord::Base.
|
|
110
|
+
@connection = ActiveRecord::Base.lease_connection
|
|
109
111
|
@connection.execute <<~SQL
|
|
110
112
|
CREATE VIEW paperbacks
|
|
111
113
|
AS SELECT name, status FROM books WHERE format = 'paperback'
|
|
@@ -113,7 +115,7 @@ if ActiveRecord::Base.connection.supports_views?
|
|
|
113
115
|
end
|
|
114
116
|
|
|
115
117
|
teardown do
|
|
116
|
-
@connection.execute "DROP VIEW paperbacks" if @connection
|
|
118
|
+
@connection.execute "DROP VIEW paperbacks" if @connection&.view_exists? "paperbacks"
|
|
117
119
|
end
|
|
118
120
|
|
|
119
121
|
def test_reading
|
|
@@ -122,7 +124,11 @@ if ActiveRecord::Base.connection.supports_views?
|
|
|
122
124
|
end
|
|
123
125
|
|
|
124
126
|
def test_views
|
|
125
|
-
|
|
127
|
+
if current_adapter?(:IBM_DBAdapter)
|
|
128
|
+
assert_includes @connection.views, Paperback.table_name
|
|
129
|
+
else
|
|
130
|
+
assert_equal [Paperback.table_name], @connection.views
|
|
131
|
+
end
|
|
126
132
|
end
|
|
127
133
|
|
|
128
134
|
def test_view_exists
|
|
@@ -155,10 +161,9 @@ if ActiveRecord::Base.connection.supports_views?
|
|
|
155
161
|
end
|
|
156
162
|
end
|
|
157
163
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
class UpdateableViewTest < ActiveRecord::TestCase
|
|
164
|
+
class UpdateableViewTest < ActiveRecord::TestCase
|
|
165
|
+
# SQLite does not support CREATE, INSERT, and DELETE for VIEW
|
|
166
|
+
if current_adapter?(:Mysql2Adapter, :TrilogyAdapter, :PostgreSQLAdapter, :IBM_DBAdapter)
|
|
162
167
|
self.use_transactional_tests = false
|
|
163
168
|
fixtures :books
|
|
164
169
|
|
|
@@ -167,7 +172,7 @@ if ActiveRecord::Base.connection.supports_views?
|
|
|
167
172
|
end
|
|
168
173
|
|
|
169
174
|
setup do
|
|
170
|
-
@connection = ActiveRecord::Base.
|
|
175
|
+
@connection = ActiveRecord::Base.lease_connection
|
|
171
176
|
@connection.execute <<~SQL
|
|
172
177
|
CREATE VIEW printed_books
|
|
173
178
|
AS SELECT id, name, status, format FROM books WHERE format = 'paperback'
|
|
@@ -193,6 +198,12 @@ if ActiveRecord::Base.connection.supports_views?
|
|
|
193
198
|
assert_equal "Rails in Action", new_book.name
|
|
194
199
|
end
|
|
195
200
|
|
|
201
|
+
def test_insert_record_populates_primary_key
|
|
202
|
+
book = PrintedBook.create! name: "Rails in Action", status: 0, format: "paperback"
|
|
203
|
+
assert_not_nil book.id
|
|
204
|
+
assert book.id > 0
|
|
205
|
+
end if current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter) && supports_insert_returning?
|
|
206
|
+
|
|
196
207
|
def test_update_record_to_fail_view_conditions
|
|
197
208
|
book = PrintedBook.first
|
|
198
209
|
book.format = "ebook"
|
|
@@ -202,11 +213,11 @@ if ActiveRecord::Base.connection.supports_views?
|
|
|
202
213
|
book.reload
|
|
203
214
|
end
|
|
204
215
|
end
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
end # end of `if ActiveRecord::Base.
|
|
216
|
+
end # end of `if current_adapter?(:Mysql2Adapter, :TrilogyAdapter, :PostgreSQLAdapter, :IBM_DBAdapter)`
|
|
217
|
+
end
|
|
218
|
+
end # end of `if ActiveRecord::Base.lease_connection.supports_views?`
|
|
208
219
|
|
|
209
|
-
if ActiveRecord::Base.
|
|
220
|
+
if ActiveRecord::Base.lease_connection.supports_materialized_views?
|
|
210
221
|
class MaterializedViewTest < ActiveRecord::PostgreSQLTestCase
|
|
211
222
|
include ViewBehavior
|
|
212
223
|
|