ibm_db 5.2.0-x86-mingw32 → 5.3.2-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/ext/Makefile +15 -13
- data/ext/ibm_db.c +62 -57
- 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 +1463 -1279
- data/lib/ibm_db.so +1 -0
- data/lib/mswin32/rb3x/i386/ruby30/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 +190 -14
data/test/cases/base_test.rb
CHANGED
@@ -1,42 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "cases/helper"
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
4
|
+
require "models/post"
|
5
|
+
require "models/author"
|
6
|
+
require "models/topic"
|
7
|
+
require "models/reply"
|
8
|
+
require "models/category"
|
9
|
+
require "models/categorization"
|
10
|
+
require "models/company"
|
11
|
+
require "models/customer"
|
12
|
+
require "models/developer"
|
13
|
+
require "models/computer"
|
14
|
+
require "models/project"
|
15
|
+
require "models/default"
|
16
|
+
require "models/auto_id"
|
17
|
+
require "models/column_name"
|
18
|
+
require "models/subscriber"
|
19
|
+
require "models/comment"
|
20
|
+
require "models/minimalistic"
|
21
|
+
require "models/warehouse_thing"
|
22
|
+
require "models/parrot"
|
23
|
+
require "models/person"
|
24
|
+
require "models/edge"
|
25
|
+
require "models/joke"
|
26
|
+
require "models/bird"
|
27
|
+
require "models/car"
|
28
|
+
require "models/bulb"
|
29
|
+
require "models/pet"
|
30
|
+
require "concurrent/atomic/count_down_latch"
|
31
|
+
require "active_support/core_ext/enumerable"
|
30
32
|
|
31
33
|
class FirstAbstractClass < ActiveRecord::Base
|
32
34
|
self.abstract_class = true
|
35
|
+
|
36
|
+
connects_to database: { writing: :arunit, reading: :arunit }
|
33
37
|
end
|
38
|
+
|
34
39
|
class SecondAbstractClass < FirstAbstractClass
|
35
40
|
self.abstract_class = true
|
41
|
+
|
42
|
+
connects_to database: { writing: :arunit, reading: :arunit }
|
43
|
+
end
|
44
|
+
|
45
|
+
class ThirdAbstractClass < SecondAbstractClass
|
46
|
+
self.abstract_class = true
|
36
47
|
end
|
48
|
+
|
37
49
|
class Photo < SecondAbstractClass; end
|
38
|
-
class Category < ActiveRecord::Base; end
|
39
|
-
class Categorization < ActiveRecord::Base; end
|
40
50
|
class Smarts < ActiveRecord::Base; end
|
41
51
|
class CreditCard < ActiveRecord::Base
|
42
52
|
class PinNumber < ActiveRecord::Base
|
@@ -47,8 +57,6 @@ class CreditCard < ActiveRecord::Base
|
|
47
57
|
class Brand < Category; end
|
48
58
|
end
|
49
59
|
class MasterCreditCard < ActiveRecord::Base; end
|
50
|
-
class Post < ActiveRecord::Base; end
|
51
|
-
class Computer < ActiveRecord::Base; end
|
52
60
|
class NonExistentTable < ActiveRecord::Base; end
|
53
61
|
class TestOracleDefault < ActiveRecord::Base; end
|
54
62
|
|
@@ -58,12 +66,6 @@ end
|
|
58
66
|
|
59
67
|
class Weird < ActiveRecord::Base; end
|
60
68
|
|
61
|
-
class Boolean < ActiveRecord::Base
|
62
|
-
def has_fun
|
63
|
-
super
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
69
|
class LintTest < ActiveRecord::TestCase
|
68
70
|
include ActiveModel::Lint::Tests
|
69
71
|
|
@@ -75,20 +77,60 @@ class LintTest < ActiveRecord::TestCase
|
|
75
77
|
end
|
76
78
|
|
77
79
|
class BasicsTest < ActiveRecord::TestCase
|
78
|
-
|
79
|
-
|
80
|
+
fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, "warehouse_things", :authors, :author_addresses, :categorizations, :categories, :posts
|
81
|
+
|
82
|
+
def test_generated_association_methods_module_name
|
83
|
+
mod = Post.send(:generated_association_methods)
|
84
|
+
assert_equal "Post::GeneratedAssociationMethods", mod.inspect
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_generated_relation_methods_module_name
|
88
|
+
mod = Post.send(:generated_relation_methods)
|
89
|
+
assert_equal "Post::GeneratedRelationMethods", mod.inspect
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_arel_attribute_normalization
|
93
|
+
assert_equal Post.arel_table["body"], Post.arel_table[:body]
|
94
|
+
assert_equal Post.arel_table["body"], Post.arel_table[:text]
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_deprecated_arel_attribute
|
98
|
+
assert_deprecated do
|
99
|
+
assert_equal Post.arel_table["body"], Post.arel_attribute(:body)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_deprecated_arel_attribute_on_relation
|
104
|
+
assert_deprecated do
|
105
|
+
assert_equal Post.arel_table["body"], Post.all.arel_attribute(:body)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_incomplete_schema_loading
|
110
|
+
topic = Topic.first
|
111
|
+
payload = { foo: 42 }
|
112
|
+
topic.update!(content: payload)
|
113
|
+
|
114
|
+
Topic.reset_column_information
|
115
|
+
|
116
|
+
Topic.connection.stub(:lookup_cast_type_from_column, ->(_) { raise "Some Error" }) do
|
117
|
+
assert_raises RuntimeError do
|
118
|
+
Topic.columns_hash
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
assert_equal payload, Topic.first.content
|
123
|
+
end
|
80
124
|
|
81
125
|
def test_column_names_are_escaped
|
82
|
-
puts "In base_test test_column_names_are_escaped"
|
83
126
|
conn = ActiveRecord::Base.connection
|
84
127
|
classname = conn.class.name[/[^:]*$/]
|
85
128
|
badchar = {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
'FbAdapter' => '"'
|
129
|
+
"SQLite3Adapter" => '"',
|
130
|
+
"Mysql2Adapter" => "`",
|
131
|
+
"PostgreSQLAdapter" => '"',
|
132
|
+
"OracleAdapter" => '"',
|
133
|
+
"IBM_DBAdapter" => '"',
|
92
134
|
}.fetch(classname) {
|
93
135
|
raise "need a bad char for #{classname}"
|
94
136
|
}
|
@@ -98,35 +140,30 @@ class BasicsTest < ActiveRecord::TestCase
|
|
98
140
|
# Oracle does not allow double quotes in table and column names at all
|
99
141
|
# therefore quoting removes them
|
100
142
|
assert_equal("#{badchar}foobar#{badchar}", quoted)
|
101
|
-
|
102
|
-
assert_equal("
|
143
|
+
elsif current_adapter?(:IBM_DBAdapter)
|
144
|
+
assert_equal("foobar", quoted)
|
103
145
|
else
|
104
146
|
assert_equal("#{badchar}foo#{badchar * 2}bar#{badchar}", quoted)
|
105
147
|
end
|
106
148
|
end
|
107
149
|
|
108
150
|
def test_columns_should_obey_set_primary_key
|
109
|
-
puts "In base_test test_columns_should_obey_set_primary_key"
|
110
151
|
pk = Subscriber.columns_hash[Subscriber.primary_key]
|
111
|
-
assert_equal
|
152
|
+
assert_equal "nick", pk.name, "nick should be primary key"
|
112
153
|
end
|
113
154
|
|
114
155
|
def test_primary_key_with_no_id
|
115
|
-
puts "In base_test test_primary_key_with_no_id"
|
116
156
|
assert_nil Edge.primary_key
|
117
157
|
end
|
118
158
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
159
|
+
def test_primary_key_and_references_columns_should_be_identical_type
|
160
|
+
pk = Author.columns_hash["id"]
|
161
|
+
ref = Post.columns_hash["author_id"]
|
162
|
+
|
163
|
+
assert_equal pk.sql_type, ref.sql_type
|
126
164
|
end
|
127
165
|
|
128
166
|
def test_many_mutations
|
129
|
-
puts "In base_test test_many_mutations"
|
130
167
|
car = Car.new name: "<3<3<3"
|
131
168
|
car.engines_count = 0
|
132
169
|
20_000.times { car.engines_count += 1 }
|
@@ -134,53 +171,43 @@ class BasicsTest < ActiveRecord::TestCase
|
|
134
171
|
end
|
135
172
|
|
136
173
|
def test_limit_without_comma
|
137
|
-
puts "In base_test test_limit_without_comma"
|
138
174
|
assert_equal 1, Topic.limit("1").to_a.length
|
139
175
|
assert_equal 1, Topic.limit(1).to_a.length
|
140
176
|
end
|
141
177
|
|
142
178
|
def test_limit_should_take_value_from_latest_limit
|
143
|
-
puts "In base_test test_limit_should_take_value_from_latest_limit"
|
144
179
|
assert_equal 1, Topic.limit(2).limit(1).to_a.length
|
145
180
|
end
|
146
181
|
|
147
182
|
def test_invalid_limit
|
148
|
-
puts "In base_test test_invalid_limit"
|
149
183
|
assert_raises(ArgumentError) do
|
150
184
|
Topic.limit("asdfadf").to_a
|
151
185
|
end
|
152
186
|
end
|
153
187
|
|
154
188
|
def test_limit_should_sanitize_sql_injection_for_limit_without_commas
|
155
|
-
puts "In base_test test_limit_should_sanitize_sql_injection_for_limit_without_commas"
|
156
189
|
assert_raises(ArgumentError) do
|
157
190
|
Topic.limit("1 select * from schema").to_a
|
158
191
|
end
|
159
192
|
end
|
160
193
|
|
161
194
|
def test_limit_should_sanitize_sql_injection_for_limit_with_commas
|
162
|
-
|
163
|
-
|
164
|
-
assert_raises(ArgumentError) do
|
165
|
-
Topic.limit("1, 7 procedure help()").to_a
|
166
|
-
end
|
195
|
+
assert_raises(ArgumentError) do
|
196
|
+
Topic.limit("1, 7 procedure help()").to_a
|
167
197
|
end
|
168
198
|
end
|
169
199
|
|
170
200
|
def test_select_symbol
|
171
|
-
puts "In base_test test_select_symbol"
|
172
201
|
topic_ids = Topic.select(:id).map(&:id).sort
|
173
202
|
assert_equal Topic.pluck(:id).sort, topic_ids
|
174
203
|
end
|
175
204
|
|
176
205
|
def test_table_exists
|
177
|
-
|
178
|
-
|
179
|
-
assert Topic.table_exists?
|
206
|
+
assert_not_predicate NonExistentTable, :table_exists?
|
207
|
+
assert_predicate Topic, :table_exists?
|
180
208
|
end
|
181
209
|
|
182
210
|
def test_preserving_date_objects
|
183
|
-
puts "In base_test test_preserving_date_objects"
|
184
211
|
# Oracle enhanced adapter allows to define Date attributes in model class (see topic.rb)
|
185
212
|
assert_kind_of(
|
186
213
|
Date, Topic.find(1).last_read,
|
@@ -189,20 +216,18 @@ class BasicsTest < ActiveRecord::TestCase
|
|
189
216
|
end
|
190
217
|
|
191
218
|
def test_previously_changed
|
192
|
-
puts "In base_test test_previously_changed"
|
193
219
|
topic = Topic.first
|
194
|
-
topic.title =
|
220
|
+
topic.title = "<3<3<3"
|
195
221
|
assert_equal({}, topic.previous_changes)
|
196
222
|
|
197
223
|
topic.save!
|
198
224
|
expected = ["The First Topic", "<3<3<3"]
|
199
|
-
assert_equal(expected, topic.previous_changes[
|
225
|
+
assert_equal(expected, topic.previous_changes["title"])
|
200
226
|
end
|
201
227
|
|
202
228
|
def test_previously_changed_dup
|
203
|
-
puts "In base_test test_previously_changed_dup"
|
204
229
|
topic = Topic.first
|
205
|
-
topic.title =
|
230
|
+
topic.title = "<3<3<3"
|
206
231
|
topic.save!
|
207
232
|
|
208
233
|
t2 = topic.dup
|
@@ -216,7 +241,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
216
241
|
end
|
217
242
|
|
218
243
|
def test_preserving_time_objects
|
219
|
-
puts "In base_test test_preserving_time_objects"
|
220
244
|
assert_kind_of(
|
221
245
|
Time, Topic.find(1).bonus_time,
|
222
246
|
"The bonus_time attribute should be of the Time class"
|
@@ -228,7 +252,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
228
252
|
)
|
229
253
|
|
230
254
|
# For adapters which support microsecond resolution.
|
231
|
-
if
|
255
|
+
if supports_datetime_with_precision?
|
232
256
|
assert_equal 11, Topic.find(1).written_on.sec
|
233
257
|
assert_equal 223300, Topic.find(1).written_on.usec
|
234
258
|
assert_equal 9900, Topic.find(2).written_on.usec
|
@@ -237,11 +261,10 @@ class BasicsTest < ActiveRecord::TestCase
|
|
237
261
|
end
|
238
262
|
|
239
263
|
def test_preserving_time_objects_with_local_time_conversion_to_default_timezone_utc
|
240
|
-
puts "In base_test test_preserving_time_objects_with_local_time_conversion_to_default_timezone_utc"
|
241
264
|
with_env_tz eastern_time_zone do
|
242
265
|
with_timezone_config default: :utc do
|
243
266
|
time = Time.local(2000)
|
244
|
-
topic = Topic.create(
|
267
|
+
topic = Topic.create("written_on" => time)
|
245
268
|
saved_time = Topic.find(topic.id).reload.written_on
|
246
269
|
assert_equal time, saved_time
|
247
270
|
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "EST"], time.to_a
|
@@ -251,12 +274,11 @@ class BasicsTest < ActiveRecord::TestCase
|
|
251
274
|
end
|
252
275
|
|
253
276
|
def test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_utc
|
254
|
-
puts "In base_test test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_utc"
|
255
277
|
with_env_tz eastern_time_zone do
|
256
278
|
with_timezone_config default: :utc do
|
257
|
-
Time.use_zone
|
279
|
+
Time.use_zone "Central Time (US & Canada)" do
|
258
280
|
time = Time.zone.local(2000)
|
259
|
-
topic = Topic.create(
|
281
|
+
topic = Topic.create("written_on" => time)
|
260
282
|
saved_time = Topic.find(topic.id).reload.written_on
|
261
283
|
assert_equal time, saved_time
|
262
284
|
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a
|
@@ -267,11 +289,10 @@ class BasicsTest < ActiveRecord::TestCase
|
|
267
289
|
end
|
268
290
|
|
269
291
|
def test_preserving_time_objects_with_utc_time_conversion_to_default_timezone_local
|
270
|
-
puts "In base_test test_preserving_time_objects_with_utc_time_conversion_to_default_timezone_local"
|
271
292
|
with_env_tz eastern_time_zone do
|
272
293
|
with_timezone_config default: :local do
|
273
294
|
time = Time.utc(2000)
|
274
|
-
topic = Topic.create(
|
295
|
+
topic = Topic.create("written_on" => time)
|
275
296
|
saved_time = Topic.find(topic.id).reload.written_on
|
276
297
|
assert_equal time, saved_time
|
277
298
|
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], time.to_a
|
@@ -281,12 +302,11 @@ class BasicsTest < ActiveRecord::TestCase
|
|
281
302
|
end
|
282
303
|
|
283
304
|
def test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_local
|
284
|
-
puts "In base_test test_preserving_time_objects_with_time_with_zone_conversion_to_default_timezone_local"
|
285
305
|
with_env_tz eastern_time_zone do
|
286
306
|
with_timezone_config default: :local do
|
287
|
-
Time.use_zone
|
307
|
+
Time.use_zone "Central Time (US & Canada)" do
|
288
308
|
time = Time.zone.local(2000)
|
289
|
-
topic = Topic.create(
|
309
|
+
topic = Topic.create("written_on" => time)
|
290
310
|
saved_time = Topic.find(topic.id).reload.written_on
|
291
311
|
assert_equal time, saved_time
|
292
312
|
assert_equal [0, 0, 0, 1, 1, 2000, 6, 1, false, "CST"], time.to_a
|
@@ -296,6 +316,18 @@ class BasicsTest < ActiveRecord::TestCase
|
|
296
316
|
end
|
297
317
|
end
|
298
318
|
|
319
|
+
def test_time_zone_aware_attribute_with_default_timezone_utc_on_utc_can_be_created
|
320
|
+
with_env_tz eastern_time_zone do
|
321
|
+
with_timezone_config aware_attributes: true, default: :utc, zone: "UTC" do
|
322
|
+
pet = Pet.create(name: "Bidu")
|
323
|
+
assert_predicate pet, :persisted?
|
324
|
+
saved_pet = Pet.find(pet.id)
|
325
|
+
assert_not_nil saved_pet.created_at
|
326
|
+
assert_not_nil saved_pet.updated_at
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
299
331
|
def eastern_time_zone
|
300
332
|
if Gem.win_platform?
|
301
333
|
"EST5EDT"
|
@@ -305,7 +337,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
305
337
|
end
|
306
338
|
|
307
339
|
def test_custom_mutator
|
308
|
-
puts "In base_test test_custom_mutator"
|
309
340
|
topic = Topic.find(1)
|
310
341
|
# This mutator is protected in the class definition
|
311
342
|
topic.send(:approved=, true)
|
@@ -313,56 +344,50 @@ class BasicsTest < ActiveRecord::TestCase
|
|
313
344
|
end
|
314
345
|
|
315
346
|
def test_initialize_with_attributes
|
316
|
-
|
317
|
-
|
318
|
-
"title" => "initialized from attributes", "written_on" => "2003-12-12 23:23"
|
319
|
-
})
|
347
|
+
topic = Topic.new(
|
348
|
+
"title" => "initialized from attributes", "written_on" => "2003-12-12 23:23")
|
320
349
|
|
321
350
|
assert_equal("initialized from attributes", topic.title)
|
322
351
|
end
|
323
352
|
|
324
353
|
def test_initialize_with_invalid_attribute
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
354
|
+
ex = assert_raise(ActiveRecord::MultiparameterAssignmentErrors) do
|
355
|
+
Topic.new("title" => "test",
|
356
|
+
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00")
|
357
|
+
end
|
358
|
+
|
329
359
|
assert_equal(1, ex.errors.size)
|
330
|
-
assert_equal("
|
360
|
+
assert_equal("written_on", ex.errors[0].attribute)
|
331
361
|
end
|
332
362
|
|
333
363
|
def test_create_after_initialize_without_block
|
334
|
-
|
335
|
-
cb
|
336
|
-
assert_equal('Dude', cb.name)
|
364
|
+
cb = CustomBulb.create(name: "Dude")
|
365
|
+
assert_equal("Dude", cb.name)
|
337
366
|
assert_equal(true, cb.frickinawesome)
|
338
367
|
end
|
339
368
|
|
340
369
|
def test_create_after_initialize_with_block
|
341
|
-
|
342
|
-
cb
|
343
|
-
assert_equal('Dude', cb.name)
|
370
|
+
cb = CustomBulb.create { |c| c.name = "Dude" }
|
371
|
+
assert_equal("Dude", cb.name)
|
344
372
|
assert_equal(true, cb.frickinawesome)
|
345
373
|
end
|
346
374
|
|
347
375
|
def test_create_after_initialize_with_array_param
|
348
|
-
|
349
|
-
|
350
|
-
assert_equal
|
351
|
-
assert_equal 'Bob', cbs[1].name
|
376
|
+
cbs = CustomBulb.create([{ name: "Dude" }, { name: "Bob" }])
|
377
|
+
assert_equal "Dude", cbs[0].name
|
378
|
+
assert_equal "Bob", cbs[1].name
|
352
379
|
assert cbs[0].frickinawesome
|
353
|
-
|
380
|
+
assert_not cbs[1].frickinawesome
|
354
381
|
end
|
355
382
|
|
356
383
|
def test_load
|
357
|
-
|
358
|
-
topics = Topic.all.merge!(:order => 'id').to_a
|
384
|
+
topics = Topic.all.merge!(order: "id").to_a
|
359
385
|
assert_equal(5, topics.size)
|
360
386
|
assert_equal(topics(:first).title, topics.first.title)
|
361
387
|
end
|
362
388
|
|
363
389
|
def test_load_with_condition
|
364
|
-
|
365
|
-
topics = Topic.all.merge!(:where => "author_name = 'Mary'").to_a
|
390
|
+
topics = Topic.all.merge!(where: "author_name = 'Mary'").to_a
|
366
391
|
|
367
392
|
assert_equal(1, topics.size)
|
368
393
|
assert_equal(topics(:second).title, topics.first.title)
|
@@ -371,7 +396,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
371
396
|
GUESSED_CLASSES = [Category, Smarts, CreditCard, CreditCard::PinNumber, CreditCard::PinNumber::CvvCode, CreditCard::SubPinNumber, CreditCard::Brand, MasterCreditCard]
|
372
397
|
|
373
398
|
def test_table_name_guesses
|
374
|
-
puts "In base_test test_table_name_guesses"
|
375
399
|
assert_equal "topics", Topic.table_name
|
376
400
|
|
377
401
|
assert_equal "categories", Category.table_name
|
@@ -387,7 +411,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
387
411
|
end
|
388
412
|
|
389
413
|
def test_singular_table_name_guesses
|
390
|
-
puts "In base_test test_singular_table_name_guesses"
|
391
414
|
ActiveRecord::Base.pluralize_table_names = false
|
392
415
|
GUESSED_CLASSES.each(&:reset_table_name)
|
393
416
|
|
@@ -405,7 +428,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
405
428
|
end
|
406
429
|
|
407
430
|
def test_table_name_guesses_with_prefixes_and_suffixes
|
408
|
-
puts "In base_test test_table_name_guesses_with_prefixes_and_suffixes"
|
409
431
|
ActiveRecord::Base.table_name_prefix = "test_"
|
410
432
|
Category.reset_table_name
|
411
433
|
assert_equal "test_categories", Category.table_name
|
@@ -425,7 +447,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
425
447
|
end
|
426
448
|
|
427
449
|
def test_singular_table_name_guesses_with_prefixes_and_suffixes
|
428
|
-
puts "In base_test test_singular_table_name_guesses_with_prefixes_and_suffixes"
|
429
450
|
ActiveRecord::Base.pluralize_table_names = false
|
430
451
|
|
431
452
|
ActiveRecord::Base.table_name_prefix = "test_"
|
@@ -448,7 +469,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
448
469
|
end
|
449
470
|
|
450
471
|
def test_table_name_guesses_with_inherited_prefixes_and_suffixes
|
451
|
-
puts "In base_test test_table_name_guesses_with_inherited_prefixes_and_suffixes"
|
452
472
|
GUESSED_CLASSES.each(&:reset_table_name)
|
453
473
|
|
454
474
|
CreditCard.table_name_prefix = "test_"
|
@@ -478,7 +498,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
478
498
|
end
|
479
499
|
|
480
500
|
def test_singular_table_name_guesses_for_individual_table
|
481
|
-
puts "In base_test test_singular_table_name_guesses_for_individual_table"
|
482
501
|
Post.pluralize_table_names = false
|
483
502
|
Post.reset_table_name
|
484
503
|
assert_equal "post", Post.table_name
|
@@ -488,23 +507,14 @@ class BasicsTest < ActiveRecord::TestCase
|
|
488
507
|
Post.reset_table_name
|
489
508
|
end
|
490
509
|
|
491
|
-
if current_adapter?(:Mysql2Adapter)
|
492
|
-
puts "In base_test test_update_all_with_order_and_limit"
|
493
|
-
def test_update_all_with_order_and_limit
|
494
|
-
assert_equal 1, Topic.limit(1).order('id DESC').update_all(:content => 'bulk updated!')
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
510
|
def test_null_fields
|
499
|
-
puts "In base_test test_null_fields"
|
500
511
|
assert_nil Topic.find(1).parent_id
|
501
512
|
assert_nil Topic.create("title" => "Hey you").parent_id
|
502
513
|
end
|
503
514
|
|
504
515
|
def test_default_values
|
505
|
-
puts "In base_test test_default_values"
|
506
516
|
topic = Topic.new
|
507
|
-
|
517
|
+
assert_predicate topic, :approved?
|
508
518
|
assert_nil topic.written_on
|
509
519
|
assert_nil topic.bonus_time
|
510
520
|
assert_nil topic.last_read
|
@@ -512,7 +522,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
512
522
|
topic.save
|
513
523
|
|
514
524
|
topic = Topic.find(topic.id)
|
515
|
-
|
525
|
+
assert_predicate topic, :approved?
|
516
526
|
assert_nil topic.last_read
|
517
527
|
|
518
528
|
# Oracle has some funky default handling, so it requires a bit of
|
@@ -526,27 +536,24 @@ class BasicsTest < ActiveRecord::TestCase
|
|
526
536
|
end
|
527
537
|
|
528
538
|
# Oracle does not have a TIME datatype.
|
529
|
-
unless current_adapter?(:OracleAdapter
|
539
|
+
unless current_adapter?(:OracleAdapter)
|
530
540
|
def test_utc_as_time_zone
|
531
|
-
puts "In base_test test_utc_as_time_zone"
|
532
541
|
with_timezone_config default: :utc do
|
533
542
|
attributes = { "bonus_time" => "5:42:00AM" }
|
534
543
|
topic = Topic.find(1)
|
535
544
|
topic.attributes = attributes
|
536
545
|
assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time
|
537
546
|
end
|
538
|
-
|
539
|
-
end
|
547
|
+
end
|
540
548
|
|
541
549
|
def test_utc_as_time_zone_and_new
|
542
|
-
puts "In base_test test_utc_as_time_zone_and_new"
|
543
550
|
with_timezone_config default: :utc do
|
544
|
-
attributes = { "bonus_time(1i)"=>"2000",
|
545
|
-
"bonus_time(2i)"=>"1",
|
546
|
-
"bonus_time(3i)"=>"1",
|
547
|
-
"bonus_time(4i)"=>"10",
|
548
|
-
"bonus_time(5i)"=>"35",
|
549
|
-
"bonus_time(6i)"=>"50" }
|
551
|
+
attributes = { "bonus_time(1i)" => "2000",
|
552
|
+
"bonus_time(2i)" => "1",
|
553
|
+
"bonus_time(3i)" => "1",
|
554
|
+
"bonus_time(4i)" => "10",
|
555
|
+
"bonus_time(5i)" => "35",
|
556
|
+
"bonus_time(6i)" => "50" }
|
550
557
|
topic = Topic.new(attributes)
|
551
558
|
assert_equal Time.utc(2000, 1, 1, 10, 35, 50), topic.bonus_time
|
552
559
|
end
|
@@ -554,7 +561,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
554
561
|
end
|
555
562
|
|
556
563
|
def test_default_values_on_empty_strings
|
557
|
-
puts "In base_test test_default_values_on_empty_strings"
|
558
564
|
topic = Topic.new
|
559
565
|
topic.approved = nil
|
560
566
|
topic.last_read = nil
|
@@ -568,35 +574,33 @@ class BasicsTest < ActiveRecord::TestCase
|
|
568
574
|
end
|
569
575
|
|
570
576
|
def test_equality
|
571
|
-
puts "In base_test test_equality"
|
572
577
|
assert_equal Topic.find(1), Topic.find(2).topic
|
573
578
|
end
|
574
579
|
|
575
580
|
def test_find_by_slug
|
576
|
-
|
577
|
-
|
581
|
+
assert_equal Topic.find("1-meowmeow"), Topic.find(1)
|
582
|
+
end
|
583
|
+
|
584
|
+
def test_out_of_range_slugs
|
585
|
+
assert_equal [Topic.find(1)], Topic.where(id: ["1-meowmeow", "9223372036854775808-hello"])
|
578
586
|
end
|
579
587
|
|
580
588
|
def test_find_by_slug_with_array
|
581
|
-
|
582
|
-
assert_equal Topic
|
583
|
-
assert_equal 'The Second Topic of the day', Topic.find(['2-hello', '1-meowmeow']).first.title
|
589
|
+
assert_equal Topic.find([1, 2]), Topic.find(["1-meowmeow", "2-hello"])
|
590
|
+
assert_equal "The Second Topic of the day", Topic.find(["2-hello", "1-meowmeow"]).first.title
|
584
591
|
end
|
585
592
|
|
586
593
|
def test_find_by_slug_with_range
|
587
|
-
|
588
|
-
assert_equal Topic.where(id: '1-meowmeow'..'2-hello'), Topic.where(id: 1..2)
|
594
|
+
assert_equal Topic.where(id: "1-meowmeow".."2-hello"), Topic.where(id: 1..2)
|
589
595
|
end
|
590
596
|
|
591
597
|
def test_equality_of_new_records
|
592
|
-
puts "In base_test test_equality_of_new_records"
|
593
598
|
assert_not_equal Topic.new, Topic.new
|
594
599
|
assert_equal false, Topic.new == Topic.new
|
595
600
|
end
|
596
601
|
|
597
602
|
def test_equality_of_destroyed_records
|
598
|
-
|
599
|
-
topic_1 = Topic.new(:title => 'test_1')
|
603
|
+
topic_1 = Topic.new(title: "test_1")
|
600
604
|
topic_1.save
|
601
605
|
topic_2 = Topic.find(topic_1.id)
|
602
606
|
topic_1.destroy
|
@@ -605,58 +609,51 @@ class BasicsTest < ActiveRecord::TestCase
|
|
605
609
|
end
|
606
610
|
|
607
611
|
def test_equality_with_blank_ids
|
608
|
-
|
609
|
-
|
610
|
-
two = Subscriber.new(:id => '')
|
612
|
+
one = Subscriber.new(id: "")
|
613
|
+
two = Subscriber.new(id: "")
|
611
614
|
assert_equal one, two
|
612
615
|
end
|
613
616
|
|
614
617
|
def test_equality_of_relation_and_collection_proxy
|
615
|
-
puts "In base_test test_equality_of_relation_and_collection_proxy"
|
616
618
|
car = Car.create!
|
617
619
|
car.bulbs.build
|
618
620
|
car.save
|
619
621
|
|
620
|
-
assert car.bulbs == Bulb.where(car_id: car.id),
|
621
|
-
assert Bulb.where(car_id: car.id) == car.bulbs,
|
622
|
+
assert car.bulbs == Bulb.where(car_id: car.id), "CollectionProxy should be comparable with Relation"
|
623
|
+
assert Bulb.where(car_id: car.id) == car.bulbs, "Relation should be comparable with CollectionProxy"
|
622
624
|
end
|
623
625
|
|
624
626
|
def test_equality_of_relation_and_array
|
625
|
-
puts "In base_test test_equality_of_relation_and_array"
|
626
627
|
car = Car.create!
|
627
628
|
car.bulbs.build
|
628
629
|
car.save
|
629
630
|
|
630
|
-
assert Bulb.where(car_id: car.id) == car.bulbs.to_a,
|
631
|
+
assert Bulb.where(car_id: car.id) == car.bulbs.to_a, "Relation should be comparable with Array"
|
631
632
|
end
|
632
633
|
|
633
634
|
def test_equality_of_relation_and_association_relation
|
634
|
-
puts "In base_test test_equality_of_relation_and_association_relation"
|
635
635
|
car = Car.create!
|
636
636
|
car.bulbs.build
|
637
637
|
car.save
|
638
638
|
|
639
|
-
assert_equal Bulb.where(car_id: car.id), car.bulbs.includes(:car),
|
640
|
-
assert_equal car.bulbs.includes(:car), Bulb.where(car_id: car.id),
|
639
|
+
assert_equal Bulb.where(car_id: car.id), car.bulbs.includes(:car), "Relation should be comparable with AssociationRelation"
|
640
|
+
assert_equal car.bulbs.includes(:car), Bulb.where(car_id: car.id), "AssociationRelation should be comparable with Relation"
|
641
641
|
end
|
642
642
|
|
643
643
|
def test_equality_of_collection_proxy_and_association_relation
|
644
|
-
puts "In base_test test_equality_of_collection_proxy_and_association_relation"
|
645
644
|
car = Car.create!
|
646
645
|
car.bulbs.build
|
647
646
|
car.save
|
648
647
|
|
649
|
-
assert_equal car.bulbs, car.bulbs.includes(:car),
|
650
|
-
assert_equal car.bulbs.includes(:car), car.bulbs,
|
648
|
+
assert_equal car.bulbs, car.bulbs.includes(:car), "CollectionProxy should be comparable with AssociationRelation"
|
649
|
+
assert_equal car.bulbs.includes(:car), car.bulbs, "AssociationRelation should be comparable with CollectionProxy"
|
651
650
|
end
|
652
651
|
|
653
652
|
def test_hashing
|
654
|
-
puts "In base_test test_hashing"
|
655
653
|
assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ]
|
656
654
|
end
|
657
655
|
|
658
656
|
def test_successful_comparison_of_like_class_records
|
659
|
-
puts "In base_test test_successful_comparison_of_like_class_records"
|
660
657
|
topic_1 = Topic.create!
|
661
658
|
topic_2 = Topic.create!
|
662
659
|
|
@@ -664,40 +661,35 @@ class BasicsTest < ActiveRecord::TestCase
|
|
664
661
|
end
|
665
662
|
|
666
663
|
def test_failed_comparison_of_unlike_class_records
|
667
|
-
puts "In base_test test_failed_comparison_of_unlike_class_records"
|
668
664
|
assert_raises ArgumentError do
|
669
665
|
[ topics(:first), posts(:welcome) ].sort
|
670
666
|
end
|
671
667
|
end
|
672
668
|
|
673
669
|
def test_create_without_prepared_statement
|
674
|
-
puts "In base_test test_create_without_prepared_statement"
|
675
670
|
topic = Topic.connection.unprepared_statement do
|
676
|
-
Topic.create(:
|
671
|
+
Topic.create(title: "foo")
|
677
672
|
end
|
678
673
|
|
679
674
|
assert_equal topic, Topic.find(topic.id)
|
680
675
|
end
|
681
676
|
|
682
677
|
def test_destroy_without_prepared_statement
|
683
|
-
|
684
|
-
topic = Topic.create(title: 'foo')
|
678
|
+
topic = Topic.create(title: "foo")
|
685
679
|
Topic.connection.unprepared_statement do
|
686
680
|
Topic.find(topic.id).destroy
|
687
681
|
end
|
688
682
|
|
689
|
-
|
683
|
+
assert_nil Topic.find_by_id(topic.id)
|
690
684
|
end
|
691
685
|
|
692
686
|
def test_comparison_with_different_objects
|
693
|
-
puts "In base_test test_comparison_with_different_objects"
|
694
687
|
topic = Topic.create
|
695
|
-
category = Category.create(:
|
688
|
+
category = Category.create(name: "comparison")
|
696
689
|
assert_nil topic <=> category
|
697
690
|
end
|
698
691
|
|
699
692
|
def test_comparison_with_different_objects_in_array
|
700
|
-
puts "In base_test test_comparison_with_different_objects_in_array"
|
701
693
|
topic = Topic.create
|
702
694
|
assert_raises(ArgumentError) do
|
703
695
|
[1, topic].sort
|
@@ -705,10 +697,9 @@ class BasicsTest < ActiveRecord::TestCase
|
|
705
697
|
end
|
706
698
|
|
707
699
|
def test_readonly_attributes
|
708
|
-
|
709
|
-
assert_equal Set.new([ 'title' , 'comments_count' ]), ReadonlyTitlePost.readonly_attributes
|
700
|
+
assert_equal Set.new([ "title", "comments_count" ]), ReadonlyTitlePost.readonly_attributes
|
710
701
|
|
711
|
-
post = ReadonlyTitlePost.create(:
|
702
|
+
post = ReadonlyTitlePost.create(title: "cannot change this", body: "changeable")
|
712
703
|
post.reload
|
713
704
|
assert_equal "cannot change this", post.title
|
714
705
|
|
@@ -719,21 +710,19 @@ class BasicsTest < ActiveRecord::TestCase
|
|
719
710
|
end
|
720
711
|
|
721
712
|
def test_unicode_column_name
|
722
|
-
puts "In base_test test_unicode_column_name"
|
723
713
|
Weird.reset_column_information
|
724
|
-
weird = Weird.create(
|
725
|
-
assert_equal
|
714
|
+
weird = Weird.create(なまえ: "たこ焼き仮面")
|
715
|
+
assert_equal "たこ焼き仮面", weird.なまえ
|
726
716
|
end
|
727
717
|
|
728
718
|
unless current_adapter?(:PostgreSQLAdapter)
|
729
719
|
def test_respect_internal_encoding
|
730
|
-
puts "In base_test test_respect_internal_encoding"
|
731
720
|
old_default_internal = Encoding.default_internal
|
732
721
|
silence_warnings { Encoding.default_internal = "EUC-JP" }
|
733
722
|
|
734
723
|
Weird.reset_column_information
|
735
724
|
|
736
|
-
assert_equal ["EUC-JP"], Weird.columns.map {|c| c.name.encoding.name }.uniq
|
725
|
+
assert_equal ["EUC-JP"], Weird.columns.map { |c| c.name.encoding.name }.uniq
|
737
726
|
ensure
|
738
727
|
silence_warnings { Encoding.default_internal = old_default_internal }
|
739
728
|
Weird.reset_column_information
|
@@ -741,27 +730,24 @@ class BasicsTest < ActiveRecord::TestCase
|
|
741
730
|
end
|
742
731
|
|
743
732
|
def test_non_valid_identifier_column_name
|
744
|
-
|
745
|
-
weird = Weird.create('a$b' => 'value')
|
733
|
+
weird = Weird.create("a$b" => "value")
|
746
734
|
weird.reload
|
747
|
-
assert_equal
|
748
|
-
assert_equal
|
735
|
+
assert_equal "value", weird.public_send("a$b")
|
736
|
+
assert_equal "value", weird.read_attribute("a$b")
|
749
737
|
|
750
|
-
weird.update_columns(
|
738
|
+
weird.update_columns("a$b" => "value2")
|
751
739
|
weird.reload
|
752
|
-
assert_equal
|
753
|
-
assert_equal
|
740
|
+
assert_equal "value2", weird.public_send("a$b")
|
741
|
+
assert_equal "value2", weird.read_attribute("a$b")
|
754
742
|
end
|
755
743
|
|
756
744
|
def test_group_weirds_by_from
|
757
|
-
|
758
|
-
Weird.create('a$b' => 'value', :from => 'aaron')
|
745
|
+
Weird.create("a$b" => "value", :from => "aaron")
|
759
746
|
count = Weird.group(Weird.arel_table[:from]).count
|
760
|
-
assert_equal 1, count[
|
747
|
+
assert_equal 1, count["aaron"]
|
761
748
|
end
|
762
749
|
|
763
750
|
def test_attributes_on_dummy_time
|
764
|
-
puts "In base_test test_attributes_on_dummy_time"
|
765
751
|
# Oracle does not have a TIME datatype.
|
766
752
|
return true if current_adapter?(:OracleAdapter)
|
767
753
|
|
@@ -772,11 +758,13 @@ class BasicsTest < ActiveRecord::TestCase
|
|
772
758
|
topic = Topic.find(1)
|
773
759
|
topic.attributes = attributes
|
774
760
|
assert_equal Time.local(2000, 1, 1, 5, 42, 0), topic.bonus_time
|
761
|
+
|
762
|
+
topic.save!
|
763
|
+
assert_equal topic, Topic.find_by(attributes)
|
775
764
|
end
|
776
765
|
end
|
777
766
|
|
778
767
|
def test_attributes_on_dummy_time_with_invalid_time
|
779
|
-
puts "In base_test test_attributes_on_dummy_time_with_invalid_time"
|
780
768
|
# Oracle does not have a TIME datatype.
|
781
769
|
return true if current_adapter?(:OracleAdapter)
|
782
770
|
|
@@ -788,64 +776,34 @@ class BasicsTest < ActiveRecord::TestCase
|
|
788
776
|
assert_nil topic.bonus_time
|
789
777
|
end
|
790
778
|
|
791
|
-
def
|
792
|
-
|
793
|
-
b_nil = Boolean.create({ "value" => nil })
|
794
|
-
nil_id = b_nil.id
|
795
|
-
b_false = Boolean.create({ "value" => false })
|
796
|
-
false_id = b_false.id
|
797
|
-
b_true = Boolean.create({ "value" => true })
|
798
|
-
true_id = b_true.id
|
779
|
+
def test_attributes
|
780
|
+
category = Category.new(name: "Ruby")
|
799
781
|
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
assert !b_false.value?
|
804
|
-
b_true = Boolean.find(true_id)
|
805
|
-
assert b_true.value?
|
806
|
-
end
|
807
|
-
|
808
|
-
def test_boolean_without_questionmark
|
809
|
-
puts "In base_test test_boolean_without_questionmark"
|
810
|
-
b_true = Boolean.create({ "value" => true })
|
811
|
-
true_id = b_true.id
|
812
|
-
|
813
|
-
subclass = Class.new(Boolean).find true_id
|
814
|
-
superclass = Boolean.find true_id
|
815
|
-
|
816
|
-
assert_equal superclass.read_attribute(:has_fun), subclass.read_attribute(:has_fun)
|
817
|
-
end
|
818
|
-
|
819
|
-
def test_boolean_cast_from_string
|
820
|
-
puts "In base_test test_boolean_cast_from_string"
|
821
|
-
b_blank = Boolean.create({ "value" => "" })
|
822
|
-
blank_id = b_blank.id
|
823
|
-
b_false = Boolean.create({ "value" => "0" })
|
824
|
-
false_id = b_false.id
|
825
|
-
b_true = Boolean.create({ "value" => "1" })
|
826
|
-
true_id = b_true.id
|
782
|
+
expected_attributes = category.attribute_names.index_with do |attribute_name|
|
783
|
+
category.public_send(attribute_name)
|
784
|
+
end
|
827
785
|
|
828
|
-
|
829
|
-
|
830
|
-
b_false = Boolean.find(false_id)
|
831
|
-
assert !b_false.value?
|
832
|
-
b_true = Boolean.find(true_id)
|
833
|
-
assert b_true.value?
|
786
|
+
assert_instance_of Hash, category.attributes
|
787
|
+
assert_equal expected_attributes, category.attributes
|
834
788
|
end
|
835
789
|
|
836
790
|
def test_new_record_returns_boolean
|
837
|
-
puts "In base_test test_new_record_returns_boolean"
|
838
791
|
assert_equal false, Topic.new.persisted?
|
839
792
|
assert_equal true, Topic.find(1).persisted?
|
840
793
|
end
|
841
794
|
|
795
|
+
def test_previously_new_record_returns_boolean
|
796
|
+
assert_equal false, Topic.new.previously_new_record?
|
797
|
+
assert_equal true, Topic.create.previously_new_record?
|
798
|
+
assert_equal false, Topic.find(1).previously_new_record?
|
799
|
+
end
|
800
|
+
|
842
801
|
def test_dup
|
843
|
-
puts "In base_test test_dup"
|
844
802
|
topic = Topic.find(1)
|
845
803
|
duped_topic = nil
|
846
804
|
assert_nothing_raised { duped_topic = topic.dup }
|
847
805
|
assert_equal topic.title, duped_topic.title
|
848
|
-
|
806
|
+
assert_not_predicate duped_topic, :persisted?
|
849
807
|
|
850
808
|
# test if the attributes have been duped
|
851
809
|
topic.title = "a"
|
@@ -863,7 +821,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
863
821
|
|
864
822
|
# test if saved clone object differs from original
|
865
823
|
duped_topic.save
|
866
|
-
|
824
|
+
assert_predicate duped_topic, :persisted?
|
867
825
|
assert_not_equal duped_topic.id, topic.id
|
868
826
|
|
869
827
|
duped_topic.reload
|
@@ -872,10 +830,9 @@ class BasicsTest < ActiveRecord::TestCase
|
|
872
830
|
|
873
831
|
DeveloperSalary = Struct.new(:amount)
|
874
832
|
def test_dup_with_aggregate_of_same_name_as_attribute
|
875
|
-
puts "In base_test test_dup_with_aggregate_of_same_name_as_attribute"
|
876
833
|
developer_with_aggregate = Class.new(ActiveRecord::Base) do
|
877
|
-
self.table_name =
|
878
|
-
composed_of :salary, :
|
834
|
+
self.table_name = "developers"
|
835
|
+
composed_of :salary, class_name: "BasicsTest::DeveloperSalary", mapping: [%w(salary amount)]
|
879
836
|
end
|
880
837
|
|
881
838
|
dev = developer_with_aggregate.find(1)
|
@@ -885,7 +842,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
885
842
|
assert_nothing_raised { dup = dev.dup }
|
886
843
|
assert_kind_of DeveloperSalary, dup.salary
|
887
844
|
assert_equal dev.salary.amount, dup.salary.amount
|
888
|
-
|
845
|
+
assert_not_predicate dup, :persisted?
|
889
846
|
|
890
847
|
# test if the attributes have been duped
|
891
848
|
original_amount = dup.salary.amount
|
@@ -893,12 +850,11 @@ class BasicsTest < ActiveRecord::TestCase
|
|
893
850
|
assert_equal original_amount, dup.salary.amount
|
894
851
|
|
895
852
|
assert dup.save
|
896
|
-
|
853
|
+
assert_predicate dup, :persisted?
|
897
854
|
assert_not_equal dup.id, dev.id
|
898
855
|
end
|
899
856
|
|
900
857
|
def test_dup_does_not_copy_associations
|
901
|
-
puts "In base_test test_dup_does_not_copy_associations"
|
902
858
|
author = authors(:david)
|
903
859
|
assert_not_equal [], author.posts
|
904
860
|
|
@@ -907,190 +863,107 @@ class BasicsTest < ActiveRecord::TestCase
|
|
907
863
|
end
|
908
864
|
|
909
865
|
def test_clone_preserves_subtype
|
910
|
-
puts "In base_test test_clone_preserves_subtype"
|
911
866
|
clone = nil
|
912
867
|
assert_nothing_raised { clone = Company.find(3).clone }
|
913
868
|
assert_kind_of Client, clone
|
914
869
|
end
|
915
870
|
|
916
871
|
def test_clone_of_new_object_with_defaults
|
917
|
-
puts "In base_test test_clone_of_new_object_with_defaults"
|
918
872
|
developer = Developer.new
|
919
|
-
|
920
|
-
|
873
|
+
assert_not_predicate developer, :name_changed?
|
874
|
+
assert_not_predicate developer, :salary_changed?
|
921
875
|
|
922
876
|
cloned_developer = developer.clone
|
923
|
-
|
924
|
-
|
877
|
+
assert_not_predicate cloned_developer, :name_changed?
|
878
|
+
assert_not_predicate cloned_developer, :salary_changed?
|
925
879
|
end
|
926
880
|
|
927
881
|
def test_clone_of_new_object_marks_attributes_as_dirty
|
928
|
-
|
929
|
-
developer
|
930
|
-
|
931
|
-
assert developer.salary_changed?
|
882
|
+
developer = Developer.new name: "Bjorn", salary: 100000
|
883
|
+
assert_predicate developer, :name_changed?
|
884
|
+
assert_predicate developer, :salary_changed?
|
932
885
|
|
933
886
|
cloned_developer = developer.clone
|
934
|
-
|
935
|
-
|
887
|
+
assert_predicate cloned_developer, :name_changed?
|
888
|
+
assert_predicate cloned_developer, :salary_changed?
|
936
889
|
end
|
937
890
|
|
938
891
|
def test_clone_of_new_object_marks_as_dirty_only_changed_attributes
|
939
|
-
|
940
|
-
developer = Developer.new :name => 'Bjorn'
|
892
|
+
developer = Developer.new name: "Bjorn"
|
941
893
|
assert developer.name_changed? # obviously
|
942
|
-
|
894
|
+
assert_not developer.salary_changed? # attribute has non-nil default value, so treated as not changed
|
943
895
|
|
944
896
|
cloned_developer = developer.clone
|
945
|
-
|
946
|
-
|
897
|
+
assert_predicate cloned_developer, :name_changed?
|
898
|
+
assert_not cloned_developer.salary_changed? # ... and cloned instance should behave same
|
947
899
|
end
|
948
900
|
|
949
901
|
def test_dup_of_saved_object_marks_attributes_as_dirty
|
950
|
-
|
951
|
-
developer
|
952
|
-
|
953
|
-
assert !developer.salary_changed?
|
902
|
+
developer = Developer.create! name: "Bjorn", salary: 100000
|
903
|
+
assert_not_predicate developer, :name_changed?
|
904
|
+
assert_not_predicate developer, :salary_changed?
|
954
905
|
|
955
906
|
cloned_developer = developer.dup
|
956
907
|
assert cloned_developer.name_changed? # both attributes differ from defaults
|
957
|
-
|
908
|
+
assert_predicate cloned_developer, :salary_changed?
|
958
909
|
end
|
959
910
|
|
960
911
|
def test_dup_of_saved_object_marks_as_dirty_only_changed_attributes
|
961
|
-
|
962
|
-
developer
|
963
|
-
|
964
|
-
assert !developer.salary_changed?
|
912
|
+
developer = Developer.create! name: "Bjorn"
|
913
|
+
assert_not developer.name_changed? # both attributes of saved object should be treated as not changed
|
914
|
+
assert_not_predicate developer, :salary_changed?
|
965
915
|
|
966
916
|
cloned_developer = developer.dup
|
967
917
|
assert cloned_developer.name_changed? # ... but on cloned object should be
|
968
|
-
|
918
|
+
assert_not cloned_developer.salary_changed? # ... BUT salary has non-nil default which should be treated as not changed on cloned instance
|
969
919
|
end
|
970
920
|
|
971
921
|
def test_bignum
|
972
|
-
puts "In base_test test_bignum"
|
973
922
|
company = Company.find(1)
|
974
|
-
company.rating =
|
923
|
+
company.rating = 2147483648
|
975
924
|
company.save
|
976
925
|
company = Company.find(1)
|
977
|
-
assert_equal
|
926
|
+
assert_equal 2147483648, company.rating
|
927
|
+
end
|
928
|
+
|
929
|
+
def test_bignum_pk
|
930
|
+
company = Company.create!(id: 2147483648, name: "foo")
|
931
|
+
assert_equal company, Company.find(company.id)
|
978
932
|
end
|
979
933
|
|
980
|
-
|
981
|
-
if current_adapter?(:PostgreSQLAdapter)
|
934
|
+
if current_adapter?(:PostgreSQLAdapter, :Mysql2Adapter, :SQLite3Adapter)
|
982
935
|
def test_default
|
983
|
-
puts "In base_test test_default"
|
984
936
|
with_timezone_config default: :local do
|
985
937
|
default = Default.new
|
986
938
|
|
987
939
|
# fixed dates / times
|
988
940
|
assert_equal Date.new(2004, 1, 1), default.fixed_date
|
989
|
-
assert_equal Time.local(2004, 1,1,0,0,0,0), default.fixed_time
|
941
|
+
assert_equal Time.local(2004, 1, 1, 0, 0, 0, 0), default.fixed_time
|
990
942
|
|
991
943
|
# char types
|
992
|
-
assert_equal
|
993
|
-
assert_equal
|
994
|
-
|
944
|
+
assert_equal "Y", default.char1
|
945
|
+
assert_equal "a varchar field", default.char2
|
946
|
+
# Mysql text type can't have default value
|
947
|
+
unless current_adapter?(:Mysql2Adapter)
|
948
|
+
assert_equal "a text field", default.char3
|
949
|
+
end
|
995
950
|
end
|
996
951
|
end
|
997
952
|
end
|
998
953
|
|
999
|
-
class NumericData < ActiveRecord::Base
|
1000
|
-
self.table_name = 'numeric_data'
|
1001
|
-
|
1002
|
-
attribute :my_house_population, :integer
|
1003
|
-
attribute :atoms_in_universe, :integer
|
1004
|
-
end
|
1005
|
-
|
1006
|
-
def test_big_decimal_conditions
|
1007
|
-
puts "In base_test test_big_decimal_conditions"
|
1008
|
-
m = NumericData.new(
|
1009
|
-
:bank_balance => 1586.43,
|
1010
|
-
:big_bank_balance => BigDecimal("1000234000567.95"),
|
1011
|
-
:world_population => 6000000000,
|
1012
|
-
:my_house_population => 3
|
1013
|
-
)
|
1014
|
-
assert m.save
|
1015
|
-
assert_equal 0, NumericData.where("bank_balance > ?", 2000.0).count
|
1016
|
-
end
|
1017
|
-
|
1018
|
-
def test_numeric_fields
|
1019
|
-
puts "In base_test test_numeric_fields"
|
1020
|
-
m = NumericData.new(
|
1021
|
-
:bank_balance => 1586.43,
|
1022
|
-
:big_bank_balance => BigDecimal("1000234000567.95"),
|
1023
|
-
:world_population => 6000000000,
|
1024
|
-
:my_house_population => 3
|
1025
|
-
)
|
1026
|
-
assert m.save
|
1027
|
-
|
1028
|
-
m1 = NumericData.find(m.id)
|
1029
|
-
assert_not_nil m1
|
1030
|
-
|
1031
|
-
# As with migration_test.rb, we should make world_population >= 2**62
|
1032
|
-
# to cover 64-bit platforms and test it is a Bignum, but the main thing
|
1033
|
-
# is that it's an Integer.
|
1034
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1035
|
-
assert_kind_of Integer, m1.world_population
|
1036
|
-
else
|
1037
|
-
assert_equal 6000000000, m1.world_population
|
1038
|
-
|
1039
|
-
assert_kind_of Integer, m1.my_house_population
|
1040
|
-
assert_equal 3, m1.my_house_population
|
1041
|
-
|
1042
|
-
assert_kind_of BigDecimal, m1.bank_balance
|
1043
|
-
assert_equal BigDecimal("1586.43"), m1.bank_balance
|
1044
|
-
|
1045
|
-
assert_kind_of BigDecimal, m1.big_bank_balance
|
1046
|
-
assert_equal BigDecimal("1000234000567.95"), m1.big_bank_balance
|
1047
|
-
end
|
1048
|
-
|
1049
|
-
def test_numeric_fields_with_scale
|
1050
|
-
puts "In base_test test_numeric_fields_with_scale"
|
1051
|
-
m = NumericData.new(
|
1052
|
-
:bank_balance => 1586.43122334,
|
1053
|
-
:big_bank_balance => BigDecimal("234000567.952344"),
|
1054
|
-
:world_population => 6000000000,
|
1055
|
-
:my_house_population => 3
|
1056
|
-
)
|
1057
|
-
assert m.save
|
1058
|
-
|
1059
|
-
m1 = NumericData.find(m.id)
|
1060
|
-
assert_not_nil m1
|
1061
|
-
|
1062
|
-
# As with migration_test.rb, we should make world_population >= 2**62
|
1063
|
-
# to cover 64-bit platforms and test it is a Bignum, but the main thing
|
1064
|
-
# is that it's an Integer.
|
1065
|
-
assert_kind_of Integer, m1.world_population
|
1066
|
-
assert_equal 6000000000, m1.world_population
|
1067
|
-
|
1068
|
-
assert_kind_of Integer, m1.my_house_population
|
1069
|
-
assert_equal 3, m1.my_house_population
|
1070
|
-
|
1071
|
-
assert_kind_of BigDecimal, m1.bank_balance
|
1072
|
-
assert_equal BigDecimal("1586.43"), m1.bank_balance
|
1073
|
-
|
1074
|
-
assert_kind_of BigDecimal, m1.big_bank_balance
|
1075
|
-
assert_equal BigDecimal("234000567.95"), m1.big_bank_balance
|
1076
|
-
end
|
1077
|
-
|
1078
954
|
def test_auto_id
|
1079
|
-
puts "In base_test test_auto_id"
|
1080
955
|
auto = AutoId.new
|
1081
956
|
auto.save
|
1082
957
|
assert(auto.id > 0)
|
1083
958
|
end
|
1084
959
|
|
1085
960
|
def test_sql_injection_via_find
|
1086
|
-
puts "In base_test test_sql_injection_via_find"
|
1087
961
|
assert_raise(ActiveRecord::RecordNotFound, ActiveRecord::StatementInvalid) do
|
1088
962
|
Topic.find("123456 OR id > 0")
|
1089
963
|
end
|
1090
964
|
end
|
1091
965
|
|
1092
966
|
def test_column_name_properly_quoted
|
1093
|
-
puts "In base_test test_column_name_properly_quoted"
|
1094
967
|
col_record = ColumnName.new
|
1095
968
|
col_record.references = 40
|
1096
969
|
assert col_record.save
|
@@ -1101,35 +974,31 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1101
974
|
end
|
1102
975
|
|
1103
976
|
def test_quoting_arrays
|
1104
|
-
|
1105
|
-
replies = Reply.all.merge!(:where => [ "id IN (?)", topics(:first).replies.collect(&:id) ]).to_a
|
977
|
+
replies = Reply.all.merge!(where: [ "id IN (?)", topics(:first).replies.collect(&:id) ]).to_a
|
1106
978
|
assert_equal topics(:first).replies.size, replies.size
|
1107
979
|
|
1108
|
-
replies = Reply.all.merge!(:
|
980
|
+
replies = Reply.all.merge!(where: [ "id IN (?)", [] ]).to_a
|
1109
981
|
assert_equal 0, replies.size
|
1110
982
|
end
|
1111
983
|
|
1112
984
|
def test_quote
|
1113
|
-
puts "In base_test test_quote"
|
1114
985
|
author_name = "\\ \001 ' \n \\n \""
|
1115
|
-
topic = Topic.create(
|
986
|
+
topic = Topic.create("author_name" => author_name)
|
1116
987
|
assert_equal author_name, Topic.find(topic.id).author_name
|
1117
988
|
end
|
1118
989
|
|
1119
990
|
def test_toggle_attribute
|
1120
|
-
|
1121
|
-
assert !topics(:first).approved?
|
991
|
+
assert_not_predicate topics(:first), :approved?
|
1122
992
|
topics(:first).toggle!(:approved)
|
1123
|
-
|
993
|
+
assert_predicate topics(:first), :approved?
|
1124
994
|
topic = topics(:first)
|
1125
995
|
topic.toggle(:approved)
|
1126
|
-
|
996
|
+
assert_not_predicate topic, :approved?
|
1127
997
|
topic.reload
|
1128
|
-
|
998
|
+
assert_predicate topic, :approved?
|
1129
999
|
end
|
1130
1000
|
|
1131
1001
|
def test_reload
|
1132
|
-
puts "In base_test test_reload"
|
1133
1002
|
t1 = Topic.find(1)
|
1134
1003
|
t2 = Topic.find(1)
|
1135
1004
|
t1.title = "something else"
|
@@ -1138,15 +1007,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1138
1007
|
assert_equal t1.title, t2.title
|
1139
1008
|
end
|
1140
1009
|
|
1141
|
-
def test_reload_with_exclusive_scope
|
1142
|
-
puts "In base_test test_reload_with_exclusive_scope"
|
1143
|
-
dev = DeveloperCalledDavid.first
|
1144
|
-
dev.update!(name: "NotDavid" )
|
1145
|
-
assert_equal dev, dev.reload
|
1146
|
-
end
|
1147
|
-
|
1148
1010
|
def test_switching_between_table_name
|
1149
|
-
puts "In base_test test_switching_between_table_name"
|
1150
1011
|
k = Class.new(Joke)
|
1151
1012
|
|
1152
1013
|
assert_difference("GoodJoke.count") do
|
@@ -1158,8 +1019,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1158
1019
|
end
|
1159
1020
|
end
|
1160
1021
|
|
1161
|
-
def
|
1162
|
-
puts "In base_test test_clear_cash_when_setting_table_name"
|
1022
|
+
def test_clear_cache_when_setting_table_name
|
1163
1023
|
original_table_name = Joke.table_name
|
1164
1024
|
|
1165
1025
|
Joke.table_name = "funny_jokes"
|
@@ -1177,7 +1037,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1177
1037
|
end
|
1178
1038
|
|
1179
1039
|
def test_dont_clear_sequence_name_when_setting_explicitly
|
1180
|
-
puts "In base_test test_dont_clear_sequence_name_when_setting_explicitly"
|
1181
1040
|
k = Class.new(Joke)
|
1182
1041
|
k.sequence_name = "black_jokes_seq"
|
1183
1042
|
k.table_name = "cold_jokes"
|
@@ -1190,7 +1049,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1190
1049
|
end
|
1191
1050
|
|
1192
1051
|
def test_dont_clear_inheritance_column_when_setting_explicitly
|
1193
|
-
puts "In base_test test_dont_clear_inheritance_column_when_setting_explicitly"
|
1194
1052
|
k = Class.new(Joke)
|
1195
1053
|
k.inheritance_column = "my_type"
|
1196
1054
|
before_inherit = k.inheritance_column
|
@@ -1202,14 +1060,12 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1202
1060
|
end
|
1203
1061
|
|
1204
1062
|
def test_set_table_name_symbol_converted_to_string
|
1205
|
-
puts "In base_test test_set_table_name_symbol_converted_to_string"
|
1206
1063
|
k = Class.new(Joke)
|
1207
1064
|
k.table_name = :cold_jokes
|
1208
|
-
assert_equal
|
1065
|
+
assert_equal "cold_jokes", k.table_name
|
1209
1066
|
end
|
1210
1067
|
|
1211
1068
|
def test_quoted_table_name_after_set_table_name
|
1212
|
-
puts "In base_test test_quoted_table_name_after_set_table_name"
|
1213
1069
|
klass = Class.new(ActiveRecord::Base)
|
1214
1070
|
|
1215
1071
|
klass.table_name = "foo"
|
@@ -1222,15 +1078,13 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1222
1078
|
end
|
1223
1079
|
|
1224
1080
|
def test_set_table_name_with_inheritance
|
1225
|
-
|
1226
|
-
k = Class.new( ActiveRecord::Base )
|
1081
|
+
k = Class.new(ActiveRecord::Base)
|
1227
1082
|
def k.name; "Foo"; end
|
1228
1083
|
def k.table_name; super + "ks"; end
|
1229
1084
|
assert_equal "foosks", k.table_name
|
1230
1085
|
end
|
1231
1086
|
|
1232
1087
|
def test_sequence_name_with_abstract_class
|
1233
|
-
puts "In base_test test_sequence_name_with_abstract_class"
|
1234
1088
|
ak = Class.new(ActiveRecord::Base)
|
1235
1089
|
ak.abstract_class = true
|
1236
1090
|
k = Class.new(ak)
|
@@ -1241,111 +1095,78 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1241
1095
|
end
|
1242
1096
|
|
1243
1097
|
def test_count_with_join
|
1244
|
-
puts "In base_test test_count_with_join"
|
1245
1098
|
res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'"
|
1246
|
-
|
1247
1099
|
res2 = Post.where("posts.#{QUOTED_TYPE} = 'Post'").joins("LEFT JOIN comments ON posts.id=comments.post_id").count
|
1248
1100
|
assert_equal res, res2
|
1249
1101
|
|
1250
|
-
res3 = nil
|
1251
|
-
assert_nothing_raised do
|
1252
|
-
res3 = Post.where("posts.#{QUOTED_TYPE} = 'Post'").joins("LEFT JOIN comments ON posts.id=comments.post_id").count
|
1253
|
-
end
|
1254
|
-
assert_equal res, res3
|
1255
|
-
|
1256
1102
|
res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
|
1257
|
-
res5 =
|
1258
|
-
assert_nothing_raised do
|
1259
|
-
res5 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").count
|
1260
|
-
end
|
1261
|
-
|
1103
|
+
res5 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").count
|
1262
1104
|
assert_equal res4, res5
|
1263
1105
|
|
1264
1106
|
res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id"
|
1265
|
-
res7 =
|
1266
|
-
assert_nothing_raised do
|
1267
|
-
res7 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").distinct.count
|
1268
|
-
end
|
1107
|
+
res7 = Post.where("p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id").joins("p, comments co").select("p.id").distinct.count
|
1269
1108
|
assert_equal res6, res7
|
1270
1109
|
end
|
1271
1110
|
|
1272
1111
|
def test_no_limit_offset
|
1273
|
-
puts "In base_test test_no_limit_offset"
|
1274
1112
|
assert_nothing_raised do
|
1275
|
-
Developer.all.merge!(:
|
1113
|
+
Developer.all.merge!(offset: 2).to_a
|
1276
1114
|
end
|
1277
1115
|
end
|
1278
1116
|
|
1279
|
-
def test_find_last
|
1280
|
-
puts "In base_test test_find_last"
|
1281
|
-
last = Developer.last
|
1282
|
-
assert_equal last, Developer.all.merge!(:order => 'id desc').first
|
1283
|
-
end
|
1284
|
-
|
1285
1117
|
def test_last
|
1286
|
-
|
1287
|
-
assert_equal Developer.all.merge!(:order => 'id desc').first, Developer.last
|
1118
|
+
assert_equal Developer.all.merge!(order: "id desc").first, Developer.last
|
1288
1119
|
end
|
1289
1120
|
|
1290
1121
|
def test_all
|
1291
|
-
puts "In base_test test_all"
|
1292
1122
|
developers = Developer.all
|
1293
1123
|
assert_kind_of ActiveRecord::Relation, developers
|
1294
1124
|
assert_equal Developer.all, developers
|
1295
1125
|
end
|
1296
1126
|
|
1297
1127
|
def test_all_with_conditions
|
1298
|
-
|
1299
|
-
assert_equal Developer.all.merge!(:order => 'id desc').to_a, Developer.order('id desc').to_a
|
1128
|
+
assert_equal Developer.all.merge!(order: "id desc").to_a, Developer.order("id desc").to_a
|
1300
1129
|
end
|
1301
1130
|
|
1302
1131
|
def test_find_ordered_last
|
1303
|
-
|
1304
|
-
last
|
1305
|
-
assert_equal last, Developer.all.merge!(:order => 'developers.salary ASC').to_a.last
|
1132
|
+
last = Developer.order("developers.salary ASC").last
|
1133
|
+
assert_equal last, Developer.order("developers.salary": "ASC").to_a.last
|
1306
1134
|
end
|
1307
1135
|
|
1308
1136
|
def test_find_reverse_ordered_last
|
1309
|
-
|
1310
|
-
last
|
1311
|
-
assert_equal last, Developer.all.merge!(:order => 'developers.salary DESC').to_a.last
|
1137
|
+
last = Developer.order("developers.salary DESC").last
|
1138
|
+
assert_equal last, Developer.order("developers.salary": "DESC").to_a.last
|
1312
1139
|
end
|
1313
1140
|
|
1314
1141
|
def test_find_multiple_ordered_last
|
1315
|
-
|
1316
|
-
last
|
1317
|
-
assert_equal last, Developer.all.merge!(:order => 'developers.name, developers.salary DESC').to_a.last
|
1142
|
+
last = Developer.order("developers.name, developers.salary DESC").last
|
1143
|
+
assert_equal last, Developer.order(:"developers.name", "developers.salary": "DESC").to_a.last
|
1318
1144
|
end
|
1319
1145
|
|
1320
1146
|
def test_find_keeps_multiple_order_values
|
1321
|
-
|
1322
|
-
combined
|
1323
|
-
assert_equal combined, Developer.all.merge!(:order => ['developers.name', 'developers.salary']).to_a
|
1147
|
+
combined = Developer.order("developers.name, developers.salary").to_a
|
1148
|
+
assert_equal combined, Developer.order(:"developers.name", :"developers.salary").to_a
|
1324
1149
|
end
|
1325
1150
|
|
1326
1151
|
def test_find_keeps_multiple_group_values
|
1327
|
-
|
1328
|
-
combined
|
1329
|
-
assert_equal combined, Developer.all.merge!(:group => ['developers.name', 'developers.salary', 'developers.id', 'developers.created_at', 'developers.updated_at', 'developers.created_on', 'developers.updated_on']).to_a
|
1152
|
+
combined = Developer.merge(group: "developers.name, developers.salary, developers.id, developers.mentor_id, developers.firm_id, developers.legacy_created_at, developers.legacy_updated_at, developers.legacy_created_on, developers.legacy_updated_on").to_a
|
1153
|
+
assert_equal combined, Developer.merge(group: ["developers.name", "developers.salary", "developers.id", "developers.mentor_id", "developers.firm_id", "developers.created_at", "developers.updated_at", "developers.created_on", "developers.updated_on"]).to_a
|
1330
1154
|
end
|
1331
1155
|
|
1332
1156
|
def test_find_symbol_ordered_last
|
1333
|
-
|
1334
|
-
last
|
1335
|
-
assert_equal last, Developer.all.merge!(:order => :salary).to_a.last
|
1157
|
+
last = Developer.all.merge!(order: :salary).last
|
1158
|
+
assert_equal last, Developer.all.merge!(order: :salary).to_a.last
|
1336
1159
|
end
|
1337
1160
|
|
1338
1161
|
def test_abstract_class_table_name
|
1339
|
-
puts "In base_test test_abstract_class_table_name"
|
1340
1162
|
assert_nil AbstractCompany.table_name
|
1341
1163
|
end
|
1342
1164
|
|
1343
1165
|
def test_find_on_abstract_base_class_doesnt_use_type_condition
|
1344
|
-
puts "In base_test test_find_on_abstract_base_class_doesnt_use_type_condition"
|
1345
1166
|
old_class = LooseDescendant
|
1346
1167
|
Object.send :remove_const, :LooseDescendant
|
1347
1168
|
|
1348
|
-
descendant = old_class.create! :
|
1169
|
+
descendant = old_class.create! first_name: "bob"
|
1349
1170
|
assert_not_nil LoosePerson.find(descendant.id), "Should have found instance of LooseDescendant when finding abstract LoosePerson: #{descendant.inspect}"
|
1350
1171
|
ensure
|
1351
1172
|
unless Object.const_defined?(:LooseDescendant)
|
@@ -1354,22 +1175,20 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1354
1175
|
end
|
1355
1176
|
|
1356
1177
|
def test_assert_queries
|
1357
|
-
|
1358
|
-
query = lambda { ActiveRecord::Base.connection.execute 'select count(*) from developers' }
|
1178
|
+
query = lambda { ActiveRecord::Base.connection.execute "select count(*) from developers" }
|
1359
1179
|
assert_queries(2) { 2.times { query.call } }
|
1360
1180
|
assert_queries 1, &query
|
1361
1181
|
assert_no_queries { assert true }
|
1362
1182
|
end
|
1363
1183
|
|
1364
1184
|
def test_benchmark_with_log_level
|
1365
|
-
puts "In base_test test_benchmark_with_log_level"
|
1366
1185
|
original_logger = ActiveRecord::Base.logger
|
1367
1186
|
log = StringIO.new
|
1368
1187
|
ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
|
1369
1188
|
ActiveRecord::Base.logger.level = Logger::WARN
|
1370
|
-
ActiveRecord::Base.benchmark("Debug Topic Count", :
|
1371
|
-
ActiveRecord::Base.benchmark("Warn Topic Count", :
|
1372
|
-
ActiveRecord::Base.benchmark("Error Topic Count", :
|
1189
|
+
ActiveRecord::Base.benchmark("Debug Topic Count", level: :debug) { Topic.count }
|
1190
|
+
ActiveRecord::Base.benchmark("Warn Topic Count", level: :warn) { Topic.count }
|
1191
|
+
ActiveRecord::Base.benchmark("Error Topic Count", level: :error) { Topic.count }
|
1373
1192
|
assert_no_match(/Debug Topic Count/, log.string)
|
1374
1193
|
assert_match(/Warn Topic Count/, log.string)
|
1375
1194
|
assert_match(/Error Topic Count/, log.string)
|
@@ -1378,33 +1197,33 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1378
1197
|
end
|
1379
1198
|
|
1380
1199
|
def test_benchmark_with_use_silence
|
1381
|
-
puts "In base_test test_benchmark_with_use_silence"
|
1382
1200
|
original_logger = ActiveRecord::Base.logger
|
1383
1201
|
log = StringIO.new
|
1384
1202
|
ActiveRecord::Base.logger = ActiveSupport::Logger.new(log)
|
1385
1203
|
ActiveRecord::Base.logger.level = Logger::DEBUG
|
1386
|
-
ActiveRecord::Base.benchmark("Logging", :
|
1204
|
+
ActiveRecord::Base.benchmark("Logging", level: :debug, silence: false) { ActiveRecord::Base.logger.debug "Quiet" }
|
1387
1205
|
assert_match(/Quiet/, log.string)
|
1388
1206
|
ensure
|
1389
1207
|
ActiveRecord::Base.logger = original_logger
|
1390
1208
|
end
|
1391
1209
|
|
1392
1210
|
def test_clear_cache!
|
1393
|
-
puts "In base_test test_clear_cache"
|
1394
1211
|
# preheat cache
|
1395
|
-
c1 = Post.connection.schema_cache.columns(
|
1212
|
+
c1 = Post.connection.schema_cache.columns("posts")
|
1213
|
+
assert_not_equal 0, Post.connection.schema_cache.size
|
1214
|
+
|
1396
1215
|
ActiveRecord::Base.clear_cache!
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1216
|
+
assert_equal 0, Post.connection.schema_cache.size
|
1217
|
+
|
1218
|
+
c2 = Post.connection.schema_cache.columns("posts")
|
1219
|
+
assert_not_equal 0, Post.connection.schema_cache.size
|
1220
|
+
|
1401
1221
|
assert_equal c1, c2
|
1402
1222
|
end
|
1403
1223
|
|
1404
1224
|
def test_current_scope_is_reset
|
1405
|
-
puts "In base_test test_current_scope_is_reset"
|
1406
1225
|
Object.const_set :UnloadablePost, Class.new(ActiveRecord::Base)
|
1407
|
-
UnloadablePost.
|
1226
|
+
UnloadablePost.current_scope = UnloadablePost.all
|
1408
1227
|
|
1409
1228
|
UnloadablePost.unloadable
|
1410
1229
|
klass = UnloadablePost
|
@@ -1412,20 +1231,28 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1412
1231
|
ActiveSupport::Dependencies.remove_unloadable_constants!
|
1413
1232
|
assert_nil ActiveRecord::Scoping::ScopeRegistry.value_for(:current_scope, klass)
|
1414
1233
|
ensure
|
1415
|
-
Object.class_eval{ remove_const :UnloadablePost } if defined?(UnloadablePost)
|
1234
|
+
Object.class_eval { remove_const :UnloadablePost } if defined?(UnloadablePost)
|
1416
1235
|
end
|
1417
1236
|
|
1418
1237
|
def test_marshal_round_trip
|
1419
|
-
puts "In base_test test_marshal_round_trip"
|
1420
1238
|
expected = posts(:welcome)
|
1421
1239
|
marshalled = Marshal.dump(expected)
|
1422
|
-
actual
|
1240
|
+
actual = Marshal.load(marshalled)
|
1241
|
+
|
1242
|
+
assert_equal expected.attributes, actual.attributes
|
1243
|
+
end
|
1244
|
+
|
1245
|
+
def test_marshal_inspected_round_trip
|
1246
|
+
expected = posts(:welcome)
|
1247
|
+
expected.inspect
|
1248
|
+
|
1249
|
+
marshalled = Marshal.dump(expected)
|
1250
|
+
actual = Marshal.load(marshalled)
|
1423
1251
|
|
1424
1252
|
assert_equal expected.attributes, actual.attributes
|
1425
1253
|
end
|
1426
1254
|
|
1427
1255
|
def test_marshal_new_record_round_trip
|
1428
|
-
puts "In base_test test_marshal_new_record_round_trip"
|
1429
1256
|
marshalled = Marshal.dump(Post.new)
|
1430
1257
|
post = Marshal.load(marshalled)
|
1431
1258
|
|
@@ -1433,7 +1260,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1433
1260
|
end
|
1434
1261
|
|
1435
1262
|
def test_marshalling_with_associations
|
1436
|
-
puts "In base_test test_marshalling_with_associations"
|
1437
1263
|
post = Post.new
|
1438
1264
|
post.comments.build
|
1439
1265
|
|
@@ -1443,9 +1269,23 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1443
1269
|
assert_equal 1, post.comments.length
|
1444
1270
|
end
|
1445
1271
|
|
1272
|
+
if current_adapter?(:Mysql2Adapter)
|
1273
|
+
def test_marshal_load_legacy_6_0_record_mysql
|
1274
|
+
path = File.expand_path(
|
1275
|
+
"support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump",
|
1276
|
+
TEST_ROOT
|
1277
|
+
)
|
1278
|
+
topic = Marshal.load(File.read(path))
|
1279
|
+
|
1280
|
+
assert_not_predicate topic, :new_record?
|
1281
|
+
assert_equal 1, topic.id
|
1282
|
+
assert_equal "The First Topic", topic.title
|
1283
|
+
assert_equal "Have a nice day", topic.content
|
1284
|
+
end
|
1285
|
+
end
|
1286
|
+
|
1446
1287
|
if Process.respond_to?(:fork) && !in_memory_db?
|
1447
1288
|
def test_marshal_between_processes
|
1448
|
-
puts "In base_test test_marshal_between_processes"
|
1449
1289
|
# Define a new model to ensure there are no caches
|
1450
1290
|
if self.class.const_defined?("Post", false)
|
1451
1291
|
flunk "there should be no post constant"
|
@@ -1472,11 +1312,12 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1472
1312
|
wr.close
|
1473
1313
|
assert Marshal.load rd.read
|
1474
1314
|
rd.close
|
1315
|
+
ensure
|
1316
|
+
self.class.send(:remove_const, "Post") if self.class.const_defined?("Post", false)
|
1475
1317
|
end
|
1476
1318
|
end
|
1477
1319
|
|
1478
1320
|
def test_marshalling_new_record_round_trip_with_associations
|
1479
|
-
puts "In base_test test_marshalling_new_record_round_trip_with_associations"
|
1480
1321
|
post = Post.new
|
1481
1322
|
post.comments.build
|
1482
1323
|
|
@@ -1486,114 +1327,143 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1486
1327
|
end
|
1487
1328
|
|
1488
1329
|
def test_attribute_names
|
1489
|
-
|
1490
|
-
assert_equal
|
1491
|
-
Company.attribute_names
|
1330
|
+
expected = ["id", "type", "firm_id", "firm_name", "name", "client_of", "rating", "account_id", "description", "metadata"]
|
1331
|
+
assert_equal expected, Company.attribute_names
|
1492
1332
|
end
|
1493
1333
|
|
1494
1334
|
def test_has_attribute
|
1495
|
-
|
1496
|
-
assert Company.has_attribute?(
|
1497
|
-
assert Company.has_attribute?(
|
1498
|
-
assert Company.has_attribute?(
|
1499
|
-
|
1500
|
-
assert_not Company.has_attribute?(
|
1335
|
+
assert Company.has_attribute?("id")
|
1336
|
+
assert Company.has_attribute?("type")
|
1337
|
+
assert Company.has_attribute?("name")
|
1338
|
+
assert Company.has_attribute?("new_name")
|
1339
|
+
assert Company.has_attribute?("metadata")
|
1340
|
+
assert_not Company.has_attribute?("lastname")
|
1341
|
+
assert_not Company.has_attribute?("age")
|
1342
|
+
|
1343
|
+
company = Company.new
|
1344
|
+
assert company.has_attribute?("id")
|
1345
|
+
assert company.has_attribute?("type")
|
1346
|
+
assert company.has_attribute?("name")
|
1347
|
+
assert company.has_attribute?("new_name")
|
1348
|
+
assert company.has_attribute?("metadata")
|
1349
|
+
assert_not company.has_attribute?("lastname")
|
1350
|
+
assert_not company.has_attribute?("age")
|
1501
1351
|
end
|
1502
1352
|
|
1503
1353
|
def test_has_attribute_with_symbol
|
1504
|
-
puts "In base_test test_has_attribute_with_symbol"
|
1505
1354
|
assert Company.has_attribute?(:id)
|
1355
|
+
assert Company.has_attribute?(:type)
|
1356
|
+
assert Company.has_attribute?(:name)
|
1357
|
+
assert Company.has_attribute?(:new_name)
|
1358
|
+
assert Company.has_attribute?(:metadata)
|
1359
|
+
assert_not Company.has_attribute?(:lastname)
|
1506
1360
|
assert_not Company.has_attribute?(:age)
|
1361
|
+
|
1362
|
+
company = Company.new
|
1363
|
+
assert company.has_attribute?(:id)
|
1364
|
+
assert company.has_attribute?(:type)
|
1365
|
+
assert company.has_attribute?(:name)
|
1366
|
+
assert company.has_attribute?(:new_name)
|
1367
|
+
assert company.has_attribute?(:metadata)
|
1368
|
+
assert_not company.has_attribute?(:lastname)
|
1369
|
+
assert_not company.has_attribute?(:age)
|
1507
1370
|
end
|
1508
1371
|
|
1509
1372
|
def test_attribute_names_on_table_not_exists
|
1510
|
-
puts "In base_test test_attribute_names_on_table_not_exists"
|
1511
1373
|
assert_equal [], NonExistentTable.attribute_names
|
1512
1374
|
end
|
1513
1375
|
|
1514
1376
|
def test_attribute_names_on_abstract_class
|
1515
|
-
puts "In base_test test_attribute_names_on_abstract_class"
|
1516
1377
|
assert_equal [], AbstractCompany.attribute_names
|
1517
1378
|
end
|
1518
1379
|
|
1519
1380
|
def test_touch_should_raise_error_on_a_new_object
|
1520
|
-
|
1521
|
-
company = Company.new(:rating => 1, :name => "37signals", :firm_name => "37signals")
|
1381
|
+
company = Company.new(rating: 1, name: "37signals", firm_name: "37signals")
|
1522
1382
|
assert_raises(ActiveRecord::ActiveRecordError) do
|
1523
1383
|
company.touch :updated_at
|
1524
1384
|
end
|
1525
1385
|
end
|
1526
1386
|
|
1527
|
-
def test_uniq_delegates_to_scoped
|
1528
|
-
puts "In base_test test_uniq_delegates_to_scoped"
|
1529
|
-
assert_deprecated do
|
1530
|
-
assert_equal Bird.all.distinct, Bird.uniq
|
1531
|
-
end
|
1532
|
-
end
|
1533
|
-
|
1534
1387
|
def test_distinct_delegates_to_scoped
|
1535
|
-
puts "In base_test test_distinct_delegates_to_scoped"
|
1536
1388
|
assert_equal Bird.all.distinct, Bird.distinct
|
1537
1389
|
end
|
1538
1390
|
|
1539
1391
|
def test_table_name_with_2_abstract_subclasses
|
1540
|
-
puts "In base_test test_table_name_with_2_abstract_subclasses"
|
1541
1392
|
assert_equal "photos", Photo.table_name
|
1542
1393
|
end
|
1543
1394
|
|
1544
1395
|
def test_column_types_typecast
|
1545
|
-
puts "In base_test test_column_types_typecast"
|
1546
1396
|
topic = Topic.first
|
1547
|
-
assert_not_equal
|
1397
|
+
assert_not_equal "t.lo", topic.author_name
|
1548
1398
|
|
1549
1399
|
attrs = topic.attributes.dup
|
1550
|
-
attrs.delete
|
1400
|
+
attrs.delete "id"
|
1551
1401
|
|
1552
1402
|
typecast = Class.new(ActiveRecord::Type::Value) {
|
1553
|
-
def cast
|
1403
|
+
def cast(value)
|
1554
1404
|
"t.lo"
|
1555
1405
|
end
|
1556
1406
|
}
|
1557
1407
|
|
1558
|
-
types = {
|
1408
|
+
types = { "author_name" => typecast.new }
|
1559
1409
|
topic = Topic.instantiate(attrs, types)
|
1560
1410
|
|
1561
|
-
assert_equal
|
1411
|
+
assert_equal "t.lo", topic.author_name
|
1562
1412
|
end
|
1563
1413
|
|
1564
1414
|
def test_typecasting_aliases
|
1565
|
-
|
1566
|
-
assert_equal 10, Topic.select('10 as tenderlove').first.tenderlove
|
1415
|
+
assert_equal 10, Topic.select("10 as tenderlove").first.tenderlove
|
1567
1416
|
end
|
1568
1417
|
|
1569
1418
|
def test_slice
|
1570
|
-
|
1571
|
-
company = Company.new(:rating => 1, :name => "37signals", :firm_name => "37signals")
|
1419
|
+
company = Company.new(rating: 1, name: "37signals", firm_name: "37signals")
|
1572
1420
|
hash = company.slice(:name, :rating, "arbitrary_method")
|
1573
1421
|
assert_equal hash[:name], company.name
|
1574
|
-
assert_equal hash[
|
1422
|
+
assert_equal hash["name"], company.name
|
1575
1423
|
assert_equal hash[:rating], company.rating
|
1576
|
-
assert_equal hash[
|
1424
|
+
assert_equal hash["arbitrary_method"], company.arbitrary_method
|
1577
1425
|
assert_equal hash[:arbitrary_method], company.arbitrary_method
|
1578
1426
|
assert_nil hash[:firm_name]
|
1579
|
-
assert_nil hash[
|
1427
|
+
assert_nil hash["firm_name"]
|
1428
|
+
end
|
1429
|
+
|
1430
|
+
def test_slice_accepts_array_argument
|
1431
|
+
attrs = {
|
1432
|
+
title: "slice",
|
1433
|
+
author_name: "@Cohen-Carlisle",
|
1434
|
+
content: "accept arrays so I don't have to splat"
|
1435
|
+
}.with_indifferent_access
|
1436
|
+
topic = Topic.new(attrs)
|
1437
|
+
assert_equal attrs, topic.slice(attrs.keys)
|
1438
|
+
end
|
1439
|
+
|
1440
|
+
def test_values_at
|
1441
|
+
company = Company.new(name: "37signals", rating: 1)
|
1442
|
+
|
1443
|
+
assert_equal [ "37signals", 1, "I am Jack's profound disappointment" ],
|
1444
|
+
company.values_at(:name, :rating, :arbitrary_method)
|
1445
|
+
assert_equal [ "I am Jack's profound disappointment", 1, "37signals" ],
|
1446
|
+
company.values_at(:arbitrary_method, :rating, :name)
|
1447
|
+
end
|
1448
|
+
|
1449
|
+
def test_values_at_accepts_array_argument
|
1450
|
+
topic = Topic.new(title: "Budget", author_name: "Jason")
|
1451
|
+
|
1452
|
+
assert_equal %w( Budget Jason ), topic.values_at(%w( title author_name ))
|
1580
1453
|
end
|
1581
1454
|
|
1582
1455
|
def test_default_values_are_deeply_dupped
|
1583
|
-
puts "In base_test test_default_values_are_deeply_dupped"
|
1584
1456
|
company = Company.new
|
1585
1457
|
company.description << "foo"
|
1586
1458
|
assert_equal "", Company.new.description
|
1587
1459
|
end
|
1588
1460
|
|
1589
1461
|
test "scoped can take a values hash" do
|
1590
|
-
puts "In base_test scoped can take a values hash"
|
1591
1462
|
klass = Class.new(ActiveRecord::Base)
|
1592
|
-
assert_equal [
|
1463
|
+
assert_equal ["foo"], klass.all.merge!(select: "foo").select_values
|
1593
1464
|
end
|
1594
1465
|
|
1595
1466
|
test "connection_handler can be overridden" do
|
1596
|
-
puts "In base_test connection_handler can be overridden"
|
1597
1467
|
klass = Class.new(ActiveRecord::Base)
|
1598
1468
|
orig_handler = klass.connection_handler
|
1599
1469
|
new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
@@ -1610,7 +1480,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1610
1480
|
end
|
1611
1481
|
|
1612
1482
|
test "new threads get default the default connection handler" do
|
1613
|
-
puts "In base_test new threads get default the default connection handler"
|
1614
1483
|
klass = Class.new(ActiveRecord::Base)
|
1615
1484
|
orig_handler = klass.connection_handler
|
1616
1485
|
handler = nil
|
@@ -1626,7 +1495,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1626
1495
|
end
|
1627
1496
|
|
1628
1497
|
test "changing a connection handler in a main thread does not poison the other threads" do
|
1629
|
-
puts "In base_test changing a connection handler in a main thread does not poison the other threads"
|
1630
1498
|
klass = Class.new(ActiveRecord::Base)
|
1631
1499
|
orig_handler = klass.connection_handler
|
1632
1500
|
new_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
@@ -1655,23 +1523,24 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1655
1523
|
# AR::Base objects. If the future has made this irrelevant, feel free to
|
1656
1524
|
# delete this.
|
1657
1525
|
test "records without an id have unique hashes" do
|
1658
|
-
puts "In base_test records without an id have unique hashes"
|
1659
1526
|
assert_not_equal Post.new.hash, Post.new.hash
|
1660
1527
|
end
|
1661
1528
|
|
1529
|
+
test "records of different classes have different hashes" do
|
1530
|
+
assert_not_equal Post.new(id: 1).hash, Developer.new(id: 1).hash
|
1531
|
+
end
|
1532
|
+
|
1662
1533
|
test "resetting column information doesn't remove attribute methods" do
|
1663
|
-
puts "In base_test changing a connection handler in a main thread does not poison the other threads"
|
1664
1534
|
topic = topics(:first)
|
1665
1535
|
|
1666
|
-
|
1536
|
+
assert_not_predicate topic, :id_changed?
|
1667
1537
|
|
1668
1538
|
Topic.reset_column_information
|
1669
1539
|
|
1670
|
-
|
1540
|
+
assert_not_predicate topic, :id_changed?
|
1671
1541
|
end
|
1672
1542
|
|
1673
1543
|
test "ignored columns are not present in columns_hash" do
|
1674
|
-
puts "In base_test ignored columns are not present in columns_hash"
|
1675
1544
|
cache_columns = Developer.connection.schema_cache.columns_hash(Developer.table_name)
|
1676
1545
|
assert_includes cache_columns.keys, "first_name"
|
1677
1546
|
assert_not_includes Developer.columns_hash.keys, "first_name"
|
@@ -1679,35 +1548,223 @@ class BasicsTest < ActiveRecord::TestCase
|
|
1679
1548
|
assert_not_includes SymbolIgnoredDeveloper.columns_hash.keys, "first_name"
|
1680
1549
|
end
|
1681
1550
|
|
1551
|
+
test ".columns_hash raises an error if the record has an empty table name" do
|
1552
|
+
expected_message = "FirstAbstractClass has no table configured. Set one with FirstAbstractClass.table_name="
|
1553
|
+
exception = assert_raises(ActiveRecord::TableNotSpecified) do
|
1554
|
+
FirstAbstractClass.columns_hash
|
1555
|
+
end
|
1556
|
+
assert_equal expected_message, exception.message
|
1557
|
+
end
|
1558
|
+
|
1682
1559
|
test "ignored columns have no attribute methods" do
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
refute SymbolIgnoredDeveloper.new.respond_to?(:first_name?)
|
1560
|
+
assert_not_respond_to Developer.new, :first_name
|
1561
|
+
assert_not_respond_to Developer.new, :first_name=
|
1562
|
+
assert_not_respond_to Developer.new, :first_name?
|
1563
|
+
assert_not_respond_to SubDeveloper.new, :first_name
|
1564
|
+
assert_not_respond_to SubDeveloper.new, :first_name=
|
1565
|
+
assert_not_respond_to SubDeveloper.new, :first_name?
|
1566
|
+
assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name
|
1567
|
+
assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name=
|
1568
|
+
assert_not_respond_to SymbolIgnoredDeveloper.new, :first_name?
|
1693
1569
|
end
|
1694
1570
|
|
1695
1571
|
test "ignored columns don't prevent explicit declaration of attribute methods" do
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
assert SymbolIgnoredDeveloper.new.respond_to?(:last_name?)
|
1572
|
+
assert_respond_to Developer.new, :last_name
|
1573
|
+
assert_respond_to Developer.new, :last_name=
|
1574
|
+
assert_respond_to Developer.new, :last_name?
|
1575
|
+
assert_respond_to SubDeveloper.new, :last_name
|
1576
|
+
assert_respond_to SubDeveloper.new, :last_name=
|
1577
|
+
assert_respond_to SubDeveloper.new, :last_name?
|
1578
|
+
assert_respond_to SymbolIgnoredDeveloper.new, :last_name
|
1579
|
+
assert_respond_to SymbolIgnoredDeveloper.new, :last_name=
|
1580
|
+
assert_respond_to SymbolIgnoredDeveloper.new, :last_name?
|
1706
1581
|
end
|
1707
1582
|
|
1708
1583
|
test "ignored columns are stored as an array of string" do
|
1709
|
-
puts "In base_test ignored columns are stored as an array of string"
|
1710
1584
|
assert_equal(%w(first_name last_name), Developer.ignored_columns)
|
1711
1585
|
assert_equal(%w(first_name last_name), SymbolIgnoredDeveloper.ignored_columns)
|
1712
1586
|
end
|
1587
|
+
|
1588
|
+
test "when #reload called, ignored columns' attribute methods are not defined" do
|
1589
|
+
developer = Developer.create!(name: "Developer")
|
1590
|
+
assert_not_respond_to developer, :first_name
|
1591
|
+
assert_not_respond_to developer, :first_name=
|
1592
|
+
|
1593
|
+
developer.reload
|
1594
|
+
|
1595
|
+
assert_not_respond_to developer, :first_name
|
1596
|
+
assert_not_respond_to developer, :first_name=
|
1597
|
+
end
|
1598
|
+
|
1599
|
+
test "when ignored attribute is loaded, cast type should be preferred over DB type" do
|
1600
|
+
developer = AttributedDeveloper.create
|
1601
|
+
developer.update_column :name, "name"
|
1602
|
+
|
1603
|
+
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
1604
|
+
assert_equal "Developer: name", loaded_developer.name
|
1605
|
+
end
|
1606
|
+
|
1607
|
+
test "when assigning new ignored columns it invalidates cache for column names" do
|
1608
|
+
assert_not_includes ColumnNamesCachedDeveloper.column_names, "name"
|
1609
|
+
end
|
1610
|
+
|
1611
|
+
test "ignored columns not included in SELECT" do
|
1612
|
+
query = Developer.all.to_sql.downcase
|
1613
|
+
|
1614
|
+
# ignored column
|
1615
|
+
assert_not query.include?("first_name")
|
1616
|
+
|
1617
|
+
# regular column
|
1618
|
+
assert query.include?("name")
|
1619
|
+
end
|
1620
|
+
|
1621
|
+
test "column names are quoted when using #from clause and model has ignored columns" do
|
1622
|
+
assert_not_empty Developer.ignored_columns
|
1623
|
+
query = Developer.from("developers").to_sql
|
1624
|
+
quoted_id = "#{Developer.quoted_table_name}.#{Developer.quoted_primary_key}"
|
1625
|
+
|
1626
|
+
assert_match(/SELECT #{Regexp.escape(quoted_id)}.* FROM developers/, query)
|
1627
|
+
end
|
1628
|
+
|
1629
|
+
test "using table name qualified column names unless having SELECT list explicitly" do
|
1630
|
+
assert_equal developers(:david), Developer.from("developers").joins(:shared_computers).take
|
1631
|
+
end
|
1632
|
+
|
1633
|
+
test "protected environments by default is an array with production" do
|
1634
|
+
assert_equal ["production"], ActiveRecord::Base.protected_environments
|
1635
|
+
end
|
1636
|
+
|
1637
|
+
def test_protected_environments_are_stored_as_an_array_of_string
|
1638
|
+
previous_protected_environments = ActiveRecord::Base.protected_environments
|
1639
|
+
ActiveRecord::Base.protected_environments = [:staging, "production"]
|
1640
|
+
assert_equal ["staging", "production"], ActiveRecord::Base.protected_environments
|
1641
|
+
ensure
|
1642
|
+
ActiveRecord::Base.protected_environments = previous_protected_environments
|
1643
|
+
end
|
1644
|
+
|
1645
|
+
test "cannot call connects_to on non-abstract or non-ActiveRecord::Base classes" do
|
1646
|
+
error = assert_raises(NotImplementedError) do
|
1647
|
+
Bird.connects_to(database: { writing: :arunit })
|
1648
|
+
end
|
1649
|
+
|
1650
|
+
assert_equal "`connects_to` can only be called on ActiveRecord::Base or abstract classes", error.message
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
test "cannot call connected_to on subclasses of ActiveRecord::Base with legacy connection handling" do
|
1654
|
+
old_value = ActiveRecord::Base.legacy_connection_handling
|
1655
|
+
ActiveRecord::Base.legacy_connection_handling = true
|
1656
|
+
|
1657
|
+
error = assert_raises(NotImplementedError) do
|
1658
|
+
Bird.connected_to(role: :reading) { }
|
1659
|
+
end
|
1660
|
+
|
1661
|
+
assert_equal "`connected_to` can only be called on ActiveRecord::Base with legacy connection handling.", error.message
|
1662
|
+
ensure
|
1663
|
+
clean_up_legacy_connection_handlers
|
1664
|
+
ActiveRecord::Base.legacy_connection_handling = old_value
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
test "cannot call connected_to with role and shard on non-abstract classes" do
|
1668
|
+
error = assert_raises(NotImplementedError) do
|
1669
|
+
Bird.connected_to(role: :reading, shard: :default) { }
|
1670
|
+
end
|
1671
|
+
|
1672
|
+
assert_equal "calling `connected_to` is only allowed on ActiveRecord::Base or abstract classes.", error.message
|
1673
|
+
end
|
1674
|
+
|
1675
|
+
test "can call connected_to with role and shard on abstract classes" do
|
1676
|
+
SecondAbstractClass.connected_to(role: :reading, shard: :default) do
|
1677
|
+
assert SecondAbstractClass.connected_to?(role: :reading, shard: :default)
|
1678
|
+
end
|
1679
|
+
end
|
1680
|
+
|
1681
|
+
test "cannot call connected_to on the abstract class that did not establish the connection" do
|
1682
|
+
error = assert_raises(NotImplementedError) do
|
1683
|
+
ThirdAbstractClass.connected_to(role: :reading) { }
|
1684
|
+
end
|
1685
|
+
|
1686
|
+
assert_equal "calling `connected_to` is only allowed on the abstract class that established the connection.", error.message
|
1687
|
+
end
|
1688
|
+
|
1689
|
+
test "#connecting_to with role" do
|
1690
|
+
SecondAbstractClass.connecting_to(role: :reading)
|
1691
|
+
|
1692
|
+
assert SecondAbstractClass.connected_to?(role: :reading)
|
1693
|
+
assert SecondAbstractClass.current_preventing_writes
|
1694
|
+
ensure
|
1695
|
+
ActiveRecord::Base.connected_to_stack.pop
|
1696
|
+
end
|
1697
|
+
|
1698
|
+
test "#connecting_to with role and shard" do
|
1699
|
+
SecondAbstractClass.connecting_to(role: :reading, shard: :default)
|
1700
|
+
|
1701
|
+
assert SecondAbstractClass.connected_to?(role: :reading, shard: :default)
|
1702
|
+
ensure
|
1703
|
+
ActiveRecord::Base.connected_to_stack.pop
|
1704
|
+
end
|
1705
|
+
|
1706
|
+
test "#connecting_to with prevent_writes" do
|
1707
|
+
SecondAbstractClass.connecting_to(role: :writing, prevent_writes: true)
|
1708
|
+
|
1709
|
+
assert SecondAbstractClass.connected_to?(role: :writing)
|
1710
|
+
assert SecondAbstractClass.current_preventing_writes
|
1711
|
+
ensure
|
1712
|
+
ActiveRecord::Base.connected_to_stack.pop
|
1713
|
+
end
|
1714
|
+
|
1715
|
+
test "#connecting_to doesn't work with legacy connection handling" do
|
1716
|
+
old_value = ActiveRecord::Base.legacy_connection_handling
|
1717
|
+
ActiveRecord::Base.legacy_connection_handling = true
|
1718
|
+
|
1719
|
+
assert_raises NotImplementedError do
|
1720
|
+
SecondAbstractClass.connecting_to(role: :writing, prevent_writes: true)
|
1721
|
+
end
|
1722
|
+
ensure
|
1723
|
+
ActiveRecord::Base.legacy_connection_handling = old_value
|
1724
|
+
end
|
1725
|
+
|
1726
|
+
test "#connected_to_many doesn't work with legacy connection handling" do
|
1727
|
+
old_value = ActiveRecord::Base.legacy_connection_handling
|
1728
|
+
ActiveRecord::Base.legacy_connection_handling = true
|
1729
|
+
|
1730
|
+
assert_raises NotImplementedError do
|
1731
|
+
ActiveRecord::Base.connected_to_many([SecondAbstractClass], role: :writing)
|
1732
|
+
end
|
1733
|
+
ensure
|
1734
|
+
ActiveRecord::Base.legacy_connection_handling = old_value
|
1735
|
+
end
|
1736
|
+
|
1737
|
+
test "#connected_to_many cannot be called on anything but ActiveRecord::Base" do
|
1738
|
+
assert_raises NotImplementedError do
|
1739
|
+
SecondAbstractClass.connected_to_many([SecondAbstractClass], role: :writing)
|
1740
|
+
end
|
1741
|
+
end
|
1742
|
+
|
1743
|
+
test "#connected_to_many cannot be called with classes that include ActiveRecord::Base" do
|
1744
|
+
assert_raises NotImplementedError do
|
1745
|
+
ActiveRecord::Base.connected_to_many([ActiveRecord::Base], role: :writing)
|
1746
|
+
end
|
1747
|
+
end
|
1748
|
+
|
1749
|
+
test "#connected_to_many sets prevent_writes if role is reading" do
|
1750
|
+
ActiveRecord::Base.connected_to_many([SecondAbstractClass], role: :reading) do
|
1751
|
+
assert SecondAbstractClass.current_preventing_writes
|
1752
|
+
assert_not ActiveRecord::Base.current_preventing_writes
|
1753
|
+
end
|
1754
|
+
end
|
1755
|
+
|
1756
|
+
test "#connected_to_many with a single argument for classes" do
|
1757
|
+
ActiveRecord::Base.connected_to_many(SecondAbstractClass, role: :reading) do
|
1758
|
+
assert SecondAbstractClass.current_preventing_writes
|
1759
|
+
assert_not ActiveRecord::Base.current_preventing_writes
|
1760
|
+
end
|
1761
|
+
end
|
1762
|
+
|
1763
|
+
test "#connected_to_many with a multiple classes without brackets works" do
|
1764
|
+
ActiveRecord::Base.connected_to_many(FirstAbstractClass, SecondAbstractClass, role: :reading) do
|
1765
|
+
assert FirstAbstractClass.current_preventing_writes
|
1766
|
+
assert SecondAbstractClass.current_preventing_writes
|
1767
|
+
assert_not ActiveRecord::Base.current_preventing_writes
|
1768
|
+
end
|
1769
|
+
end
|
1713
1770
|
end
|