ibm_db 5.2.0-x86-mingw32 → 5.4.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +9 -0
- data/LICENSE +55 -18
- data/README +1 -1
- data/debug.log +1 -0
- data/ext/Makefile +28 -24
- data/ext/ibm_db.c +66 -65
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +26 -24
- data/ext/ruby_ibm_db_cli.c +1 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +1520 -1282
- data/lib/ibm_db.so +1 -0
- data/lib/mswin32/ibm_db.rb +3 -1
- data/lib/mswin32/rb3x/i386/ruby30/ibm_db.so +0 -0
- data/lib/mswin32/rb3x/i386/ruby31/ibm_db.so +0 -0
- data/test/active_record/connection_adapters/fake_adapter.rb +5 -2
- data/test/activejob/destroy_association_async_test.rb +305 -0
- data/test/activejob/destroy_async_job_not_present_test.rb +31 -0
- data/test/activejob/helper.rb +15 -0
- data/test/assets/schema_dump_5_1.yml +345 -0
- data/test/cases/adapter_prevent_writes_test.rb +334 -0
- data/test/cases/adapter_test.rb +432 -218
- data/test/cases/adapters/mysql2/active_schema_test.rb +85 -75
- data/test/cases/adapters/mysql2/auto_increment_test.rb +34 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +5 -3
- data/test/cases/adapters/mysql2/boolean_test.rb +6 -4
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +26 -24
- data/test/cases/adapters/mysql2/charset_collation_test.rb +20 -17
- data/test/cases/adapters/mysql2/connection_test.rb +48 -50
- data/test/cases/adapters/mysql2/count_deleted_rows_with_lock_test.rb +28 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +23 -19
- data/test/cases/adapters/mysql2/enum_test.rb +32 -11
- data/test/cases/adapters/mysql2/explain_test.rb +13 -11
- data/test/cases/adapters/mysql2/json_test.rb +17 -188
- data/test/cases/adapters/mysql2/mysql2_adapter_prevent_writes_test.rb +208 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +183 -28
- data/test/cases/adapters/mysql2/nested_deadlock_test.rb +75 -0
- data/test/cases/adapters/mysql2/optimizer_hints_test.rb +69 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +26 -21
- data/test/cases/adapters/mysql2/schema_test.rb +24 -22
- data/test/cases/adapters/mysql2/set_test.rb +32 -0
- data/test/cases/adapters/mysql2/sp_test.rb +10 -8
- data/test/cases/adapters/mysql2/sql_types_test.rb +8 -6
- data/test/cases/adapters/mysql2/table_options_test.rb +93 -10
- data/test/cases/adapters/mysql2/transaction_test.rb +151 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +11 -9
- data/test/cases/adapters/mysql2/virtual_column_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +40 -25
- data/test/cases/adapters/postgresql/array_test.rb +118 -63
- data/test/cases/adapters/postgresql/bit_string_test.rb +12 -10
- data/test/cases/adapters/postgresql/bytea_test.rb +26 -25
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +10 -9
- data/test/cases/adapters/postgresql/change_schema_test.rb +7 -5
- data/test/cases/adapters/postgresql/cidr_test.rb +2 -0
- data/test/cases/adapters/postgresql/citext_test.rb +58 -58
- data/test/cases/adapters/postgresql/collation_test.rb +17 -15
- data/test/cases/adapters/postgresql/composite_test.rb +25 -23
- data/test/cases/adapters/postgresql/connection_test.rb +73 -85
- data/test/cases/adapters/postgresql/create_unlogged_tables_test.rb +74 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +19 -22
- data/test/cases/adapters/postgresql/date_test.rb +42 -0
- data/test/cases/adapters/postgresql/domain_test.rb +9 -7
- data/test/cases/adapters/postgresql/enum_test.rb +12 -10
- data/test/cases/adapters/postgresql/explain_test.rb +10 -8
- data/test/cases/adapters/postgresql/extension_migration_test.rb +13 -12
- data/test/cases/adapters/postgresql/foreign_table_test.rb +109 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +8 -6
- data/test/cases/adapters/postgresql/geometric_test.rb +57 -63
- data/test/cases/adapters/postgresql/hstore_test.rb +288 -280
- data/test/cases/adapters/postgresql/infinity_test.rb +54 -15
- data/test/cases/adapters/postgresql/integer_test.rb +2 -0
- data/test/cases/adapters/postgresql/interval_test.rb +99 -0
- data/test/cases/adapters/postgresql/json_test.rb +16 -201
- data/test/cases/adapters/postgresql/ltree_test.rb +14 -16
- data/test/cases/adapters/postgresql/money_test.rb +47 -16
- data/test/cases/adapters/postgresql/network_test.rb +36 -28
- data/test/cases/adapters/postgresql/numbers_test.rb +7 -5
- data/test/cases/adapters/postgresql/optimizer_hints_test.rb +71 -0
- data/test/cases/adapters/postgresql/partitions_test.rb +22 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_prevent_writes_test.rb +205 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +178 -136
- data/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb +27 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +12 -6
- data/test/cases/adapters/postgresql/range_test.rb +406 -292
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +16 -15
- data/test/cases/adapters/postgresql/rename_table_test.rb +9 -8
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +14 -23
- data/test/cases/adapters/postgresql/schema_test.rb +207 -91
- data/test/cases/adapters/postgresql/serial_test.rb +9 -7
- data/test/cases/adapters/postgresql/statement_pool_test.rb +26 -6
- data/test/cases/adapters/postgresql/timestamp_test.rb +17 -15
- data/test/cases/adapters/postgresql/transaction_nested_test.rb +114 -0
- data/test/cases/adapters/postgresql/transaction_test.rb +189 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +12 -10
- data/test/cases/adapters/postgresql/utils_test.rb +11 -9
- data/test/cases/adapters/postgresql/uuid_test.rb +226 -109
- data/test/cases/adapters/postgresql/xml_test.rb +10 -14
- data/test/cases/adapters/sqlite3/collation_test.rb +26 -15
- data/test/cases/adapters/sqlite3/copy_table_test.rb +31 -28
- data/test/cases/adapters/sqlite3/explain_test.rb +13 -11
- data/test/cases/adapters/sqlite3/json_test.rb +29 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +35 -57
- data/test/cases/adapters/sqlite3/sqlite3_adapter_prevent_writes_test.rb +186 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +318 -131
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +11 -11
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +7 -6
- data/test/cases/adapters/sqlite3/transaction_test.rb +123 -0
- data/test/cases/aggregations_test.rb +14 -12
- data/test/cases/annotate_test.rb +46 -0
- data/test/cases/ar_schema_test.rb +153 -86
- data/test/cases/arel/attributes/attribute_test.rb +1145 -0
- data/test/cases/arel/attributes/math_test.rb +83 -0
- data/test/cases/arel/attributes_test.rb +27 -0
- data/test/cases/arel/collectors/bind_test.rb +40 -0
- data/test/cases/arel/collectors/composite_test.rb +47 -0
- data/test/cases/arel/collectors/sql_string_test.rb +41 -0
- data/test/cases/arel/collectors/substitute_bind_collector_test.rb +48 -0
- data/test/cases/arel/crud_test.rb +65 -0
- data/test/cases/arel/delete_manager_test.rb +53 -0
- data/test/cases/arel/factory_methods_test.rb +46 -0
- data/test/cases/arel/helper.rb +45 -0
- data/test/cases/arel/insert_manager_test.rb +241 -0
- data/test/cases/arel/nodes/and_test.rb +30 -0
- data/test/cases/arel/nodes/as_test.rb +36 -0
- data/test/cases/arel/nodes/ascending_test.rb +46 -0
- data/test/cases/arel/nodes/bin_test.rb +35 -0
- data/test/cases/arel/nodes/binary_test.rb +29 -0
- data/test/cases/arel/nodes/bind_param_test.rb +22 -0
- data/test/cases/arel/nodes/case_test.rb +96 -0
- data/test/cases/arel/nodes/casted_test.rb +18 -0
- data/test/cases/arel/nodes/comment_test.rb +22 -0
- data/test/cases/arel/nodes/count_test.rb +35 -0
- data/test/cases/arel/nodes/delete_statement_test.rb +36 -0
- data/test/cases/arel/nodes/descending_test.rb +46 -0
- data/test/cases/arel/nodes/distinct_test.rb +21 -0
- data/test/cases/arel/nodes/equality_test.rb +62 -0
- data/test/cases/arel/nodes/extract_test.rb +43 -0
- data/test/cases/arel/nodes/false_test.rb +21 -0
- data/test/cases/arel/nodes/grouping_test.rb +26 -0
- data/test/cases/arel/nodes/infix_operation_test.rb +42 -0
- data/test/cases/arel/nodes/insert_statement_test.rb +44 -0
- data/test/cases/arel/nodes/named_function_test.rb +48 -0
- data/test/cases/arel/nodes/node_test.rb +22 -0
- data/test/cases/arel/nodes/not_test.rb +31 -0
- data/test/cases/arel/nodes/or_test.rb +36 -0
- data/test/cases/arel/nodes/over_test.rb +69 -0
- data/test/cases/arel/nodes/select_core_test.rb +79 -0
- data/test/cases/arel/nodes/select_statement_test.rb +51 -0
- data/test/cases/arel/nodes/sql_literal_test.rb +75 -0
- data/test/cases/arel/nodes/sum_test.rb +35 -0
- data/test/cases/arel/nodes/table_alias_test.rb +29 -0
- data/test/cases/arel/nodes/true_test.rb +21 -0
- data/test/cases/arel/nodes/unary_operation_test.rb +41 -0
- data/test/cases/arel/nodes/update_statement_test.rb +60 -0
- data/test/cases/arel/nodes/window_test.rb +81 -0
- data/test/cases/arel/nodes_test.rb +34 -0
- data/test/cases/arel/select_manager_test.rb +1238 -0
- data/test/cases/arel/support/fake_record.rb +135 -0
- data/test/cases/arel/table_test.rb +216 -0
- data/test/cases/arel/update_manager_test.rb +126 -0
- data/test/cases/arel/visitors/dispatch_contamination_test.rb +78 -0
- data/test/cases/arel/visitors/dot_test.rb +90 -0
- data/test/cases/arel/visitors/mysql_test.rb +157 -0
- data/test/cases/arel/visitors/postgres_test.rb +366 -0
- data/test/cases/arel/visitors/sqlite_test.rb +75 -0
- data/test/cases/arel/visitors/to_sql_test.rb +750 -0
- data/test/cases/associations/belongs_to_associations_test.rb +510 -158
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +4 -2
- data/test/cases/associations/callbacks_test.rb +56 -38
- data/test/cases/associations/cascaded_eager_loading_test.rb +118 -61
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +138 -18
- data/test/cases/associations/eager_load_nested_include_test.rb +38 -37
- data/test/cases/associations/eager_singularization_test.rb +21 -21
- data/test/cases/associations/eager_test.rb +559 -415
- data/test/cases/associations/extension_test.rb +18 -12
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +234 -213
- data/test/cases/associations/has_many_associations_test.rb +1038 -465
- data/test/cases/associations/has_many_through_associations_test.rb +558 -249
- data/test/cases/associations/has_one_associations_test.rb +294 -129
- data/test/cases/associations/has_one_through_associations_test.rb +121 -75
- data/test/cases/associations/inner_join_association_test.rb +114 -38
- data/test/cases/associations/inverse_associations_test.rb +606 -398
- data/test/cases/associations/join_model_test.rb +158 -148
- data/test/cases/associations/left_outer_join_association_test.rb +59 -24
- data/test/cases/associations/nested_through_associations_test.rb +166 -109
- data/test/cases/associations/required_test.rb +35 -10
- data/test/cases/associations_test.rb +241 -110
- data/test/cases/attribute_methods/read_test.rb +11 -11
- data/test/cases/attribute_methods_test.rb +413 -298
- data/test/cases/attributes_test.rb +145 -27
- data/test/cases/autosave_association_test.rb +681 -436
- data/test/cases/base_prevent_writes_test.rb +229 -0
- data/test/cases/base_test.rb +599 -542
- data/test/cases/batches_test.rb +288 -82
- data/test/cases/binary_test.rb +26 -31
- data/test/cases/bind_parameter_test.rb +194 -21
- data/test/cases/boolean_test.rb +52 -0
- data/test/cases/cache_key_test.rb +110 -5
- data/test/cases/calculations_test.rb +740 -177
- data/test/cases/callbacks_test.rb +74 -207
- data/test/cases/clone_test.rb +15 -10
- data/test/cases/coders/json_test.rb +2 -0
- data/test/cases/coders/yaml_column_test.rb +16 -13
- data/test/cases/collection_cache_key_test.rb +177 -20
- data/test/cases/column_alias_test.rb +9 -7
- data/test/cases/column_definition_test.rb +10 -68
- data/test/cases/comment_test.rb +166 -107
- data/test/cases/connection_adapters/adapter_leasing_test.rb +14 -10
- data/test/cases/connection_adapters/connection_handler_test.rb +358 -51
- data/test/cases/connection_adapters/connection_handlers_multi_db_test.rb +400 -0
- data/test/cases/connection_adapters/connection_handlers_multi_pool_config_test.rb +103 -0
- data/test/cases/connection_adapters/connection_handlers_sharding_db_test.rb +499 -0
- data/test/cases/connection_adapters/connection_swapping_nested_test.rb +457 -0
- data/test/cases/connection_adapters/legacy_connection_handlers_multi_db_test.rb +486 -0
- data/test/cases/connection_adapters/legacy_connection_handlers_sharding_db_test.rb +586 -0
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +319 -138
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +62 -50
- data/test/cases/connection_adapters/schema_cache_test.rb +259 -26
- data/test/cases/connection_adapters/type_lookup_test.rb +96 -95
- data/test/cases/connection_management_test.rb +13 -11
- data/test/cases/connection_pool_test.rb +316 -83
- data/test/cases/core_test.rb +82 -58
- data/test/cases/counter_cache_test.rb +204 -50
- data/test/cases/custom_locking_test.rb +5 -3
- data/test/cases/database_configurations/hash_config_test.rb +74 -0
- data/test/cases/database_configurations/resolver_test.rb +150 -0
- data/test/cases/database_configurations_test.rb +145 -0
- data/test/cases/database_selector_test.rb +296 -0
- data/test/cases/database_statements_test.rb +18 -16
- data/test/cases/date_test.rb +8 -16
- data/test/cases/date_time_precision_test.rb +100 -78
- data/test/cases/date_time_test.rb +23 -8
- data/test/cases/defaults_test.rb +106 -71
- data/test/cases/delegated_type_test.rb +57 -0
- data/test/cases/dirty_test.rb +419 -223
- data/test/cases/disconnected_test.rb +6 -6
- data/test/cases/dup_test.rb +54 -27
- data/test/cases/enum_test.rb +461 -82
- data/test/cases/errors_test.rb +7 -7
- data/test/cases/explain_subscriber_test.rb +17 -15
- data/test/cases/explain_test.rb +11 -19
- data/test/cases/filter_attributes_test.rb +153 -0
- data/test/cases/finder_respond_to_test.rb +14 -14
- data/test/cases/finder_test.rb +669 -287
- data/test/cases/fixture_set/file_test.rb +34 -38
- data/test/cases/fixtures_test.rb +833 -176
- data/test/cases/forbidden_attributes_protection_test.rb +32 -67
- data/test/cases/habtm_destroy_order_test.rb +25 -25
- data/test/cases/helper.rb +78 -49
- data/test/cases/hot_compatibility_test.rb +33 -32
- data/test/cases/i18n_test.rb +18 -17
- data/test/cases/inheritance_test.rb +180 -115
- data/test/cases/insert_all_test.rb +489 -0
- data/test/cases/instrumentation_test.rb +101 -0
- data/test/cases/integration_test.rb +119 -31
- data/test/cases/invalid_connection_test.rb +18 -16
- data/test/cases/invertible_migration_test.rb +183 -43
- data/test/cases/json_attribute_test.rb +35 -0
- data/test/cases/json_serialization_test.rb +57 -58
- data/test/cases/json_shared_test_cases.rb +290 -0
- data/test/cases/locking_test.rb +413 -119
- data/test/cases/log_subscriber_test.rb +68 -26
- data/test/cases/marshal_serialization_test.rb +39 -0
- data/test/cases/migration/change_schema_test.rb +118 -72
- data/test/cases/migration/change_table_test.rb +138 -30
- data/test/cases/migration/check_constraint_test.rb +162 -0
- data/test/cases/migration/column_attributes_test.rb +45 -35
- data/test/cases/migration/column_positioning_test.rb +18 -6
- data/test/cases/migration/columns_test.rb +93 -77
- data/test/cases/migration/command_recorder_test.rb +121 -34
- data/test/cases/migration/compatibility_test.rb +578 -23
- data/test/cases/migration/create_join_table_test.rb +35 -25
- data/test/cases/migration/foreign_key_test.rb +503 -284
- data/test/cases/migration/helper.rb +4 -3
- data/test/cases/migration/index_test.rb +119 -70
- data/test/cases/migration/logger_test.rb +9 -6
- data/test/cases/migration/pending_migrations_test.rb +88 -34
- data/test/cases/migration/references_foreign_key_test.rb +164 -150
- data/test/cases/migration/references_index_test.rb +38 -19
- data/test/cases/migration/references_statements_test.rb +15 -14
- data/test/cases/migration/rename_table_test.rb +53 -30
- data/test/cases/migration_test.rb +637 -269
- data/test/cases/migrator_test.rb +191 -135
- data/test/cases/mixin_test.rb +7 -11
- data/test/cases/modules_test.rb +36 -34
- data/test/cases/multi_db_migrator_test.rb +223 -0
- data/test/cases/multiparameter_attributes_test.rb +60 -33
- data/test/cases/multiple_db_test.rb +16 -22
- data/test/cases/nested_attributes_test.rb +341 -320
- data/test/cases/nested_attributes_with_callbacks_test.rb +26 -24
- data/test/cases/null_relation_test.rb +84 -0
- data/test/cases/numeric_data_test.rb +93 -0
- data/test/cases/persistence_test.rb +361 -269
- data/test/cases/pooled_connections_test.rb +18 -26
- data/test/cases/prepared_statement_status_test.rb +48 -0
- data/test/cases/primary_keys_test.rb +210 -104
- data/test/cases/query_cache_test.rb +610 -141
- data/test/cases/quoting_test.rb +132 -31
- data/test/cases/readonly_test.rb +49 -48
- data/test/cases/reaper_test.rb +146 -32
- data/test/cases/reflection_test.rb +167 -156
- data/test/cases/relation/delegation_test.rb +49 -36
- data/test/cases/relation/delete_all_test.rb +117 -0
- data/test/cases/relation/merging_test.rb +319 -42
- data/test/cases/relation/mutation_test.rb +55 -93
- data/test/cases/relation/or_test.rb +129 -29
- data/test/cases/relation/predicate_builder_test.rb +21 -6
- data/test/cases/relation/record_fetch_warning_test.rb +5 -3
- data/test/cases/relation/select_test.rb +67 -0
- data/test/cases/relation/update_all_test.rb +317 -0
- data/test/cases/relation/where_chain_test.rb +68 -32
- data/test/cases/relation/where_clause_test.rb +136 -61
- data/test/cases/relation/where_test.rb +155 -48
- data/test/cases/relation_test.rb +266 -112
- data/test/cases/relations_test.rb +969 -744
- data/test/cases/reload_models_test.rb +13 -9
- data/test/cases/reserved_word_test.rb +141 -0
- data/test/cases/result_test.rb +68 -17
- data/test/cases/sanitize_test.rb +87 -71
- data/test/cases/schema_dumper_test.rb +221 -128
- data/test/cases/schema_loading_test.rb +3 -2
- data/test/cases/scoping/default_scoping_test.rb +185 -144
- data/test/cases/scoping/named_scoping_test.rb +177 -89
- data/test/cases/scoping/relation_scoping_test.rb +197 -75
- data/test/cases/secure_token_test.rb +18 -3
- data/test/cases/serialization_test.rb +30 -28
- data/test/cases/serialized_attribute_test.rb +133 -42
- data/test/cases/signed_id_test.rb +168 -0
- data/test/cases/statement_cache_test.rb +41 -24
- data/test/cases/statement_invalid_test.rb +42 -0
- data/test/cases/store_test.rb +180 -55
- data/test/cases/strict_loading_test.rb +473 -0
- data/test/cases/suppressor_test.rb +26 -12
- data/test/cases/tasks/database_tasks_test.rb +1258 -194
- data/test/cases/tasks/mysql_rake_test.rb +370 -298
- data/test/cases/tasks/postgresql_rake_test.rb +481 -251
- data/test/cases/tasks/sqlite_rake_test.rb +225 -178
- data/test/cases/test_case.rb +51 -40
- data/test/cases/test_databases_test.rb +79 -0
- data/test/cases/test_fixtures_test.rb +79 -19
- data/test/cases/time_precision_test.rb +98 -76
- data/test/cases/timestamp_test.rb +102 -99
- data/test/cases/touch_later_test.rb +12 -10
- data/test/cases/transaction_callbacks_test.rb +344 -90
- data/test/cases/transaction_isolation_test.rb +12 -12
- data/test/cases/transactions_test.rb +612 -162
- data/test/cases/type/adapter_specific_registry_test.rb +14 -2
- data/test/cases/type/date_time_test.rb +4 -2
- data/test/cases/type/integer_test.rb +4 -2
- data/test/cases/type/string_test.rb +10 -8
- data/test/cases/type/time_test.rb +28 -0
- data/test/cases/type/type_map_test.rb +29 -28
- data/test/cases/type/unsigned_integer_test.rb +19 -0
- data/test/cases/type_test.rb +2 -0
- data/test/cases/types_test.rb +3 -1
- data/test/cases/unconnected_test.rb +14 -1
- data/test/cases/unsafe_raw_sql_test.rb +274 -0
- data/test/cases/validations/absence_validation_test.rb +19 -17
- data/test/cases/validations/association_validation_test.rb +30 -28
- data/test/cases/validations/i18n_generate_message_validation_test.rb +34 -16
- data/test/cases/validations/i18n_validation_test.rb +22 -21
- data/test/cases/validations/length_validation_test.rb +34 -33
- data/test/cases/validations/numericality_validation_test.rb +181 -0
- data/test/cases/validations/presence_validation_test.rb +21 -19
- data/test/cases/validations/uniqueness_validation_test.rb +156 -86
- data/test/cases/validations_repair_helper.rb +2 -0
- data/test/cases/validations_test.rb +61 -26
- data/test/cases/view_test.rb +122 -116
- data/test/cases/yaml_serialization_test.rb +79 -34
- data/test/config.example.yml +19 -19
- data/test/config.rb +3 -1
- data/test/config.yml +16 -6
- data/test/fixtures/all/namespaced/accounts.yml +2 -0
- data/test/fixtures/author_addresses.yml +1 -8
- data/test/fixtures/authors.yml +1 -7
- data/test/fixtures/binaries.yml +4 -0
- data/test/fixtures/books.yml +9 -2
- data/test/fixtures/categories_posts.yml +3 -0
- data/test/fixtures/citations.yml +5 -0
- data/test/fixtures/comments.yml +7 -0
- data/test/fixtures/companies.yml +5 -0
- data/test/fixtures/computers.yml +2 -0
- data/test/fixtures/customers.yml +10 -1
- data/test/fixtures/developers.yml +1 -1
- data/test/fixtures/essays.yml +10 -0
- data/test/fixtures/faces.yml +3 -3
- data/test/fixtures/humans.yml +5 -0
- data/test/fixtures/interests.yml +7 -7
- data/test/fixtures/memberships.yml +7 -0
- data/test/fixtures/minimalistics.yml +3 -0
- data/test/fixtures/mixed_case_monkeys.yml +2 -2
- data/test/fixtures/naked/yml/courses_with_invalid_key.yml +3 -0
- data/test/fixtures/naked/yml/parrots.yml +1 -0
- data/test/fixtures/other_books.yml +26 -0
- data/test/fixtures/other_posts.yml +1 -0
- data/test/fixtures/parrots.yml +7 -1
- data/test/fixtures/pirates.yml +3 -0
- data/test/fixtures/posts.yml +11 -3
- data/test/fixtures/readers.yml +6 -0
- data/test/fixtures/reserved_words/values.yml +2 -2
- data/test/fixtures/sponsors.yml +3 -0
- data/test/fixtures/strict_zines.yml +2 -0
- data/test/fixtures/subscribers.yml +1 -1
- data/test/fixtures/tasks.yml +1 -1
- data/test/fixtures/warehouse-things.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +2 -0
- data/test/migrations/decimal/1_give_me_big_numbers.rb +6 -4
- data/test/migrations/magic/1_currencies_have_symbols.rb +3 -2
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -0
- data/test/migrations/missing/1_people_have_last_names.rb +2 -0
- data/test/migrations/missing/3_we_need_reminders.rb +2 -0
- data/test/migrations/missing/4_innocent_jointable.rb +3 -1
- data/test/migrations/rename/1_we_need_things.rb +2 -0
- data/test/migrations/rename/2_rename_things.rb +2 -0
- data/test/migrations/to_copy/1_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +3 -1
- data/test/migrations/to_copy2/1_create_articles.rb +2 -0
- data/test/migrations/to_copy2/2_create_comments.rb +3 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +3 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +3 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +2 -0
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +2 -0
- data/test/migrations/valid/1_valid_people_have_last_names.rb +2 -0
- data/test/migrations/valid/2_we_need_reminders.rb +2 -0
- data/test/migrations/valid/3_innocent_jointable.rb +3 -1
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +2 -0
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -0
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +3 -1
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +2 -0
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +2 -0
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +3 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +2 -0
- data/test/models/account.rb +46 -0
- data/test/models/admin/account.rb +3 -1
- data/test/models/admin/randomly_named_c1.rb +2 -0
- data/test/models/admin/user.rb +16 -8
- data/test/models/admin.rb +4 -2
- data/test/models/aircraft.rb +3 -1
- data/test/models/arunit2_model.rb +2 -0
- data/test/models/author.rb +153 -102
- data/test/models/auto_id.rb +2 -0
- data/test/models/autoloadable/extra_firm.rb +2 -0
- data/test/models/binary.rb +3 -1
- data/test/models/binary_field.rb +6 -0
- data/test/models/bird.rb +13 -1
- data/test/models/book.rb +14 -4
- data/test/models/book_destroy_async.rb +24 -0
- data/test/models/boolean.rb +5 -0
- data/test/models/bulb.rb +13 -4
- data/test/models/cake_designer.rb +2 -0
- data/test/models/car.rb +17 -10
- data/test/models/carrier.rb +2 -0
- data/test/models/cart.rb +5 -0
- data/test/models/cat.rb +2 -0
- data/test/models/categorization.rb +8 -6
- data/test/models/category.rb +28 -16
- data/test/models/chef.rb +2 -0
- data/test/models/citation.rb +5 -1
- data/test/models/club.rb +13 -10
- data/test/models/college.rb +4 -2
- data/test/models/column.rb +2 -0
- data/test/models/column_name.rb +2 -0
- data/test/models/comment.rb +32 -10
- data/test/models/company.rb +102 -106
- data/test/models/company_in_module.rb +27 -26
- data/test/models/computer.rb +3 -1
- data/test/models/contact.rb +15 -13
- data/test/models/content.rb +5 -3
- data/test/models/contract.rb +21 -3
- data/test/models/country.rb +2 -4
- data/test/models/course.rb +3 -1
- data/test/models/customer.rb +10 -8
- data/test/models/customer_carrier.rb +2 -0
- data/test/models/dashboard.rb +2 -0
- data/test/models/default.rb +2 -0
- data/test/models/department.rb +2 -0
- data/test/models/destroy_async_parent.rb +15 -0
- data/test/models/destroy_async_parent_soft_delete.rb +20 -0
- data/test/models/developer.rb +152 -85
- data/test/models/dl_keyed_belongs_to.rb +13 -0
- data/test/models/dl_keyed_belongs_to_soft_delete.rb +19 -0
- data/test/models/dl_keyed_has_many.rb +5 -0
- data/test/models/dl_keyed_has_many_through.rb +5 -0
- data/test/models/dl_keyed_has_one.rb +5 -0
- data/test/models/dl_keyed_join.rb +10 -0
- data/test/models/dog.rb +2 -0
- data/test/models/dog_lover.rb +2 -0
- data/test/models/doubloon.rb +3 -1
- data/test/models/drink_designer.rb +17 -0
- data/test/models/edge.rb +4 -2
- data/test/models/electron.rb +2 -0
- data/test/models/engine.rb +3 -2
- data/test/models/entrant.rb +2 -0
- data/test/models/entry.rb +5 -0
- data/test/models/essay.rb +6 -3
- data/test/models/essay_destroy_async.rb +12 -0
- data/test/models/event.rb +3 -1
- data/test/models/eye.rb +5 -3
- data/test/models/face.rb +14 -6
- data/test/models/family.rb +6 -0
- data/test/models/family_tree.rb +6 -0
- data/test/models/friendship.rb +5 -3
- data/test/models/frog.rb +8 -0
- data/test/models/guid.rb +3 -1
- data/test/models/guitar.rb +2 -0
- data/test/models/hotel.rb +5 -3
- data/test/models/human.rb +39 -0
- data/test/models/image.rb +3 -1
- data/test/models/interest.rb +14 -3
- data/test/models/invoice.rb +4 -2
- data/test/models/item.rb +3 -1
- data/test/models/job.rb +5 -3
- data/test/models/joke.rb +4 -2
- data/test/models/keyboard.rb +3 -1
- data/test/models/legacy_thing.rb +2 -0
- data/test/models/lesson.rb +2 -0
- data/test/models/line_item.rb +3 -1
- data/test/models/liquid.rb +2 -0
- data/test/models/matey.rb +3 -1
- data/test/models/measurement.rb +4 -0
- data/test/models/member.rb +23 -20
- data/test/models/member_detail.rb +3 -0
- data/test/models/member_type.rb +2 -0
- data/test/models/membership.rb +4 -1
- data/test/models/mentor.rb +3 -1
- data/test/models/message.rb +5 -0
- data/test/models/minimalistic.rb +2 -0
- data/test/models/minivan.rb +3 -2
- data/test/models/mixed_case_monkey.rb +3 -1
- data/test/models/molecule.rb +2 -0
- data/test/models/mouse.rb +6 -0
- data/test/models/movie.rb +2 -0
- data/test/models/node.rb +4 -2
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +2 -0
- data/test/models/numeric_data.rb +12 -0
- data/test/models/order.rb +4 -2
- data/test/models/organization.rb +9 -7
- data/test/models/other_dog.rb +3 -1
- data/test/models/owner.rb +6 -4
- data/test/models/parrot.rb +12 -4
- data/test/models/person.rb +59 -54
- data/test/models/personal_legacy_thing.rb +3 -1
- data/test/models/pet.rb +4 -2
- data/test/models/pet_treasure.rb +2 -0
- data/test/models/pirate.rb +67 -43
- data/test/models/possession.rb +3 -1
- data/test/models/post.rb +184 -86
- data/test/models/price_estimate.rb +11 -1
- data/test/models/professor.rb +3 -1
- data/test/models/project.rb +14 -12
- data/test/models/publisher/article.rb +2 -0
- data/test/models/publisher/magazine.rb +2 -0
- data/test/models/publisher.rb +2 -0
- data/test/models/randomly_named_c1.rb +2 -0
- data/test/models/rating.rb +5 -1
- data/test/models/reader.rb +7 -5
- data/test/models/recipe.rb +2 -0
- data/test/models/record.rb +2 -0
- data/test/models/reference.rb +6 -3
- data/test/models/reply.rb +39 -21
- data/test/models/room.rb +6 -0
- data/test/models/section.rb +6 -0
- data/test/models/seminar.rb +6 -0
- data/test/models/session.rb +6 -0
- data/test/models/ship.rb +12 -9
- data/test/models/ship_part.rb +5 -3
- data/test/models/shop.rb +4 -2
- data/test/models/shop_account.rb +2 -0
- data/test/models/speedometer.rb +2 -0
- data/test/models/sponsor.rb +8 -5
- data/test/models/squeak.rb +6 -0
- data/test/models/strict_zine.rb +7 -0
- data/test/models/string_key_object.rb +2 -0
- data/test/models/student.rb +2 -0
- data/test/models/subscriber.rb +4 -2
- data/test/models/subscription.rb +5 -1
- data/test/models/tag.rb +6 -3
- data/test/models/tagging.rb +13 -6
- data/test/models/task.rb +2 -0
- data/test/models/topic.rb +54 -19
- data/test/models/toy.rb +4 -0
- data/test/models/traffic_light.rb +2 -0
- data/test/models/treasure.rb +5 -3
- data/test/models/treaty.rb +2 -4
- data/test/models/tree.rb +2 -0
- data/test/models/tuning_peg.rb +2 -0
- data/test/models/tyre.rb +2 -0
- data/test/models/user.rb +12 -4
- data/test/models/uuid_child.rb +2 -0
- data/test/models/uuid_item.rb +2 -0
- data/test/models/uuid_parent.rb +2 -0
- data/test/models/vegetables.rb +12 -3
- data/test/models/vertex.rb +6 -4
- data/test/models/warehouse_thing.rb +2 -0
- data/test/models/wheel.rb +3 -1
- data/test/models/without_table.rb +3 -1
- data/test/models/zine.rb +3 -1
- data/test/schema/mysql2_specific_schema.rb +49 -35
- data/test/schema/oracle_specific_schema.rb +13 -15
- data/test/schema/postgresql_specific_schema.rb +51 -40
- data/test/schema/schema.rb +334 -154
- data/test/schema/sqlite_specific_schema.rb +9 -16
- data/test/support/config.rb +26 -26
- data/test/support/connection.rb +14 -8
- data/test/support/connection_helper.rb +3 -1
- data/test/support/ddl_helper.rb +2 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/IBM_DB/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/Mysql2/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/PostgreSQL/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/SQLite/rails_6_0_topic_associations.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/legacy_6_0_record_mysql.dump +0 -0
- data/test/support/marshal_compatibility_fixtures/legacy_relation.dump +0 -0
- data/test/support/schema_dumping_helper.rb +2 -0
- data/test/support/stubs/strong_parameters.rb +40 -0
- data/test/support/yaml_compatibility_fixtures/rails_v1_mysql.yml +206 -0
- data/test/support/yaml_compatibility_fixtures/rails_v2.yml +55 -0
- metadata +192 -14
@@ -1,43 +1,47 @@
|
|
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
|
4
|
+
require "models/human"
|
5
|
+
require "models/face"
|
6
|
+
require "models/interest"
|
7
|
+
require "models/zine"
|
8
|
+
require "models/club"
|
9
|
+
require "models/sponsor"
|
10
|
+
require "models/rating"
|
11
|
+
require "models/post"
|
12
|
+
require "models/comment"
|
13
|
+
require "models/car"
|
14
|
+
require "models/bulb"
|
15
|
+
require "models/mixed_case_monkey"
|
16
|
+
require "models/admin"
|
17
|
+
require "models/admin/account"
|
18
|
+
require "models/admin/user"
|
19
|
+
require "models/developer"
|
20
|
+
require "models/company"
|
21
|
+
require "models/project"
|
22
|
+
require "models/author"
|
23
|
+
require "models/post"
|
24
|
+
require "models/user"
|
25
|
+
require "models/room"
|
19
26
|
|
20
27
|
class AutomaticInverseFindingTests < ActiveRecord::TestCase
|
21
28
|
fixtures :ratings, :comments, :cars
|
22
29
|
|
23
30
|
def test_has_one_and_belongs_to_should_find_inverse_automatically_on_multiple_word_name
|
24
|
-
monkey_reflection = MixedCaseMonkey.reflect_on_association(:
|
25
|
-
|
31
|
+
monkey_reflection = MixedCaseMonkey.reflect_on_association(:human)
|
32
|
+
human_reflection = Human.reflect_on_association(:mixed_case_monkey)
|
26
33
|
|
27
|
-
assert_respond_to monkey_reflection, :has_inverse?
|
28
34
|
assert monkey_reflection.has_inverse?, "The monkey reflection should have an inverse"
|
29
|
-
assert_equal
|
35
|
+
assert_equal human_reflection, monkey_reflection.inverse_of, "The monkey reflection's inverse should be the human reflection"
|
30
36
|
|
31
|
-
|
32
|
-
|
33
|
-
assert_equal monkey_reflection, man_reflection.inverse_of, "The man reflection's inverse should be the monkey reflection"
|
37
|
+
assert human_reflection.has_inverse?, "The human reflection should have an inverse"
|
38
|
+
assert_equal monkey_reflection, human_reflection.inverse_of, "The human reflection's inverse should be the monkey reflection"
|
34
39
|
end
|
35
40
|
|
36
41
|
def test_has_many_and_belongs_to_should_find_inverse_automatically_for_model_in_module
|
37
42
|
account_reflection = Admin::Account.reflect_on_association(:users)
|
38
43
|
user_reflection = Admin::User.reflect_on_association(:account)
|
39
44
|
|
40
|
-
assert_respond_to account_reflection, :has_inverse?
|
41
45
|
assert account_reflection.has_inverse?, "The Admin::Account reflection should have an inverse"
|
42
46
|
assert_equal user_reflection, account_reflection.inverse_of, "The Admin::Account reflection's inverse should be the Admin::User reflection"
|
43
47
|
end
|
@@ -46,11 +50,9 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase
|
|
46
50
|
car_reflection = Car.reflect_on_association(:bulb)
|
47
51
|
bulb_reflection = Bulb.reflect_on_association(:car)
|
48
52
|
|
49
|
-
assert_respond_to car_reflection, :has_inverse?
|
50
53
|
assert car_reflection.has_inverse?, "The Car reflection should have an inverse"
|
51
54
|
assert_equal bulb_reflection, car_reflection.inverse_of, "The Car reflection's inverse should be the Bulb reflection"
|
52
55
|
|
53
|
-
assert_respond_to bulb_reflection, :has_inverse?
|
54
56
|
assert bulb_reflection.has_inverse?, "The Bulb reflection should have an inverse"
|
55
57
|
assert_equal car_reflection, bulb_reflection.inverse_of, "The Bulb reflection's inverse should be the Car reflection"
|
56
58
|
end
|
@@ -59,11 +61,55 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase
|
|
59
61
|
comment_reflection = Comment.reflect_on_association(:ratings)
|
60
62
|
rating_reflection = Rating.reflect_on_association(:comment)
|
61
63
|
|
62
|
-
assert_respond_to comment_reflection, :has_inverse?
|
63
64
|
assert comment_reflection.has_inverse?, "The Comment reflection should have an inverse"
|
64
65
|
assert_equal rating_reflection, comment_reflection.inverse_of, "The Comment reflection's inverse should be the Rating reflection"
|
65
66
|
end
|
66
67
|
|
68
|
+
def test_has_many_and_belongs_to_should_find_inverse_automatically_for_extension_block
|
69
|
+
comment_reflection = Comment.reflect_on_association(:post)
|
70
|
+
post_reflection = Post.reflect_on_association(:comments)
|
71
|
+
|
72
|
+
assert_predicate post_reflection, :has_inverse?
|
73
|
+
assert_equal comment_reflection, post_reflection.inverse_of
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_has_many_and_belongs_to_should_find_inverse_automatically_for_sti
|
77
|
+
author_reflection = Author.reflect_on_association(:posts)
|
78
|
+
author_child_reflection = Author.reflect_on_association(:special_posts)
|
79
|
+
post_reflection = Post.reflect_on_association(:author)
|
80
|
+
|
81
|
+
assert_respond_to author_reflection, :has_inverse?
|
82
|
+
assert author_reflection.has_inverse?, "The Author reflection should have an inverse"
|
83
|
+
assert_equal post_reflection, author_reflection.inverse_of, "The Author reflection's inverse should be the Post reflection"
|
84
|
+
|
85
|
+
assert_respond_to author_child_reflection, :has_inverse?
|
86
|
+
assert author_child_reflection.has_inverse?, "The Author reflection should have an inverse"
|
87
|
+
assert_equal post_reflection, author_child_reflection.inverse_of, "The Author reflection's inverse should be the Post reflection"
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_has_one_and_belongs_to_with_non_default_foreign_key_should_not_find_inverse_automatically
|
91
|
+
user = User.create!
|
92
|
+
owned_room = Room.create!(owner: user)
|
93
|
+
|
94
|
+
assert_nil user.room
|
95
|
+
assert_nil owned_room.user
|
96
|
+
|
97
|
+
assert_equal user, owned_room.owner
|
98
|
+
assert_equal owned_room, user.owned_room
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_has_one_and_belongs_to_with_custom_association_name_should_not_find_wrong_inverse_automatically
|
102
|
+
user_reflection = Room.reflect_on_association(:user)
|
103
|
+
owner_reflection = Room.reflect_on_association(:owner)
|
104
|
+
room_reflection = User.reflect_on_association(:room)
|
105
|
+
|
106
|
+
assert_predicate user_reflection, :has_inverse?
|
107
|
+
assert_equal room_reflection, user_reflection.inverse_of
|
108
|
+
|
109
|
+
assert_not_predicate owner_reflection, :has_inverse?
|
110
|
+
assert_not_equal room_reflection, owner_reflection.inverse_of
|
111
|
+
end
|
112
|
+
|
67
113
|
def test_has_one_and_belongs_to_automatic_inverse_shares_objects
|
68
114
|
car = Car.first
|
69
115
|
bulb = Bulb.create!(car: car)
|
@@ -107,88 +153,64 @@ class AutomaticInverseFindingTests < ActiveRecord::TestCase
|
|
107
153
|
def test_polymorphic_and_has_many_through_relationships_should_not_have_inverses
|
108
154
|
sponsor_reflection = Sponsor.reflect_on_association(:sponsorable)
|
109
155
|
|
110
|
-
|
111
|
-
assert !sponsor_reflection.has_inverse?, "A polymorphic association should not find an inverse automatically"
|
156
|
+
assert_not sponsor_reflection.has_inverse?, "A polymorphic association should not find an inverse automatically"
|
112
157
|
|
113
158
|
club_reflection = Club.reflect_on_association(:members)
|
114
159
|
|
115
|
-
|
116
|
-
assert !club_reflection.has_inverse?, "A has_many_through association should not find an inverse automatically"
|
160
|
+
assert_not club_reflection.has_inverse?, "A has_many_through association should not find an inverse automatically"
|
117
161
|
end
|
118
162
|
|
119
|
-
def
|
120
|
-
|
121
|
-
face_reflection = Face.reflect_on_association(:man)
|
163
|
+
def test_polymorphic_has_one_should_find_inverse_automatically
|
164
|
+
human_reflection = Human.reflect_on_association(:polymorphic_face_without_inverse)
|
122
165
|
|
123
|
-
|
124
|
-
assert face_reflection.has_inverse?, "For this test, the non-polymorphic association must have an inverse"
|
125
|
-
|
126
|
-
assert_respond_to man_reflection, :has_inverse?
|
127
|
-
assert !man_reflection.has_inverse?, "The target of a polymorphic association should not find an inverse automatically"
|
166
|
+
assert_predicate human_reflection, :has_inverse?
|
128
167
|
end
|
129
168
|
end
|
130
169
|
|
131
170
|
class InverseAssociationTests < ActiveRecord::TestCase
|
132
171
|
def test_should_allow_for_inverse_of_options_in_associations
|
133
172
|
assert_nothing_raised do
|
134
|
-
Class.new(ActiveRecord::Base).has_many(:wheels, :
|
173
|
+
Class.new(ActiveRecord::Base).has_many(:wheels, inverse_of: :car)
|
135
174
|
end
|
136
175
|
|
137
176
|
assert_nothing_raised do
|
138
|
-
Class.new(ActiveRecord::Base).has_one(:engine, :
|
177
|
+
Class.new(ActiveRecord::Base).has_one(:engine, inverse_of: :car)
|
139
178
|
end
|
140
179
|
|
141
180
|
assert_nothing_raised do
|
142
|
-
Class.new(ActiveRecord::Base).belongs_to(:car, :
|
181
|
+
Class.new(ActiveRecord::Base).belongs_to(:car, inverse_of: :driver)
|
143
182
|
end
|
144
183
|
end
|
145
184
|
|
146
185
|
def test_should_be_able_to_ask_a_reflection_if_it_has_an_inverse
|
147
|
-
has_one_with_inverse_ref =
|
148
|
-
|
149
|
-
assert has_one_with_inverse_ref.has_inverse?
|
186
|
+
has_one_with_inverse_ref = Human.reflect_on_association(:face)
|
187
|
+
assert_predicate has_one_with_inverse_ref, :has_inverse?
|
150
188
|
|
151
|
-
has_many_with_inverse_ref =
|
152
|
-
|
153
|
-
assert has_many_with_inverse_ref.has_inverse?
|
189
|
+
has_many_with_inverse_ref = Human.reflect_on_association(:interests)
|
190
|
+
assert_predicate has_many_with_inverse_ref, :has_inverse?
|
154
191
|
|
155
|
-
belongs_to_with_inverse_ref = Face.reflect_on_association(:
|
156
|
-
|
157
|
-
assert belongs_to_with_inverse_ref.has_inverse?
|
192
|
+
belongs_to_with_inverse_ref = Face.reflect_on_association(:human)
|
193
|
+
assert_predicate belongs_to_with_inverse_ref, :has_inverse?
|
158
194
|
|
159
195
|
has_one_without_inverse_ref = Club.reflect_on_association(:sponsor)
|
160
|
-
|
161
|
-
assert !has_one_without_inverse_ref.has_inverse?
|
196
|
+
assert_not_predicate has_one_without_inverse_ref, :has_inverse?
|
162
197
|
|
163
198
|
has_many_without_inverse_ref = Club.reflect_on_association(:memberships)
|
164
|
-
|
165
|
-
assert !has_many_without_inverse_ref.has_inverse?
|
199
|
+
assert_not_predicate has_many_without_inverse_ref, :has_inverse?
|
166
200
|
|
167
201
|
belongs_to_without_inverse_ref = Sponsor.reflect_on_association(:sponsor_club)
|
168
|
-
|
169
|
-
assert !belongs_to_without_inverse_ref.has_inverse?
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_should_be_able_to_ask_a_reflection_what_it_is_the_inverse_of
|
173
|
-
has_one_ref = Man.reflect_on_association(:face)
|
174
|
-
assert_respond_to has_one_ref, :inverse_of
|
175
|
-
|
176
|
-
has_many_ref = Man.reflect_on_association(:interests)
|
177
|
-
assert_respond_to has_many_ref, :inverse_of
|
178
|
-
|
179
|
-
belongs_to_ref = Face.reflect_on_association(:man)
|
180
|
-
assert_respond_to belongs_to_ref, :inverse_of
|
202
|
+
assert_not_predicate belongs_to_without_inverse_ref, :has_inverse?
|
181
203
|
end
|
182
204
|
|
183
205
|
def test_inverse_of_method_should_supply_the_actual_reflection_instance_it_is_the_inverse_of
|
184
|
-
has_one_ref =
|
185
|
-
assert_equal Face.reflect_on_association(:
|
206
|
+
has_one_ref = Human.reflect_on_association(:face)
|
207
|
+
assert_equal Face.reflect_on_association(:human), has_one_ref.inverse_of
|
186
208
|
|
187
|
-
has_many_ref =
|
188
|
-
assert_equal Interest.reflect_on_association(:
|
209
|
+
has_many_ref = Human.reflect_on_association(:interests)
|
210
|
+
assert_equal Interest.reflect_on_association(:human), has_many_ref.inverse_of
|
189
211
|
|
190
|
-
belongs_to_ref = Face.reflect_on_association(:
|
191
|
-
assert_equal
|
212
|
+
belongs_to_ref = Face.reflect_on_association(:human)
|
213
|
+
assert_equal Human.reflect_on_association(:face), belongs_to_ref.inverse_of
|
192
214
|
end
|
193
215
|
|
194
216
|
def test_associations_with_no_inverse_of_should_return_nil
|
@@ -202,10 +224,20 @@ class InverseAssociationTests < ActiveRecord::TestCase
|
|
202
224
|
assert_nil belongs_to_ref.inverse_of
|
203
225
|
end
|
204
226
|
|
227
|
+
def test_polymorphic_associations_dont_attempt_to_find_inverse_of
|
228
|
+
belongs_to_ref = Sponsor.reflect_on_association(:sponsor)
|
229
|
+
assert_raise(ArgumentError) { belongs_to_ref.klass }
|
230
|
+
assert_nil belongs_to_ref.inverse_of
|
231
|
+
|
232
|
+
belongs_to_ref = Face.reflect_on_association(:super_human)
|
233
|
+
assert_raise(ArgumentError) { belongs_to_ref.klass }
|
234
|
+
assert_nil belongs_to_ref.inverse_of
|
235
|
+
end
|
236
|
+
|
205
237
|
def test_this_inverse_stuff
|
206
|
-
firm = Firm.create!(name:
|
207
|
-
Project.create!(name:
|
208
|
-
Developer.create!(name:
|
238
|
+
firm = Firm.create!(name: "Adequate Holdings")
|
239
|
+
Project.create!(name: "Project 1", firm: firm)
|
240
|
+
Developer.create!(name: "Gorbypuff", firm: firm)
|
209
241
|
|
210
242
|
new_project = Project.last
|
211
243
|
assert Project.reflect_on_association(:lead_developer).inverse_of.present?, "Expected inverse of to be present"
|
@@ -214,249 +246,310 @@ class InverseAssociationTests < ActiveRecord::TestCase
|
|
214
246
|
end
|
215
247
|
|
216
248
|
class InverseHasOneTests < ActiveRecord::TestCase
|
217
|
-
fixtures :
|
249
|
+
fixtures :humans, :faces
|
218
250
|
|
219
251
|
def test_parent_instance_should_be_shared_with_child_on_find
|
220
|
-
|
221
|
-
|
222
|
-
assert_equal
|
223
|
-
|
224
|
-
assert_equal
|
225
|
-
|
226
|
-
assert_equal
|
252
|
+
human = humans(:gordon)
|
253
|
+
face = human.face
|
254
|
+
assert_equal human.name, face.human.name, "Name of human should be the same before changes to parent instance"
|
255
|
+
human.name = "Bongo"
|
256
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to parent instance"
|
257
|
+
face.human.name = "Mungo"
|
258
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to child-owned instance"
|
227
259
|
end
|
228
260
|
|
229
|
-
|
230
261
|
def test_parent_instance_should_be_shared_with_eager_loaded_child_on_find
|
231
|
-
|
232
|
-
|
233
|
-
assert_equal
|
234
|
-
|
235
|
-
assert_equal
|
236
|
-
|
237
|
-
assert_equal
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
assert_equal
|
242
|
-
|
243
|
-
assert_equal
|
244
|
-
|
245
|
-
assert_equal
|
262
|
+
human = Human.all.merge!(where: { name: "Gordon" }, includes: :face).first
|
263
|
+
face = human.face
|
264
|
+
assert_equal human.name, face.human.name, "Name of human should be the same before changes to parent instance"
|
265
|
+
human.name = "Bongo"
|
266
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to parent instance"
|
267
|
+
face.human.name = "Mungo"
|
268
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to child-owned instance"
|
269
|
+
|
270
|
+
human = Human.all.merge!(where: { name: "Gordon" }, includes: :face, order: "faces.id").first
|
271
|
+
face = human.face
|
272
|
+
assert_equal human.name, face.human.name, "Name of human should be the same before changes to parent instance"
|
273
|
+
human.name = "Bongo"
|
274
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to parent instance"
|
275
|
+
face.human.name = "Mungo"
|
276
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to child-owned instance"
|
246
277
|
end
|
247
278
|
|
248
279
|
def test_parent_instance_should_be_shared_with_newly_built_child
|
249
|
-
|
250
|
-
|
251
|
-
assert_not_nil
|
252
|
-
assert_equal
|
253
|
-
|
254
|
-
assert_equal
|
255
|
-
|
256
|
-
assert_equal
|
280
|
+
human = Human.first
|
281
|
+
face = human.build_face(description: "haunted")
|
282
|
+
assert_not_nil face.human
|
283
|
+
assert_equal human.name, face.human.name, "Name of human should be the same before changes to parent instance"
|
284
|
+
human.name = "Bongo"
|
285
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to parent instance"
|
286
|
+
face.human.name = "Mungo"
|
287
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to just-built-child-owned instance"
|
257
288
|
end
|
258
289
|
|
259
290
|
def test_parent_instance_should_be_shared_with_newly_created_child
|
260
|
-
|
261
|
-
|
262
|
-
assert_not_nil
|
263
|
-
assert_equal
|
264
|
-
|
265
|
-
assert_equal
|
266
|
-
|
267
|
-
assert_equal
|
291
|
+
human = Human.first
|
292
|
+
face = human.create_face(description: "haunted")
|
293
|
+
assert_not_nil face.human
|
294
|
+
assert_equal human.name, face.human.name, "Name of human should be the same before changes to parent instance"
|
295
|
+
human.name = "Bongo"
|
296
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to parent instance"
|
297
|
+
face.human.name = "Mungo"
|
298
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to newly-created-child-owned instance"
|
268
299
|
end
|
269
300
|
|
270
301
|
def test_parent_instance_should_be_shared_with_newly_created_child_via_bang_method
|
271
|
-
|
272
|
-
|
273
|
-
assert_not_nil
|
274
|
-
assert_equal
|
275
|
-
|
276
|
-
assert_equal
|
277
|
-
|
278
|
-
assert_equal
|
302
|
+
human = Human.first
|
303
|
+
face = human.create_face!(description: "haunted")
|
304
|
+
assert_not_nil face.human
|
305
|
+
assert_equal human.name, face.human.name, "Name of human should be the same before changes to parent instance"
|
306
|
+
human.name = "Bongo"
|
307
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to parent instance"
|
308
|
+
face.human.name = "Mungo"
|
309
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to newly-created-child-owned instance"
|
279
310
|
end
|
280
311
|
|
281
312
|
def test_parent_instance_should_be_shared_with_replaced_via_accessor_child
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
assert_not_nil
|
286
|
-
assert_equal
|
287
|
-
|
288
|
-
assert_equal
|
289
|
-
|
290
|
-
assert_equal
|
313
|
+
human = Human.first
|
314
|
+
face = Face.new(description: "haunted")
|
315
|
+
human.face = face
|
316
|
+
assert_not_nil face.human
|
317
|
+
assert_equal human.name, face.human.name, "Name of human should be the same before changes to parent instance"
|
318
|
+
human.name = "Bongo"
|
319
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to parent instance"
|
320
|
+
face.human.name = "Mungo"
|
321
|
+
assert_equal human.name, face.human.name, "Name of human should be the same after changes to replaced-child-owned instance"
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_child_instance_should_be_shared_with_replaced_via_accessor_parent
|
325
|
+
human = Human.first
|
326
|
+
face = Face.create!(description: "haunted", human: Human.last)
|
327
|
+
face.human = human
|
328
|
+
assert_equal face, human.face
|
329
|
+
assert_equal face.description, human.face.description, "Description of the face should be the same before changes to child instance"
|
330
|
+
face.description = "Bongo"
|
331
|
+
assert_equal face.description, human.face.description, "Description of the face should be the same after changes to chield instance"
|
332
|
+
human.face.description = "Mungo"
|
333
|
+
assert_equal face.description, human.face.description, "Description of the face should be the same after changes to replaced-parent-owned instance"
|
291
334
|
end
|
292
335
|
|
293
336
|
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
|
294
|
-
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) {
|
337
|
+
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Human.first.confused_face }
|
338
|
+
end
|
339
|
+
|
340
|
+
if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error)
|
341
|
+
def test_trying_to_use_inverses_that_dont_exist_should_have_suggestions_for_fix
|
342
|
+
error = assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) {
|
343
|
+
Human.first.confused_face
|
344
|
+
}
|
345
|
+
|
346
|
+
assert_match "Did you mean?", error.message
|
347
|
+
assert_equal "super_human", error.corrections.first
|
348
|
+
end
|
295
349
|
end
|
296
350
|
end
|
297
351
|
|
298
352
|
class InverseHasManyTests < ActiveRecord::TestCase
|
299
|
-
fixtures :
|
353
|
+
fixtures :humans, :interests, :posts, :authors, :author_addresses, :comments
|
300
354
|
|
301
355
|
def test_parent_instance_should_be_shared_with_every_child_on_find
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
assert_equal
|
306
|
-
|
307
|
-
assert_equal
|
308
|
-
|
309
|
-
assert_equal
|
356
|
+
human = humans(:gordon)
|
357
|
+
interests = human.interests
|
358
|
+
interests.each do |interest|
|
359
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
360
|
+
human.name = "Bongo"
|
361
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
362
|
+
interest.human.name = "Mungo"
|
363
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to child-owned instance"
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_parent_instance_should_be_shared_with_every_child_on_find_for_sti
|
368
|
+
author = authors(:david)
|
369
|
+
posts = author.posts
|
370
|
+
posts.each do |post|
|
371
|
+
assert_equal author.name, post.author.name, "Name of human should be the same before changes to parent instance"
|
372
|
+
author.name = "Bongo"
|
373
|
+
assert_equal author.name, post.author.name, "Name of human should be the same after changes to parent instance"
|
374
|
+
post.author.name = "Mungo"
|
375
|
+
assert_equal author.name, post.author.name, "Name of human should be the same after changes to child-owned instance"
|
376
|
+
end
|
377
|
+
|
378
|
+
special_posts = author.special_posts
|
379
|
+
special_posts.each do |post|
|
380
|
+
assert_equal author.name, post.author.name, "Name of human should be the same before changes to parent instance"
|
381
|
+
author.name = "Bongo"
|
382
|
+
assert_equal author.name, post.author.name, "Name of human should be the same after changes to parent instance"
|
383
|
+
post.author.name = "Mungo"
|
384
|
+
assert_equal author.name, post.author.name, "Name of human should be the same after changes to child-owned instance"
|
310
385
|
end
|
311
386
|
end
|
312
387
|
|
313
388
|
def test_parent_instance_should_be_shared_with_eager_loaded_children
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
assert_equal
|
318
|
-
|
319
|
-
assert_equal
|
320
|
-
|
321
|
-
assert_equal
|
389
|
+
human = Human.all.merge!(where: { name: "Gordon" }, includes: :interests).first
|
390
|
+
interests = human.interests
|
391
|
+
interests.each do |interest|
|
392
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
393
|
+
human.name = "Bongo"
|
394
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
395
|
+
interest.human.name = "Mungo"
|
396
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to child-owned instance"
|
322
397
|
end
|
323
398
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
assert_equal
|
328
|
-
|
329
|
-
assert_equal
|
330
|
-
|
331
|
-
assert_equal
|
399
|
+
human = Human.all.merge!(where: { name: "Gordon" }, includes: :interests, order: "interests.id").first
|
400
|
+
interests = human.interests
|
401
|
+
interests.each do |interest|
|
402
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
403
|
+
human.name = "Bongo"
|
404
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
405
|
+
interest.human.name = "Mungo"
|
406
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to child-owned instance"
|
332
407
|
end
|
333
408
|
end
|
334
409
|
|
335
410
|
def test_parent_instance_should_be_shared_with_newly_block_style_built_child
|
336
|
-
|
337
|
-
|
338
|
-
assert_not_nil
|
339
|
-
assert_not_nil
|
340
|
-
assert_equal
|
341
|
-
|
342
|
-
assert_equal
|
343
|
-
|
344
|
-
assert_equal
|
411
|
+
human = Human.first
|
412
|
+
interest = human.interests.build { |ii| ii.topic = "Industrial Revolution Re-enactment" }
|
413
|
+
assert_not_nil interest.topic, "Child attributes supplied to build via blocks should be populated"
|
414
|
+
assert_not_nil interest.human
|
415
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
416
|
+
human.name = "Bongo"
|
417
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
418
|
+
interest.human.name = "Mungo"
|
419
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to just-built-child-owned instance"
|
345
420
|
end
|
346
421
|
|
347
422
|
def test_parent_instance_should_be_shared_with_newly_created_via_bang_method_child
|
348
|
-
|
349
|
-
|
350
|
-
assert_not_nil
|
351
|
-
assert_equal
|
352
|
-
|
353
|
-
assert_equal
|
354
|
-
|
355
|
-
assert_equal
|
423
|
+
human = Human.first
|
424
|
+
interest = human.interests.create!(topic: "Industrial Revolution Re-enactment")
|
425
|
+
assert_not_nil interest.human
|
426
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
427
|
+
human.name = "Bongo"
|
428
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
429
|
+
interest.human.name = "Mungo"
|
430
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to newly-created-child-owned instance"
|
356
431
|
end
|
357
432
|
|
358
433
|
def test_parent_instance_should_be_shared_with_newly_block_style_created_child
|
359
|
-
|
360
|
-
|
361
|
-
assert_not_nil
|
362
|
-
assert_not_nil
|
363
|
-
assert_equal
|
364
|
-
|
365
|
-
assert_equal
|
366
|
-
|
367
|
-
assert_equal
|
434
|
+
human = Human.first
|
435
|
+
interest = human.interests.create { |ii| ii.topic = "Industrial Revolution Re-enactment" }
|
436
|
+
assert_not_nil interest.topic, "Child attributes supplied to create via blocks should be populated"
|
437
|
+
assert_not_nil interest.human
|
438
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
439
|
+
human.name = "Bongo"
|
440
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
441
|
+
interest.human.name = "Mungo"
|
442
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to newly-created-child-owned instance"
|
368
443
|
end
|
369
444
|
|
370
445
|
def test_parent_instance_should_be_shared_within_create_block_of_new_child
|
371
|
-
|
372
|
-
interest =
|
373
|
-
assert i.
|
446
|
+
human = Human.first
|
447
|
+
interest = human.interests.create do |i|
|
448
|
+
assert i.human.equal?(human), "Human of child should be the same instance as a parent"
|
374
449
|
end
|
375
|
-
assert interest.
|
450
|
+
assert interest.human.equal?(human), "Human of the child should still be the same instance as a parent"
|
376
451
|
end
|
377
452
|
|
378
453
|
def test_parent_instance_should_be_shared_within_build_block_of_new_child
|
379
|
-
|
380
|
-
interest =
|
381
|
-
assert i.
|
454
|
+
human = Human.first
|
455
|
+
interest = human.interests.build do |i|
|
456
|
+
assert i.human.equal?(human), "Human of child should be the same instance as a parent"
|
382
457
|
end
|
383
|
-
assert interest.
|
458
|
+
assert interest.human.equal?(human), "Human of the child should still be the same instance as a parent"
|
384
459
|
end
|
385
460
|
|
386
461
|
def test_parent_instance_should_be_shared_with_poked_in_child
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
assert_not_nil
|
391
|
-
assert_equal
|
392
|
-
|
393
|
-
assert_equal
|
394
|
-
|
395
|
-
assert_equal
|
462
|
+
human = humans(:gordon)
|
463
|
+
interest = Interest.create(topic: "Industrial Revolution Re-enactment")
|
464
|
+
human.interests << interest
|
465
|
+
assert_not_nil interest.human
|
466
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
467
|
+
human.name = "Bongo"
|
468
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
469
|
+
interest.human.name = "Mungo"
|
470
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to newly-created-child-owned instance"
|
396
471
|
end
|
397
472
|
|
398
473
|
def test_parent_instance_should_be_shared_with_replaced_via_accessor_children
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
assert_not_nil
|
403
|
-
assert_equal
|
404
|
-
|
405
|
-
assert_equal
|
406
|
-
|
407
|
-
assert_equal
|
474
|
+
human = Human.first
|
475
|
+
interest = Interest.new(topic: "Industrial Revolution Re-enactment")
|
476
|
+
human.interests = [interest]
|
477
|
+
assert_not_nil interest.human
|
478
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same before changes to parent instance"
|
479
|
+
human.name = "Bongo"
|
480
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to parent instance"
|
481
|
+
interest.human.name = "Mungo"
|
482
|
+
assert_equal human.name, interest.human.name, "Name of human should be the same after changes to replaced-child-owned instance"
|
408
483
|
end
|
409
484
|
|
410
485
|
def test_parent_instance_should_be_shared_with_first_and_last_child
|
411
|
-
|
486
|
+
human = Human.first
|
412
487
|
|
413
|
-
assert
|
414
|
-
assert
|
488
|
+
assert human.interests.first.human.equal? human
|
489
|
+
assert human.interests.last.human.equal? human
|
415
490
|
end
|
416
491
|
|
417
492
|
def test_parent_instance_should_be_shared_with_first_n_and_last_n_children
|
418
|
-
|
493
|
+
human = Human.first
|
419
494
|
|
420
|
-
interests =
|
421
|
-
assert interests[0].
|
422
|
-
assert interests[1].
|
495
|
+
interests = human.interests.first(2)
|
496
|
+
assert interests[0].human.equal? human
|
497
|
+
assert interests[1].human.equal? human
|
423
498
|
|
424
|
-
interests =
|
425
|
-
assert interests[0].
|
426
|
-
assert interests[1].
|
499
|
+
interests = human.interests.last(2)
|
500
|
+
assert interests[0].human.equal? human
|
501
|
+
assert interests[1].human.equal? human
|
427
502
|
end
|
428
503
|
|
429
504
|
def test_parent_instance_should_find_child_instance_using_child_instance_id
|
430
|
-
|
505
|
+
human = Human.create!
|
431
506
|
interest = Interest.create!
|
432
|
-
|
507
|
+
human.interests = [interest]
|
433
508
|
|
434
|
-
assert interest.equal?(
|
435
|
-
assert interest.equal?(
|
436
|
-
assert
|
437
|
-
assert
|
509
|
+
assert interest.equal?(human.interests.first), "The inverse association should use the interest already created and held in memory"
|
510
|
+
assert interest.equal?(human.interests.find(interest.id)), "The inverse association should use the interest already created and held in memory"
|
511
|
+
assert human.equal?(human.interests.first.human), "Two inversion should lead back to the same object that was originally held"
|
512
|
+
assert human.equal?(human.interests.find(interest.id).human), "Two inversions should lead back to the same object that was originally held"
|
438
513
|
end
|
439
514
|
|
440
515
|
def test_parent_instance_should_find_child_instance_using_child_instance_id_when_created
|
441
|
-
|
442
|
-
interest = Interest.create!(
|
516
|
+
human = Human.create!
|
517
|
+
interest = Interest.create!(human: human)
|
443
518
|
|
444
|
-
assert
|
445
|
-
assert
|
519
|
+
assert human.equal?(human.interests.first.human), "Two inverses should lead back to the same object that was originally held"
|
520
|
+
assert human.equal?(human.interests.find(interest.id).human), "Two inversions should lead back to the same object that was originally held"
|
446
521
|
|
447
|
-
|
448
|
-
|
449
|
-
assert_equal
|
450
|
-
|
451
|
-
assert_equal
|
522
|
+
assert_nil human.interests.find(interest.id).human.name, "The name of the human should match before the name is changed"
|
523
|
+
human.name = "Ben Bitdiddle"
|
524
|
+
assert_equal human.name, human.interests.find(interest.id).human.name, "The name of the human should match after the parent name is changed"
|
525
|
+
human.interests.find(interest.id).human.name = "Alyssa P. Hacker"
|
526
|
+
assert_equal human.name, human.interests.find(interest.id).human.name, "The name of the human should match after the child name is changed"
|
452
527
|
end
|
453
528
|
|
454
529
|
def test_find_on_child_instance_with_id_should_not_load_all_child_records
|
455
|
-
|
456
|
-
interest = Interest.create!(
|
530
|
+
human = Human.create!
|
531
|
+
interest = Interest.create!(human: human)
|
532
|
+
|
533
|
+
human.interests.find(interest.id)
|
534
|
+
assert_not_predicate human.interests, :loaded?
|
535
|
+
end
|
536
|
+
|
537
|
+
def test_find_on_child_instance_with_id_should_set_inverse_instances
|
538
|
+
human = Human.create!
|
539
|
+
interest = Interest.create!(human: human)
|
457
540
|
|
458
|
-
|
459
|
-
|
541
|
+
child = human.interests.find(interest.id)
|
542
|
+
assert_predicate child.association(:human), :loaded?
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_find_on_child_instances_with_ids_should_set_inverse_instances
|
546
|
+
human = Human.create!
|
547
|
+
interests = Array.new(2) { Interest.create!(human: human) }
|
548
|
+
|
549
|
+
children = human.interests.find(interests.pluck(:id))
|
550
|
+
children.each do |child|
|
551
|
+
assert_predicate child.association(:human), :loaded?
|
552
|
+
end
|
460
553
|
end
|
461
554
|
|
462
555
|
def test_raise_record_not_found_error_when_invalid_ids_are_passed
|
@@ -464,270 +557,385 @@ class InverseHasManyTests < ActiveRecord::TestCase
|
|
464
557
|
# are indeed invalid.
|
465
558
|
Interest.delete_all
|
466
559
|
|
467
|
-
|
560
|
+
human = Human.create!
|
468
561
|
|
469
562
|
invalid_id = 245324523
|
470
|
-
assert_raise(ActiveRecord::RecordNotFound) {
|
563
|
+
assert_raise(ActiveRecord::RecordNotFound) { human.interests.find(invalid_id) }
|
471
564
|
|
472
565
|
invalid_ids = [8432342, 2390102913, 2453245234523452]
|
473
|
-
assert_raise(ActiveRecord::RecordNotFound) {
|
566
|
+
assert_raise(ActiveRecord::RecordNotFound) { human.interests.find(invalid_ids) }
|
474
567
|
end
|
475
568
|
|
476
569
|
def test_raise_record_not_found_error_when_no_ids_are_passed
|
477
|
-
|
570
|
+
human = Human.create!
|
571
|
+
|
572
|
+
exception = assert_raise(ActiveRecord::RecordNotFound) { human.interests.load.find() }
|
478
573
|
|
479
|
-
|
574
|
+
assert_equal exception.model, "Interest"
|
575
|
+
assert_equal exception.primary_key, "id"
|
480
576
|
end
|
481
577
|
|
482
578
|
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
|
483
|
-
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) {
|
579
|
+
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Human.first.secret_interests }
|
484
580
|
end
|
485
581
|
|
486
582
|
def test_child_instance_should_point_to_parent_without_saving
|
487
|
-
|
488
|
-
|
583
|
+
human = Human.new
|
584
|
+
interest = Interest.create(topic: "Industrial Revolution Re-enactment")
|
489
585
|
|
490
|
-
|
491
|
-
assert_not_nil
|
586
|
+
human.interests << interest
|
587
|
+
assert_not_nil interest.human
|
492
588
|
|
493
|
-
|
494
|
-
assert_equal
|
589
|
+
interest.human.name = "Charles"
|
590
|
+
assert_equal interest.human.name, human.name
|
495
591
|
|
496
|
-
|
592
|
+
assert_not_predicate human, :persisted?
|
497
593
|
end
|
498
594
|
|
499
595
|
def test_inverse_instance_should_be_set_before_find_callbacks_are_run
|
500
596
|
reset_callbacks(Interest, :find) do
|
501
|
-
Interest.after_find { raise unless association(:
|
597
|
+
Interest.after_find { raise unless association(:human).loaded? && human.present? }
|
502
598
|
|
503
|
-
|
504
|
-
|
505
|
-
|
599
|
+
assert_predicate Human.first.interests.reload, :any?
|
600
|
+
assert_predicate Human.includes(:interests).first.interests, :any?
|
601
|
+
assert_predicate Human.joins(:interests).includes(:interests).first.interests, :any?
|
506
602
|
end
|
507
603
|
end
|
508
604
|
|
509
605
|
def test_inverse_instance_should_be_set_before_initialize_callbacks_are_run
|
510
606
|
reset_callbacks(Interest, :initialize) do
|
511
|
-
Interest.after_initialize { raise unless association(:
|
607
|
+
Interest.after_initialize { raise unless association(:human).loaded? && human.present? }
|
512
608
|
|
513
|
-
|
514
|
-
|
515
|
-
|
609
|
+
assert_predicate Human.first.interests.reload, :any?
|
610
|
+
assert_predicate Human.includes(:interests).first.interests, :any?
|
611
|
+
assert_predicate Human.joins(:interests).includes(:interests).first.interests, :any?
|
516
612
|
end
|
517
613
|
end
|
518
614
|
|
519
|
-
def
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
615
|
+
def test_inverse_works_when_the_association_self_references_the_same_object
|
616
|
+
comment = comments(:greetings)
|
617
|
+
Comment.create!(parent: comment, post_id: comment.post_id, body: "New Comment")
|
618
|
+
|
619
|
+
comment.body = "OMG"
|
620
|
+
assert_equal comment.body, comment.children.first.parent.body
|
524
621
|
end
|
525
622
|
end
|
526
623
|
|
527
624
|
class InverseBelongsToTests < ActiveRecord::TestCase
|
528
|
-
fixtures :
|
625
|
+
fixtures :humans, :faces, :interests
|
529
626
|
|
530
627
|
def test_child_instance_should_be_shared_with_parent_on_find
|
531
|
-
|
532
|
-
|
533
|
-
assert_equal
|
534
|
-
|
535
|
-
assert_equal
|
536
|
-
|
537
|
-
assert_equal
|
628
|
+
face = faces(:trusting)
|
629
|
+
human = face.human
|
630
|
+
assert_equal face.description, human.face.description, "Description of face should be the same before changes to child instance"
|
631
|
+
face.description = "gormless"
|
632
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to child instance"
|
633
|
+
human.face.description = "pleasing"
|
634
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to parent-owned instance"
|
538
635
|
end
|
539
636
|
|
540
637
|
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
|
541
|
-
|
542
|
-
|
543
|
-
assert_equal
|
544
|
-
|
545
|
-
assert_equal
|
546
|
-
|
547
|
-
assert_equal
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
assert_equal
|
552
|
-
|
553
|
-
assert_equal
|
554
|
-
|
555
|
-
assert_equal
|
638
|
+
face = Face.all.merge!(includes: :human, where: { description: "trusting" }).first
|
639
|
+
human = face.human
|
640
|
+
assert_equal face.description, human.face.description, "Description of face should be the same before changes to child instance"
|
641
|
+
face.description = "gormless"
|
642
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to child instance"
|
643
|
+
human.face.description = "pleasing"
|
644
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to parent-owned instance"
|
645
|
+
|
646
|
+
face = Face.all.merge!(includes: :human, order: "humans.id", where: { description: "trusting" }).first
|
647
|
+
human = face.human
|
648
|
+
assert_equal face.description, human.face.description, "Description of face should be the same before changes to child instance"
|
649
|
+
face.description = "gormless"
|
650
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to child instance"
|
651
|
+
human.face.description = "pleasing"
|
652
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to parent-owned instance"
|
556
653
|
end
|
557
654
|
|
558
655
|
def test_child_instance_should_be_shared_with_newly_built_parent
|
559
|
-
|
560
|
-
|
561
|
-
assert_not_nil
|
562
|
-
assert_equal
|
563
|
-
|
564
|
-
assert_equal
|
565
|
-
|
566
|
-
assert_equal
|
656
|
+
face = faces(:trusting)
|
657
|
+
human = face.build_human(name: "Charles")
|
658
|
+
assert_not_nil human.face
|
659
|
+
assert_equal face.description, human.face.description, "Description of face should be the same before changes to child instance"
|
660
|
+
face.description = "gormless"
|
661
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to child instance"
|
662
|
+
human.face.description = "pleasing"
|
663
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to just-built-parent-owned instance"
|
567
664
|
end
|
568
665
|
|
569
666
|
def test_child_instance_should_be_shared_with_newly_created_parent
|
570
|
-
|
571
|
-
|
572
|
-
assert_not_nil
|
573
|
-
assert_equal
|
574
|
-
|
575
|
-
assert_equal
|
576
|
-
|
577
|
-
assert_equal
|
667
|
+
face = faces(:trusting)
|
668
|
+
human = face.create_human(name: "Charles")
|
669
|
+
assert_not_nil human.face
|
670
|
+
assert_equal face.description, human.face.description, "Description of face should be the same before changes to child instance"
|
671
|
+
face.description = "gormless"
|
672
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to child instance"
|
673
|
+
human.face.description = "pleasing"
|
674
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to newly-created-parent-owned instance"
|
578
675
|
end
|
579
676
|
|
580
677
|
def test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
|
581
|
-
|
582
|
-
|
583
|
-
assert_not_nil
|
584
|
-
iz =
|
678
|
+
interest = interests(:trainspotting)
|
679
|
+
human = interest.human
|
680
|
+
assert_not_nil human.interests
|
681
|
+
iz = human.interests.detect { |_iz| _iz.id == interest.id }
|
585
682
|
assert_not_nil iz
|
586
|
-
assert_equal
|
587
|
-
|
588
|
-
assert_not_equal
|
589
|
-
iz.topic =
|
590
|
-
assert_not_equal
|
683
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same before changes to child"
|
684
|
+
interest.topic = "Eating cheese with a spoon"
|
685
|
+
assert_not_equal interest.topic, iz.topic, "Interest topics should not be the same after changes to child"
|
686
|
+
iz.topic = "Cow tipping"
|
687
|
+
assert_not_equal interest.topic, iz.topic, "Interest topics should not be the same after changes to parent-owned instance"
|
688
|
+
end
|
689
|
+
|
690
|
+
def test_with_has_many_inversing_should_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
|
691
|
+
with_has_many_inversing do
|
692
|
+
interest = interests(:trainspotting)
|
693
|
+
human = interest.human
|
694
|
+
assert_not_nil human.interests
|
695
|
+
iz = human.interests.detect { |_iz| _iz.id == interest.id }
|
696
|
+
assert_not_nil iz
|
697
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same before changes to child"
|
698
|
+
interest.topic = "Eating cheese with a spoon"
|
699
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same after changes to child"
|
700
|
+
iz.topic = "Cow tipping"
|
701
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same after changes to parent-owned instance"
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
def test_with_has_many_inversing_should_have_single_record_when_setting_record_through_attribute_in_build_method
|
706
|
+
with_has_many_inversing do
|
707
|
+
human = Human.create!
|
708
|
+
human.interests.build(
|
709
|
+
human: human
|
710
|
+
)
|
711
|
+
assert_equal 1, human.interests.size
|
712
|
+
human.save!
|
713
|
+
assert_equal 1, human.interests.size
|
714
|
+
end
|
715
|
+
end
|
716
|
+
|
717
|
+
def test_with_has_many_inversing_does_not_trigger_association_callbacks_on_set_when_the_inverse_is_a_has_many
|
718
|
+
with_has_many_inversing do
|
719
|
+
human = interests(:trainspotting).human_with_callbacks
|
720
|
+
assert_not_predicate human, :add_callback_called?
|
721
|
+
end
|
722
|
+
end
|
723
|
+
|
724
|
+
def test_with_hash_many_inversing_does_not_add_duplicate_associated_objects
|
725
|
+
with_has_many_inversing do
|
726
|
+
human = Human.new
|
727
|
+
interest = Interest.new(human: human)
|
728
|
+
human.interests << interest
|
729
|
+
assert_equal 1, human.interests.size
|
730
|
+
end
|
731
|
+
end
|
732
|
+
|
733
|
+
def test_unscope_does_not_set_inverse_when_incorrect
|
734
|
+
interest = interests(:trainspotting)
|
735
|
+
human = interest.human
|
736
|
+
created_human = Human.create(name: "wrong human")
|
737
|
+
found_interest = created_human.interests.or(human.interests).detect { |this_interest| interest.id == this_interest.id }
|
738
|
+
|
739
|
+
assert_equal human, found_interest.human
|
740
|
+
end
|
741
|
+
|
742
|
+
def test_or_does_not_set_inverse_when_incorrect
|
743
|
+
interest = interests(:trainspotting)
|
744
|
+
human = interest.human
|
745
|
+
created_human = Human.create(name: "wrong human")
|
746
|
+
found_interest = created_human.interests.unscope(:where).detect { |this_interest| interest.id == this_interest.id }
|
747
|
+
|
748
|
+
assert_equal human, found_interest.human
|
591
749
|
end
|
592
750
|
|
593
751
|
def test_child_instance_should_be_shared_with_replaced_via_accessor_parent
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
assert_not_nil
|
598
|
-
assert_equal
|
599
|
-
|
600
|
-
assert_equal
|
601
|
-
|
602
|
-
assert_equal
|
752
|
+
face = Face.first
|
753
|
+
human = Human.new(name: "Charles")
|
754
|
+
face.human = human
|
755
|
+
assert_not_nil human.face
|
756
|
+
assert_equal face.description, human.face.description, "Description of face should be the same before changes to child instance"
|
757
|
+
face.description = "gormless"
|
758
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to child instance"
|
759
|
+
human.face.description = "pleasing"
|
760
|
+
assert_equal face.description, human.face.description, "Description of face should be the same after changes to replaced-parent-owned instance"
|
603
761
|
end
|
604
762
|
|
605
763
|
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
|
606
|
-
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.
|
764
|
+
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.puzzled_human }
|
765
|
+
end
|
766
|
+
|
767
|
+
if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error)
|
768
|
+
def test_trying_to_use_inverses_that_dont_exist_should_have_suggestions_for_fix
|
769
|
+
error = assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) {
|
770
|
+
Face.first.puzzled_human
|
771
|
+
}
|
772
|
+
|
773
|
+
assert_match "Did you mean?", error.message
|
774
|
+
assert_equal "confused_face", error.corrections.first
|
775
|
+
end
|
776
|
+
end
|
777
|
+
|
778
|
+
def test_building_has_many_parent_association_inverses_one_record
|
779
|
+
with_has_many_inversing do
|
780
|
+
interest = Interest.new
|
781
|
+
interest.build_human
|
782
|
+
assert_equal 1, interest.human.interests.size
|
783
|
+
interest.save!
|
784
|
+
assert_equal 1, interest.human.interests.size
|
785
|
+
end
|
607
786
|
end
|
608
787
|
end
|
609
788
|
|
610
789
|
class InversePolymorphicBelongsToTests < ActiveRecord::TestCase
|
611
|
-
fixtures :
|
790
|
+
fixtures :humans, :faces, :interests
|
612
791
|
|
613
792
|
def test_child_instance_should_be_shared_with_parent_on_find
|
614
|
-
|
615
|
-
|
616
|
-
assert_equal
|
617
|
-
|
618
|
-
assert_equal
|
619
|
-
|
620
|
-
assert_equal
|
793
|
+
face = Face.all.merge!(where: { description: "confused" }).first
|
794
|
+
human = face.polymorphic_human
|
795
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same before changes to child instance"
|
796
|
+
face.description = "gormless"
|
797
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same after changes to child instance"
|
798
|
+
human.polymorphic_face.description = "pleasing"
|
799
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same after changes to parent-owned instance"
|
621
800
|
end
|
622
801
|
|
623
802
|
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
|
624
|
-
|
625
|
-
|
626
|
-
assert_equal
|
627
|
-
|
628
|
-
assert_equal
|
629
|
-
|
630
|
-
assert_equal
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
assert_equal
|
635
|
-
|
636
|
-
assert_equal
|
637
|
-
|
638
|
-
assert_equal
|
803
|
+
face = Face.all.merge!(where: { description: "confused" }, includes: :human).first
|
804
|
+
human = face.polymorphic_human
|
805
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same before changes to child instance"
|
806
|
+
face.description = "gormless"
|
807
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same after changes to child instance"
|
808
|
+
human.polymorphic_face.description = "pleasing"
|
809
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same after changes to parent-owned instance"
|
810
|
+
|
811
|
+
face = Face.all.merge!(where: { description: "confused" }, includes: :human, order: "humans.id").first
|
812
|
+
human = face.polymorphic_human
|
813
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same before changes to child instance"
|
814
|
+
face.description = "gormless"
|
815
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same after changes to child instance"
|
816
|
+
human.polymorphic_face.description = "pleasing"
|
817
|
+
assert_equal face.description, human.polymorphic_face.description, "Description of face should be the same after changes to parent-owned instance"
|
639
818
|
end
|
640
819
|
|
641
820
|
def test_child_instance_should_be_shared_with_replaced_via_accessor_parent
|
642
821
|
face = faces(:confused)
|
643
|
-
|
822
|
+
new_human = Human.new
|
644
823
|
|
645
|
-
assert_not_nil face.
|
646
|
-
face.
|
824
|
+
assert_not_nil face.polymorphic_human
|
825
|
+
face.polymorphic_human = new_human
|
647
826
|
|
648
|
-
assert_equal face.description,
|
649
|
-
face.description =
|
650
|
-
assert_equal face.description,
|
651
|
-
|
652
|
-
assert_equal face.description,
|
827
|
+
assert_equal face.description, new_human.polymorphic_face.description, "Description of face should be the same before changes to parent instance"
|
828
|
+
face.description = "Bongo"
|
829
|
+
assert_equal face.description, new_human.polymorphic_face.description, "Description of face should be the same after changes to parent instance"
|
830
|
+
new_human.polymorphic_face.description = "Mungo"
|
831
|
+
assert_equal face.description, new_human.polymorphic_face.description, "Description of face should be the same after changes to replaced-parent-owned instance"
|
653
832
|
end
|
654
833
|
|
655
|
-
def
|
656
|
-
|
657
|
-
|
834
|
+
def test_inversed_instance_should_not_be_reloaded_after_stale_state_changed
|
835
|
+
new_human = Human.new
|
836
|
+
face = Face.new
|
837
|
+
new_human.face = face
|
658
838
|
|
659
|
-
|
660
|
-
|
839
|
+
old_inversed_human = face.human
|
840
|
+
new_human.save!
|
841
|
+
new_inversed_human = face.human
|
661
842
|
|
662
|
-
|
663
|
-
face.description = 'Bongo'
|
664
|
-
assert_equal face.description, new_man.polymorphic_face.description, "Description of face should be the same after changes to parent instance"
|
665
|
-
new_man.polymorphic_face.description = 'Mungo'
|
666
|
-
assert_equal face.description, new_man.polymorphic_face.description, "Description of face should be the same after changes to replaced-parent-owned instance"
|
843
|
+
assert_same old_inversed_human, new_inversed_human
|
667
844
|
end
|
668
845
|
|
669
|
-
def
|
670
|
-
|
671
|
-
|
672
|
-
|
846
|
+
def test_inversed_instance_should_not_be_reloaded_after_stale_state_changed_with_validation
|
847
|
+
face = Face.new human: Human.new
|
848
|
+
|
849
|
+
old_inversed_human = face.human
|
850
|
+
face.save!
|
851
|
+
new_inversed_human = face.human
|
852
|
+
|
853
|
+
assert_same old_inversed_human, new_inversed_human
|
854
|
+
end
|
673
855
|
|
674
|
-
|
675
|
-
|
676
|
-
|
856
|
+
def test_inversed_instance_should_load_after_autosave_if_it_is_not_already_loaded
|
857
|
+
human = Human.create!
|
858
|
+
human.create_autosave_face!
|
677
859
|
|
678
|
-
|
860
|
+
human.autosave_face.reload # clear cached load of autosave_human
|
861
|
+
human.autosave_face.description = "new description"
|
862
|
+
human.save!
|
863
|
+
|
864
|
+
assert_not_nil human.autosave_face.autosave_human
|
679
865
|
end
|
680
866
|
|
681
867
|
def test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
|
682
|
-
|
683
|
-
|
684
|
-
assert_not_nil
|
685
|
-
iz =
|
868
|
+
interest = interests(:llama_wrangling)
|
869
|
+
human = interest.polymorphic_human
|
870
|
+
assert_not_nil human.polymorphic_interests
|
871
|
+
iz = human.polymorphic_interests.detect { |_iz| _iz.id == interest.id }
|
686
872
|
assert_not_nil iz
|
687
|
-
assert_equal
|
688
|
-
|
689
|
-
assert_not_equal
|
690
|
-
iz.topic =
|
691
|
-
assert_not_equal
|
873
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same before changes to child"
|
874
|
+
interest.topic = "Eating cheese with a spoon"
|
875
|
+
assert_not_equal interest.topic, iz.topic, "Interest topics should not be the same after changes to child"
|
876
|
+
iz.topic = "Cow tipping"
|
877
|
+
assert_not_equal interest.topic, iz.topic, "Interest topics should not be the same after changes to parent-owned instance"
|
878
|
+
end
|
879
|
+
|
880
|
+
def test_with_has_many_inversing_should_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
|
881
|
+
with_has_many_inversing do
|
882
|
+
interest = interests(:llama_wrangling)
|
883
|
+
human = interest.polymorphic_human
|
884
|
+
assert_not_nil human.polymorphic_interests
|
885
|
+
iz = human.polymorphic_interests.detect { |_iz| _iz.id == interest.id }
|
886
|
+
assert_not_nil iz
|
887
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same before changes to child"
|
888
|
+
interest.topic = "Eating cheese with a spoon"
|
889
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same after changes to child"
|
890
|
+
iz.topic = "Cow tipping"
|
891
|
+
assert_equal interest.topic, iz.topic, "Interest topics should be the same after changes to parent-owned instance"
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
def test_with_has_many_inversing_does_not_trigger_association_callbacks_on_set_when_the_inverse_is_a_has_many
|
896
|
+
with_has_many_inversing do
|
897
|
+
human = interests(:llama_wrangling).polymorphic_human_with_callbacks
|
898
|
+
assert_not_predicate human, :add_callback_called?
|
899
|
+
end
|
692
900
|
end
|
693
901
|
|
694
902
|
def test_trying_to_access_inverses_that_dont_exist_shouldnt_raise_an_error
|
695
903
|
# Ideally this would, if only for symmetry's sake with other association types
|
696
|
-
assert_nothing_raised { Face.first.
|
904
|
+
assert_nothing_raised { Face.first.puzzled_polymorphic_human }
|
697
905
|
end
|
698
906
|
|
699
907
|
def test_trying_to_set_polymorphic_inverses_that_dont_exist_at_all_should_raise_an_error
|
700
|
-
# fails because no class has the correct inverse_of for
|
701
|
-
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.
|
908
|
+
# fails because no class has the correct inverse_of for puzzled_polymorphic_human
|
909
|
+
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.puzzled_polymorphic_human = Human.first }
|
702
910
|
end
|
703
911
|
|
704
912
|
def test_trying_to_set_polymorphic_inverses_that_dont_exist_on_the_instance_being_set_should_raise_an_error
|
705
|
-
# passes because
|
706
|
-
assert_nothing_raised { Face.first.
|
913
|
+
# passes because Human does have the correct inverse_of
|
914
|
+
assert_nothing_raised { Face.first.polymorphic_human = Human.first }
|
707
915
|
# fails because Interest does have the correct inverse_of
|
708
|
-
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.
|
916
|
+
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.polymorphic_human = Interest.first }
|
709
917
|
end
|
710
918
|
end
|
711
919
|
|
712
920
|
# NOTE - these tests might not be meaningful, ripped as they were from the parental_control plugin
|
713
921
|
# which would guess the inverse rather than look for an explicit configuration option.
|
714
922
|
class InverseMultipleHasManyInversesForSameModel < ActiveRecord::TestCase
|
715
|
-
fixtures :
|
923
|
+
fixtures :humans, :interests, :zines
|
716
924
|
|
717
925
|
def test_that_we_can_load_associations_that_have_the_same_reciprocal_name_from_different_models
|
718
926
|
assert_nothing_raised do
|
719
|
-
|
720
|
-
|
721
|
-
|
927
|
+
interest = Interest.first
|
928
|
+
interest.zine
|
929
|
+
interest.human
|
722
930
|
end
|
723
931
|
end
|
724
932
|
|
725
933
|
def test_that_we_can_create_associations_that_have_the_same_reciprocal_name_from_different_models
|
726
934
|
assert_nothing_raised do
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
935
|
+
interest = Interest.first
|
936
|
+
interest.build_zine(title: "Get Some in Winter! 2008")
|
937
|
+
interest.build_human(name: "Gordon")
|
938
|
+
interest.save!
|
731
939
|
end
|
732
940
|
end
|
733
941
|
end
|