ibm_db 5.6.1-arm64-darwin-24
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 +7 -0
- data/CHANGES +299 -0
- data/LICENSE +55 -0
- data/MANIFEST +14 -0
- data/ParameterizedQueries README +39 -0
- data/README +210 -0
- data/ext/Makefile +270 -0
- data/ext/Makefile.nt32 +181 -0
- data/ext/Makefile.nt32.191 +212 -0
- data/ext/extconf.rb +320 -0
- data/ext/gil_release_version.h +3 -0
- data/ext/ibm_db.bundle +0 -0
- data/ext/ibm_db.c +11865 -0
- data/ext/ibm_db.o +0 -0
- data/ext/mkmf.log +98 -0
- data/ext/ruby_ibm_db.h +241 -0
- data/ext/ruby_ibm_db_cli.c +867 -0
- data/ext/ruby_ibm_db_cli.h +508 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/ext/unicode_support_version.h +3 -0
- data/init.rb +42 -0
- data/lib/IBM_DB.rb +27 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +4407 -0
- data/lib/active_record/connection_adapters/ibm_db_pstmt.rb +1965 -0
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +5 -0
- data/lib/active_record/vendor/db2-i5-zOS.yaml +328 -0
- data/lib/ibm_db.bundle +0 -0
- data/test/active_record/connection_adapters/fake_adapter.rb +52 -0
- 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/example.log +1 -0
- data/test/assets/flowers.jpg +0 -0
- data/test/assets/schema_dump_5_1.yml +345 -0
- data/test/assets/test.txt +1 -0
- data/test/cases/adapter_prevent_writes_test.rb +334 -0
- data/test/cases/adapter_test.rb +565 -0
- data/test/cases/adapters/mysql2/active_schema_test.rb +203 -0
- data/test/cases/adapters/mysql2/auto_increment_test.rb +34 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +52 -0
- data/test/cases/adapters/mysql2/boolean_test.rb +102 -0
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +65 -0
- data/test/cases/adapters/mysql2/charset_collation_test.rb +57 -0
- data/test/cases/adapters/mysql2/connection_test.rb +208 -0
- data/test/cases/adapters/mysql2/count_deleted_rows_with_lock_test.rb +28 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +49 -0
- data/test/cases/adapters/mysql2/enum_test.rb +47 -0
- data/test/cases/adapters/mysql2/explain_test.rb +23 -0
- data/test/cases/adapters/mysql2/json_test.rb +24 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_prevent_writes_test.rb +208 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +238 -0
- 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/reserved_word_test.rb +152 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +64 -0
- data/test/cases/adapters/mysql2/schema_test.rb +128 -0
- data/test/cases/adapters/mysql2/set_test.rb +32 -0
- data/test/cases/adapters/mysql2/sp_test.rb +38 -0
- data/test/cases/adapters/mysql2/sql_types_test.rb +16 -0
- data/test/cases/adapters/mysql2/table_options_test.rb +125 -0
- data/test/cases/adapters/mysql2/transaction_test.rb +151 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +68 -0
- data/test/cases/adapters/mysql2/virtual_column_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +113 -0
- data/test/cases/adapters/postgresql/array_test.rb +394 -0
- data/test/cases/adapters/postgresql/bit_string_test.rb +84 -0
- data/test/cases/adapters/postgresql/bytea_test.rb +135 -0
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +27 -0
- data/test/cases/adapters/postgresql/change_schema_test.rb +40 -0
- data/test/cases/adapters/postgresql/cidr_test.rb +27 -0
- data/test/cases/adapters/postgresql/citext_test.rb +78 -0
- data/test/cases/adapters/postgresql/collation_test.rb +55 -0
- data/test/cases/adapters/postgresql/composite_test.rb +134 -0
- data/test/cases/adapters/postgresql/connection_test.rb +245 -0
- data/test/cases/adapters/postgresql/create_unlogged_tables_test.rb +74 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +89 -0
- data/test/cases/adapters/postgresql/date_test.rb +42 -0
- data/test/cases/adapters/postgresql/domain_test.rb +49 -0
- data/test/cases/adapters/postgresql/enum_test.rb +93 -0
- data/test/cases/adapters/postgresql/explain_test.rb +22 -0
- data/test/cases/adapters/postgresql/extension_migration_test.rb +64 -0
- data/test/cases/adapters/postgresql/foreign_table_test.rb +109 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +46 -0
- data/test/cases/adapters/postgresql/geometric_test.rb +372 -0
- data/test/cases/adapters/postgresql/hstore_test.rb +390 -0
- data/test/cases/adapters/postgresql/infinity_test.rb +108 -0
- data/test/cases/adapters/postgresql/integer_test.rb +27 -0
- data/test/cases/adapters/postgresql/interval_test.rb +99 -0
- data/test/cases/adapters/postgresql/json_test.rb +52 -0
- data/test/cases/adapters/postgresql/ltree_test.rb +51 -0
- data/test/cases/adapters/postgresql/money_test.rb +127 -0
- data/test/cases/adapters/postgresql/network_test.rb +102 -0
- data/test/cases/adapters/postgresql/numbers_test.rb +51 -0
- 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 +447 -0
- data/test/cases/adapters/postgresql/prepared_statements_disabled_test.rb +27 -0
- data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +50 -0
- data/test/cases/adapters/postgresql/range_test.rb +457 -0
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +112 -0
- data/test/cases/adapters/postgresql/rename_table_test.rb +35 -0
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +110 -0
- data/test/cases/adapters/postgresql/schema_test.rb +713 -0
- data/test/cases/adapters/postgresql/serial_test.rb +156 -0
- data/test/cases/adapters/postgresql/statement_pool_test.rb +61 -0
- data/test/cases/adapters/postgresql/timestamp_test.rb +92 -0
- 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 +35 -0
- data/test/cases/adapters/postgresql/utils_test.rb +64 -0
- data/test/cases/adapters/postgresql/uuid_test.rb +411 -0
- data/test/cases/adapters/postgresql/xml_test.rb +50 -0
- data/test/cases/adapters/sqlite3/collation_test.rb +64 -0
- data/test/cases/adapters/sqlite3/copy_table_test.rb +101 -0
- data/test/cases/adapters/sqlite3/explain_test.rb +23 -0
- data/test/cases/adapters/sqlite3/json_test.rb +29 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +79 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_prevent_writes_test.rb +186 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +628 -0
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +21 -0
- data/test/cases/adapters/sqlite3/transaction_test.rb +123 -0
- data/test/cases/aggregations_test.rb +170 -0
- data/test/cases/annotate_test.rb +46 -0
- data/test/cases/ar_schema_test.rb +213 -0
- 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/association_scope_test.rb +16 -0
- data/test/cases/associations/belongs_to_associations_test.rb +1493 -0
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +43 -0
- data/test/cases/associations/callbacks_test.rb +208 -0
- data/test/cases/associations/cascaded_eager_loading_test.rb +245 -0
- data/test/cases/associations/eager_load_includes_full_sti_class_test.rb +156 -0
- data/test/cases/associations/eager_load_nested_include_test.rb +127 -0
- data/test/cases/associations/eager_singularization_test.rb +148 -0
- data/test/cases/associations/eager_test.rb +1658 -0
- data/test/cases/associations/extension_test.rb +93 -0
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +1025 -0
- data/test/cases/associations/has_many_associations_test.rb +3074 -0
- data/test/cases/associations/has_many_through_associations_test.rb +1580 -0
- data/test/cases/associations/has_one_associations_test.rb +872 -0
- data/test/cases/associations/has_one_through_associations_test.rb +429 -0
- data/test/cases/associations/inner_join_association_test.rb +215 -0
- data/test/cases/associations/inverse_associations_test.rb +941 -0
- data/test/cases/associations/join_model_test.rb +787 -0
- data/test/cases/associations/left_outer_join_association_test.rb +123 -0
- data/test/cases/associations/nested_through_associations_test.rb +636 -0
- data/test/cases/associations/required_test.rb +127 -0
- data/test/cases/associations_test.rb +516 -0
- data/test/cases/attribute_decorators_test.rb +126 -0
- data/test/cases/attribute_methods/read_test.rb +60 -0
- data/test/cases/attribute_methods_test.rb +1124 -0
- data/test/cases/attribute_set_test.rb +270 -0
- data/test/cases/attribute_test.rb +246 -0
- data/test/cases/attributes_test.rb +371 -0
- data/test/cases/autosave_association_test.rb +1953 -0
- data/test/cases/base_prevent_writes_test.rb +229 -0
- data/test/cases/base_test.rb +1770 -0
- data/test/cases/batches_test.rb +695 -0
- data/test/cases/binary_test.rb +39 -0
- data/test/cases/bind_parameter_test.rb +283 -0
- data/test/cases/boolean_test.rb +52 -0
- data/test/cases/cache_key_test.rb +131 -0
- data/test/cases/calculations_test.rb +1361 -0
- data/test/cases/callbacks_test.rb +503 -0
- data/test/cases/clone_test.rb +45 -0
- data/test/cases/coders/json_test.rb +17 -0
- data/test/cases/coders/yaml_column_test.rb +66 -0
- data/test/cases/collection_cache_key_test.rb +272 -0
- data/test/cases/column_alias_test.rb +19 -0
- data/test/cases/column_definition_test.rb +34 -0
- data/test/cases/comment_test.rb +204 -0
- data/test/cases/connection_adapters/adapter_leasing_test.rb +60 -0
- data/test/cases/connection_adapters/connection_handler_test.rb +467 -0
- 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_specification_test.rb +12 -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 +436 -0
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +81 -0
- data/test/cases/connection_adapters/quoting_test.rb +13 -0
- data/test/cases/connection_adapters/schema_cache_test.rb +294 -0
- data/test/cases/connection_adapters/type_lookup_test.rb +119 -0
- data/test/cases/connection_management_test.rb +114 -0
- data/test/cases/connection_pool_test.rb +754 -0
- data/test/cases/connection_specification/resolver_test.rb +131 -0
- data/test/cases/core_test.rb +136 -0
- data/test/cases/counter_cache_test.rb +368 -0
- data/test/cases/custom_locking_test.rb +19 -0
- 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 +36 -0
- data/test/cases/date_test.rb +36 -0
- data/test/cases/date_time_precision_test.rb +129 -0
- data/test/cases/date_time_test.rb +76 -0
- data/test/cases/defaults_test.rb +254 -0
- data/test/cases/delegated_type_test.rb +57 -0
- data/test/cases/dirty_test.rb +959 -0
- data/test/cases/disconnected_test.rb +30 -0
- data/test/cases/dup_test.rb +184 -0
- data/test/cases/enum_test.rb +823 -0
- data/test/cases/errors_test.rb +16 -0
- data/test/cases/explain_subscriber_test.rb +66 -0
- data/test/cases/explain_test.rb +79 -0
- data/test/cases/filter_attributes_test.rb +153 -0
- data/test/cases/finder_respond_to_test.rb +60 -0
- data/test/cases/finder_test.rb +1676 -0
- data/test/cases/fixture_set/file_test.rb +152 -0
- data/test/cases/fixtures_test.rb +1645 -0
- data/test/cases/forbidden_attributes_protection_test.rb +130 -0
- data/test/cases/habtm_destroy_order_test.rb +61 -0
- data/test/cases/helper.rb +233 -0
- data/test/cases/hot_compatibility_test.rb +143 -0
- data/test/cases/i18n_test.rb +46 -0
- data/test/cases/inheritance_test.rb +671 -0
- data/test/cases/insert_all_test.rb +489 -0
- data/test/cases/instrumentation_test.rb +101 -0
- data/test/cases/integration_test.rb +243 -0
- data/test/cases/invalid_connection_test.rb +26 -0
- data/test/cases/invertible_migration_test.rb +527 -0
- data/test/cases/json_attribute_test.rb +35 -0
- data/test/cases/json_serialization_test.rb +310 -0
- data/test/cases/json_shared_test_cases.rb +290 -0
- data/test/cases/locking_test.rb +787 -0
- data/test/cases/log_subscriber_test.rb +267 -0
- data/test/cases/marshal_serialization_test.rb +39 -0
- data/test/cases/migration/change_schema_test.rb +504 -0
- data/test/cases/migration/change_table_test.rb +364 -0
- data/test/cases/migration/check_constraint_test.rb +162 -0
- data/test/cases/migration/column_attributes_test.rb +186 -0
- data/test/cases/migration/column_positioning_test.rb +68 -0
- data/test/cases/migration/columns_test.rb +326 -0
- data/test/cases/migration/command_recorder_test.rb +437 -0
- data/test/cases/migration/compatibility_test.rb +673 -0
- data/test/cases/migration/create_join_table_test.rb +167 -0
- data/test/cases/migration/foreign_key_test.rb +581 -0
- data/test/cases/migration/helper.rb +40 -0
- data/test/cases/migration/index_test.rb +267 -0
- data/test/cases/migration/logger_test.rb +39 -0
- data/test/cases/migration/pending_migrations_test.rb +106 -0
- data/test/cases/migration/references_foreign_key_test.rb +235 -0
- data/test/cases/migration/references_index_test.rb +120 -0
- data/test/cases/migration/references_statements_test.rb +137 -0
- data/test/cases/migration/rename_table_test.rb +116 -0
- data/test/cases/migration_test.rb +1525 -0
- data/test/cases/migrator_test.rb +527 -0
- data/test/cases/mixin_test.rb +64 -0
- data/test/cases/modules_test.rb +174 -0
- data/test/cases/multi_db_migrator_test.rb +223 -0
- data/test/cases/multiparameter_attributes_test.rb +399 -0
- data/test/cases/multiple_db_test.rb +116 -0
- data/test/cases/nested_attributes_test.rb +1119 -0
- data/test/cases/nested_attributes_with_callbacks_test.rb +146 -0
- data/test/cases/null_relation_test.rb +84 -0
- data/test/cases/numeric_data_test.rb +93 -0
- data/test/cases/persistence_test.rb +1093 -0
- data/test/cases/pooled_connections_test.rb +73 -0
- data/test/cases/prepared_statement_status_test.rb +48 -0
- data/test/cases/primary_keys_test.rb +482 -0
- data/test/cases/query_cache_test.rb +915 -0
- data/test/cases/quoting_test.rb +303 -0
- data/test/cases/readonly_test.rb +120 -0
- data/test/cases/reaper_test.rb +199 -0
- data/test/cases/reflection_test.rb +520 -0
- data/test/cases/relation/delegation_test.rb +76 -0
- data/test/cases/relation/delete_all_test.rb +117 -0
- data/test/cases/relation/merging_test.rb +434 -0
- data/test/cases/relation/mutation_test.rb +145 -0
- data/test/cases/relation/or_test.rb +192 -0
- data/test/cases/relation/predicate_builder_test.rb +31 -0
- data/test/cases/relation/record_fetch_warning_test.rb +42 -0
- 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 +141 -0
- data/test/cases/relation/where_clause_test.rb +257 -0
- data/test/cases/relation/where_test.rb +429 -0
- data/test/cases/relation_test.rb +482 -0
- data/test/cases/relations_test.rb +2251 -0
- data/test/cases/reload_models_test.rb +26 -0
- data/test/cases/reserved_word_test.rb +141 -0
- data/test/cases/result_test.rb +141 -0
- data/test/cases/sanitize_test.rb +192 -0
- data/test/cases/schema_dumper_test.rb +550 -0
- data/test/cases/schema_loading_test.rb +53 -0
- data/test/cases/scoping/default_scoping_test.rb +569 -0
- data/test/cases/scoping/named_scoping_test.rb +649 -0
- data/test/cases/scoping/relation_scoping_test.rb +522 -0
- data/test/cases/secure_token_test.rb +47 -0
- data/test/cases/serialization_test.rb +106 -0
- data/test/cases/serialized_attribute_test.rb +455 -0
- data/test/cases/signed_id_test.rb +168 -0
- data/test/cases/statement_cache_test.rb +153 -0
- data/test/cases/statement_invalid_test.rb +42 -0
- data/test/cases/store_test.rb +320 -0
- data/test/cases/strict_loading_test.rb +473 -0
- data/test/cases/suppressor_test.rb +77 -0
- data/test/cases/tasks/database_tasks_test.rb +1526 -0
- data/test/cases/tasks/mysql_rake_test.rb +417 -0
- data/test/cases/tasks/postgresql_rake_test.rb +534 -0
- data/test/cases/tasks/sqlite_rake_test.rb +267 -0
- data/test/cases/test_case.rb +142 -0
- data/test/cases/test_databases_test.rb +79 -0
- data/test/cases/test_fixtures_test.rb +96 -0
- data/test/cases/time_precision_test.rb +125 -0
- data/test/cases/timestamp_test.rb +504 -0
- data/test/cases/touch_later_test.rb +123 -0
- data/test/cases/transaction_callbacks_test.rb +772 -0
- data/test/cases/transaction_isolation_test.rb +106 -0
- data/test/cases/transactions_test.rb +1285 -0
- data/test/cases/type/adapter_specific_registry_test.rb +145 -0
- data/test/cases/type/date_time_test.rb +16 -0
- data/test/cases/type/integer_test.rb +29 -0
- data/test/cases/type/string_test.rb +24 -0
- data/test/cases/type/time_test.rb +28 -0
- data/test/cases/type/type_map_test.rb +178 -0
- data/test/cases/type/unsigned_integer_test.rb +19 -0
- data/test/cases/type_test.rb +41 -0
- data/test/cases/types_test.rb +26 -0
- data/test/cases/unconnected_test.rb +46 -0
- data/test/cases/unsafe_raw_sql_test.rb +274 -0
- data/test/cases/validations/absence_validation_test.rb +75 -0
- data/test/cases/validations/association_validation_test.rb +99 -0
- data/test/cases/validations/i18n_generate_message_validation_test.rb +102 -0
- data/test/cases/validations/i18n_validation_test.rb +87 -0
- data/test/cases/validations/length_validation_test.rb +80 -0
- data/test/cases/validations/numericality_validation_test.rb +181 -0
- data/test/cases/validations/presence_validation_test.rb +105 -0
- data/test/cases/validations/uniqueness_validation_test.rb +618 -0
- data/test/cases/validations_repair_helper.rb +21 -0
- data/test/cases/validations_test.rb +229 -0
- data/test/cases/view_test.rb +222 -0
- data/test/cases/yaml_serialization_test.rb +166 -0
- data/test/config.example.yml +97 -0
- data/test/config.rb +7 -0
- data/test/config.yml +220 -0
- data/test/connections/native_ibm_db/connection.rb +44 -0
- data/test/fixtures/accounts.yml +29 -0
- data/test/fixtures/admin/accounts.yml +2 -0
- data/test/fixtures/admin/randomly_named_a9.yml +7 -0
- data/test/fixtures/admin/randomly_named_b0.yml +7 -0
- data/test/fixtures/admin/users.yml +10 -0
- data/test/fixtures/all/admin +1 -0
- data/test/fixtures/all/developers.yml +0 -0
- data/test/fixtures/all/namespaced/accounts.yml +2 -0
- data/test/fixtures/all/people.yml +0 -0
- data/test/fixtures/all/tasks.yml +0 -0
- data/test/fixtures/author_addresses.yml +11 -0
- data/test/fixtures/author_favorites.yml +4 -0
- data/test/fixtures/authors.yml +17 -0
- data/test/fixtures/bad_posts.yml +9 -0
- data/test/fixtures/binaries.yml +137 -0
- data/test/fixtures/books.yml +38 -0
- data/test/fixtures/bulbs.yml +5 -0
- data/test/fixtures/cars.yml +9 -0
- data/test/fixtures/categories/special_categories.yml +9 -0
- data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
- data/test/fixtures/categories.yml +19 -0
- data/test/fixtures/categories_ordered.yml +7 -0
- data/test/fixtures/categories_posts.yml +34 -0
- data/test/fixtures/categorizations.yml +23 -0
- data/test/fixtures/citations.yml +5 -0
- data/test/fixtures/clubs.yml +8 -0
- data/test/fixtures/collections.yml +3 -0
- data/test/fixtures/colleges.yml +3 -0
- data/test/fixtures/comments.yml +72 -0
- data/test/fixtures/companies.yml +72 -0
- data/test/fixtures/computers.yml +12 -0
- data/test/fixtures/content.yml +3 -0
- data/test/fixtures/content_positions.yml +3 -0
- data/test/fixtures/courses.yml +8 -0
- data/test/fixtures/customers.yml +35 -0
- data/test/fixtures/dashboards.yml +6 -0
- data/test/fixtures/dead_parrots.yml +5 -0
- data/test/fixtures/developers.yml +22 -0
- data/test/fixtures/developers_projects.yml +17 -0
- data/test/fixtures/dog_lovers.yml +7 -0
- data/test/fixtures/dogs.yml +4 -0
- data/test/fixtures/doubloons.yml +3 -0
- data/test/fixtures/edges.yml +5 -0
- data/test/fixtures/entrants.yml +14 -0
- data/test/fixtures/essays.yml +16 -0
- data/test/fixtures/faces.yml +11 -0
- data/test/fixtures/fk_test_has_fk.yml +3 -0
- data/test/fixtures/fk_test_has_pk.yml +2 -0
- data/test/fixtures/friendships.yml +4 -0
- data/test/fixtures/funny_jokes.yml +10 -0
- data/test/fixtures/humans.yml +5 -0
- data/test/fixtures/interests.yml +33 -0
- data/test/fixtures/items.yml +3 -0
- data/test/fixtures/jobs.yml +7 -0
- data/test/fixtures/legacy_things.yml +3 -0
- data/test/fixtures/live_parrots.yml +4 -0
- data/test/fixtures/mateys.yml +4 -0
- data/test/fixtures/member_details.yml +8 -0
- data/test/fixtures/member_types.yml +6 -0
- data/test/fixtures/members.yml +11 -0
- data/test/fixtures/memberships.yml +41 -0
- data/test/fixtures/men.yml +5 -0
- data/test/fixtures/minimalistics.yml +5 -0
- data/test/fixtures/minivans.yml +5 -0
- data/test/fixtures/mixed_case_monkeys.yml +6 -0
- data/test/fixtures/mixins.yml +29 -0
- data/test/fixtures/movies.yml +7 -0
- data/test/fixtures/naked/yml/accounts.yml +1 -0
- data/test/fixtures/naked/yml/companies.yml +1 -0
- data/test/fixtures/naked/yml/courses.yml +1 -0
- data/test/fixtures/naked/yml/courses_with_invalid_key.yml +3 -0
- data/test/fixtures/naked/yml/parrots.yml +3 -0
- data/test/fixtures/naked/yml/trees.yml +3 -0
- data/test/fixtures/nodes.yml +29 -0
- data/test/fixtures/organizations.yml +5 -0
- data/test/fixtures/other_books.yml +26 -0
- data/test/fixtures/other_comments.yml +6 -0
- data/test/fixtures/other_dogs.yml +2 -0
- data/test/fixtures/other_posts.yml +8 -0
- data/test/fixtures/other_topics.yml +42 -0
- data/test/fixtures/owners.yml +9 -0
- data/test/fixtures/parrots.yml +33 -0
- data/test/fixtures/parrots_pirates.yml +7 -0
- data/test/fixtures/people.yml +24 -0
- data/test/fixtures/peoples_treasures.yml +3 -0
- data/test/fixtures/pets.yml +19 -0
- data/test/fixtures/pirates.yml +15 -0
- data/test/fixtures/posts.yml +88 -0
- data/test/fixtures/price_estimates.yml +16 -0
- data/test/fixtures/products.yml +4 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/randomly_named_a9.yml +7 -0
- data/test/fixtures/ratings.yml +14 -0
- data/test/fixtures/readers.yml +17 -0
- data/test/fixtures/references.yml +17 -0
- data/test/fixtures/reserved_words/distinct.yml +5 -0
- data/test/fixtures/reserved_words/distinct_select.yml +11 -0
- data/test/fixtures/reserved_words/group.yml +14 -0
- data/test/fixtures/reserved_words/select.yml +8 -0
- data/test/fixtures/reserved_words/values.yml +7 -0
- data/test/fixtures/ships.yml +6 -0
- data/test/fixtures/speedometers.yml +8 -0
- data/test/fixtures/sponsors.yml +15 -0
- data/test/fixtures/strict_zines.yml +2 -0
- data/test/fixtures/string_key_objects.yml +7 -0
- data/test/fixtures/subscribers.yml +11 -0
- data/test/fixtures/subscriptions.yml +12 -0
- data/test/fixtures/taggings.yml +78 -0
- data/test/fixtures/tags.yml +11 -0
- data/test/fixtures/tasks.yml +7 -0
- data/test/fixtures/teapots.yml +3 -0
- data/test/fixtures/to_be_linked/accounts.yml +2 -0
- data/test/fixtures/to_be_linked/users.yml +10 -0
- data/test/fixtures/topics.yml +49 -0
- data/test/fixtures/toys.yml +14 -0
- data/test/fixtures/traffic_lights.yml +10 -0
- data/test/fixtures/treasures.yml +10 -0
- data/test/fixtures/trees.yml +3 -0
- data/test/fixtures/uuid_children.yml +3 -0
- data/test/fixtures/uuid_parents.yml +2 -0
- data/test/fixtures/variants.yml +4 -0
- data/test/fixtures/vegetables.yml +20 -0
- data/test/fixtures/vertices.yml +4 -0
- data/test/fixtures/warehouse-things.yml +3 -0
- data/test/fixtures/warehouse_things.yml +3 -0
- data/test/fixtures/zines.yml +5 -0
- data/test/ibm_db_test.rb +25 -0
- data/test/migrations/10_urban/9_add_expressions.rb +13 -0
- data/test/migrations/decimal/1_give_me_big_numbers.rb +17 -0
- data/test/migrations/magic/1_currencies_have_symbols.rb +13 -0
- data/test/migrations/missing/1000_people_have_middle_names.rb +11 -0
- data/test/migrations/missing/1_people_have_last_names.rb +11 -0
- data/test/migrations/missing/3_we_need_reminders.rb +14 -0
- data/test/migrations/missing/4_innocent_jointable.rb +14 -0
- data/test/migrations/rename/1_we_need_things.rb +13 -0
- data/test/migrations/rename/2_rename_things.rb +11 -0
- data/test/migrations/to_copy/1_people_have_hobbies.rb +11 -0
- data/test/migrations/to_copy/2_people_have_descriptions.rb +11 -0
- data/test/migrations/to_copy2/1_create_articles.rb +9 -0
- data/test/migrations/to_copy2/2_create_comments.rb +9 -0
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +11 -0
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +11 -0
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +11 -0
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +9 -0
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +9 -0
- data/test/migrations/valid/1_valid_people_have_last_names.rb +11 -0
- data/test/migrations/valid/2_we_need_reminders.rb +14 -0
- data/test/migrations/valid/3_innocent_jointable.rb +14 -0
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +11 -0
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +14 -0
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +14 -0
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +11 -0
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +14 -0
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +14 -0
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +10 -0
- data/test/models/account.rb +46 -0
- data/test/models/admin/account.rb +5 -0
- data/test/models/admin/randomly_named_c1.rb +9 -0
- data/test/models/admin/user.rb +48 -0
- data/test/models/admin.rb +7 -0
- data/test/models/aircraft.rb +7 -0
- data/test/models/arunit2_model.rb +5 -0
- data/test/models/author.rb +260 -0
- data/test/models/auto_id.rb +6 -0
- data/test/models/autoloadable/extra_firm.rb +4 -0
- data/test/models/binary.rb +4 -0
- data/test/models/binary_field.rb +6 -0
- data/test/models/bird.rb +24 -0
- data/test/models/book.rb +33 -0
- data/test/models/book_destroy_async.rb +24 -0
- data/test/models/boolean.rb +7 -0
- data/test/models/bulb.rb +61 -0
- data/test/models/cake_designer.rb +5 -0
- data/test/models/car.rb +36 -0
- data/test/models/carrier.rb +4 -0
- data/test/models/cart.rb +5 -0
- data/test/models/cat.rb +12 -0
- data/test/models/categorization.rb +21 -0
- data/test/models/category.rb +47 -0
- data/test/models/chef.rb +10 -0
- data/test/models/citation.rb +7 -0
- data/test/models/club.rb +28 -0
- data/test/models/college.rb +12 -0
- data/test/models/column.rb +5 -0
- data/test/models/column_name.rb +5 -0
- data/test/models/comment.rb +98 -0
- data/test/models/company.rb +226 -0
- data/test/models/company_in_module.rb +99 -0
- data/test/models/computer.rb +5 -0
- data/test/models/contact.rb +43 -0
- data/test/models/content.rb +42 -0
- data/test/models/contract.rb +38 -0
- data/test/models/country.rb +5 -0
- data/test/models/course.rb +8 -0
- data/test/models/customer.rb +85 -0
- data/test/models/customer_carrier.rb +16 -0
- data/test/models/dashboard.rb +5 -0
- data/test/models/default.rb +4 -0
- data/test/models/department.rb +6 -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 +341 -0
- 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 +7 -0
- data/test/models/dog_lover.rb +7 -0
- data/test/models/doubloon.rb +14 -0
- data/test/models/drink_designer.rb +20 -0
- data/test/models/edge.rb +7 -0
- data/test/models/electron.rb +7 -0
- data/test/models/engine.rb +5 -0
- data/test/models/entrant.rb +5 -0
- data/test/models/entry.rb +5 -0
- data/test/models/essay.rb +8 -0
- data/test/models/essay_destroy_async.rb +12 -0
- data/test/models/event.rb +5 -0
- data/test/models/eye.rb +39 -0
- data/test/models/face.rb +17 -0
- data/test/models/family.rb +6 -0
- data/test/models/family_tree.rb +6 -0
- data/test/models/friendship.rb +8 -0
- data/test/models/frog.rb +8 -0
- data/test/models/guid.rb +4 -0
- data/test/models/guitar.rb +6 -0
- data/test/models/hotel.rb +13 -0
- data/test/models/human.rb +39 -0
- data/test/models/image.rb +5 -0
- data/test/models/interest.rb +16 -0
- data/test/models/invoice.rb +6 -0
- data/test/models/item.rb +9 -0
- data/test/models/job.rb +9 -0
- data/test/models/joke.rb +9 -0
- data/test/models/keyboard.rb +5 -0
- data/test/models/legacy_thing.rb +5 -0
- data/test/models/lesson.rb +13 -0
- data/test/models/line_item.rb +5 -0
- data/test/models/liquid.rb +6 -0
- data/test/models/man.rb +11 -0
- data/test/models/matey.rb +6 -0
- data/test/models/measurement.rb +4 -0
- data/test/models/member.rb +45 -0
- data/test/models/member_detail.rb +11 -0
- data/test/models/member_type.rb +5 -0
- data/test/models/membership.rb +38 -0
- data/test/models/mentor.rb +5 -0
- data/test/models/message.rb +5 -0
- data/test/models/minimalistic.rb +4 -0
- data/test/models/minivan.rb +10 -0
- data/test/models/mixed_case_monkey.rb +5 -0
- data/test/models/mocktail_designer.rb +2 -0
- data/test/models/molecule.rb +8 -0
- data/test/models/mouse.rb +6 -0
- data/test/models/movie.rb +7 -0
- data/test/models/node.rb +7 -0
- data/test/models/non_primary_key.rb +4 -0
- data/test/models/notification.rb +5 -0
- data/test/models/numeric_data.rb +12 -0
- data/test/models/order.rb +6 -0
- data/test/models/organization.rb +16 -0
- data/test/models/other_dog.rb +7 -0
- data/test/models/owner.rb +39 -0
- data/test/models/parrot.rb +36 -0
- data/test/models/person.rb +147 -0
- data/test/models/personal_legacy_thing.rb +6 -0
- data/test/models/pet.rb +20 -0
- data/test/models/pet_treasure.rb +8 -0
- data/test/models/pirate.rb +116 -0
- data/test/models/possession.rb +5 -0
- data/test/models/post.rb +371 -0
- data/test/models/price_estimate.rb +14 -0
- data/test/models/professor.rb +7 -0
- data/test/models/project.rb +42 -0
- data/test/models/publisher/article.rb +6 -0
- data/test/models/publisher/magazine.rb +5 -0
- data/test/models/publisher.rb +4 -0
- data/test/models/randomly_named_c1.rb +5 -0
- data/test/models/rating.rb +8 -0
- data/test/models/reader.rb +25 -0
- data/test/models/recipe.rb +5 -0
- data/test/models/record.rb +4 -0
- data/test/models/reference.rb +25 -0
- data/test/models/reply.rb +79 -0
- 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 +42 -0
- data/test/models/ship_part.rb +10 -0
- data/test/models/shop.rb +19 -0
- data/test/models/shop_account.rb +8 -0
- data/test/models/speedometer.rb +8 -0
- data/test/models/sponsor.rb +10 -0
- data/test/models/squeak.rb +6 -0
- data/test/models/strict_zine.rb +7 -0
- data/test/models/string_key_object.rb +5 -0
- data/test/models/student.rb +6 -0
- data/test/models/subject.rb +16 -0
- data/test/models/subscriber.rb +10 -0
- data/test/models/subscription.rb +8 -0
- data/test/models/tag.rb +16 -0
- data/test/models/tagging.rb +20 -0
- data/test/models/task.rb +7 -0
- data/test/models/topic.rb +153 -0
- data/test/models/toy.rb +10 -0
- data/test/models/traffic_light.rb +6 -0
- data/test/models/treasure.rb +16 -0
- data/test/models/treaty.rb +5 -0
- data/test/models/tree.rb +5 -0
- data/test/models/tuning_peg.rb +6 -0
- data/test/models/tyre.rb +13 -0
- data/test/models/user.rb +22 -0
- data/test/models/uuid_child.rb +5 -0
- data/test/models/uuid_item.rb +8 -0
- data/test/models/uuid_parent.rb +5 -0
- data/test/models/vegetables.rb +33 -0
- data/test/models/vehicle.rb +7 -0
- data/test/models/vertex.rb +11 -0
- data/test/models/warehouse_thing.rb +7 -0
- data/test/models/wheel.rb +5 -0
- data/test/models/without_table.rb +5 -0
- data/test/models/zine.rb +5 -0
- data/test/schema/i5/ibm_db_specific_schema.rb +137 -0
- data/test/schema/ids/ibm_db_specific_schema.rb +140 -0
- data/test/schema/luw/ibm_db_specific_schema.rb +137 -0
- data/test/schema/mysql2_specific_schema.rb +82 -0
- data/test/schema/oracle_specific_schema.rb +38 -0
- data/test/schema/postgresql_specific_schema.rb +125 -0
- data/test/schema/schema.rb +1237 -0
- data/test/schema/schema.rb.original +1057 -0
- data/test/schema/sqlite_specific_schema.rb +11 -0
- data/test/schema/zOS/ibm_db_specific_schema.rb +208 -0
- data/test/support/config.rb +43 -0
- data/test/support/connection.rb +29 -0
- data/test/support/connection_helper.rb +16 -0
- data/test/support/ddl_helper.rb +10 -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 +22 -0
- data/test/support/stubs/strong_parameters.rb +40 -0
- data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
- data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -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 +876 -0
@@ -0,0 +1,941 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cases/helper"
|
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"
|
26
|
+
|
27
|
+
class AutomaticInverseFindingTests < ActiveRecord::TestCase
|
28
|
+
fixtures :ratings, :comments, :cars
|
29
|
+
|
30
|
+
def test_has_one_and_belongs_to_should_find_inverse_automatically_on_multiple_word_name
|
31
|
+
monkey_reflection = MixedCaseMonkey.reflect_on_association(:human)
|
32
|
+
human_reflection = Human.reflect_on_association(:mixed_case_monkey)
|
33
|
+
|
34
|
+
assert monkey_reflection.has_inverse?, "The monkey reflection should have an inverse"
|
35
|
+
assert_equal human_reflection, monkey_reflection.inverse_of, "The monkey reflection's inverse should be the human reflection"
|
36
|
+
|
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"
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_has_many_and_belongs_to_should_find_inverse_automatically_for_model_in_module
|
42
|
+
account_reflection = Admin::Account.reflect_on_association(:users)
|
43
|
+
user_reflection = Admin::User.reflect_on_association(:account)
|
44
|
+
|
45
|
+
assert account_reflection.has_inverse?, "The Admin::Account reflection should have an inverse"
|
46
|
+
assert_equal user_reflection, account_reflection.inverse_of, "The Admin::Account reflection's inverse should be the Admin::User reflection"
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_has_one_and_belongs_to_should_find_inverse_automatically
|
50
|
+
car_reflection = Car.reflect_on_association(:bulb)
|
51
|
+
bulb_reflection = Bulb.reflect_on_association(:car)
|
52
|
+
|
53
|
+
assert car_reflection.has_inverse?, "The Car reflection should have an inverse"
|
54
|
+
assert_equal bulb_reflection, car_reflection.inverse_of, "The Car reflection's inverse should be the Bulb reflection"
|
55
|
+
|
56
|
+
assert bulb_reflection.has_inverse?, "The Bulb reflection should have an inverse"
|
57
|
+
assert_equal car_reflection, bulb_reflection.inverse_of, "The Bulb reflection's inverse should be the Car reflection"
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_has_many_and_belongs_to_should_find_inverse_automatically
|
61
|
+
comment_reflection = Comment.reflect_on_association(:ratings)
|
62
|
+
rating_reflection = Rating.reflect_on_association(:comment)
|
63
|
+
|
64
|
+
assert comment_reflection.has_inverse?, "The Comment reflection should have an inverse"
|
65
|
+
assert_equal rating_reflection, comment_reflection.inverse_of, "The Comment reflection's inverse should be the Rating reflection"
|
66
|
+
end
|
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
|
+
|
113
|
+
def test_has_one_and_belongs_to_automatic_inverse_shares_objects
|
114
|
+
car = Car.first
|
115
|
+
bulb = Bulb.create!(car: car)
|
116
|
+
|
117
|
+
assert_equal car.bulb, bulb, "The Car's bulb should be the original bulb"
|
118
|
+
|
119
|
+
car.bulb.color = "Blue"
|
120
|
+
assert_equal car.bulb.color, bulb.color, "Changing the bulb's color on the car association should change the bulb's color"
|
121
|
+
|
122
|
+
bulb.color = "Red"
|
123
|
+
assert_equal bulb.color, car.bulb.color, "Changing the bulb's color should change the bulb's color on the car association"
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_has_many_and_belongs_to_automatic_inverse_shares_objects_on_rating
|
127
|
+
comment = Comment.first
|
128
|
+
rating = Rating.create!(comment: comment)
|
129
|
+
|
130
|
+
assert_equal rating.comment, comment, "The Rating's comment should be the original Comment"
|
131
|
+
|
132
|
+
rating.comment.body = "Fennec foxes are the smallest of the foxes."
|
133
|
+
assert_equal rating.comment.body, comment.body, "Changing the Comment's body on the association should change the original Comment's body"
|
134
|
+
|
135
|
+
comment.body = "Kittens are adorable."
|
136
|
+
assert_equal comment.body, rating.comment.body, "Changing the original Comment's body should change the Comment's body on the association"
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_has_many_and_belongs_to_automatic_inverse_shares_objects_on_comment
|
140
|
+
rating = Rating.create!
|
141
|
+
comment = Comment.first
|
142
|
+
rating.comment = comment
|
143
|
+
|
144
|
+
assert_equal rating.comment, comment, "The Rating's comment should be the original Comment"
|
145
|
+
|
146
|
+
rating.comment.body = "Fennec foxes are the smallest of the foxes."
|
147
|
+
assert_equal rating.comment.body, comment.body, "Changing the Comment's body on the association should change the original Comment's body"
|
148
|
+
|
149
|
+
comment.body = "Kittens are adorable."
|
150
|
+
assert_equal comment.body, rating.comment.body, "Changing the original Comment's body should change the Comment's body on the association"
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_polymorphic_and_has_many_through_relationships_should_not_have_inverses
|
154
|
+
sponsor_reflection = Sponsor.reflect_on_association(:sponsorable)
|
155
|
+
|
156
|
+
assert_not sponsor_reflection.has_inverse?, "A polymorphic association should not find an inverse automatically"
|
157
|
+
|
158
|
+
club_reflection = Club.reflect_on_association(:members)
|
159
|
+
|
160
|
+
assert_not club_reflection.has_inverse?, "A has_many_through association should not find an inverse automatically"
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_polymorphic_has_one_should_find_inverse_automatically
|
164
|
+
human_reflection = Human.reflect_on_association(:polymorphic_face_without_inverse)
|
165
|
+
|
166
|
+
assert_predicate human_reflection, :has_inverse?
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class InverseAssociationTests < ActiveRecord::TestCase
|
171
|
+
def test_should_allow_for_inverse_of_options_in_associations
|
172
|
+
assert_nothing_raised do
|
173
|
+
Class.new(ActiveRecord::Base).has_many(:wheels, inverse_of: :car)
|
174
|
+
end
|
175
|
+
|
176
|
+
assert_nothing_raised do
|
177
|
+
Class.new(ActiveRecord::Base).has_one(:engine, inverse_of: :car)
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_nothing_raised do
|
181
|
+
Class.new(ActiveRecord::Base).belongs_to(:car, inverse_of: :driver)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_should_be_able_to_ask_a_reflection_if_it_has_an_inverse
|
186
|
+
has_one_with_inverse_ref = Human.reflect_on_association(:face)
|
187
|
+
assert_predicate has_one_with_inverse_ref, :has_inverse?
|
188
|
+
|
189
|
+
has_many_with_inverse_ref = Human.reflect_on_association(:interests)
|
190
|
+
assert_predicate has_many_with_inverse_ref, :has_inverse?
|
191
|
+
|
192
|
+
belongs_to_with_inverse_ref = Face.reflect_on_association(:human)
|
193
|
+
assert_predicate belongs_to_with_inverse_ref, :has_inverse?
|
194
|
+
|
195
|
+
has_one_without_inverse_ref = Club.reflect_on_association(:sponsor)
|
196
|
+
assert_not_predicate has_one_without_inverse_ref, :has_inverse?
|
197
|
+
|
198
|
+
has_many_without_inverse_ref = Club.reflect_on_association(:memberships)
|
199
|
+
assert_not_predicate has_many_without_inverse_ref, :has_inverse?
|
200
|
+
|
201
|
+
belongs_to_without_inverse_ref = Sponsor.reflect_on_association(:sponsor_club)
|
202
|
+
assert_not_predicate belongs_to_without_inverse_ref, :has_inverse?
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_inverse_of_method_should_supply_the_actual_reflection_instance_it_is_the_inverse_of
|
206
|
+
has_one_ref = Human.reflect_on_association(:face)
|
207
|
+
assert_equal Face.reflect_on_association(:human), has_one_ref.inverse_of
|
208
|
+
|
209
|
+
has_many_ref = Human.reflect_on_association(:interests)
|
210
|
+
assert_equal Interest.reflect_on_association(:human), has_many_ref.inverse_of
|
211
|
+
|
212
|
+
belongs_to_ref = Face.reflect_on_association(:human)
|
213
|
+
assert_equal Human.reflect_on_association(:face), belongs_to_ref.inverse_of
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_associations_with_no_inverse_of_should_return_nil
|
217
|
+
has_one_ref = Club.reflect_on_association(:sponsor)
|
218
|
+
assert_nil has_one_ref.inverse_of
|
219
|
+
|
220
|
+
has_many_ref = Club.reflect_on_association(:memberships)
|
221
|
+
assert_nil has_many_ref.inverse_of
|
222
|
+
|
223
|
+
belongs_to_ref = Sponsor.reflect_on_association(:sponsor_club)
|
224
|
+
assert_nil belongs_to_ref.inverse_of
|
225
|
+
end
|
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
|
+
|
237
|
+
def test_this_inverse_stuff
|
238
|
+
firm = Firm.create!(name: "Adequate Holdings")
|
239
|
+
Project.create!(name: "Project 1", firm: firm)
|
240
|
+
Developer.create!(name: "Gorbypuff", firm: firm)
|
241
|
+
|
242
|
+
new_project = Project.last
|
243
|
+
assert Project.reflect_on_association(:lead_developer).inverse_of.present?, "Expected inverse of to be present"
|
244
|
+
assert new_project.lead_developer.present?, "Expected lead developer to be present on the project"
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
class InverseHasOneTests < ActiveRecord::TestCase
|
249
|
+
fixtures :humans, :faces
|
250
|
+
|
251
|
+
def test_parent_instance_should_be_shared_with_child_on_find
|
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"
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_parent_instance_should_be_shared_with_eager_loaded_child_on_find
|
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"
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_parent_instance_should_be_shared_with_newly_built_child
|
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"
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_parent_instance_should_be_shared_with_newly_created_child
|
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"
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_parent_instance_should_be_shared_with_newly_created_child_via_bang_method
|
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"
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_parent_instance_should_be_shared_with_replaced_via_accessor_child
|
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"
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
|
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
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
class InverseHasManyTests < ActiveRecord::TestCase
|
353
|
+
fixtures :humans, :interests, :posts, :authors, :author_addresses, :comments
|
354
|
+
|
355
|
+
def test_parent_instance_should_be_shared_with_every_child_on_find
|
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"
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
def test_parent_instance_should_be_shared_with_eager_loaded_children
|
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"
|
397
|
+
end
|
398
|
+
|
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"
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
def test_parent_instance_should_be_shared_with_newly_block_style_built_child
|
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"
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_parent_instance_should_be_shared_with_newly_created_via_bang_method_child
|
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"
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_parent_instance_should_be_shared_with_newly_block_style_created_child
|
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"
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_parent_instance_should_be_shared_within_create_block_of_new_child
|
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"
|
449
|
+
end
|
450
|
+
assert interest.human.equal?(human), "Human of the child should still be the same instance as a parent"
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_parent_instance_should_be_shared_within_build_block_of_new_child
|
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"
|
457
|
+
end
|
458
|
+
assert interest.human.equal?(human), "Human of the child should still be the same instance as a parent"
|
459
|
+
end
|
460
|
+
|
461
|
+
def test_parent_instance_should_be_shared_with_poked_in_child
|
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"
|
471
|
+
end
|
472
|
+
|
473
|
+
def test_parent_instance_should_be_shared_with_replaced_via_accessor_children
|
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"
|
483
|
+
end
|
484
|
+
|
485
|
+
def test_parent_instance_should_be_shared_with_first_and_last_child
|
486
|
+
human = Human.first
|
487
|
+
|
488
|
+
assert human.interests.first.human.equal? human
|
489
|
+
assert human.interests.last.human.equal? human
|
490
|
+
end
|
491
|
+
|
492
|
+
def test_parent_instance_should_be_shared_with_first_n_and_last_n_children
|
493
|
+
human = Human.first
|
494
|
+
|
495
|
+
interests = human.interests.first(2)
|
496
|
+
assert interests[0].human.equal? human
|
497
|
+
assert interests[1].human.equal? human
|
498
|
+
|
499
|
+
interests = human.interests.last(2)
|
500
|
+
assert interests[0].human.equal? human
|
501
|
+
assert interests[1].human.equal? human
|
502
|
+
end
|
503
|
+
|
504
|
+
def test_parent_instance_should_find_child_instance_using_child_instance_id
|
505
|
+
human = Human.create!
|
506
|
+
interest = Interest.create!
|
507
|
+
human.interests = [interest]
|
508
|
+
|
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"
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_parent_instance_should_find_child_instance_using_child_instance_id_when_created
|
516
|
+
human = Human.create!
|
517
|
+
interest = Interest.create!(human: human)
|
518
|
+
|
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"
|
521
|
+
|
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"
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_find_on_child_instance_with_id_should_not_load_all_child_records
|
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)
|
540
|
+
|
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
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_raise_record_not_found_error_when_invalid_ids_are_passed
|
556
|
+
# delete all interest records to ensure that hard coded invalid_id(s)
|
557
|
+
# are indeed invalid.
|
558
|
+
Interest.delete_all
|
559
|
+
|
560
|
+
human = Human.create!
|
561
|
+
|
562
|
+
invalid_id = 245324523
|
563
|
+
assert_raise(ActiveRecord::RecordNotFound) { human.interests.find(invalid_id) }
|
564
|
+
|
565
|
+
invalid_ids = [8432342, 2390102913, 2453245234523452]
|
566
|
+
assert_raise(ActiveRecord::RecordNotFound) { human.interests.find(invalid_ids) }
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_raise_record_not_found_error_when_no_ids_are_passed
|
570
|
+
human = Human.create!
|
571
|
+
|
572
|
+
exception = assert_raise(ActiveRecord::RecordNotFound) { human.interests.load.find() }
|
573
|
+
|
574
|
+
assert_equal exception.model, "Interest"
|
575
|
+
assert_equal exception.primary_key, "id"
|
576
|
+
end
|
577
|
+
|
578
|
+
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
|
579
|
+
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Human.first.secret_interests }
|
580
|
+
end
|
581
|
+
|
582
|
+
def test_child_instance_should_point_to_parent_without_saving
|
583
|
+
human = Human.new
|
584
|
+
interest = Interest.create(topic: "Industrial Revolution Re-enactment")
|
585
|
+
|
586
|
+
human.interests << interest
|
587
|
+
assert_not_nil interest.human
|
588
|
+
|
589
|
+
interest.human.name = "Charles"
|
590
|
+
assert_equal interest.human.name, human.name
|
591
|
+
|
592
|
+
assert_not_predicate human, :persisted?
|
593
|
+
end
|
594
|
+
|
595
|
+
def test_inverse_instance_should_be_set_before_find_callbacks_are_run
|
596
|
+
reset_callbacks(Interest, :find) do
|
597
|
+
Interest.after_find { raise unless association(:human).loaded? && human.present? }
|
598
|
+
|
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?
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
def test_inverse_instance_should_be_set_before_initialize_callbacks_are_run
|
606
|
+
reset_callbacks(Interest, :initialize) do
|
607
|
+
Interest.after_initialize { raise unless association(:human).loaded? && human.present? }
|
608
|
+
|
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?
|
612
|
+
end
|
613
|
+
end
|
614
|
+
|
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
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
class InverseBelongsToTests < ActiveRecord::TestCase
|
625
|
+
fixtures :humans, :faces, :interests
|
626
|
+
|
627
|
+
def test_child_instance_should_be_shared_with_parent_on_find
|
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"
|
635
|
+
end
|
636
|
+
|
637
|
+
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
|
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"
|
653
|
+
end
|
654
|
+
|
655
|
+
def test_child_instance_should_be_shared_with_newly_built_parent
|
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"
|
664
|
+
end
|
665
|
+
|
666
|
+
def test_child_instance_should_be_shared_with_newly_created_parent
|
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"
|
675
|
+
end
|
676
|
+
|
677
|
+
def test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
|
678
|
+
interest = interests(:trainspotting)
|
679
|
+
human = interest.human
|
680
|
+
assert_not_nil human.interests
|
681
|
+
iz = human.interests.detect { |_iz| _iz.id == interest.id }
|
682
|
+
assert_not_nil iz
|
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
|
749
|
+
end
|
750
|
+
|
751
|
+
def test_child_instance_should_be_shared_with_replaced_via_accessor_parent
|
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"
|
761
|
+
end
|
762
|
+
|
763
|
+
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
|
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
|
786
|
+
end
|
787
|
+
end
|
788
|
+
|
789
|
+
class InversePolymorphicBelongsToTests < ActiveRecord::TestCase
|
790
|
+
fixtures :humans, :faces, :interests
|
791
|
+
|
792
|
+
def test_child_instance_should_be_shared_with_parent_on_find
|
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"
|
800
|
+
end
|
801
|
+
|
802
|
+
def test_eager_loaded_child_instance_should_be_shared_with_parent_on_find
|
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"
|
818
|
+
end
|
819
|
+
|
820
|
+
def test_child_instance_should_be_shared_with_replaced_via_accessor_parent
|
821
|
+
face = faces(:confused)
|
822
|
+
new_human = Human.new
|
823
|
+
|
824
|
+
assert_not_nil face.polymorphic_human
|
825
|
+
face.polymorphic_human = new_human
|
826
|
+
|
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"
|
832
|
+
end
|
833
|
+
|
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
|
838
|
+
|
839
|
+
old_inversed_human = face.human
|
840
|
+
new_human.save!
|
841
|
+
new_inversed_human = face.human
|
842
|
+
|
843
|
+
assert_same old_inversed_human, new_inversed_human
|
844
|
+
end
|
845
|
+
|
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
|
855
|
+
|
856
|
+
def test_inversed_instance_should_load_after_autosave_if_it_is_not_already_loaded
|
857
|
+
human = Human.create!
|
858
|
+
human.create_autosave_face!
|
859
|
+
|
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
|
865
|
+
end
|
866
|
+
|
867
|
+
def test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
|
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 }
|
872
|
+
assert_not_nil iz
|
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
|
900
|
+
end
|
901
|
+
|
902
|
+
def test_trying_to_access_inverses_that_dont_exist_shouldnt_raise_an_error
|
903
|
+
# Ideally this would, if only for symmetry's sake with other association types
|
904
|
+
assert_nothing_raised { Face.first.puzzled_polymorphic_human }
|
905
|
+
end
|
906
|
+
|
907
|
+
def test_trying_to_set_polymorphic_inverses_that_dont_exist_at_all_should_raise_an_error
|
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 }
|
910
|
+
end
|
911
|
+
|
912
|
+
def test_trying_to_set_polymorphic_inverses_that_dont_exist_on_the_instance_being_set_should_raise_an_error
|
913
|
+
# passes because Human does have the correct inverse_of
|
914
|
+
assert_nothing_raised { Face.first.polymorphic_human = Human.first }
|
915
|
+
# fails because Interest does have the correct inverse_of
|
916
|
+
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.polymorphic_human = Interest.first }
|
917
|
+
end
|
918
|
+
end
|
919
|
+
|
920
|
+
# NOTE - these tests might not be meaningful, ripped as they were from the parental_control plugin
|
921
|
+
# which would guess the inverse rather than look for an explicit configuration option.
|
922
|
+
class InverseMultipleHasManyInversesForSameModel < ActiveRecord::TestCase
|
923
|
+
fixtures :humans, :interests, :zines
|
924
|
+
|
925
|
+
def test_that_we_can_load_associations_that_have_the_same_reciprocal_name_from_different_models
|
926
|
+
assert_nothing_raised do
|
927
|
+
interest = Interest.first
|
928
|
+
interest.zine
|
929
|
+
interest.human
|
930
|
+
end
|
931
|
+
end
|
932
|
+
|
933
|
+
def test_that_we_can_create_associations_that_have_the_same_reciprocal_name_from_different_models
|
934
|
+
assert_nothing_raised do
|
935
|
+
interest = Interest.first
|
936
|
+
interest.build_zine(title: "Get Some in Winter! 2008")
|
937
|
+
interest.build_human(name: "Gordon")
|
938
|
+
interest.save!
|
939
|
+
end
|
940
|
+
end
|
941
|
+
end
|