ibm_db 5.2.0-x86-mingw32 → 5.4.0-x86-mingw32
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/CHANGES +9 -0
- data/LICENSE +55 -18
- data/README +1 -1
- data/debug.log +1 -0
- data/ext/Makefile +28 -24
- data/ext/ibm_db.c +66 -65
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +26 -24
- data/ext/ruby_ibm_db_cli.c +1 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +1520 -1282
- data/lib/ibm_db.so +1 -0
- data/lib/mswin32/ibm_db.rb +3 -1
- data/lib/mswin32/rb3x/i386/ruby30/ibm_db.so +0 -0
- data/lib/mswin32/rb3x/i386/ruby31/ibm_db.so +0 -0
- data/test/active_record/connection_adapters/fake_adapter.rb +5 -2
- data/test/activejob/destroy_association_async_test.rb +305 -0
- data/test/activejob/destroy_async_job_not_present_test.rb +31 -0
- data/test/activejob/helper.rb +15 -0
- data/test/assets/schema_dump_5_1.yml +345 -0
- data/test/cases/adapter_prevent_writes_test.rb +334 -0
- data/test/cases/adapter_test.rb +432 -218
- data/test/cases/adapters/mysql2/active_schema_test.rb +85 -75
- data/test/cases/adapters/mysql2/auto_increment_test.rb +34 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +5 -3
- data/test/cases/adapters/mysql2/boolean_test.rb +6 -4
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +26 -24
- data/test/cases/adapters/mysql2/charset_collation_test.rb +20 -17
- data/test/cases/adapters/mysql2/connection_test.rb +48 -50
- data/test/cases/adapters/mysql2/count_deleted_rows_with_lock_test.rb +28 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +23 -19
- data/test/cases/adapters/mysql2/enum_test.rb +32 -11
- data/test/cases/adapters/mysql2/explain_test.rb +13 -11
- data/test/cases/adapters/mysql2/json_test.rb +17 -188
- data/test/cases/adapters/mysql2/mysql2_adapter_prevent_writes_test.rb +208 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +183 -28
- data/test/cases/adapters/mysql2/nested_deadlock_test.rb +75 -0
- data/test/cases/adapters/mysql2/optimizer_hints_test.rb +69 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +26 -21
- data/test/cases/adapters/mysql2/schema_test.rb +24 -22
- data/test/cases/adapters/mysql2/set_test.rb +32 -0
- data/test/cases/adapters/mysql2/sp_test.rb +10 -8
- data/test/cases/adapters/mysql2/sql_types_test.rb +8 -6
- data/test/cases/adapters/mysql2/table_options_test.rb +93 -10
- data/test/cases/adapters/mysql2/transaction_test.rb +151 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +11 -9
- data/test/cases/adapters/mysql2/virtual_column_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +40 -25
- data/test/cases/adapters/postgresql/array_test.rb +118 -63
- data/test/cases/adapters/postgresql/bit_string_test.rb +12 -10
- data/test/cases/adapters/postgresql/bytea_test.rb +26 -25
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +10 -9
- data/test/cases/adapters/postgresql/change_schema_test.rb +7 -5
- data/test/cases/adapters/postgresql/cidr_test.rb +2 -0
- data/test/cases/adapters/postgresql/citext_test.rb +58 -58
- data/test/cases/adapters/postgresql/collation_test.rb +17 -15
- data/test/cases/adapters/postgresql/composite_test.rb +25 -23
- data/test/cases/adapters/postgresql/connection_test.rb +73 -85
- data/test/cases/adapters/postgresql/create_unlogged_tables_test.rb +74 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +19 -22
- data/test/cases/adapters/postgresql/date_test.rb +42 -0
- data/test/cases/adapters/postgresql/domain_test.rb +9 -7
- data/test/cases/adapters/postgresql/enum_test.rb +12 -10
- data/test/cases/adapters/postgresql/explain_test.rb +10 -8
- data/test/cases/adapters/postgresql/extension_migration_test.rb +13 -12
- data/test/cases/adapters/postgresql/foreign_table_test.rb +109 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +8 -6
- data/test/cases/adapters/postgresql/geometric_test.rb +57 -63
- data/test/cases/adapters/postgresql/hstore_test.rb +288 -280
- data/test/cases/adapters/postgresql/infinity_test.rb +54 -15
- data/test/cases/adapters/postgresql/integer_test.rb +2 -0
- data/test/cases/adapters/postgresql/interval_test.rb +99 -0
- data/test/cases/adapters/postgresql/json_test.rb +16 -201
- data/test/cases/adapters/postgresql/ltree_test.rb +14 -16
- data/test/cases/adapters/postgresql/money_test.rb +47 -16
- data/test/cases/adapters/postgresql/network_test.rb +36 -28
- data/test/cases/adapters/postgresql/numbers_test.rb +7 -5
- data/test/cases/adapters/postgresql/optimizer_hints_test.rb +71 -0
- data/test/cases/adapters/postgresql/partitions_test.rb +22 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_prevent_writes_test.rb +205 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +178 -136
- data/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb +27 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +12 -6
- data/test/cases/adapters/postgresql/range_test.rb +406 -292
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +16 -15
- data/test/cases/adapters/postgresql/rename_table_test.rb +9 -8
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +14 -23
- data/test/cases/adapters/postgresql/schema_test.rb +207 -91
- data/test/cases/adapters/postgresql/serial_test.rb +9 -7
- data/test/cases/adapters/postgresql/statement_pool_test.rb +26 -6
- data/test/cases/adapters/postgresql/timestamp_test.rb +17 -15
- data/test/cases/adapters/postgresql/transaction_nested_test.rb +114 -0
- data/test/cases/adapters/postgresql/transaction_test.rb +189 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +12 -10
- data/test/cases/adapters/postgresql/utils_test.rb +11 -9
- data/test/cases/adapters/postgresql/uuid_test.rb +226 -109
- data/test/cases/adapters/postgresql/xml_test.rb +10 -14
- data/test/cases/adapters/sqlite3/collation_test.rb +26 -15
- data/test/cases/adapters/sqlite3/copy_table_test.rb +31 -28
- data/test/cases/adapters/sqlite3/explain_test.rb +13 -11
- data/test/cases/adapters/sqlite3/json_test.rb +29 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +35 -57
- data/test/cases/adapters/sqlite3/sqlite3_adapter_prevent_writes_test.rb +186 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +318 -131
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +11 -11
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +7 -6
- data/test/cases/adapters/sqlite3/transaction_test.rb +123 -0
- data/test/cases/aggregations_test.rb +14 -12
- data/test/cases/annotate_test.rb +46 -0
- data/test/cases/ar_schema_test.rb +153 -86
- data/test/cases/arel/attributes/attribute_test.rb +1145 -0
- data/test/cases/arel/attributes/math_test.rb +83 -0
- data/test/cases/arel/attributes_test.rb +27 -0
- data/test/cases/arel/collectors/bind_test.rb +40 -0
- data/test/cases/arel/collectors/composite_test.rb +47 -0
- data/test/cases/arel/collectors/sql_string_test.rb +41 -0
- data/test/cases/arel/collectors/substitute_bind_collector_test.rb +48 -0
- data/test/cases/arel/crud_test.rb +65 -0
- data/test/cases/arel/delete_manager_test.rb +53 -0
- data/test/cases/arel/factory_methods_test.rb +46 -0
- data/test/cases/arel/helper.rb +45 -0
- data/test/cases/arel/insert_manager_test.rb +241 -0
- data/test/cases/arel/nodes/and_test.rb +30 -0
- data/test/cases/arel/nodes/as_test.rb +36 -0
- data/test/cases/arel/nodes/ascending_test.rb +46 -0
- data/test/cases/arel/nodes/bin_test.rb +35 -0
- data/test/cases/arel/nodes/binary_test.rb +29 -0
- data/test/cases/arel/nodes/bind_param_test.rb +22 -0
- data/test/cases/arel/nodes/case_test.rb +96 -0
- data/test/cases/arel/nodes/casted_test.rb +18 -0
- data/test/cases/arel/nodes/comment_test.rb +22 -0
- data/test/cases/arel/nodes/count_test.rb +35 -0
- data/test/cases/arel/nodes/delete_statement_test.rb +36 -0
- data/test/cases/arel/nodes/descending_test.rb +46 -0
- data/test/cases/arel/nodes/distinct_test.rb +21 -0
- data/test/cases/arel/nodes/equality_test.rb +62 -0
- data/test/cases/arel/nodes/extract_test.rb +43 -0
- data/test/cases/arel/nodes/false_test.rb +21 -0
- data/test/cases/arel/nodes/grouping_test.rb +26 -0
- data/test/cases/arel/nodes/infix_operation_test.rb +42 -0
- data/test/cases/arel/nodes/insert_statement_test.rb +44 -0
- data/test/cases/arel/nodes/named_function_test.rb +48 -0
- data/test/cases/arel/nodes/node_test.rb +22 -0
- data/test/cases/arel/nodes/not_test.rb +31 -0
- data/test/cases/arel/nodes/or_test.rb +36 -0
- data/test/cases/arel/nodes/over_test.rb +69 -0
- data/test/cases/arel/nodes/select_core_test.rb +79 -0
- data/test/cases/arel/nodes/select_statement_test.rb +51 -0
- data/test/cases/arel/nodes/sql_literal_test.rb +75 -0
- data/test/cases/arel/nodes/sum_test.rb +35 -0
- data/test/cases/arel/nodes/table_alias_test.rb +29 -0
- data/test/cases/arel/nodes/true_test.rb +21 -0
- data/test/cases/arel/nodes/unary_operation_test.rb +41 -0
- data/test/cases/arel/nodes/update_statement_test.rb +60 -0
- data/test/cases/arel/nodes/window_test.rb +81 -0
- data/test/cases/arel/nodes_test.rb +34 -0
- data/test/cases/arel/select_manager_test.rb +1238 -0
- data/test/cases/arel/support/fake_record.rb +135 -0
- data/test/cases/arel/table_test.rb +216 -0
- data/test/cases/arel/update_manager_test.rb +126 -0
- data/test/cases/arel/visitors/dispatch_contamination_test.rb +78 -0
- data/test/cases/arel/visitors/dot_test.rb +90 -0
- data/test/cases/arel/visitors/mysql_test.rb +157 -0
- data/test/cases/arel/visitors/postgres_test.rb +366 -0
- data/test/cases/arel/visitors/sqlite_test.rb +75 -0
- data/test/cases/arel/visitors/to_sql_test.rb +750 -0
- data/test/cases/associations/belongs_to_associations_test.rb +510 -158
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +4 -2
- data/test/cases/associations/callbacks_test.rb +56 -38
- data/test/cases/associations/cascaded_eager_loading_test.rb +118 -61
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +138 -18
- data/test/cases/associations/eager_load_nested_include_test.rb +38 -37
- data/test/cases/associations/eager_singularization_test.rb +21 -21
- data/test/cases/associations/eager_test.rb +559 -415
- data/test/cases/associations/extension_test.rb +18 -12
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +234 -213
- data/test/cases/associations/has_many_associations_test.rb +1038 -465
- data/test/cases/associations/has_many_through_associations_test.rb +558 -249
- data/test/cases/associations/has_one_associations_test.rb +294 -129
- data/test/cases/associations/has_one_through_associations_test.rb +121 -75
- data/test/cases/associations/inner_join_association_test.rb +114 -38
- data/test/cases/associations/inverse_associations_test.rb +606 -398
- data/test/cases/associations/join_model_test.rb +158 -148
- data/test/cases/associations/left_outer_join_association_test.rb +59 -24
- data/test/cases/associations/nested_through_associations_test.rb +166 -109
- data/test/cases/associations/required_test.rb +35 -10
- data/test/cases/associations_test.rb +241 -110
- data/test/cases/attribute_methods/read_test.rb +11 -11
- data/test/cases/attribute_methods_test.rb +413 -298
- data/test/cases/attributes_test.rb +145 -27
- data/test/cases/autosave_association_test.rb +681 -436
- data/test/cases/base_prevent_writes_test.rb +229 -0
- data/test/cases/base_test.rb +599 -542
- data/test/cases/batches_test.rb +288 -82
- data/test/cases/binary_test.rb +26 -31
- data/test/cases/bind_parameter_test.rb +194 -21
- data/test/cases/boolean_test.rb +52 -0
- data/test/cases/cache_key_test.rb +110 -5
- data/test/cases/calculations_test.rb +740 -177
- data/test/cases/callbacks_test.rb +74 -207
- data/test/cases/clone_test.rb +15 -10
- data/test/cases/coders/json_test.rb +2 -0
- data/test/cases/coders/yaml_column_test.rb +16 -13
- data/test/cases/collection_cache_key_test.rb +177 -20
- data/test/cases/column_alias_test.rb +9 -7
- data/test/cases/column_definition_test.rb +10 -68
- data/test/cases/comment_test.rb +166 -107
- data/test/cases/connection_adapters/adapter_leasing_test.rb +14 -10
- data/test/cases/connection_adapters/connection_handler_test.rb +358 -51
- data/test/cases/connection_adapters/connection_handlers_multi_db_test.rb +400 -0
- data/test/cases/connection_adapters/connection_handlers_multi_pool_config_test.rb +103 -0
- data/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb +499 -0
- data/test/cases/connection_adapters/connection_swapping_nested_test.rb +457 -0
- data/test/cases/connection_adapters/legacy_connection_handlers_multi_db_test.rb +486 -0
- data/test/cases/connection_adapters/legacy_connection_handlers_sharding_db_test.rb +586 -0
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +319 -138
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +62 -50
- data/test/cases/connection_adapters/schema_cache_test.rb +259 -26
- data/test/cases/connection_adapters/type_lookup_test.rb +96 -95
- data/test/cases/connection_management_test.rb +13 -11
- data/test/cases/connection_pool_test.rb +316 -83
- data/test/cases/core_test.rb +82 -58
- data/test/cases/counter_cache_test.rb +204 -50
- data/test/cases/custom_locking_test.rb +5 -3
- data/test/cases/database_configurations/hash_config_test.rb +74 -0
- data/test/cases/database_configurations/resolver_test.rb +150 -0
- data/test/cases/database_configurations_test.rb +145 -0
- data/test/cases/database_selector_test.rb +296 -0
- data/test/cases/database_statements_test.rb +18 -16
- data/test/cases/date_test.rb +8 -16
- data/test/cases/date_time_precision_test.rb +100 -78
- data/test/cases/date_time_test.rb +23 -8
- data/test/cases/defaults_test.rb +106 -71
- data/test/cases/delegated_type_test.rb +57 -0
- data/test/cases/dirty_test.rb +419 -223
- data/test/cases/disconnected_test.rb +6 -6
- data/test/cases/dup_test.rb +54 -27
- data/test/cases/enum_test.rb +461 -82
- data/test/cases/errors_test.rb +7 -7
- data/test/cases/explain_subscriber_test.rb +17 -15
- data/test/cases/explain_test.rb +11 -19
- data/test/cases/filter_attributes_test.rb +153 -0
- data/test/cases/finder_respond_to_test.rb +14 -14
- data/test/cases/finder_test.rb +669 -287
- data/test/cases/fixture_set/file_test.rb +34 -38
- data/test/cases/fixtures_test.rb +833 -176
- data/test/cases/forbidden_attributes_protection_test.rb +32 -67
- data/test/cases/habtm_destroy_order_test.rb +25 -25
- data/test/cases/helper.rb +78 -49
- data/test/cases/hot_compatibility_test.rb +33 -32
- data/test/cases/i18n_test.rb +18 -17
- data/test/cases/inheritance_test.rb +180 -115
- data/test/cases/insert_all_test.rb +489 -0
- data/test/cases/instrumentation_test.rb +101 -0
- data/test/cases/integration_test.rb +119 -31
- data/test/cases/invalid_connection_test.rb +18 -16
- data/test/cases/invertible_migration_test.rb +183 -43
- data/test/cases/json_attribute_test.rb +35 -0
- data/test/cases/json_serialization_test.rb +57 -58
- data/test/cases/json_shared_test_cases.rb +290 -0
- data/test/cases/locking_test.rb +413 -119
- data/test/cases/log_subscriber_test.rb +68 -26
- data/test/cases/marshal_serialization_test.rb +39 -0
- data/test/cases/migration/change_schema_test.rb +118 -72
- data/test/cases/migration/change_table_test.rb +138 -30
- data/test/cases/migration/check_constraint_test.rb +162 -0
- data/test/cases/migration/column_attributes_test.rb +45 -35
- data/test/cases/migration/column_positioning_test.rb +18 -6
- data/test/cases/migration/columns_test.rb +93 -77
- data/test/cases/migration/command_recorder_test.rb +121 -34
- data/test/cases/migration/compatibility_test.rb +578 -23
- data/test/cases/migration/create_join_table_test.rb +35 -25
- data/test/cases/migration/foreign_key_test.rb +503 -284
- data/test/cases/migration/helper.rb +4 -3
- data/test/cases/migration/index_test.rb +119 -70
- data/test/cases/migration/logger_test.rb +9 -6
- data/test/cases/migration/pending_migrations_test.rb +88 -34
- data/test/cases/migration/references_foreign_key_test.rb +164 -150
- data/test/cases/migration/references_index_test.rb +38 -19
- data/test/cases/migration/references_statements_test.rb +15 -14
- data/test/cases/migration/rename_table_test.rb +53 -30
- data/test/cases/migration_test.rb +637 -269
- data/test/cases/migrator_test.rb +191 -135
- data/test/cases/mixin_test.rb +7 -11
- data/test/cases/modules_test.rb +36 -34
- data/test/cases/multi_db_migrator_test.rb +223 -0
- data/test/cases/multiparameter_attributes_test.rb +60 -33
- data/test/cases/multiple_db_test.rb +16 -22
- data/test/cases/nested_attributes_test.rb +341 -320
- data/test/cases/nested_attributes_with_callbacks_test.rb +26 -24
- data/test/cases/null_relation_test.rb +84 -0
- data/test/cases/numeric_data_test.rb +93 -0
- data/test/cases/persistence_test.rb +361 -269
- data/test/cases/pooled_connections_test.rb +18 -26
- data/test/cases/prepared_statement_status_test.rb +48 -0
- data/test/cases/primary_keys_test.rb +210 -104
- data/test/cases/query_cache_test.rb +610 -141
- data/test/cases/quoting_test.rb +132 -31
- data/test/cases/readonly_test.rb +49 -48
- data/test/cases/reaper_test.rb +146 -32
- data/test/cases/reflection_test.rb +167 -156
- data/test/cases/relation/delegation_test.rb +49 -36
- data/test/cases/relation/delete_all_test.rb +117 -0
- data/test/cases/relation/merging_test.rb +319 -42
- data/test/cases/relation/mutation_test.rb +55 -93
- data/test/cases/relation/or_test.rb +129 -29
- data/test/cases/relation/predicate_builder_test.rb +21 -6
- data/test/cases/relation/record_fetch_warning_test.rb +5 -3
- data/test/cases/relation/select_test.rb +67 -0
- data/test/cases/relation/update_all_test.rb +317 -0
- data/test/cases/relation/where_chain_test.rb +68 -32
- data/test/cases/relation/where_clause_test.rb +136 -61
- data/test/cases/relation/where_test.rb +155 -48
- data/test/cases/relation_test.rb +266 -112
- data/test/cases/relations_test.rb +969 -744
- data/test/cases/reload_models_test.rb +13 -9
- data/test/cases/reserved_word_test.rb +141 -0
- data/test/cases/result_test.rb +68 -17
- data/test/cases/sanitize_test.rb +87 -71
- data/test/cases/schema_dumper_test.rb +221 -128
- data/test/cases/schema_loading_test.rb +3 -2
- data/test/cases/scoping/default_scoping_test.rb +185 -144
- data/test/cases/scoping/named_scoping_test.rb +177 -89
- data/test/cases/scoping/relation_scoping_test.rb +197 -75
- data/test/cases/secure_token_test.rb +18 -3
- data/test/cases/serialization_test.rb +30 -28
- data/test/cases/serialized_attribute_test.rb +133 -42
- data/test/cases/signed_id_test.rb +168 -0
- data/test/cases/statement_cache_test.rb +41 -24
- data/test/cases/statement_invalid_test.rb +42 -0
- data/test/cases/store_test.rb +180 -55
- data/test/cases/strict_loading_test.rb +473 -0
- data/test/cases/suppressor_test.rb +26 -12
- data/test/cases/tasks/database_tasks_test.rb +1258 -194
- data/test/cases/tasks/mysql_rake_test.rb +370 -298
- data/test/cases/tasks/postgresql_rake_test.rb +481 -251
- data/test/cases/tasks/sqlite_rake_test.rb +225 -178
- data/test/cases/test_case.rb +51 -40
- data/test/cases/test_databases_test.rb +79 -0
- data/test/cases/test_fixtures_test.rb +79 -19
- data/test/cases/time_precision_test.rb +98 -76
- data/test/cases/timestamp_test.rb +102 -99
- data/test/cases/touch_later_test.rb +12 -10
- data/test/cases/transaction_callbacks_test.rb +344 -90
- data/test/cases/transaction_isolation_test.rb +12 -12
- data/test/cases/transactions_test.rb +612 -162
- data/test/cases/type/adapter_specific_registry_test.rb +14 -2
- data/test/cases/type/date_time_test.rb +4 -2
- data/test/cases/type/integer_test.rb +4 -2
- data/test/cases/type/string_test.rb +10 -8
- data/test/cases/type/time_test.rb +28 -0
- data/test/cases/type/type_map_test.rb +29 -28
- data/test/cases/type/unsigned_integer_test.rb +19 -0
- data/test/cases/type_test.rb +2 -0
- data/test/cases/types_test.rb +3 -1
- data/test/cases/unconnected_test.rb +14 -1
- data/test/cases/unsafe_raw_sql_test.rb +274 -0
- data/test/cases/validations/absence_validation_test.rb +19 -17
- data/test/cases/validations/association_validation_test.rb +30 -28
- data/test/cases/validations/i18n_generate_message_validation_test.rb +34 -16
- data/test/cases/validations/i18n_validation_test.rb +22 -21
- data/test/cases/validations/length_validation_test.rb +34 -33
- data/test/cases/validations/numericality_validation_test.rb +181 -0
- data/test/cases/validations/presence_validation_test.rb +21 -19
- data/test/cases/validations/uniqueness_validation_test.rb +156 -86
- data/test/cases/validations_repair_helper.rb +2 -0
- data/test/cases/validations_test.rb +61 -26
- data/test/cases/view_test.rb +122 -116
- data/test/cases/yaml_serialization_test.rb +79 -34
- data/test/config.example.yml +19 -19
- data/test/config.rb +3 -1
- data/test/config.yml +16 -6
- data/test/fixtures/all/namespaced/accounts.yml +2 -0
- data/test/fixtures/author_addresses.yml +1 -8
- data/test/fixtures/authors.yml +1 -7
- data/test/fixtures/binaries.yml +4 -0
- data/test/fixtures/books.yml +9 -2
- data/test/fixtures/categories_posts.yml +3 -0
- data/test/fixtures/citations.yml +5 -0
- data/test/fixtures/comments.yml +7 -0
- data/test/fixtures/companies.yml +5 -0
- data/test/fixtures/computers.yml +2 -0
- data/test/fixtures/customers.yml +10 -1
- data/test/fixtures/developers.yml +1 -1
- data/test/fixtures/essays.yml +10 -0
- data/test/fixtures/faces.yml +3 -3
- data/test/fixtures/humans.yml +5 -0
- data/test/fixtures/interests.yml +7 -7
- data/test/fixtures/memberships.yml +7 -0
- data/test/fixtures/minimalistics.yml +3 -0
- data/test/fixtures/mixed_case_monkeys.yml +2 -2
- data/test/fixtures/naked/yml/courses_with_invalid_key.yml +3 -0
- data/test/fixtures/naked/yml/parrots.yml +1 -0
- data/test/fixtures/other_books.yml +26 -0
- data/test/fixtures/other_posts.yml +1 -0
- data/test/fixtures/parrots.yml +7 -1
- data/test/fixtures/pirates.yml +3 -0
- data/test/fixtures/posts.yml +11 -3
- data/test/fixtures/readers.yml +6 -0
- data/test/fixtures/reserved_words/values.yml +2 -2
- data/test/fixtures/sponsors.yml +3 -0
- data/test/fixtures/strict_zines.yml +2 -0
- data/test/fixtures/subscribers.yml +1 -1
- data/test/fixtures/tasks.yml +1 -1
- data/test/fixtures/warehouse-things.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +2 -0
- data/test/migrations/decimal/1_give_me_big_numbers.rb +6 -4
- data/test/migrations/magic/1_currencies_have_symbols.rb +3 -2
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -0
- data/test/migrations/missing/1_people_have_last_names.rb +2 -0
- data/test/migrations/missing/3_we_need_reminders.rb +2 -0
- data/test/migrations/missing/4_innocent_jointable.rb +3 -1
- data/test/migrations/rename/1_we_need_things.rb +2 -0
- data/test/migrations/rename/2_rename_things.rb +2 -0
- data/test/migrations/to_copy/1_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +3 -1
- data/test/migrations/to_copy2/1_create_articles.rb +2 -0
- data/test/migrations/to_copy2/2_create_comments.rb +3 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +3 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +2 -0
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +2 -0
- data/test/migrations/valid/1_valid_people_have_last_names.rb +2 -0
- data/test/migrations/valid/2_we_need_reminders.rb +2 -0
- data/test/migrations/valid/3_innocent_jointable.rb +3 -1
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +2 -0
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -0
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +3 -1
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +2 -0
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +2 -0
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +3 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +2 -0
- data/test/models/account.rb +46 -0
- data/test/models/admin/account.rb +3 -1
- data/test/models/admin/randomly_named_c1.rb +2 -0
- data/test/models/admin/user.rb +16 -8
- data/test/models/admin.rb +4 -2
- data/test/models/aircraft.rb +3 -1
- data/test/models/arunit2_model.rb +2 -0
- data/test/models/author.rb +153 -102
- data/test/models/auto_id.rb +2 -0
- data/test/models/autoloadable/extra_firm.rb +2 -0
- data/test/models/binary.rb +3 -1
- data/test/models/binary_field.rb +6 -0
- data/test/models/bird.rb +13 -1
- data/test/models/book.rb +14 -4
- data/test/models/book_destroy_async.rb +24 -0
- data/test/models/boolean.rb +5 -0
- data/test/models/bulb.rb +13 -4
- data/test/models/cake_designer.rb +2 -0
- data/test/models/car.rb +17 -10
- data/test/models/carrier.rb +2 -0
- data/test/models/cart.rb +5 -0
- data/test/models/cat.rb +2 -0
- data/test/models/categorization.rb +8 -6
- data/test/models/category.rb +28 -16
- data/test/models/chef.rb +2 -0
- data/test/models/citation.rb +5 -1
- data/test/models/club.rb +13 -10
- data/test/models/college.rb +4 -2
- data/test/models/column.rb +2 -0
- data/test/models/column_name.rb +2 -0
- data/test/models/comment.rb +32 -10
- data/test/models/company.rb +102 -106
- data/test/models/company_in_module.rb +27 -26
- data/test/models/computer.rb +3 -1
- data/test/models/contact.rb +15 -13
- data/test/models/content.rb +5 -3
- data/test/models/contract.rb +21 -3
- data/test/models/country.rb +2 -4
- data/test/models/course.rb +3 -1
- data/test/models/customer.rb +10 -8
- data/test/models/customer_carrier.rb +2 -0
- data/test/models/dashboard.rb +2 -0
- data/test/models/default.rb +2 -0
- data/test/models/department.rb +2 -0
- data/test/models/destroy_async_parent.rb +15 -0
- data/test/models/destroy_async_parent_soft_delete.rb +20 -0
- data/test/models/developer.rb +152 -85
- data/test/models/dl_keyed_belongs_to.rb +13 -0
- data/test/models/dl_keyed_belongs_to_soft_delete.rb +19 -0
- data/test/models/dl_keyed_has_many.rb +5 -0
- data/test/models/dl_keyed_has_many_through.rb +5 -0
- data/test/models/dl_keyed_has_one.rb +5 -0
- data/test/models/dl_keyed_join.rb +10 -0
- data/test/models/dog.rb +2 -0
- data/test/models/dog_lover.rb +2 -0
- data/test/models/doubloon.rb +3 -1
- data/test/models/drink_designer.rb +17 -0
- data/test/models/edge.rb +4 -2
- data/test/models/electron.rb +2 -0
- data/test/models/engine.rb +3 -2
- data/test/models/entrant.rb +2 -0
- data/test/models/entry.rb +5 -0
- data/test/models/essay.rb +6 -3
- data/test/models/essay_destroy_async.rb +12 -0
- data/test/models/event.rb +3 -1
- data/test/models/eye.rb +5 -3
- data/test/models/face.rb +14 -6
- data/test/models/family.rb +6 -0
- data/test/models/family_tree.rb +6 -0
- data/test/models/friendship.rb +5 -3
- data/test/models/frog.rb +8 -0
- data/test/models/guid.rb +3 -1
- data/test/models/guitar.rb +2 -0
- data/test/models/hotel.rb +5 -3
- data/test/models/human.rb +39 -0
- data/test/models/image.rb +3 -1
- data/test/models/interest.rb +14 -3
- data/test/models/invoice.rb +4 -2
- data/test/models/item.rb +3 -1
- data/test/models/job.rb +5 -3
- data/test/models/joke.rb +4 -2
- data/test/models/keyboard.rb +3 -1
- data/test/models/legacy_thing.rb +2 -0
- data/test/models/lesson.rb +2 -0
- data/test/models/line_item.rb +3 -1
- data/test/models/liquid.rb +2 -0
- data/test/models/matey.rb +3 -1
- data/test/models/measurement.rb +4 -0
- data/test/models/member.rb +23 -20
- data/test/models/member_detail.rb +3 -0
- data/test/models/member_type.rb +2 -0
- data/test/models/membership.rb +4 -1
- data/test/models/mentor.rb +3 -1
- data/test/models/message.rb +5 -0
- data/test/models/minimalistic.rb +2 -0
- data/test/models/minivan.rb +3 -2
- data/test/models/mixed_case_monkey.rb +3 -1
- data/test/models/molecule.rb +2 -0
- data/test/models/mouse.rb +6 -0
- data/test/models/movie.rb +2 -0
- data/test/models/node.rb +4 -2
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +2 -0
- data/test/models/numeric_data.rb +12 -0
- data/test/models/order.rb +4 -2
- data/test/models/organization.rb +9 -7
- data/test/models/other_dog.rb +3 -1
- data/test/models/owner.rb +6 -4
- data/test/models/parrot.rb +12 -4
- data/test/models/person.rb +59 -54
- data/test/models/personal_legacy_thing.rb +3 -1
- data/test/models/pet.rb +4 -2
- data/test/models/pet_treasure.rb +2 -0
- data/test/models/pirate.rb +67 -43
- data/test/models/possession.rb +3 -1
- data/test/models/post.rb +184 -86
- data/test/models/price_estimate.rb +11 -1
- data/test/models/professor.rb +3 -1
- data/test/models/project.rb +14 -12
- data/test/models/publisher/article.rb +2 -0
- data/test/models/publisher/magazine.rb +2 -0
- data/test/models/publisher.rb +2 -0
- data/test/models/randomly_named_c1.rb +2 -0
- data/test/models/rating.rb +5 -1
- data/test/models/reader.rb +7 -5
- data/test/models/recipe.rb +2 -0
- data/test/models/record.rb +2 -0
- data/test/models/reference.rb +6 -3
- data/test/models/reply.rb +39 -21
- data/test/models/room.rb +6 -0
- data/test/models/section.rb +6 -0
- data/test/models/seminar.rb +6 -0
- data/test/models/session.rb +6 -0
- data/test/models/ship.rb +12 -9
- data/test/models/ship_part.rb +5 -3
- data/test/models/shop.rb +4 -2
- data/test/models/shop_account.rb +2 -0
- data/test/models/speedometer.rb +2 -0
- data/test/models/sponsor.rb +8 -5
- data/test/models/squeak.rb +6 -0
- data/test/models/strict_zine.rb +7 -0
- data/test/models/string_key_object.rb +2 -0
- data/test/models/student.rb +2 -0
- data/test/models/subscriber.rb +4 -2
- data/test/models/subscription.rb +5 -1
- data/test/models/tag.rb +6 -3
- data/test/models/tagging.rb +13 -6
- data/test/models/task.rb +2 -0
- data/test/models/topic.rb +54 -19
- data/test/models/toy.rb +4 -0
- data/test/models/traffic_light.rb +2 -0
- data/test/models/treasure.rb +5 -3
- data/test/models/treaty.rb +2 -4
- data/test/models/tree.rb +2 -0
- data/test/models/tuning_peg.rb +2 -0
- data/test/models/tyre.rb +2 -0
- data/test/models/user.rb +12 -4
- data/test/models/uuid_child.rb +2 -0
- data/test/models/uuid_item.rb +2 -0
- data/test/models/uuid_parent.rb +2 -0
- data/test/models/vegetables.rb +12 -3
- data/test/models/vertex.rb +6 -4
- data/test/models/warehouse_thing.rb +2 -0
- data/test/models/wheel.rb +3 -1
- data/test/models/without_table.rb +3 -1
- data/test/models/zine.rb +3 -1
- data/test/schema/mysql2_specific_schema.rb +49 -35
- data/test/schema/oracle_specific_schema.rb +13 -15
- data/test/schema/postgresql_specific_schema.rb +51 -40
- data/test/schema/schema.rb +334 -154
- data/test/schema/sqlite_specific_schema.rb +9 -16
- data/test/support/config.rb +26 -26
- data/test/support/connection.rb +14 -8
- data/test/support/connection_helper.rb +3 -1
- data/test/support/ddl_helper.rb +2 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/legacy_relation.dump +0 -0
- data/test/support/schema_dumping_helper.rb +2 -0
- data/test/support/stubs/strong_parameters.rb +40 -0
- data/test/support/yaml_compatibility_fixtures/rails_v1_mysql.yml +206 -0
- data/test/support/yaml_compatibility_fixtures/rails_v2.yml +55 -0
- metadata +192 -14
@@ -1,13 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cases/helper"
|
4
|
+
require "active_record/tasks/database_tasks"
|
5
|
+
require "models/author"
|
3
6
|
|
4
7
|
module ActiveRecord
|
5
8
|
module DatabaseTasksSetupper
|
6
9
|
def setup
|
7
|
-
@mysql_tasks, @postgresql_tasks, @sqlite_tasks =
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
@mysql_tasks, @postgresql_tasks, @sqlite_tasks = Array.new(
|
11
|
+
3,
|
12
|
+
Class.new do
|
13
|
+
def create; end
|
14
|
+
def drop; end
|
15
|
+
def purge; end
|
16
|
+
def charset; end
|
17
|
+
def charset_current; end
|
18
|
+
def collation; end
|
19
|
+
def collation_current; end
|
20
|
+
def structure_dump(*); end
|
21
|
+
def structure_load(*); end
|
22
|
+
end.new
|
23
|
+
)
|
11
24
|
|
12
25
|
$stdout, @original_stdout = StringIO.new, $stdout
|
13
26
|
$stderr, @original_stderr = StringIO.new, $stderr
|
@@ -16,6 +29,16 @@ module ActiveRecord
|
|
16
29
|
def teardown
|
17
30
|
$stdout, $stderr = @original_stdout, @original_stderr
|
18
31
|
end
|
32
|
+
|
33
|
+
def with_stubbed_new
|
34
|
+
ActiveRecord::Tasks::MySQLDatabaseTasks.stub(:new, @mysql_tasks) do
|
35
|
+
ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stub(:new, @postgresql_tasks) do
|
36
|
+
ActiveRecord::Tasks::SQLiteDatabaseTasks.stub(:new, @sqlite_tasks) do
|
37
|
+
yield
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
19
42
|
end
|
20
43
|
|
21
44
|
ADAPTERS_TASKS = {
|
@@ -24,32 +47,126 @@ module ActiveRecord
|
|
24
47
|
sqlite3: :sqlite_tasks
|
25
48
|
}
|
26
49
|
|
27
|
-
class DatabaseTasksUtilsTask< ActiveRecord::TestCase
|
50
|
+
class DatabaseTasksUtilsTask < ActiveRecord::TestCase
|
28
51
|
def test_raises_an_error_when_called_with_protected_environment
|
29
|
-
ActiveRecord::
|
52
|
+
protected_environments = ActiveRecord::Base.protected_environments
|
53
|
+
current_env = ActiveRecord::Base.connection.migration_context.current_environment
|
54
|
+
|
55
|
+
InternalMetadata[:environment] = current_env
|
56
|
+
|
57
|
+
assert_called_on_instance_of(
|
58
|
+
ActiveRecord::MigrationContext,
|
59
|
+
:current_version,
|
60
|
+
times: 6,
|
61
|
+
returns: 1
|
62
|
+
) do
|
63
|
+
assert_not_includes protected_environments, current_env
|
64
|
+
# Assert no error
|
65
|
+
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
|
66
|
+
|
67
|
+
ActiveRecord::Base.protected_environments = [current_env]
|
68
|
+
|
69
|
+
assert_raise(ActiveRecord::ProtectedEnvironmentError) do
|
70
|
+
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
|
71
|
+
end
|
72
|
+
end
|
73
|
+
ensure
|
74
|
+
ActiveRecord::Base.protected_environments = protected_environments
|
75
|
+
end
|
30
76
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# Assert no error
|
35
|
-
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
|
77
|
+
def test_raises_an_error_when_called_with_protected_environment_which_name_is_a_symbol
|
78
|
+
protected_environments = ActiveRecord::Base.protected_environments
|
79
|
+
current_env = ActiveRecord::Base.connection.migration_context.current_environment
|
36
80
|
|
37
|
-
|
38
|
-
|
81
|
+
InternalMetadata[:environment] = current_env
|
82
|
+
|
83
|
+
assert_called_on_instance_of(
|
84
|
+
ActiveRecord::MigrationContext,
|
85
|
+
:current_version,
|
86
|
+
times: 6,
|
87
|
+
returns: 1
|
88
|
+
) do
|
89
|
+
assert_not_includes protected_environments, current_env
|
90
|
+
# Assert no error
|
39
91
|
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
|
92
|
+
|
93
|
+
ActiveRecord::Base.protected_environments = [current_env.to_sym]
|
94
|
+
assert_raise(ActiveRecord::ProtectedEnvironmentError) do
|
95
|
+
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
|
96
|
+
end
|
40
97
|
end
|
41
98
|
ensure
|
42
99
|
ActiveRecord::Base.protected_environments = protected_environments
|
43
100
|
end
|
44
101
|
|
45
102
|
def test_raises_an_error_if_no_migrations_have_been_made
|
46
|
-
ActiveRecord::InternalMetadata.
|
47
|
-
|
103
|
+
ActiveRecord::InternalMetadata.stub(:table_exists?, false) do
|
104
|
+
assert_called_on_instance_of(
|
105
|
+
ActiveRecord::MigrationContext,
|
106
|
+
:current_version,
|
107
|
+
returns: 1
|
108
|
+
) do
|
109
|
+
assert_raise(ActiveRecord::NoEnvironmentInSchemaError) do
|
110
|
+
ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
48
116
|
|
49
|
-
|
50
|
-
|
117
|
+
class DatabaseTasksCurrentConfigTask < ActiveRecord::TestCase
|
118
|
+
def test_current_config_set
|
119
|
+
hash = {}
|
120
|
+
|
121
|
+
with_stubbed_configurations do
|
122
|
+
ActiveRecord::Tasks::DatabaseTasks.current_config(config: hash, env: "production")
|
123
|
+
|
124
|
+
assert_equal hash, ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_current_config_read_none_found
|
129
|
+
with_stubbed_configurations do
|
130
|
+
config = ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production", spec: "empty")
|
131
|
+
|
132
|
+
assert_nil config
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_current_config_read_found
|
137
|
+
with_stubbed_configurations do
|
138
|
+
config = ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production", spec: "exists")
|
139
|
+
|
140
|
+
assert_equal({ database: "my-db" }, config)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_current_config_read_after_set
|
145
|
+
hash = {}
|
146
|
+
|
147
|
+
with_stubbed_configurations do
|
148
|
+
ActiveRecord::Tasks::DatabaseTasks.current_config(config: hash, env: "production")
|
149
|
+
|
150
|
+
config = ActiveRecord::Tasks::DatabaseTasks.current_config(env: "production", spec: "exists")
|
151
|
+
|
152
|
+
assert_equal hash, config
|
51
153
|
end
|
52
154
|
end
|
155
|
+
|
156
|
+
private
|
157
|
+
def with_stubbed_configurations
|
158
|
+
old_configurations = ActiveRecord::Base.configurations
|
159
|
+
ActiveRecord::Base.configurations = { "production" => { "exists" => { "database" => "my-db" } } }
|
160
|
+
|
161
|
+
assert_deprecated do
|
162
|
+
yield
|
163
|
+
end
|
164
|
+
ensure
|
165
|
+
ActiveRecord::Base.configurations = old_configurations
|
166
|
+
assert_deprecated do
|
167
|
+
ActiveRecord::Tasks::DatabaseTasks.current_config = nil
|
168
|
+
end
|
169
|
+
end
|
53
170
|
end
|
54
171
|
|
55
172
|
class DatabaseTasksRegisterTask < ActiveRecord::TestCase
|
@@ -60,16 +177,17 @@ module ActiveRecord
|
|
60
177
|
end
|
61
178
|
instance = klazz.new
|
62
179
|
|
63
|
-
klazz.
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
180
|
+
klazz.stub(:new, instance) do
|
181
|
+
assert_called_with(instance, :structure_dump, ["awesome-file.sql", nil]) do
|
182
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(/foo/, klazz)
|
183
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump({ "adapter" => :foo }, "awesome-file.sql")
|
184
|
+
end
|
185
|
+
end
|
68
186
|
end
|
69
187
|
|
70
188
|
def test_unregistered_task
|
71
189
|
assert_raise(ActiveRecord::Tasks::DatabaseNotSupported) do
|
72
|
-
ActiveRecord::Tasks::DatabaseTasks.structure_dump({
|
190
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump({ "adapter" => :bar }, "awesome-file.sql")
|
73
191
|
end
|
74
192
|
end
|
75
193
|
end
|
@@ -79,125 +197,441 @@ module ActiveRecord
|
|
79
197
|
|
80
198
|
ADAPTERS_TASKS.each do |k, v|
|
81
199
|
define_method("test_#{k}_create") do
|
82
|
-
|
83
|
-
|
200
|
+
with_stubbed_new do
|
201
|
+
assert_called(eval("@#{v}"), :create) do
|
202
|
+
ActiveRecord::Tasks::DatabaseTasks.create "adapter" => k
|
203
|
+
end
|
204
|
+
end
|
84
205
|
end
|
85
206
|
end
|
86
207
|
end
|
87
208
|
|
209
|
+
class DatabaseTasksDumpSchemaCacheTest < ActiveRecord::TestCase
|
210
|
+
def test_dump_schema_cache
|
211
|
+
Dir.mktmpdir do |dir|
|
212
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, dir) do
|
213
|
+
path = File.join(dir, "schema_cache.yml")
|
214
|
+
assert_not File.file?(path)
|
215
|
+
ActiveRecord::Tasks::DatabaseTasks.dump_schema_cache(ActiveRecord::Base.connection, path)
|
216
|
+
assert File.file?(path)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
ensure
|
220
|
+
ActiveRecord::Base.clear_cache!
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_clear_schema_cache
|
224
|
+
Dir.mktmpdir do |dir|
|
225
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, dir) do
|
226
|
+
path = File.join(dir, "schema_cache.yml")
|
227
|
+
File.open(path, "wb") do |f|
|
228
|
+
f.puts "This is a cache."
|
229
|
+
end
|
230
|
+
assert File.file?(path)
|
231
|
+
ActiveRecord::Tasks::DatabaseTasks.clear_schema_cache(path)
|
232
|
+
assert_not File.file?(path)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_cache_dump_default_filename
|
238
|
+
old_path = ENV["SCHEMA_CACHE"]
|
239
|
+
ENV.delete("SCHEMA_CACHE")
|
240
|
+
|
241
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "db") do
|
242
|
+
path = ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename("primary")
|
243
|
+
assert_equal "db/schema_cache.yml", path
|
244
|
+
end
|
245
|
+
ensure
|
246
|
+
ENV["SCHEMA_CACHE"] = old_path
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_cache_dump_alternate_filename
|
250
|
+
old_path = ENV["SCHEMA_CACHE"]
|
251
|
+
ENV.delete("SCHEMA_CACHE")
|
252
|
+
|
253
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "db") do
|
254
|
+
path = ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename("alternate")
|
255
|
+
assert_equal "db/alternate_schema_cache.yml", path
|
256
|
+
end
|
257
|
+
ensure
|
258
|
+
ENV["SCHEMA_CACHE"] = old_path
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_cache_dump_filename_with_env_override
|
262
|
+
old_path = ENV["SCHEMA_CACHE"]
|
263
|
+
ENV["SCHEMA_CACHE"] = "tmp/something.yml"
|
264
|
+
|
265
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "db") do
|
266
|
+
path = ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename("primary")
|
267
|
+
assert_equal "tmp/something.yml", path
|
268
|
+
end
|
269
|
+
ensure
|
270
|
+
ENV["SCHEMA_CACHE"] = old_path
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_cache_dump_filename_with_path_from_db_config
|
274
|
+
old_path = ENV["SCHEMA_CACHE"]
|
275
|
+
ENV.delete("SCHEMA_CACHE")
|
276
|
+
|
277
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "db") do
|
278
|
+
path = ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename("primary", schema_cache_path: "tmp/something.yml")
|
279
|
+
assert_equal "tmp/something.yml", path
|
280
|
+
end
|
281
|
+
ensure
|
282
|
+
ENV["SCHEMA_CACHE"] = old_path
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
class DatabaseTasksDumpSchemaTest < ActiveRecord::TestCase
|
287
|
+
def test_ensure_db_dir
|
288
|
+
Dir.mktmpdir do |dir|
|
289
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, dir) do
|
290
|
+
db_config = OpenStruct.new(name: "fake_db_config")
|
291
|
+
path = "#{dir}/fake_db_config_schema.rb"
|
292
|
+
|
293
|
+
FileUtils.rm_rf(dir)
|
294
|
+
assert_not File.file?(path)
|
295
|
+
|
296
|
+
ActiveRecord::Tasks::DatabaseTasks.dump_schema(db_config)
|
297
|
+
|
298
|
+
assert File.file?(path)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
ensure
|
302
|
+
ActiveRecord::Base.clear_cache!
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
88
306
|
class DatabaseTasksCreateAllTest < ActiveRecord::TestCase
|
89
307
|
def setup
|
90
|
-
@configurations = {
|
308
|
+
@configurations = { "development" => { "database" => "my-db" } }
|
91
309
|
|
92
|
-
|
310
|
+
$stdout, @original_stdout = StringIO.new, $stdout
|
311
|
+
$stderr, @original_stderr = StringIO.new, $stderr
|
93
312
|
end
|
94
313
|
|
95
|
-
def
|
96
|
-
@
|
314
|
+
def teardown
|
315
|
+
$stdout, $stderr = @original_stdout, @original_stderr
|
316
|
+
end
|
97
317
|
|
98
|
-
|
318
|
+
def test_ignores_configurations_without_databases
|
319
|
+
@configurations["development"]["database"] = nil
|
99
320
|
|
100
|
-
|
321
|
+
with_stubbed_configurations_establish_connection do
|
322
|
+
assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :create) do
|
323
|
+
ActiveRecord::Tasks::DatabaseTasks.create_all
|
324
|
+
end
|
325
|
+
end
|
101
326
|
end
|
102
327
|
|
103
328
|
def test_ignores_remote_databases
|
104
|
-
@configurations[
|
105
|
-
$stderr.stubs(:puts).returns(nil)
|
106
|
-
|
107
|
-
ActiveRecord::Tasks::DatabaseTasks.expects(:create).never
|
329
|
+
@configurations["development"]["host"] = "my.server.tld"
|
108
330
|
|
109
|
-
|
331
|
+
with_stubbed_configurations_establish_connection do
|
332
|
+
assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :create) do
|
333
|
+
ActiveRecord::Tasks::DatabaseTasks.create_all
|
334
|
+
end
|
335
|
+
end
|
110
336
|
end
|
111
337
|
|
112
338
|
def test_warning_for_remote_databases
|
113
|
-
@configurations[
|
339
|
+
@configurations["development"]["host"] = "my.server.tld"
|
114
340
|
|
115
|
-
|
341
|
+
with_stubbed_configurations_establish_connection do
|
342
|
+
ActiveRecord::Tasks::DatabaseTasks.create_all
|
116
343
|
|
117
|
-
|
344
|
+
assert_match "This task only modifies local databases. my-db is on a remote host.",
|
345
|
+
$stderr.string
|
346
|
+
end
|
118
347
|
end
|
119
348
|
|
120
349
|
def test_creates_configurations_with_local_ip
|
121
|
-
@configurations[
|
122
|
-
|
123
|
-
ActiveRecord::Tasks::DatabaseTasks.expects(:create)
|
350
|
+
@configurations["development"]["host"] = "127.0.0.1"
|
124
351
|
|
125
|
-
|
352
|
+
with_stubbed_configurations_establish_connection do
|
353
|
+
assert_called(ActiveRecord::Tasks::DatabaseTasks, :create) do
|
354
|
+
ActiveRecord::Tasks::DatabaseTasks.create_all
|
355
|
+
end
|
356
|
+
end
|
126
357
|
end
|
127
358
|
|
128
359
|
def test_creates_configurations_with_local_host
|
129
|
-
@configurations[
|
130
|
-
|
131
|
-
ActiveRecord::Tasks::DatabaseTasks.expects(:create)
|
360
|
+
@configurations["development"]["host"] = "localhost"
|
132
361
|
|
133
|
-
|
362
|
+
with_stubbed_configurations_establish_connection do
|
363
|
+
assert_called(ActiveRecord::Tasks::DatabaseTasks, :create) do
|
364
|
+
ActiveRecord::Tasks::DatabaseTasks.create_all
|
365
|
+
end
|
366
|
+
end
|
134
367
|
end
|
135
368
|
|
136
369
|
def test_creates_configurations_with_blank_hosts
|
137
|
-
@configurations[
|
370
|
+
@configurations["development"]["host"] = nil
|
138
371
|
|
139
|
-
|
140
|
-
|
141
|
-
|
372
|
+
with_stubbed_configurations_establish_connection do
|
373
|
+
assert_called(ActiveRecord::Tasks::DatabaseTasks, :create) do
|
374
|
+
ActiveRecord::Tasks::DatabaseTasks.create_all
|
375
|
+
end
|
376
|
+
end
|
142
377
|
end
|
378
|
+
|
379
|
+
private
|
380
|
+
def with_stubbed_configurations_establish_connection
|
381
|
+
old_configurations = ActiveRecord::Base.configurations
|
382
|
+
ActiveRecord::Base.configurations = @configurations
|
383
|
+
|
384
|
+
# To refrain from connecting to a newly created empty DB in
|
385
|
+
# sqlite3_mem tests
|
386
|
+
ActiveRecord::Base.connection_handler.stub(:establish_connection, nil) do
|
387
|
+
yield
|
388
|
+
end
|
389
|
+
ensure
|
390
|
+
ActiveRecord::Base.configurations = old_configurations
|
391
|
+
end
|
143
392
|
end
|
144
393
|
|
145
394
|
class DatabaseTasksCreateCurrentTest < ActiveRecord::TestCase
|
146
395
|
def setup
|
147
396
|
@configurations = {
|
148
|
-
|
149
|
-
|
150
|
-
|
397
|
+
"development" => { "database" => "dev-db" },
|
398
|
+
"test" => { "database" => "test-db" },
|
399
|
+
"production" => { "url" => "abstract://prod-db-host/prod-db" }
|
151
400
|
}
|
152
|
-
|
153
|
-
ActiveRecord::Base.stubs(:configurations).returns(@configurations)
|
154
|
-
ActiveRecord::Base.stubs(:establish_connection).returns(true)
|
155
401
|
end
|
156
402
|
|
157
403
|
def test_creates_current_environment_database
|
158
|
-
|
159
|
-
|
404
|
+
with_stubbed_configurations_establish_connection do
|
405
|
+
assert_called_with(
|
406
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
407
|
+
:create,
|
408
|
+
[config_for("test", "primary")]
|
409
|
+
) do
|
410
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
411
|
+
ActiveSupport::StringInquirer.new("test")
|
412
|
+
)
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
160
416
|
|
161
|
-
|
162
|
-
|
163
|
-
|
417
|
+
def test_creates_current_environment_database_with_url
|
418
|
+
with_stubbed_configurations_establish_connection do
|
419
|
+
assert_called_with(
|
420
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
421
|
+
:create,
|
422
|
+
[config_for("production", "primary")]
|
423
|
+
) do
|
424
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
425
|
+
ActiveSupport::StringInquirer.new("production")
|
426
|
+
)
|
427
|
+
end
|
428
|
+
end
|
164
429
|
end
|
165
430
|
|
166
431
|
def test_creates_test_and_development_databases_when_env_was_not_specified
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
432
|
+
with_stubbed_configurations_establish_connection do
|
433
|
+
assert_called_with(
|
434
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
435
|
+
:create,
|
436
|
+
[
|
437
|
+
[config_for("development", "primary")],
|
438
|
+
[config_for("test", "primary")]
|
439
|
+
],
|
440
|
+
) do
|
441
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
442
|
+
ActiveSupport::StringInquirer.new("development")
|
443
|
+
)
|
444
|
+
end
|
445
|
+
end
|
175
446
|
end
|
176
447
|
|
177
448
|
def test_creates_test_and_development_databases_when_rails_env_is_development
|
178
|
-
old_env = ENV[
|
179
|
-
ENV[
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
449
|
+
old_env = ENV["RAILS_ENV"]
|
450
|
+
ENV["RAILS_ENV"] = "development"
|
451
|
+
|
452
|
+
with_stubbed_configurations_establish_connection do
|
453
|
+
assert_called_with(
|
454
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
455
|
+
:create,
|
456
|
+
[
|
457
|
+
[config_for("development", "primary")],
|
458
|
+
[config_for("test", "primary")]
|
459
|
+
],
|
460
|
+
) do
|
461
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
462
|
+
ActiveSupport::StringInquirer.new("development")
|
463
|
+
)
|
464
|
+
end
|
465
|
+
end
|
188
466
|
ensure
|
189
|
-
ENV[
|
467
|
+
ENV["RAILS_ENV"] = old_env
|
190
468
|
end
|
191
469
|
|
192
|
-
def
|
193
|
-
|
470
|
+
def test_creates_development_database_without_test_database_when_skip_test_database
|
471
|
+
old_env = ENV["RAILS_ENV"]
|
472
|
+
ENV["RAILS_ENV"] = "development"
|
473
|
+
ENV["SKIP_TEST_DATABASE"] = "true"
|
474
|
+
|
475
|
+
with_stubbed_configurations_establish_connection do
|
476
|
+
assert_called_with(
|
477
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
478
|
+
:create,
|
479
|
+
[
|
480
|
+
[config_for("development", "primary")]
|
481
|
+
],
|
482
|
+
) do
|
483
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
484
|
+
ActiveSupport::StringInquirer.new("development")
|
485
|
+
)
|
486
|
+
end
|
487
|
+
end
|
488
|
+
ensure
|
489
|
+
ENV["RAILS_ENV"] = old_env
|
490
|
+
ENV.delete("SKIP_TEST_DATABASE")
|
491
|
+
end
|
194
492
|
|
195
|
-
|
493
|
+
def test_establishes_connection_for_the_given_environments
|
494
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:create, nil) do
|
495
|
+
assert_called_with(ActiveRecord::Base, :establish_connection, [:development]) do
|
496
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
497
|
+
ActiveSupport::StringInquirer.new("development")
|
498
|
+
)
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
196
502
|
|
197
|
-
|
198
|
-
|
199
|
-
|
503
|
+
private
|
504
|
+
def config_for(env_name, name)
|
505
|
+
ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: name)
|
506
|
+
end
|
507
|
+
|
508
|
+
def with_stubbed_configurations_establish_connection
|
509
|
+
old_configurations = ActiveRecord::Base.configurations
|
510
|
+
ActiveRecord::Base.configurations = @configurations
|
511
|
+
|
512
|
+
ActiveRecord::Base.connection_handler.stub(:establish_connection, nil) do
|
513
|
+
yield
|
514
|
+
end
|
515
|
+
ensure
|
516
|
+
ActiveRecord::Base.configurations = old_configurations
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
class DatabaseTasksCreateCurrentThreeTierTest < ActiveRecord::TestCase
|
521
|
+
def setup
|
522
|
+
@configurations = {
|
523
|
+
"development" => { "primary" => { "database" => "dev-db" }, "secondary" => { "database" => "secondary-dev-db" } },
|
524
|
+
"test" => { "primary" => { "database" => "test-db" }, "secondary" => { "database" => "secondary-test-db" } },
|
525
|
+
"production" => { "primary" => { "url" => "abstract://prod-db-host/prod-db" }, "secondary" => { "url" => "abstract://secondary-prod-db-host/secondary-prod-db" } }
|
526
|
+
}
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_creates_current_environment_database
|
530
|
+
with_stubbed_configurations_establish_connection do
|
531
|
+
assert_called_with(
|
532
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
533
|
+
:create,
|
534
|
+
[
|
535
|
+
[config_for("test", "primary")],
|
536
|
+
[config_for("test", "secondary")]
|
537
|
+
]
|
538
|
+
) do
|
539
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
540
|
+
ActiveSupport::StringInquirer.new("test")
|
541
|
+
)
|
542
|
+
end
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
def test_creates_current_environment_database_with_url
|
547
|
+
with_stubbed_configurations_establish_connection do
|
548
|
+
assert_called_with(
|
549
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
550
|
+
:create,
|
551
|
+
[
|
552
|
+
[config_for("production", "primary")],
|
553
|
+
[config_for("production", "secondary")]
|
554
|
+
]
|
555
|
+
) do
|
556
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
557
|
+
ActiveSupport::StringInquirer.new("production")
|
558
|
+
)
|
559
|
+
end
|
560
|
+
end
|
561
|
+
end
|
562
|
+
|
563
|
+
def test_creates_test_and_development_databases_when_env_was_not_specified
|
564
|
+
with_stubbed_configurations_establish_connection do
|
565
|
+
assert_called_with(
|
566
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
567
|
+
:create,
|
568
|
+
[
|
569
|
+
[config_for("development", "primary")],
|
570
|
+
[config_for("development", "secondary")],
|
571
|
+
[config_for("test", "primary")],
|
572
|
+
[config_for("test", "secondary")]
|
573
|
+
]
|
574
|
+
) do
|
575
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
576
|
+
ActiveSupport::StringInquirer.new("development")
|
577
|
+
)
|
578
|
+
end
|
579
|
+
end
|
580
|
+
end
|
581
|
+
|
582
|
+
def test_creates_test_and_development_databases_when_rails_env_is_development
|
583
|
+
old_env = ENV["RAILS_ENV"]
|
584
|
+
ENV["RAILS_ENV"] = "development"
|
585
|
+
|
586
|
+
with_stubbed_configurations_establish_connection do
|
587
|
+
assert_called_with(
|
588
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
589
|
+
:create,
|
590
|
+
[
|
591
|
+
[config_for("development", "primary")],
|
592
|
+
[config_for("development", "secondary")],
|
593
|
+
[config_for("test", "primary")],
|
594
|
+
[config_for("test", "secondary")]
|
595
|
+
]
|
596
|
+
) do
|
597
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
598
|
+
ActiveSupport::StringInquirer.new("development")
|
599
|
+
)
|
600
|
+
end
|
601
|
+
end
|
602
|
+
ensure
|
603
|
+
ENV["RAILS_ENV"] = old_env
|
604
|
+
end
|
605
|
+
|
606
|
+
def test_establishes_connection_for_the_given_environments_config
|
607
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:create, nil) do
|
608
|
+
assert_called_with(
|
609
|
+
ActiveRecord::Base,
|
610
|
+
:establish_connection,
|
611
|
+
[:development]
|
612
|
+
) do
|
613
|
+
ActiveRecord::Tasks::DatabaseTasks.create_current(
|
614
|
+
ActiveSupport::StringInquirer.new("development")
|
615
|
+
)
|
616
|
+
end
|
617
|
+
end
|
200
618
|
end
|
619
|
+
|
620
|
+
private
|
621
|
+
def config_for(env_name, name)
|
622
|
+
ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: name)
|
623
|
+
end
|
624
|
+
|
625
|
+
def with_stubbed_configurations_establish_connection
|
626
|
+
old_configurations = ActiveRecord::Base.configurations
|
627
|
+
ActiveRecord::Base.configurations = @configurations
|
628
|
+
|
629
|
+
ActiveRecord::Base.connection_handler.stub(:establish_connection, nil) do
|
630
|
+
yield
|
631
|
+
end
|
632
|
+
ensure
|
633
|
+
ActiveRecord::Base.configurations = old_configurations
|
634
|
+
end
|
201
635
|
end
|
202
636
|
|
203
637
|
class DatabaseTasksDropTest < ActiveRecord::TestCase
|
@@ -205,151 +639,427 @@ module ActiveRecord
|
|
205
639
|
|
206
640
|
ADAPTERS_TASKS.each do |k, v|
|
207
641
|
define_method("test_#{k}_drop") do
|
208
|
-
|
209
|
-
|
642
|
+
with_stubbed_new do
|
643
|
+
assert_called(eval("@#{v}"), :drop) do
|
644
|
+
ActiveRecord::Tasks::DatabaseTasks.drop "adapter" => k
|
645
|
+
end
|
646
|
+
end
|
210
647
|
end
|
211
648
|
end
|
212
649
|
end
|
213
650
|
|
214
651
|
class DatabaseTasksDropAllTest < ActiveRecord::TestCase
|
215
652
|
def setup
|
216
|
-
@configurations = {:
|
653
|
+
@configurations = { development: { "database" => "my-db" } }
|
217
654
|
|
218
|
-
|
655
|
+
$stdout, @original_stdout = StringIO.new, $stdout
|
656
|
+
$stderr, @original_stderr = StringIO.new, $stderr
|
219
657
|
end
|
220
658
|
|
221
|
-
def
|
222
|
-
@
|
659
|
+
def teardown
|
660
|
+
$stdout, $stderr = @original_stdout, @original_stderr
|
661
|
+
end
|
223
662
|
|
224
|
-
|
663
|
+
def test_ignores_configurations_without_databases
|
664
|
+
@configurations[:development]["database"] = nil
|
225
665
|
|
226
|
-
|
666
|
+
with_stubbed_configurations do
|
667
|
+
assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do
|
668
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_all
|
669
|
+
end
|
670
|
+
end
|
227
671
|
end
|
228
672
|
|
229
673
|
def test_ignores_remote_databases
|
230
|
-
@configurations[:development]
|
231
|
-
$stderr.stubs(:puts).returns(nil)
|
232
|
-
|
233
|
-
ActiveRecord::Tasks::DatabaseTasks.expects(:drop).never
|
674
|
+
@configurations[:development]["host"] = "my.server.tld"
|
234
675
|
|
235
|
-
|
676
|
+
with_stubbed_configurations do
|
677
|
+
assert_not_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do
|
678
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_all
|
679
|
+
end
|
680
|
+
end
|
236
681
|
end
|
237
682
|
|
238
683
|
def test_warning_for_remote_databases
|
239
|
-
@configurations[:development]
|
684
|
+
@configurations[:development]["host"] = "my.server.tld"
|
240
685
|
|
241
|
-
|
686
|
+
with_stubbed_configurations do
|
687
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_all
|
242
688
|
|
243
|
-
|
689
|
+
assert_match "This task only modifies local databases. my-db is on a remote host.",
|
690
|
+
$stderr.string
|
691
|
+
end
|
244
692
|
end
|
245
693
|
|
246
694
|
def test_drops_configurations_with_local_ip
|
247
|
-
@configurations[:development]
|
248
|
-
|
249
|
-
ActiveRecord::Tasks::DatabaseTasks.expects(:drop)
|
695
|
+
@configurations[:development]["host"] = "127.0.0.1"
|
250
696
|
|
251
|
-
|
697
|
+
with_stubbed_configurations do
|
698
|
+
assert_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do
|
699
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_all
|
700
|
+
end
|
701
|
+
end
|
252
702
|
end
|
253
703
|
|
254
704
|
def test_drops_configurations_with_local_host
|
255
|
-
@configurations[:development]
|
256
|
-
|
257
|
-
ActiveRecord::Tasks::DatabaseTasks.expects(:drop)
|
705
|
+
@configurations[:development]["host"] = "localhost"
|
258
706
|
|
259
|
-
|
707
|
+
with_stubbed_configurations do
|
708
|
+
assert_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do
|
709
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_all
|
710
|
+
end
|
711
|
+
end
|
260
712
|
end
|
261
713
|
|
262
714
|
def test_drops_configurations_with_blank_hosts
|
263
|
-
@configurations[:development]
|
715
|
+
@configurations[:development]["host"] = nil
|
264
716
|
|
265
|
-
|
266
|
-
|
267
|
-
|
717
|
+
with_stubbed_configurations do
|
718
|
+
assert_called(ActiveRecord::Tasks::DatabaseTasks, :drop) do
|
719
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_all
|
720
|
+
end
|
721
|
+
end
|
268
722
|
end
|
723
|
+
|
724
|
+
private
|
725
|
+
def with_stubbed_configurations
|
726
|
+
old_configurations = ActiveRecord::Base.configurations
|
727
|
+
ActiveRecord::Base.configurations = @configurations
|
728
|
+
|
729
|
+
yield
|
730
|
+
ensure
|
731
|
+
ActiveRecord::Base.configurations = old_configurations
|
732
|
+
end
|
269
733
|
end
|
270
734
|
|
271
735
|
class DatabaseTasksDropCurrentTest < ActiveRecord::TestCase
|
272
736
|
def setup
|
273
737
|
@configurations = {
|
274
|
-
|
275
|
-
|
276
|
-
|
738
|
+
"development" => { "database" => "dev-db" },
|
739
|
+
"test" => { "database" => "test-db" },
|
740
|
+
"production" => { "url" => "abstract://prod-db-host/prod-db" }
|
277
741
|
}
|
278
|
-
|
279
|
-
ActiveRecord::Base.stubs(:configurations).returns(@configurations)
|
280
742
|
end
|
281
743
|
|
282
744
|
def test_drops_current_environment_database
|
283
|
-
|
284
|
-
|
745
|
+
with_stubbed_configurations do
|
746
|
+
assert_called_with(
|
747
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
748
|
+
:drop,
|
749
|
+
[config_for("test", "primary")]
|
750
|
+
) do
|
751
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
752
|
+
ActiveSupport::StringInquirer.new("test")
|
753
|
+
)
|
754
|
+
end
|
755
|
+
end
|
756
|
+
end
|
285
757
|
|
286
|
-
|
287
|
-
|
288
|
-
|
758
|
+
def test_drops_current_environment_database_with_url
|
759
|
+
with_stubbed_configurations do
|
760
|
+
assert_called_with(
|
761
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
762
|
+
:drop,
|
763
|
+
[config_for("production", "primary")]
|
764
|
+
) do
|
765
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
766
|
+
ActiveSupport::StringInquirer.new("production")
|
767
|
+
)
|
768
|
+
end
|
769
|
+
end
|
289
770
|
end
|
290
771
|
|
291
772
|
def test_drops_test_and_development_databases_when_env_was_not_specified
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
773
|
+
with_stubbed_configurations do
|
774
|
+
assert_called_with(
|
775
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
776
|
+
:drop,
|
777
|
+
[
|
778
|
+
[config_for("development", "primary")],
|
779
|
+
[config_for("test", "primary")]
|
780
|
+
]
|
781
|
+
) do
|
782
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
783
|
+
ActiveSupport::StringInquirer.new("development")
|
784
|
+
)
|
785
|
+
end
|
786
|
+
end
|
300
787
|
end
|
301
788
|
|
302
789
|
def test_drops_testand_development_databases_when_rails_env_is_development
|
303
|
-
old_env = ENV[
|
304
|
-
ENV[
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
790
|
+
old_env = ENV["RAILS_ENV"]
|
791
|
+
ENV["RAILS_ENV"] = "development"
|
792
|
+
|
793
|
+
with_stubbed_configurations do
|
794
|
+
assert_called_with(
|
795
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
796
|
+
:drop,
|
797
|
+
[
|
798
|
+
[config_for("development", "primary")],
|
799
|
+
[config_for("test", "primary")]
|
800
|
+
]
|
801
|
+
) do
|
802
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
803
|
+
ActiveSupport::StringInquirer.new("development")
|
804
|
+
)
|
805
|
+
end
|
806
|
+
end
|
313
807
|
ensure
|
314
|
-
ENV[
|
808
|
+
ENV["RAILS_ENV"] = old_env
|
315
809
|
end
|
316
|
-
end
|
317
810
|
|
318
|
-
|
319
|
-
|
811
|
+
private
|
812
|
+
def config_for(env_name, name)
|
813
|
+
ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: name)
|
814
|
+
end
|
815
|
+
|
816
|
+
def with_stubbed_configurations
|
817
|
+
old_configurations = ActiveRecord::Base.configurations
|
818
|
+
ActiveRecord::Base.configurations = @configurations
|
320
819
|
|
820
|
+
yield
|
821
|
+
ensure
|
822
|
+
ActiveRecord::Base.configurations = old_configurations
|
823
|
+
end
|
824
|
+
end
|
825
|
+
|
826
|
+
class DatabaseTasksDropCurrentThreeTierTest < ActiveRecord::TestCase
|
321
827
|
def setup
|
322
|
-
|
828
|
+
@configurations = {
|
829
|
+
"development" => { "primary" => { "database" => "dev-db" }, "secondary" => { "database" => "secondary-dev-db" } },
|
830
|
+
"test" => { "primary" => { "database" => "test-db" }, "secondary" => { "database" => "secondary-test-db" } },
|
831
|
+
"production" => { "primary" => { "url" => "abstract://prod-db-host/prod-db" }, "secondary" => { "url" => "abstract://secondary-prod-db-host/secondary-prod-db" } }
|
832
|
+
}
|
323
833
|
end
|
324
834
|
|
325
|
-
def
|
326
|
-
|
835
|
+
def test_drops_current_environment_database
|
836
|
+
with_stubbed_configurations do
|
837
|
+
assert_called_with(
|
838
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
839
|
+
:drop,
|
840
|
+
[
|
841
|
+
[config_for("test", "primary")],
|
842
|
+
[config_for("test", "secondary")]
|
843
|
+
]
|
844
|
+
) do
|
845
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
846
|
+
ActiveSupport::StringInquirer.new("test")
|
847
|
+
)
|
848
|
+
end
|
849
|
+
end
|
327
850
|
end
|
328
851
|
|
329
|
-
def
|
330
|
-
|
852
|
+
def test_drops_current_environment_database_with_url
|
853
|
+
with_stubbed_configurations do
|
854
|
+
assert_called_with(
|
855
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
856
|
+
:drop,
|
857
|
+
[
|
858
|
+
[config_for("production", "primary")],
|
859
|
+
[config_for("production", "secondary")]
|
860
|
+
]
|
861
|
+
) do
|
862
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
863
|
+
ActiveSupport::StringInquirer.new("production")
|
864
|
+
)
|
865
|
+
end
|
866
|
+
end
|
867
|
+
end
|
331
868
|
|
332
|
-
|
333
|
-
|
869
|
+
def test_drops_test_and_development_databases_when_env_was_not_specified
|
870
|
+
with_stubbed_configurations do
|
871
|
+
assert_called_with(
|
872
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
873
|
+
:drop,
|
874
|
+
[
|
875
|
+
[config_for("development", "primary")],
|
876
|
+
[config_for("development", "secondary")],
|
877
|
+
[config_for("test", "primary")],
|
878
|
+
[config_for("test", "secondary")]
|
879
|
+
]
|
880
|
+
) do
|
881
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
882
|
+
ActiveSupport::StringInquirer.new("development")
|
883
|
+
)
|
884
|
+
end
|
885
|
+
end
|
886
|
+
end
|
334
887
|
|
335
|
-
|
336
|
-
|
888
|
+
def test_drops_testand_development_databases_when_rails_env_is_development
|
889
|
+
old_env = ENV["RAILS_ENV"]
|
890
|
+
ENV["RAILS_ENV"] = "development"
|
891
|
+
|
892
|
+
with_stubbed_configurations do
|
893
|
+
assert_called_with(
|
894
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
895
|
+
:drop,
|
896
|
+
[
|
897
|
+
[config_for("development", "primary")],
|
898
|
+
[config_for("development", "secondary")],
|
899
|
+
[config_for("test", "primary")],
|
900
|
+
[config_for("test", "secondary")]
|
901
|
+
]
|
902
|
+
) do
|
903
|
+
ActiveRecord::Tasks::DatabaseTasks.drop_current(
|
904
|
+
ActiveSupport::StringInquirer.new("development")
|
905
|
+
)
|
906
|
+
end
|
907
|
+
end
|
337
908
|
ensure
|
338
|
-
ENV[
|
909
|
+
ENV["RAILS_ENV"] = old_env
|
339
910
|
end
|
340
911
|
|
341
|
-
|
912
|
+
private
|
913
|
+
def config_for(env_name, name)
|
914
|
+
ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: name)
|
915
|
+
end
|
916
|
+
|
917
|
+
def with_stubbed_configurations
|
918
|
+
old_configurations = ActiveRecord::Base.configurations
|
919
|
+
ActiveRecord::Base.configurations = @configurations
|
920
|
+
|
921
|
+
yield
|
922
|
+
ensure
|
923
|
+
ActiveRecord::Base.configurations = old_configurations
|
924
|
+
end
|
925
|
+
end
|
926
|
+
|
927
|
+
if current_adapter?(:SQLite3Adapter) && !in_memory_db?
|
928
|
+
class DatabaseTasksMigrationTestCase < ActiveRecord::TestCase
|
929
|
+
self.use_transactional_tests = false
|
930
|
+
|
931
|
+
# Use a memory db here to avoid having to rollback at the end
|
932
|
+
setup do
|
933
|
+
migrations_path = MIGRATIONS_ROOT + "/valid"
|
934
|
+
file = ActiveRecord::Base.connection.raw_connection.filename
|
935
|
+
@conn = ActiveRecord::Base.establish_connection adapter: "sqlite3",
|
936
|
+
database: ":memory:", migrations_paths: migrations_path
|
937
|
+
source_db = SQLite3::Database.new file
|
938
|
+
dest_db = ActiveRecord::Base.connection.raw_connection
|
939
|
+
backup = SQLite3::Backup.new(dest_db, "main", source_db, "main")
|
940
|
+
backup.step(-1)
|
941
|
+
backup.finish
|
942
|
+
end
|
943
|
+
|
944
|
+
teardown do
|
945
|
+
@conn.release_connection if @conn
|
946
|
+
ActiveRecord::Base.establish_connection :arunit
|
947
|
+
end
|
948
|
+
end
|
949
|
+
|
950
|
+
class DatabaseTasksMigrateTest < DatabaseTasksMigrationTestCase
|
951
|
+
def test_migrate_set_and_unset_empty_values_for_verbose_and_version_env_vars
|
952
|
+
verbose, version = ENV["VERBOSE"], ENV["VERSION"]
|
953
|
+
|
954
|
+
ENV["VERSION"] = "2"
|
955
|
+
ENV["VERBOSE"] = "false"
|
956
|
+
|
957
|
+
# run down migration because it was already run on copied db
|
958
|
+
assert_empty capture_migration_output
|
959
|
+
|
960
|
+
ENV["VERBOSE"] = ""
|
961
|
+
ENV["VERSION"] = ""
|
962
|
+
|
963
|
+
# re-run up migration
|
964
|
+
assert_includes capture_migration_output, "migrating"
|
965
|
+
ensure
|
966
|
+
ENV["VERBOSE"], ENV["VERSION"] = verbose, version
|
967
|
+
end
|
968
|
+
|
969
|
+
def test_migrate_set_and_unset_nonsense_values_for_verbose_and_version_env_vars
|
970
|
+
verbose, version = ENV["VERBOSE"], ENV["VERSION"]
|
971
|
+
|
972
|
+
# run down migration because it was already run on copied db
|
973
|
+
ENV["VERSION"] = "2"
|
974
|
+
ENV["VERBOSE"] = "false"
|
975
|
+
|
976
|
+
assert_empty capture_migration_output
|
977
|
+
|
978
|
+
ENV["VERBOSE"] = "yes"
|
979
|
+
ENV["VERSION"] = "2"
|
980
|
+
|
981
|
+
# run no migration because 2 was already run
|
982
|
+
assert_empty capture_migration_output
|
983
|
+
ensure
|
984
|
+
ENV["VERBOSE"], ENV["VERSION"] = verbose, version
|
985
|
+
end
|
986
|
+
|
987
|
+
private
|
988
|
+
def capture_migration_output
|
989
|
+
capture(:stdout) do
|
990
|
+
ActiveRecord::Tasks::DatabaseTasks.migrate
|
991
|
+
end
|
992
|
+
end
|
993
|
+
end
|
994
|
+
|
995
|
+
class DatabaseTasksMigrateStatusTest < DatabaseTasksMigrationTestCase
|
996
|
+
def test_migrate_status_table
|
997
|
+
ActiveRecord::SchemaMigration.create_table
|
998
|
+
output = capture_migration_status
|
999
|
+
assert_match(/database: :memory:/, output)
|
1000
|
+
assert_match(/down 001 Valid people have last names/, output)
|
1001
|
+
assert_match(/down 002 We need reminders/, output)
|
1002
|
+
assert_match(/down 003 Innocent jointable/, output)
|
1003
|
+
ActiveRecord::SchemaMigration.drop_table
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
private
|
1007
|
+
def capture_migration_status
|
1008
|
+
capture(:stdout) do
|
1009
|
+
ActiveRecord::Tasks::DatabaseTasks.migrate_status
|
1010
|
+
end
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
class DatabaseTasksMigrateErrorTest < ActiveRecord::TestCase
|
1016
|
+
self.use_transactional_tests = false
|
1017
|
+
|
1018
|
+
def test_migrate_raise_error_on_invalid_version_format
|
342
1019
|
version = ENV["VERSION"]
|
343
|
-
|
1020
|
+
|
1021
|
+
ENV["VERSION"] = "unknown"
|
1022
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
1023
|
+
assert_match(/Invalid format of target version/, e.message)
|
1024
|
+
|
1025
|
+
ENV["VERSION"] = "0.1.11"
|
1026
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
1027
|
+
assert_match(/Invalid format of target version/, e.message)
|
1028
|
+
|
1029
|
+
ENV["VERSION"] = "1.1.11"
|
1030
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
1031
|
+
assert_match(/Invalid format of target version/, e.message)
|
1032
|
+
|
1033
|
+
ENV["VERSION"] = "0 "
|
1034
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
1035
|
+
assert_match(/Invalid format of target version/, e.message)
|
1036
|
+
|
1037
|
+
ENV["VERSION"] = "1."
|
1038
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
1039
|
+
assert_match(/Invalid format of target version/, e.message)
|
1040
|
+
|
1041
|
+
ENV["VERSION"] = "1_"
|
344
1042
|
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
345
|
-
|
1043
|
+
assert_match(/Invalid format of target version/, e.message)
|
1044
|
+
|
1045
|
+
ENV["VERSION"] = "1_name"
|
1046
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
1047
|
+
assert_match(/Invalid format of target version/, e.message)
|
346
1048
|
ensure
|
347
1049
|
ENV["VERSION"] = version
|
348
1050
|
end
|
349
1051
|
|
1052
|
+
def test_migrate_raise_error_on_failed_check_target_version
|
1053
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:check_target_version, -> { raise "foo" }) do
|
1054
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.migrate }
|
1055
|
+
assert_equal "foo", e.message
|
1056
|
+
end
|
1057
|
+
end
|
1058
|
+
|
350
1059
|
def test_migrate_clears_schema_cache_afterward
|
351
|
-
ActiveRecord::Base
|
352
|
-
|
1060
|
+
assert_called(ActiveRecord::Base, :clear_cache!) do
|
1061
|
+
ActiveRecord::Tasks::DatabaseTasks.migrate
|
1062
|
+
end
|
353
1063
|
end
|
354
1064
|
end
|
355
1065
|
|
@@ -358,39 +1068,231 @@ module ActiveRecord
|
|
358
1068
|
|
359
1069
|
ADAPTERS_TASKS.each do |k, v|
|
360
1070
|
define_method("test_#{k}_purge") do
|
361
|
-
|
362
|
-
|
1071
|
+
with_stubbed_new do
|
1072
|
+
assert_called(eval("@#{v}"), :purge) do
|
1073
|
+
ActiveRecord::Tasks::DatabaseTasks.purge "adapter" => k
|
1074
|
+
end
|
1075
|
+
end
|
363
1076
|
end
|
364
1077
|
end
|
365
1078
|
end
|
366
1079
|
|
367
1080
|
class DatabaseTasksPurgeCurrentTest < ActiveRecord::TestCase
|
368
1081
|
def test_purges_current_environment_database
|
1082
|
+
old_configurations = ActiveRecord::Base.configurations
|
369
1083
|
configurations = {
|
370
|
-
|
371
|
-
|
372
|
-
|
1084
|
+
"development" => { "database" => "dev-db" },
|
1085
|
+
"test" => { "database" => "test-db" },
|
1086
|
+
"production" => { "database" => "prod-db" }
|
373
1087
|
}
|
374
|
-
ActiveRecord::Base.stubs(:configurations).returns(configurations)
|
375
1088
|
|
376
|
-
ActiveRecord::
|
377
|
-
with('database' => 'prod-db')
|
378
|
-
ActiveRecord::Base.expects(:establish_connection).with(:production)
|
1089
|
+
ActiveRecord::Base.configurations = configurations
|
379
1090
|
|
380
|
-
|
1091
|
+
assert_called_with(
|
1092
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1093
|
+
:purge,
|
1094
|
+
[ActiveRecord::Base.configurations.configs_for(env_name: "production", name: "primary")]
|
1095
|
+
) do
|
1096
|
+
assert_called_with(ActiveRecord::Base, :establish_connection, [:production]) do
|
1097
|
+
ActiveRecord::Tasks::DatabaseTasks.purge_current("production")
|
1098
|
+
end
|
1099
|
+
end
|
1100
|
+
ensure
|
1101
|
+
ActiveRecord::Base.configurations = old_configurations
|
381
1102
|
end
|
382
1103
|
end
|
383
1104
|
|
384
1105
|
class DatabaseTasksPurgeAllTest < ActiveRecord::TestCase
|
385
1106
|
def test_purge_all_local_configurations
|
386
|
-
|
387
|
-
|
1107
|
+
old_configurations = ActiveRecord::Base.configurations
|
1108
|
+
configurations = { development: { "database" => "my-db" } }
|
1109
|
+
ActiveRecord::Base.configurations = configurations
|
1110
|
+
|
1111
|
+
assert_called_with(
|
1112
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1113
|
+
:purge,
|
1114
|
+
[ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")]
|
1115
|
+
) do
|
1116
|
+
ActiveRecord::Tasks::DatabaseTasks.purge_all
|
1117
|
+
end
|
1118
|
+
ensure
|
1119
|
+
ActiveRecord::Base.configurations = old_configurations
|
1120
|
+
end
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
unless in_memory_db?
|
1124
|
+
class DatabaseTasksTruncateAllTest < ActiveRecord::TestCase
|
1125
|
+
self.use_transactional_tests = false
|
1126
|
+
|
1127
|
+
fixtures :authors, :author_addresses
|
1128
|
+
|
1129
|
+
def setup
|
1130
|
+
SchemaMigration.create_table
|
1131
|
+
SchemaMigration.create!(version: SchemaMigration.table_name)
|
1132
|
+
InternalMetadata.create_table
|
1133
|
+
InternalMetadata.create!(key: InternalMetadata.table_name)
|
1134
|
+
end
|
1135
|
+
|
1136
|
+
def teardown
|
1137
|
+
SchemaMigration.delete_all
|
1138
|
+
InternalMetadata.delete_all
|
1139
|
+
clean_up_connection_handler
|
1140
|
+
end
|
1141
|
+
|
1142
|
+
def test_truncate_tables
|
1143
|
+
assert_operator SchemaMigration.count, :>, 0
|
1144
|
+
assert_operator InternalMetadata.count, :>, 0
|
1145
|
+
assert_operator Author.count, :>, 0
|
1146
|
+
assert_operator AuthorAddress.count, :>, 0
|
1147
|
+
|
1148
|
+
old_configurations = ActiveRecord::Base.configurations
|
1149
|
+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
|
1150
|
+
configurations = { development: db_config.configuration_hash }
|
1151
|
+
ActiveRecord::Base.configurations = configurations
|
1152
|
+
|
1153
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:root, nil) do
|
1154
|
+
ActiveRecord::Tasks::DatabaseTasks.truncate_all(
|
1155
|
+
ActiveSupport::StringInquirer.new("development")
|
1156
|
+
)
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
assert_operator SchemaMigration.count, :>, 0
|
1160
|
+
assert_operator InternalMetadata.count, :>, 0
|
1161
|
+
assert_equal 0, Author.count
|
1162
|
+
assert_equal 0, AuthorAddress.count
|
1163
|
+
ensure
|
1164
|
+
ActiveRecord::Base.configurations = old_configurations
|
1165
|
+
end
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
class DatabaseTasksTruncateAllWithPrefixTest < DatabaseTasksTruncateAllTest
|
1169
|
+
setup do
|
1170
|
+
ActiveRecord::Base.table_name_prefix = "p_"
|
1171
|
+
|
1172
|
+
SchemaMigration.reset_table_name
|
1173
|
+
InternalMetadata.reset_table_name
|
1174
|
+
end
|
1175
|
+
|
1176
|
+
teardown do
|
1177
|
+
ActiveRecord::Base.table_name_prefix = nil
|
1178
|
+
|
1179
|
+
SchemaMigration.reset_table_name
|
1180
|
+
InternalMetadata.reset_table_name
|
1181
|
+
end
|
1182
|
+
end
|
1183
|
+
|
1184
|
+
class DatabaseTasksTruncateAllWithSuffixTest < DatabaseTasksTruncateAllTest
|
1185
|
+
setup do
|
1186
|
+
ActiveRecord::Base.table_name_suffix = "_s"
|
1187
|
+
|
1188
|
+
SchemaMigration.reset_table_name
|
1189
|
+
InternalMetadata.reset_table_name
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
teardown do
|
1193
|
+
ActiveRecord::Base.table_name_suffix = nil
|
1194
|
+
|
1195
|
+
SchemaMigration.reset_table_name
|
1196
|
+
InternalMetadata.reset_table_name
|
1197
|
+
end
|
1198
|
+
end
|
1199
|
+
end
|
388
1200
|
|
389
|
-
|
390
|
-
|
1201
|
+
class DatabaseTasksTruncateAllWithMultipleDatabasesTest < ActiveRecord::TestCase
|
1202
|
+
def setup
|
1203
|
+
@configurations = {
|
1204
|
+
"development" => { "primary" => { "database" => "dev-db" }, "secondary" => { "database" => "secondary-dev-db" } },
|
1205
|
+
"test" => { "primary" => { "database" => "test-db" }, "secondary" => { "database" => "secondary-test-db" } },
|
1206
|
+
"production" => { "primary" => { "url" => "abstract://prod-db-host/prod-db" }, "secondary" => { "url" => "abstract://secondary-prod-db-host/secondary-prod-db" } }
|
1207
|
+
}
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
def test_truncate_all_databases_for_environment
|
1211
|
+
with_stubbed_configurations do
|
1212
|
+
assert_called_with(
|
1213
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1214
|
+
:truncate_tables,
|
1215
|
+
[
|
1216
|
+
[config_for("test", "primary")],
|
1217
|
+
[config_for("test", "secondary")]
|
1218
|
+
]
|
1219
|
+
) do
|
1220
|
+
ActiveRecord::Tasks::DatabaseTasks.truncate_all(
|
1221
|
+
ActiveSupport::StringInquirer.new("test")
|
1222
|
+
)
|
1223
|
+
end
|
1224
|
+
end
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
def test_truncate_all_databases_with_url_for_environment
|
1228
|
+
with_stubbed_configurations do
|
1229
|
+
assert_called_with(
|
1230
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1231
|
+
:truncate_tables,
|
1232
|
+
[
|
1233
|
+
[config_for("production", "primary")],
|
1234
|
+
[config_for("production", "secondary")]
|
1235
|
+
]
|
1236
|
+
) do
|
1237
|
+
ActiveRecord::Tasks::DatabaseTasks.truncate_all(
|
1238
|
+
ActiveSupport::StringInquirer.new("production")
|
1239
|
+
)
|
1240
|
+
end
|
1241
|
+
end
|
1242
|
+
end
|
391
1243
|
|
392
|
-
|
1244
|
+
def test_truncate_all_development_databases_when_env_is_not_specified
|
1245
|
+
with_stubbed_configurations do
|
1246
|
+
assert_called_with(
|
1247
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1248
|
+
:truncate_tables,
|
1249
|
+
[
|
1250
|
+
[config_for("development", "primary")],
|
1251
|
+
[config_for("development", "secondary")]
|
1252
|
+
]
|
1253
|
+
) do
|
1254
|
+
ActiveRecord::Tasks::DatabaseTasks.truncate_all(
|
1255
|
+
ActiveSupport::StringInquirer.new("development")
|
1256
|
+
)
|
1257
|
+
end
|
1258
|
+
end
|
393
1259
|
end
|
1260
|
+
|
1261
|
+
def test_truncate_all_development_databases_when_env_is_development
|
1262
|
+
old_env = ENV["RAILS_ENV"]
|
1263
|
+
ENV["RAILS_ENV"] = "development"
|
1264
|
+
|
1265
|
+
with_stubbed_configurations do
|
1266
|
+
assert_called_with(
|
1267
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1268
|
+
:truncate_tables,
|
1269
|
+
[
|
1270
|
+
[config_for("development", "primary")],
|
1271
|
+
[config_for("development", "secondary")]
|
1272
|
+
]
|
1273
|
+
) do
|
1274
|
+
ActiveRecord::Tasks::DatabaseTasks.truncate_all(
|
1275
|
+
ActiveSupport::StringInquirer.new("development")
|
1276
|
+
)
|
1277
|
+
end
|
1278
|
+
end
|
1279
|
+
ensure
|
1280
|
+
ENV["RAILS_ENV"] = old_env
|
1281
|
+
end
|
1282
|
+
|
1283
|
+
private
|
1284
|
+
def config_for(env_name, name)
|
1285
|
+
ActiveRecord::Base.configurations.configs_for(env_name: env_name, name: name)
|
1286
|
+
end
|
1287
|
+
|
1288
|
+
def with_stubbed_configurations
|
1289
|
+
old_configurations = ActiveRecord::Base.configurations
|
1290
|
+
ActiveRecord::Base.configurations = @configurations
|
1291
|
+
|
1292
|
+
yield
|
1293
|
+
ensure
|
1294
|
+
ActiveRecord::Base.configurations = old_configurations
|
1295
|
+
end
|
394
1296
|
end
|
395
1297
|
|
396
1298
|
class DatabaseTasksCharsetTest < ActiveRecord::TestCase
|
@@ -398,10 +1300,32 @@ module ActiveRecord
|
|
398
1300
|
|
399
1301
|
ADAPTERS_TASKS.each do |k, v|
|
400
1302
|
define_method("test_#{k}_charset") do
|
401
|
-
|
402
|
-
|
1303
|
+
with_stubbed_new do
|
1304
|
+
assert_called(eval("@#{v}"), :charset) do
|
1305
|
+
ActiveRecord::Tasks::DatabaseTasks.charset "adapter" => k
|
1306
|
+
end
|
1307
|
+
end
|
403
1308
|
end
|
404
1309
|
end
|
1310
|
+
|
1311
|
+
def test_charset_current
|
1312
|
+
old_configurations = ActiveRecord::Base.configurations
|
1313
|
+
configurations = {
|
1314
|
+
"production" => { "database" => "prod-db" }
|
1315
|
+
}
|
1316
|
+
|
1317
|
+
ActiveRecord::Base.configurations = configurations
|
1318
|
+
|
1319
|
+
assert_called_with(
|
1320
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1321
|
+
:charset,
|
1322
|
+
[ActiveRecord::Base.configurations.configs_for(env_name: "production", name: "primary")]
|
1323
|
+
) do
|
1324
|
+
ActiveRecord::Tasks::DatabaseTasks.charset_current("production", "primary")
|
1325
|
+
end
|
1326
|
+
ensure
|
1327
|
+
ActiveRecord::Base.configurations = old_configurations
|
1328
|
+
end
|
405
1329
|
end
|
406
1330
|
|
407
1331
|
class DatabaseTasksCollationTest < ActiveRecord::TestCase
|
@@ -409,9 +1333,133 @@ module ActiveRecord
|
|
409
1333
|
|
410
1334
|
ADAPTERS_TASKS.each do |k, v|
|
411
1335
|
define_method("test_#{k}_collation") do
|
412
|
-
|
413
|
-
|
1336
|
+
with_stubbed_new do
|
1337
|
+
assert_called(eval("@#{v}"), :collation) do
|
1338
|
+
ActiveRecord::Tasks::DatabaseTasks.collation "adapter" => k
|
1339
|
+
end
|
1340
|
+
end
|
1341
|
+
end
|
1342
|
+
end
|
1343
|
+
|
1344
|
+
def test_collation_current
|
1345
|
+
old_configurations = ActiveRecord::Base.configurations
|
1346
|
+
configurations = {
|
1347
|
+
"production" => { "database" => "prod-db" }
|
1348
|
+
}
|
1349
|
+
|
1350
|
+
ActiveRecord::Base.configurations = configurations
|
1351
|
+
|
1352
|
+
assert_called_with(
|
1353
|
+
ActiveRecord::Tasks::DatabaseTasks,
|
1354
|
+
:collation,
|
1355
|
+
[ActiveRecord::Base.configurations.configs_for(env_name: "production", name: "primary")]
|
1356
|
+
) do
|
1357
|
+
ActiveRecord::Tasks::DatabaseTasks.collation_current("production", "primary")
|
414
1358
|
end
|
1359
|
+
ensure
|
1360
|
+
ActiveRecord::Base.configurations = old_configurations
|
1361
|
+
end
|
1362
|
+
end
|
1363
|
+
|
1364
|
+
class DatabaseTaskTargetVersionTest < ActiveRecord::TestCase
|
1365
|
+
def test_target_version_returns_nil_if_version_does_not_exist
|
1366
|
+
version = ENV.delete("VERSION")
|
1367
|
+
assert_nil ActiveRecord::Tasks::DatabaseTasks.target_version
|
1368
|
+
ensure
|
1369
|
+
ENV["VERSION"] = version
|
1370
|
+
end
|
1371
|
+
|
1372
|
+
def test_target_version_returns_nil_if_version_is_empty
|
1373
|
+
version = ENV["VERSION"]
|
1374
|
+
|
1375
|
+
ENV["VERSION"] = ""
|
1376
|
+
assert_nil ActiveRecord::Tasks::DatabaseTasks.target_version
|
1377
|
+
ensure
|
1378
|
+
ENV["VERSION"] = version
|
1379
|
+
end
|
1380
|
+
|
1381
|
+
def test_target_version_returns_converted_to_integer_env_version_if_version_exists
|
1382
|
+
version = ENV["VERSION"]
|
1383
|
+
|
1384
|
+
ENV["VERSION"] = "0"
|
1385
|
+
assert_equal ENV["VERSION"].to_i, ActiveRecord::Tasks::DatabaseTasks.target_version
|
1386
|
+
|
1387
|
+
ENV["VERSION"] = "42"
|
1388
|
+
assert_equal ENV["VERSION"].to_i, ActiveRecord::Tasks::DatabaseTasks.target_version
|
1389
|
+
|
1390
|
+
ENV["VERSION"] = "042"
|
1391
|
+
assert_equal ENV["VERSION"].to_i, ActiveRecord::Tasks::DatabaseTasks.target_version
|
1392
|
+
ensure
|
1393
|
+
ENV["VERSION"] = version
|
1394
|
+
end
|
1395
|
+
end
|
1396
|
+
|
1397
|
+
class DatabaseTaskCheckTargetVersionTest < ActiveRecord::TestCase
|
1398
|
+
def test_check_target_version_does_not_raise_error_on_empty_version
|
1399
|
+
version = ENV["VERSION"]
|
1400
|
+
ENV["VERSION"] = ""
|
1401
|
+
assert_nothing_raised { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1402
|
+
ensure
|
1403
|
+
ENV["VERSION"] = version
|
1404
|
+
end
|
1405
|
+
|
1406
|
+
def test_check_target_version_does_not_raise_error_if_version_is_not_setted
|
1407
|
+
version = ENV.delete("VERSION")
|
1408
|
+
assert_nothing_raised { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1409
|
+
ensure
|
1410
|
+
ENV["VERSION"] = version
|
1411
|
+
end
|
1412
|
+
|
1413
|
+
def test_check_target_version_raises_error_on_invalid_version_format
|
1414
|
+
version = ENV["VERSION"]
|
1415
|
+
|
1416
|
+
ENV["VERSION"] = "unknown"
|
1417
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1418
|
+
assert_match(/Invalid format of target version/, e.message)
|
1419
|
+
|
1420
|
+
ENV["VERSION"] = "0.1.11"
|
1421
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1422
|
+
assert_match(/Invalid format of target version/, e.message)
|
1423
|
+
|
1424
|
+
ENV["VERSION"] = "1.1.11"
|
1425
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1426
|
+
assert_match(/Invalid format of target version/, e.message)
|
1427
|
+
|
1428
|
+
ENV["VERSION"] = "0 "
|
1429
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1430
|
+
assert_match(/Invalid format of target version/, e.message)
|
1431
|
+
|
1432
|
+
ENV["VERSION"] = "1."
|
1433
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1434
|
+
assert_match(/Invalid format of target version/, e.message)
|
1435
|
+
|
1436
|
+
ENV["VERSION"] = "1_"
|
1437
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1438
|
+
assert_match(/Invalid format of target version/, e.message)
|
1439
|
+
|
1440
|
+
ENV["VERSION"] = "1_name"
|
1441
|
+
e = assert_raise(RuntimeError) { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1442
|
+
assert_match(/Invalid format of target version/, e.message)
|
1443
|
+
ensure
|
1444
|
+
ENV["VERSION"] = version
|
1445
|
+
end
|
1446
|
+
|
1447
|
+
def test_check_target_version_does_not_raise_error_on_valid_version_format
|
1448
|
+
version = ENV["VERSION"]
|
1449
|
+
|
1450
|
+
ENV["VERSION"] = "0"
|
1451
|
+
assert_nothing_raised { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1452
|
+
|
1453
|
+
ENV["VERSION"] = "1"
|
1454
|
+
assert_nothing_raised { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1455
|
+
|
1456
|
+
ENV["VERSION"] = "001"
|
1457
|
+
assert_nothing_raised { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1458
|
+
|
1459
|
+
ENV["VERSION"] = "001_name.rb"
|
1460
|
+
assert_nothing_raised { ActiveRecord::Tasks::DatabaseTasks.check_target_version }
|
1461
|
+
ensure
|
1462
|
+
ENV["VERSION"] = version
|
415
1463
|
end
|
416
1464
|
end
|
417
1465
|
|
@@ -420,8 +1468,14 @@ module ActiveRecord
|
|
420
1468
|
|
421
1469
|
ADAPTERS_TASKS.each do |k, v|
|
422
1470
|
define_method("test_#{k}_structure_dump") do
|
423
|
-
|
424
|
-
|
1471
|
+
with_stubbed_new do
|
1472
|
+
assert_called_with(
|
1473
|
+
eval("@#{v}"), :structure_dump,
|
1474
|
+
["awesome-file.sql", nil]
|
1475
|
+
) do
|
1476
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump({ "adapter" => k }, "awesome-file.sql")
|
1477
|
+
end
|
1478
|
+
end
|
425
1479
|
end
|
426
1480
|
end
|
427
1481
|
end
|
@@ -431,31 +1485,41 @@ module ActiveRecord
|
|
431
1485
|
|
432
1486
|
ADAPTERS_TASKS.each do |k, v|
|
433
1487
|
define_method("test_#{k}_structure_load") do
|
434
|
-
|
435
|
-
|
1488
|
+
with_stubbed_new do
|
1489
|
+
assert_called_with(
|
1490
|
+
eval("@#{v}"),
|
1491
|
+
:structure_load,
|
1492
|
+
["awesome-file.sql", nil]
|
1493
|
+
) do
|
1494
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_load({ "adapter" => k }, "awesome-file.sql")
|
1495
|
+
end
|
1496
|
+
end
|
436
1497
|
end
|
437
1498
|
end
|
438
1499
|
end
|
439
1500
|
|
440
1501
|
class DatabaseTasksCheckSchemaFileTest < ActiveRecord::TestCase
|
441
1502
|
def test_check_schema_file
|
442
|
-
Kernel
|
443
|
-
|
1503
|
+
assert_called_with(Kernel, :abort, [/awesome-file.sql/]) do
|
1504
|
+
ActiveRecord::Tasks::DatabaseTasks.check_schema_file("awesome-file.sql")
|
1505
|
+
end
|
444
1506
|
end
|
445
1507
|
end
|
446
1508
|
|
447
1509
|
class DatabaseTasksCheckSchemaFileDefaultsTest < ActiveRecord::TestCase
|
448
1510
|
def test_check_schema_file_defaults
|
449
|
-
ActiveRecord::Tasks::DatabaseTasks.
|
450
|
-
|
1511
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "/tmp") do
|
1512
|
+
assert_equal "/tmp/schema.rb", ActiveRecord::Tasks::DatabaseTasks.schema_file
|
1513
|
+
end
|
451
1514
|
end
|
452
1515
|
end
|
453
1516
|
|
454
1517
|
class DatabaseTasksCheckSchemaFileSpecifiedFormatsTest < ActiveRecord::TestCase
|
455
|
-
{ruby:
|
1518
|
+
{ ruby: "schema.rb", sql: "structure.sql" }.each_pair do |fmt, filename|
|
456
1519
|
define_method("test_check_schema_file_for_#{fmt}_format") do
|
457
|
-
ActiveRecord::Tasks::DatabaseTasks.
|
458
|
-
|
1520
|
+
ActiveRecord::Tasks::DatabaseTasks.stub(:db_dir, "/tmp") do
|
1521
|
+
assert_equal "/tmp/#{filename}", ActiveRecord::Tasks::DatabaseTasks.schema_file(fmt)
|
1522
|
+
end
|
459
1523
|
end
|
460
1524
|
end
|
461
1525
|
end
|