ibm_db 3.0.5-x86-mingw32 → 5.0.5-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGES +4 -0
- data/LICENSE +1 -1
- data/ParameterizedQueries README +6 -6
- data/README +38 -55
- data/ext/Makefile +269 -0
- data/ext/extconf.rb +34 -3
- data/ext/gil_release_version +3 -0
- data/ext/ibm_db-i386-mingw32.def +2 -0
- data/ext/ibm_db.c +100 -108
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +110 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/ext/unicode_support_version +3 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +923 -527
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
- data/lib/mswin32/ibm_db.rb +7 -39
- data/lib/mswin32/rb2x/i386/ibm_db.so +0 -0
- data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
- data/test/cases/adapter_test.rb +133 -58
- data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
- data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
- data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
- data/test/cases/adapters/mysql2/connection_test.rb +210 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
- data/test/cases/adapters/mysql2/enum_test.rb +26 -0
- data/test/cases/adapters/mysql2/explain_test.rb +21 -0
- data/test/cases/adapters/mysql2/json_test.rb +195 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
- data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
- data/test/cases/adapters/mysql2/schema_test.rb +126 -0
- data/test/cases/adapters/mysql2/sp_test.rb +36 -0
- data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
- data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
- data/test/cases/adapters/postgresql/array_test.rb +339 -0
- data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
- data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
- data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
- data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
- data/test/cases/adapters/postgresql/citext_test.rb +78 -0
- data/test/cases/adapters/postgresql/collation_test.rb +53 -0
- data/test/cases/adapters/postgresql/composite_test.rb +132 -0
- data/test/cases/adapters/postgresql/connection_test.rb +257 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
- data/test/cases/adapters/postgresql/domain_test.rb +47 -0
- data/test/cases/adapters/postgresql/enum_test.rb +91 -0
- data/test/cases/adapters/postgresql/explain_test.rb +20 -0
- data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
- data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
- data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
- data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
- data/test/cases/adapters/postgresql/integer_test.rb +25 -0
- data/test/cases/adapters/postgresql/json_test.rb +237 -0
- data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
- data/test/cases/adapters/postgresql/money_test.rb +96 -0
- data/test/cases/adapters/postgresql/network_test.rb +94 -0
- data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
- data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
- data/test/cases/adapters/postgresql/range_test.rb +343 -0
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
- data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
- data/test/cases/adapters/postgresql/schema_test.rb +597 -0
- data/test/cases/adapters/postgresql/serial_test.rb +154 -0
- data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
- data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
- data/test/cases/adapters/postgresql/utils_test.rb +62 -0
- data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
- data/test/cases/adapters/postgresql/xml_test.rb +54 -0
- data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
- data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
- data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
- data/test/cases/aggregations_test.rb +11 -1
- data/test/cases/ar_schema_test.rb +35 -50
- data/test/cases/associations/association_scope_test.rb +1 -6
- data/test/cases/associations/belongs_to_associations_test.rb +122 -10
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
- data/test/cases/associations/callbacks_test.rb +5 -7
- data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
- data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
- data/test/cases/associations/eager_test.rb +158 -73
- data/test/cases/associations/extension_test.rb +7 -2
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +64 -32
- data/test/cases/associations/has_many_associations_test.rb +362 -43
- data/test/cases/associations/has_many_through_associations_test.rb +108 -41
- data/test/cases/associations/has_one_associations_test.rb +105 -8
- data/test/cases/associations/has_one_through_associations_test.rb +6 -3
- data/test/cases/associations/inner_join_association_test.rb +3 -3
- data/test/cases/associations/inverse_associations_test.rb +38 -11
- data/test/cases/associations/join_model_test.rb +59 -36
- data/test/cases/associations/left_outer_join_association_test.rb +88 -0
- data/test/cases/associations/nested_through_associations_test.rb +2 -2
- data/test/cases/associations/required_test.rb +25 -5
- data/test/cases/associations_test.rb +39 -34
- data/test/cases/attribute_decorators_test.rb +9 -8
- data/test/cases/attribute_methods/read_test.rb +5 -5
- data/test/cases/attribute_methods_test.rb +97 -40
- data/test/cases/attribute_set_test.rb +64 -4
- data/test/cases/attribute_test.rb +84 -18
- data/test/cases/attributes_test.rb +151 -34
- data/test/cases/autosave_association_test.rb +149 -36
- data/test/cases/base_test.rb +290 -241
- data/test/cases/batches_test.rb +299 -22
- data/test/cases/binary_test.rb +2 -10
- data/test/cases/bind_parameter_test.rb +76 -66
- data/test/cases/cache_key_test.rb +26 -0
- data/test/cases/calculations_test.rb +167 -15
- data/test/cases/callbacks_test.rb +161 -68
- data/test/cases/coders/json_test.rb +15 -0
- data/test/cases/collection_cache_key_test.rb +115 -0
- data/test/cases/column_definition_test.rb +26 -57
- data/test/cases/comment_test.rb +145 -0
- data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
- data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
- data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
- data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
- data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
- data/test/cases/connection_management_test.rb +46 -56
- data/test/cases/connection_pool_test.rb +195 -20
- data/test/cases/connection_specification/resolver_test.rb +15 -0
- data/test/cases/counter_cache_test.rb +10 -5
- data/test/cases/custom_locking_test.rb +1 -1
- data/test/cases/database_statements_test.rb +18 -3
- data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
- data/test/cases/date_time_precision_test.rb +107 -0
- data/test/cases/defaults_test.rb +85 -89
- data/test/cases/dirty_test.rb +30 -52
- data/test/cases/disconnected_test.rb +4 -2
- data/test/cases/enum_test.rb +178 -24
- data/test/cases/errors_test.rb +16 -0
- data/test/cases/explain_test.rb +32 -21
- data/test/cases/finder_test.rb +273 -148
- data/test/cases/fixture_set/file_test.rb +18 -0
- data/test/cases/fixtures_test.rb +112 -32
- data/test/cases/forbidden_attributes_protection_test.rb +69 -3
- data/test/cases/helper.rb +10 -16
- data/test/cases/hot_compatibility_test.rb +89 -1
- data/test/cases/inheritance_test.rb +284 -53
- data/test/cases/integration_test.rb +23 -7
- data/test/cases/invalid_connection_test.rb +4 -2
- data/test/cases/invertible_migration_test.rb +124 -32
- data/test/cases/json_serialization_test.rb +11 -2
- data/test/cases/locking_test.rb +22 -6
- data/test/cases/log_subscriber_test.rb +106 -17
- data/test/cases/migration/change_schema_test.rb +60 -114
- data/test/cases/migration/change_table_test.rb +34 -2
- data/test/cases/migration/column_attributes_test.rb +7 -23
- data/test/cases/migration/column_positioning_test.rb +8 -8
- data/test/cases/migration/columns_test.rb +17 -11
- data/test/cases/migration/command_recorder_test.rb +47 -2
- data/test/cases/migration/compatibility_test.rb +118 -0
- data/test/cases/migration/create_join_table_test.rb +21 -12
- data/test/cases/migration/foreign_key_test.rb +52 -18
- data/test/cases/migration/index_test.rb +14 -12
- data/test/cases/migration/logger_test.rb +1 -1
- data/test/cases/migration/pending_migrations_test.rb +0 -1
- data/test/cases/migration/references_foreign_key_test.rb +59 -7
- data/test/cases/migration/references_index_test.rb +4 -4
- data/test/cases/migration/references_statements_test.rb +26 -6
- data/test/cases/migration/rename_table_test.rb +25 -25
- data/test/cases/migration_test.rb +279 -81
- data/test/cases/migrator_test.rb +91 -8
- data/test/cases/mixin_test.rb +0 -2
- data/test/cases/modules_test.rb +3 -4
- data/test/cases/multiparameter_attributes_test.rb +24 -2
- data/test/cases/multiple_db_test.rb +11 -4
- data/test/cases/nested_attributes_test.rb +61 -33
- data/test/cases/persistence_test.rb +102 -10
- data/test/cases/pooled_connections_test.rb +3 -3
- data/test/cases/primary_keys_test.rb +170 -31
- data/test/cases/query_cache_test.rb +216 -96
- data/test/cases/quoting_test.rb +65 -19
- data/test/cases/readonly_test.rb +2 -1
- data/test/cases/reflection_test.rb +68 -22
- data/test/cases/relation/delegation_test.rb +3 -8
- data/test/cases/relation/merging_test.rb +10 -14
- data/test/cases/relation/mutation_test.rb +42 -24
- data/test/cases/relation/or_test.rb +92 -0
- data/test/cases/relation/predicate_builder_test.rb +4 -2
- data/test/cases/relation/record_fetch_warning_test.rb +40 -0
- data/test/cases/relation/where_chain_test.rb +23 -99
- data/test/cases/relation/where_clause_test.rb +182 -0
- data/test/cases/relation/where_test.rb +45 -23
- data/test/cases/relation_test.rb +67 -58
- data/test/cases/relations_test.rb +249 -38
- data/test/cases/result_test.rb +10 -0
- data/test/cases/sanitize_test.rb +108 -15
- data/test/cases/schema_dumper_test.rb +119 -125
- data/test/cases/schema_loading_test.rb +52 -0
- data/test/cases/scoping/default_scoping_test.rb +113 -39
- data/test/cases/scoping/named_scoping_test.rb +46 -9
- data/test/cases/scoping/relation_scoping_test.rb +47 -4
- data/test/cases/secure_token_test.rb +32 -0
- data/test/cases/serialization_test.rb +1 -1
- data/test/cases/serialized_attribute_test.rb +93 -6
- data/test/cases/statement_cache_test.rb +38 -0
- data/test/cases/store_test.rb +2 -1
- data/test/cases/suppressor_test.rb +63 -0
- data/test/cases/tasks/database_tasks_test.rb +73 -9
- data/test/cases/tasks/mysql_rake_test.rb +139 -118
- data/test/cases/tasks/postgresql_rake_test.rb +60 -6
- data/test/cases/tasks/sqlite_rake_test.rb +30 -3
- data/test/cases/test_case.rb +28 -20
- data/test/cases/test_fixtures_test.rb +36 -0
- data/test/cases/time_precision_test.rb +103 -0
- data/test/cases/timestamp_test.rb +44 -10
- data/test/cases/touch_later_test.rb +121 -0
- data/test/cases/transaction_callbacks_test.rb +128 -62
- data/test/cases/transaction_isolation_test.rb +2 -2
- data/test/cases/transactions_test.rb +61 -43
- data/test/cases/type/adapter_specific_registry_test.rb +133 -0
- data/test/cases/type/date_time_test.rb +14 -0
- data/test/cases/type/integer_test.rb +2 -96
- data/test/cases/type/string_test.rb +0 -14
- data/test/cases/type_test.rb +39 -0
- data/test/cases/types_test.rb +1 -118
- data/test/cases/unconnected_test.rb +1 -1
- data/test/cases/validations/absence_validation_test.rb +73 -0
- data/test/cases/validations/association_validation_test.rb +13 -2
- data/test/cases/validations/i18n_validation_test.rb +6 -10
- data/test/cases/validations/length_validation_test.rb +62 -30
- data/test/cases/validations/presence_validation_test.rb +36 -1
- data/test/cases/validations/uniqueness_validation_test.rb +128 -37
- data/test/cases/validations_repair_helper.rb +2 -6
- data/test/cases/validations_test.rb +36 -7
- data/test/cases/view_test.rb +102 -5
- data/test/cases/yaml_serialization_test.rb +21 -26
- data/test/config.example.yml +97 -0
- data/test/fixtures/bad_posts.yml +9 -0
- data/test/fixtures/books.yml +20 -0
- data/test/fixtures/content.yml +3 -0
- data/test/fixtures/content_positions.yml +3 -0
- data/test/fixtures/dead_parrots.yml +5 -0
- data/test/fixtures/live_parrots.yml +4 -0
- data/test/fixtures/naked/yml/parrots.yml +2 -0
- data/test/fixtures/naked/yml/trees.yml +3 -0
- data/test/fixtures/nodes.yml +29 -0
- data/test/fixtures/other_comments.yml +6 -0
- data/test/fixtures/other_dogs.yml +2 -0
- data/test/fixtures/other_posts.yml +7 -0
- data/test/fixtures/price_estimates.yml +10 -1
- data/test/fixtures/trees.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +1 -1
- data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
- data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
- data/test/migrations/missing/1_people_have_last_names.rb +2 -2
- data/test/migrations/missing/3_we_need_reminders.rb +2 -2
- data/test/migrations/missing/4_innocent_jointable.rb +2 -2
- data/test/migrations/rename/1_we_need_things.rb +2 -2
- data/test/migrations/rename/2_rename_things.rb +2 -2
- data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy2/1_create_articles.rb +1 -1
- data/test/migrations/to_copy2/2_create_comments.rb +1 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
- data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
- data/test/models/admin/randomly_named_c1.rb +6 -2
- data/test/models/aircraft.rb +1 -0
- data/test/models/author.rb +4 -7
- data/test/models/bird.rb +1 -1
- data/test/models/book.rb +5 -0
- data/test/models/bulb.rb +2 -1
- data/test/models/car.rb +3 -0
- data/test/models/cat.rb +10 -0
- data/test/models/chef.rb +1 -0
- data/test/models/club.rb +2 -0
- data/test/models/comment.rb +17 -5
- data/test/models/company.rb +4 -2
- data/test/models/company_in_module.rb +1 -1
- data/test/models/contact.rb +1 -1
- data/test/models/content.rb +40 -0
- data/test/models/customer.rb +8 -2
- data/test/models/developer.rb +19 -0
- data/test/models/face.rb +1 -1
- data/test/models/guitar.rb +4 -0
- data/test/models/hotel.rb +2 -0
- data/test/models/member.rb +1 -0
- data/test/models/member_detail.rb +4 -3
- data/test/models/mentor.rb +3 -0
- data/test/models/mocktail_designer.rb +2 -0
- data/test/models/node.rb +5 -0
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +3 -0
- data/test/models/other_dog.rb +5 -0
- data/test/models/owner.rb +4 -1
- data/test/models/parrot.rb +6 -7
- data/test/models/person.rb +0 -1
- data/test/models/pet.rb +3 -0
- data/test/models/pet_treasure.rb +6 -0
- data/test/models/pirate.rb +3 -3
- data/test/models/post.rb +18 -9
- data/test/models/project.rb +9 -0
- data/test/models/randomly_named_c1.rb +1 -1
- data/test/models/recipe.rb +3 -0
- data/test/models/ship.rb +8 -2
- data/test/models/tag.rb +6 -0
- data/test/models/topic.rb +2 -8
- data/test/models/tree.rb +3 -0
- data/test/models/tuning_peg.rb +4 -0
- data/test/models/user.rb +14 -0
- data/test/models/uuid_item.rb +6 -0
- data/test/schema/mysql2_specific_schema.rb +33 -23
- data/test/schema/oracle_specific_schema.rb +1 -4
- data/test/schema/postgresql_specific_schema.rb +36 -124
- data/test/schema/schema.rb +170 -65
- data/test/schema/schema.rb.original +1057 -0
- data/test/schema/sqlite_specific_schema.rb +1 -5
- data/test/support/connection.rb +1 -0
- data/test/support/schema_dumping_helper.rb +1 -1
- 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
- metadata +146 -30
- data/lib/mswin32/rb19x/ibm_db.so +0 -0
- data/lib/mswin32/rb21x/i386/ibm_db.so +0 -0
- data/lib/mswin32/rb22x/i386/ibm_db.so +0 -0
- data/lib/mswin32/rb23x/i386/ibm_db.so +0 -0
- data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
- data/test/cases/attribute_methods/serialization_test.rb +0 -29
- data/test/cases/migration/change_schema_test - Copy.rb +0 -448
- data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
- data/test/cases/migration/table_and_index_test.rb +0 -24
- data/test/cases/relation/where_test2.rb +0 -36
- data/test/cases/type/decimal_test.rb +0 -56
- data/test/cases/type/unsigned_integer_test.rb +0 -18
- data/test/cases/xml_serialization_test.rb +0 -457
- data/test/fixtures/naked/csv/accounts.csv +0 -1
- data/test/schema/mysql_specific_schema.rb +0 -70
@@ -11,7 +11,9 @@ require 'models/tagging'
|
|
11
11
|
require 'models/author'
|
12
12
|
require 'models/owner'
|
13
13
|
require 'models/pet'
|
14
|
+
require 'models/pet_treasure'
|
14
15
|
require 'models/toy'
|
16
|
+
require 'models/treasure'
|
15
17
|
require 'models/contract'
|
16
18
|
require 'models/company'
|
17
19
|
require 'models/developer'
|
@@ -42,7 +44,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
42
44
|
def test_preload_sti_rhs_class
|
43
45
|
developers = Developer.includes(:firms).all.to_a
|
44
46
|
assert_no_queries do
|
45
|
-
developers.each
|
47
|
+
developers.each(&:firms)
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -188,7 +190,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
188
190
|
assert post.people.include?(person)
|
189
191
|
end
|
190
192
|
|
191
|
-
assert post.reload.people
|
193
|
+
assert post.reload.people.reload.include?(person)
|
192
194
|
end
|
193
195
|
|
194
196
|
def test_delete_all_for_with_dependent_option_destroy
|
@@ -229,7 +231,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
229
231
|
post = posts(:thinking)
|
230
232
|
post.people.concat [person]
|
231
233
|
assert_equal 1, post.people.size
|
232
|
-
assert_equal 1, post.people
|
234
|
+
assert_equal 1, post.people.reload.size
|
233
235
|
end
|
234
236
|
|
235
237
|
def test_associate_existing_record_twice_should_add_to_target_twice
|
@@ -285,7 +287,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
285
287
|
assert posts(:thinking).people.include?(new_person)
|
286
288
|
end
|
287
289
|
|
288
|
-
assert posts(:thinking).reload.people
|
290
|
+
assert posts(:thinking).reload.people.reload.include?(new_person)
|
289
291
|
end
|
290
292
|
|
291
293
|
def test_associate_new_by_building
|
@@ -310,8 +312,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
310
312
|
posts(:thinking).save
|
311
313
|
end
|
312
314
|
|
313
|
-
assert posts(:thinking).reload.people
|
314
|
-
assert posts(:thinking).reload.people
|
315
|
+
assert posts(:thinking).reload.people.reload.collect(&:first_name).include?("Bob")
|
316
|
+
assert posts(:thinking).reload.people.reload.collect(&:first_name).include?("Ted")
|
315
317
|
end
|
316
318
|
|
317
319
|
def test_build_then_save_with_has_many_inverse
|
@@ -356,7 +358,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
356
358
|
assert posts(:welcome).people.empty?
|
357
359
|
end
|
358
360
|
|
359
|
-
assert posts(:welcome).reload.people
|
361
|
+
assert posts(:welcome).reload.people.reload.empty?
|
360
362
|
end
|
361
363
|
|
362
364
|
def test_destroy_association
|
@@ -367,7 +369,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
367
369
|
end
|
368
370
|
|
369
371
|
assert posts(:welcome).reload.people.empty?
|
370
|
-
assert posts(:welcome).people
|
372
|
+
assert posts(:welcome).people.reload.empty?
|
371
373
|
end
|
372
374
|
|
373
375
|
def test_destroy_all
|
@@ -378,7 +380,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
378
380
|
end
|
379
381
|
|
380
382
|
assert posts(:welcome).reload.people.empty?
|
381
|
-
assert posts(:welcome).people
|
383
|
+
assert posts(:welcome).people.reload.empty?
|
382
384
|
end
|
383
385
|
|
384
386
|
def test_should_raise_exception_for_destroying_mismatching_records
|
@@ -539,7 +541,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
539
541
|
end
|
540
542
|
|
541
543
|
def test_replace_association
|
542
|
-
assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people
|
544
|
+
assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people.reload}
|
543
545
|
|
544
546
|
# 1 query to delete the existing reader (michael)
|
545
547
|
# 1 query to associate the new reader (david)
|
@@ -552,8 +554,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
552
554
|
assert !posts(:welcome).people.include?(people(:michael))
|
553
555
|
}
|
554
556
|
|
555
|
-
assert posts(:welcome).reload.people
|
556
|
-
assert !posts(:welcome).reload.people
|
557
|
+
assert posts(:welcome).reload.people.reload.include?(people(:david))
|
558
|
+
assert !posts(:welcome).reload.people.reload.include?(people(:michael))
|
557
559
|
end
|
558
560
|
|
559
561
|
def test_replace_order_is_preserved
|
@@ -592,7 +594,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
592
594
|
assert posts(:thinking).people.collect(&:first_name).include?("Jeb")
|
593
595
|
end
|
594
596
|
|
595
|
-
assert posts(:thinking).reload.people
|
597
|
+
assert posts(:thinking).reload.people.reload.collect(&:first_name).include?("Jeb")
|
596
598
|
end
|
597
599
|
|
598
600
|
def test_through_record_is_built_when_created_with_where
|
@@ -668,7 +670,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
668
670
|
end
|
669
671
|
|
670
672
|
def test_clear_associations
|
671
|
-
assert_queries(2) { posts(:welcome);posts(:welcome).people
|
673
|
+
assert_queries(2) { posts(:welcome);posts(:welcome).people.reload }
|
672
674
|
|
673
675
|
assert_queries(1) do
|
674
676
|
posts(:welcome).people.clear
|
@@ -678,7 +680,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
678
680
|
assert posts(:welcome).people.empty?
|
679
681
|
end
|
680
682
|
|
681
|
-
assert posts(:welcome).reload.people
|
683
|
+
assert posts(:welcome).reload.people.reload.empty?
|
682
684
|
end
|
683
685
|
|
684
686
|
def test_association_callback_ordering
|
@@ -744,13 +746,14 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
744
746
|
|
745
747
|
def test_get_ids_for_has_many_through_with_conditions_should_not_preload
|
746
748
|
Tagging.create!(:taggable_type => 'Post', :taggable_id => posts(:welcome).id, :tag => tags(:misc))
|
747
|
-
ActiveRecord::Associations::Preloader
|
748
|
-
|
749
|
+
assert_not_called(ActiveRecord::Associations::Preloader, :new) do
|
750
|
+
posts(:welcome).misc_tag_ids
|
751
|
+
end
|
749
752
|
end
|
750
753
|
|
751
754
|
def test_get_ids_for_loaded_associations
|
752
755
|
person = people(:michael)
|
753
|
-
person.posts
|
756
|
+
person.posts.reload
|
754
757
|
assert_queries(0) do
|
755
758
|
person.post_ids
|
756
759
|
person.post_ids
|
@@ -765,9 +768,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
765
768
|
end
|
766
769
|
|
767
770
|
def test_association_proxy_transaction_method_starts_transaction_in_association_class
|
768
|
-
Tag
|
769
|
-
|
770
|
-
|
771
|
+
assert_called(Tag, :transaction) do
|
772
|
+
Post.first.tags.transaction do
|
773
|
+
# nothing
|
774
|
+
end
|
771
775
|
end
|
772
776
|
end
|
773
777
|
|
@@ -828,14 +832,14 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
828
832
|
category = author.named_categories.build(:name => "Primary")
|
829
833
|
author.save
|
830
834
|
assert Categorization.exists?(:author_id => author.id, :named_category_name => category.name)
|
831
|
-
assert author.named_categories
|
835
|
+
assert author.named_categories.reload.include?(category)
|
832
836
|
end
|
833
837
|
|
834
838
|
def test_collection_create_with_nonstandard_primary_key_on_belongs_to
|
835
839
|
author = authors(:mary)
|
836
840
|
category = author.named_categories.create(:name => "Primary")
|
837
841
|
assert Categorization.exists?(:author_id => author.id, :named_category_name => category.name)
|
838
|
-
assert author.named_categories
|
842
|
+
assert author.named_categories.reload.include?(category)
|
839
843
|
end
|
840
844
|
|
841
845
|
def test_collection_exists
|
@@ -850,7 +854,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
850
854
|
category = author.named_categories.create(:name => "Primary")
|
851
855
|
author.named_categories.delete(category)
|
852
856
|
assert !Categorization.exists?(:author_id => author.id, :named_category_name => category.name)
|
853
|
-
assert author.named_categories
|
857
|
+
assert author.named_categories.reload.empty?
|
854
858
|
end
|
855
859
|
|
856
860
|
def test_collection_singular_ids_getter_with_string_primary_keys
|
@@ -871,18 +875,26 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
871
875
|
assert_nothing_raised do
|
872
876
|
book = books(:awdr)
|
873
877
|
book.subscriber_ids = [subscribers(:second).nick]
|
874
|
-
assert_equal [subscribers(:second)], book.subscribers
|
878
|
+
assert_equal [subscribers(:second)], book.subscribers.reload
|
875
879
|
|
876
880
|
book.subscriber_ids = []
|
877
|
-
assert_equal [], book.subscribers
|
881
|
+
assert_equal [], book.subscribers.reload
|
878
882
|
end
|
879
883
|
|
880
884
|
end
|
881
885
|
|
882
886
|
def test_collection_singular_ids_setter_raises_exception_when_invalid_ids_set
|
883
887
|
company = companies(:rails_core)
|
884
|
-
ids =
|
885
|
-
assert_raises(ActiveRecord::RecordNotFound) {company.developer_ids= ids}
|
888
|
+
ids = [Developer.first.id, -9999]
|
889
|
+
e = assert_raises(ActiveRecord::RecordNotFound) { company.developer_ids = ids }
|
890
|
+
assert_match(/Couldn't find all Developers with 'id'/, e.message)
|
891
|
+
end
|
892
|
+
|
893
|
+
def test_collection_singular_ids_through_setter_raises_exception_when_invalid_ids_set
|
894
|
+
author = authors(:david)
|
895
|
+
ids = [categories(:general).name, "Unknown"]
|
896
|
+
e = assert_raises(ActiveRecord::RecordNotFound) { author.essay_category_ids = ids }
|
897
|
+
assert_equal "Couldn't find all Categories with 'name': (General, Unknown) (found 1 results, but was looking for 2)", e.message
|
886
898
|
end
|
887
899
|
|
888
900
|
def test_build_a_model_from_hm_through_association_with_where_clause
|
@@ -960,7 +972,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
960
972
|
assert_equal 1, category.categorizations.where(:special => true).count
|
961
973
|
end
|
962
974
|
|
963
|
-
def
|
975
|
+
def test_joining_has_many_through_with_distinct
|
964
976
|
mary = Author.joins(:unique_categorized_posts).where(:id => authors(:mary).id).first
|
965
977
|
assert_equal 1, mary.unique_categorized_posts.length
|
966
978
|
assert_equal 1, mary.unique_categorized_post_ids.length
|
@@ -1040,14 +1052,6 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
1040
1052
|
end
|
1041
1053
|
end
|
1042
1054
|
|
1043
|
-
def test_save_should_not_raise_exception_when_join_record_has_errors
|
1044
|
-
repair_validations(Categorization) do
|
1045
|
-
Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
|
1046
|
-
c = Category.create(:name => 'Fishing', :authors => [Author.first])
|
1047
|
-
c.save
|
1048
|
-
end
|
1049
|
-
end
|
1050
|
-
|
1051
1055
|
def test_assign_array_to_new_record_builds_join_records
|
1052
1056
|
c = Category.new(:name => 'Fishing', :authors => [Author.first])
|
1053
1057
|
assert_equal 1, c.categorizations.size
|
@@ -1072,11 +1076,11 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
1072
1076
|
end
|
1073
1077
|
end
|
1074
1078
|
|
1075
|
-
def
|
1079
|
+
def test_save_returns_falsy_when_join_record_has_errors
|
1076
1080
|
repair_validations(Categorization) do
|
1077
1081
|
Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
|
1078
1082
|
c = Category.new(:name => 'Fishing', :authors => [Author.first])
|
1079
|
-
|
1083
|
+
assert_not c.save
|
1080
1084
|
end
|
1081
1085
|
end
|
1082
1086
|
|
@@ -1088,6 +1092,18 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
1088
1092
|
assert_equal [], person.posts
|
1089
1093
|
end
|
1090
1094
|
|
1095
|
+
def test_preloading_empty_through_with_polymorphic_source_association
|
1096
|
+
owner = Owner.create!(name: "Rainbow Unicat")
|
1097
|
+
pet = Pet.create!(owner: owner)
|
1098
|
+
person = Person.create!(first_name: "Gaga")
|
1099
|
+
treasure = Treasure.create!(looter: person)
|
1100
|
+
non_looted_treasure = Treasure.create!()
|
1101
|
+
PetTreasure.create!(pet: pet, treasure: treasure, rainbow_color: "Ultra violet indigo")
|
1102
|
+
PetTreasure.create!(pet: pet, treasure: non_looted_treasure, rainbow_color: "Ultra violet indigo")
|
1103
|
+
|
1104
|
+
assert_equal [person], Owner.where(name: "Rainbow Unicat").includes(pets: :persons).first.persons.to_a
|
1105
|
+
end
|
1106
|
+
|
1091
1107
|
def test_explicitly_joining_join_table
|
1092
1108
|
assert_equal owners(:blackbeard).toys, owners(:blackbeard).toys.with_pet
|
1093
1109
|
end
|
@@ -1103,6 +1119,32 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
1103
1119
|
assert_equal ["parrot", "bulbul"], owner.toys.map { |r| r.pet.name }
|
1104
1120
|
end
|
1105
1121
|
|
1122
|
+
def test_has_many_through_associations_sum_on_columns
|
1123
|
+
post1 = Post.create(title: "active", body: "sample")
|
1124
|
+
post2 = Post.create(title: "inactive", body: "sample")
|
1125
|
+
|
1126
|
+
person1 = Person.create(first_name: "aaron", followers_count: 1)
|
1127
|
+
person2 = Person.create(first_name: "schmit", followers_count: 2)
|
1128
|
+
person3 = Person.create(first_name: "bill", followers_count: 3)
|
1129
|
+
person4 = Person.create(first_name: "cal", followers_count: 4)
|
1130
|
+
|
1131
|
+
Reader.create(post_id: post1.id, person_id: person1.id)
|
1132
|
+
Reader.create(post_id: post1.id, person_id: person2.id)
|
1133
|
+
Reader.create(post_id: post1.id, person_id: person3.id)
|
1134
|
+
Reader.create(post_id: post1.id, person_id: person4.id)
|
1135
|
+
|
1136
|
+
Reader.create(post_id: post2.id, person_id: person1.id)
|
1137
|
+
Reader.create(post_id: post2.id, person_id: person2.id)
|
1138
|
+
Reader.create(post_id: post2.id, person_id: person3.id)
|
1139
|
+
Reader.create(post_id: post2.id, person_id: person4.id)
|
1140
|
+
|
1141
|
+
active_persons = Person.joins(:readers).joins(:posts).distinct(true).where("posts.title" => "active")
|
1142
|
+
|
1143
|
+
assert_equal active_persons.map(&:followers_count).reduce(:+), 10
|
1144
|
+
assert_equal active_persons.sum(:followers_count), 10
|
1145
|
+
assert_equal active_persons.sum(:followers_count), active_persons.map(&:followers_count).reduce(:+)
|
1146
|
+
end
|
1147
|
+
|
1106
1148
|
def test_has_many_through_associations_on_new_records_use_null_relations
|
1107
1149
|
person = Person.new
|
1108
1150
|
|
@@ -1117,10 +1159,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
1117
1159
|
|
1118
1160
|
def test_has_many_through_with_default_scope_on_the_target
|
1119
1161
|
person = people(:michael)
|
1120
|
-
assert_equal [posts(:thinking)], person.first_posts
|
1162
|
+
assert_equal [posts(:thinking).id], person.first_posts.map(&:id)
|
1121
1163
|
|
1122
1164
|
readers(:michael_authorless).update(first_post_id: 1)
|
1123
|
-
assert_equal [posts(:thinking)], person.reload.first_posts
|
1165
|
+
assert_equal [posts(:thinking).id], person.reload.first_posts.map(&:id)
|
1124
1166
|
end
|
1125
1167
|
|
1126
1168
|
def test_has_many_through_with_includes_in_through_association_scope
|
@@ -1174,6 +1216,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
1174
1216
|
assert_nil Club.new.special_favourites.distinct_value
|
1175
1217
|
end
|
1176
1218
|
|
1219
|
+
def test_association_force_reload_with_only_true_is_deprecated
|
1220
|
+
post = Post.find(1)
|
1221
|
+
|
1222
|
+
assert_deprecated { post.people(true) }
|
1223
|
+
end
|
1224
|
+
|
1177
1225
|
def test_has_many_through_do_not_cache_association_reader_if_the_though_method_has_default_scopes
|
1178
1226
|
member = Member.create!
|
1179
1227
|
club = Club.create!
|
@@ -1201,4 +1249,23 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
|
|
1201
1249
|
ensure
|
1202
1250
|
TenantMembership.current_member = nil
|
1203
1251
|
end
|
1252
|
+
|
1253
|
+
def test_through_scope_is_affected_by_unscoping
|
1254
|
+
author = authors(:david)
|
1255
|
+
|
1256
|
+
expected = author.comments.to_a
|
1257
|
+
FirstPost.unscoped do
|
1258
|
+
assert_equal expected.sort_by(&:id), author.comments_on_first_posts.sort_by(&:id)
|
1259
|
+
end
|
1260
|
+
end
|
1261
|
+
|
1262
|
+
def test_through_scope_isnt_affected_by_scoping
|
1263
|
+
author = authors(:david)
|
1264
|
+
|
1265
|
+
expected = author.comments_on_first_posts.to_a
|
1266
|
+
FirstPost.where(id: 2).scoping do
|
1267
|
+
author.comments_on_first_posts.reset
|
1268
|
+
assert_equal expected.sort_by(&:id), author.comments_on_first_posts.sort_by(&:id)
|
1269
|
+
end
|
1270
|
+
end
|
1204
1271
|
end
|
@@ -12,7 +12,7 @@ require 'models/image'
|
|
12
12
|
require 'models/post'
|
13
13
|
|
14
14
|
class HasOneAssociationsTest < ActiveRecord::TestCase
|
15
|
-
self.
|
15
|
+
self.use_transactional_tests = false unless supports_savepoints?
|
16
16
|
fixtures :accounts, :companies, :developers, :projects, :developers_projects, :ships, :pirates
|
17
17
|
|
18
18
|
def setup
|
@@ -107,6 +107,14 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
107
107
|
assert_nil Account.find(old_account_id).firm_id
|
108
108
|
end
|
109
109
|
|
110
|
+
def test_nullification_on_destroyed_association
|
111
|
+
developer = Developer.create!(name: "Someone")
|
112
|
+
ship = Ship.create!(name: "Planet Caravan", developer: developer)
|
113
|
+
ship.destroy
|
114
|
+
assert !ship.persisted?
|
115
|
+
assert !developer.persisted?
|
116
|
+
end
|
117
|
+
|
110
118
|
def test_natural_assignment_to_nil_after_destroy
|
111
119
|
firm = companies(:rails_core)
|
112
120
|
old_account_id = firm.account.id
|
@@ -178,6 +186,25 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
178
186
|
assert firm.account.present?
|
179
187
|
end
|
180
188
|
|
189
|
+
def test_restrict_with_error_is_deprecated_using_key_one
|
190
|
+
I18n.backend = I18n::Backend::Simple.new
|
191
|
+
I18n.backend.store_translations :en, activerecord: { errors: { messages: { restrict_dependent_destroy: { one: 'message for deprecated key' } } } }
|
192
|
+
|
193
|
+
firm = RestrictedWithErrorFirm.create!(name: 'restrict')
|
194
|
+
firm.create_account(credit_limit: 10)
|
195
|
+
|
196
|
+
assert_not_nil firm.account
|
197
|
+
|
198
|
+
assert_deprecated { firm.destroy }
|
199
|
+
|
200
|
+
assert !firm.errors.empty?
|
201
|
+
assert_equal 'message for deprecated key', firm.errors[:base].first
|
202
|
+
assert RestrictedWithErrorFirm.exists?(name: 'restrict')
|
203
|
+
assert firm.account.present?
|
204
|
+
ensure
|
205
|
+
I18n.backend.reload!
|
206
|
+
end
|
207
|
+
|
181
208
|
def test_restrict_with_error
|
182
209
|
firm = RestrictedWithErrorFirm.create!(:name => 'restrict')
|
183
210
|
firm.create_account(:credit_limit => 10)
|
@@ -192,6 +219,24 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
192
219
|
assert firm.account.present?
|
193
220
|
end
|
194
221
|
|
222
|
+
def test_restrict_with_error_with_locale
|
223
|
+
I18n.backend = I18n::Backend::Simple.new
|
224
|
+
I18n.backend.store_translations 'en', activerecord: {attributes: {restricted_with_error_firm: {account: 'firm account'}}}
|
225
|
+
firm = RestrictedWithErrorFirm.create!(name: 'restrict')
|
226
|
+
firm.create_account(credit_limit: 10)
|
227
|
+
|
228
|
+
assert_not_nil firm.account
|
229
|
+
|
230
|
+
firm.destroy
|
231
|
+
|
232
|
+
assert !firm.errors.empty?
|
233
|
+
assert_equal "Cannot delete record because a dependent firm account exists", firm.errors[:base].first
|
234
|
+
assert RestrictedWithErrorFirm.exists?(name: 'restrict')
|
235
|
+
assert firm.account.present?
|
236
|
+
ensure
|
237
|
+
I18n.backend.reload!
|
238
|
+
end
|
239
|
+
|
195
240
|
def test_successful_build_association
|
196
241
|
firm = Firm.new("name" => "GlobalMegaCorp")
|
197
242
|
firm.save
|
@@ -237,16 +282,16 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
237
282
|
|
238
283
|
def test_build_and_create_should_not_happen_within_scope
|
239
284
|
pirate = pirates(:blackbeard)
|
240
|
-
|
285
|
+
scope = pirate.association(:foo_bulb).scope.where_values_hash
|
241
286
|
|
242
287
|
bulb = pirate.build_foo_bulb
|
243
|
-
assert_not_equal
|
288
|
+
assert_not_equal scope, bulb.scope_after_initialize.where_values_hash
|
244
289
|
|
245
290
|
bulb = pirate.create_foo_bulb
|
246
|
-
assert_not_equal
|
291
|
+
assert_not_equal scope, bulb.scope_after_initialize.where_values_hash
|
247
292
|
|
248
293
|
bulb = pirate.create_foo_bulb!
|
249
|
-
assert_not_equal
|
294
|
+
assert_not_equal scope, bulb.scope_after_initialize.where_values_hash
|
250
295
|
end
|
251
296
|
|
252
297
|
def test_create_association
|
@@ -281,6 +326,16 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
281
326
|
end
|
282
327
|
end
|
283
328
|
|
329
|
+
def test_reload_association
|
330
|
+
odegy = companies(:odegy)
|
331
|
+
|
332
|
+
assert_equal 53, odegy.account.credit_limit
|
333
|
+
Account.where(id: odegy.account.id).update_all(credit_limit: 80)
|
334
|
+
assert_equal 53, odegy.account.credit_limit
|
335
|
+
|
336
|
+
assert_equal 80, odegy.reload_account.credit_limit
|
337
|
+
end
|
338
|
+
|
284
339
|
def test_build
|
285
340
|
firm = Firm.new("name" => "GlobalMegaCorp")
|
286
341
|
firm.save
|
@@ -332,7 +387,8 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
332
387
|
assert a.persisted?
|
333
388
|
assert_equal a, firm.account
|
334
389
|
assert_equal a, firm.account
|
335
|
-
|
390
|
+
firm.association(:account).reload
|
391
|
+
assert_equal a, firm.account
|
336
392
|
end
|
337
393
|
|
338
394
|
def test_save_still_works_after_accessing_nil_has_one
|
@@ -575,9 +631,9 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
575
631
|
end
|
576
632
|
|
577
633
|
def test_has_one_loading_for_new_record
|
578
|
-
Post.create!(author_id: 42, title: 'foo', body: 'bar')
|
634
|
+
post = Post.create!(author_id: 42, title: 'foo', body: 'bar')
|
579
635
|
author = Author.new(id: 42)
|
580
|
-
|
636
|
+
assert_equal post, author.post
|
581
637
|
end
|
582
638
|
|
583
639
|
def test_has_one_relationship_cannot_have_a_counter_cache
|
@@ -607,4 +663,45 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
607
663
|
end
|
608
664
|
end
|
609
665
|
end
|
666
|
+
|
667
|
+
def test_association_force_reload_with_only_true_is_deprecated
|
668
|
+
firm = Firm.find(1)
|
669
|
+
|
670
|
+
assert_deprecated("call `reload_account` instead") { firm.account(true) }
|
671
|
+
end
|
672
|
+
|
673
|
+
class SpecialBook < ActiveRecord::Base
|
674
|
+
self.table_name = "books"
|
675
|
+
belongs_to :author, class_name: "SpecialAuthor"
|
676
|
+
has_one :subscription, class_name: "SpecialSupscription", foreign_key: "subscriber_id"
|
677
|
+
end
|
678
|
+
|
679
|
+
class SpecialAuthor < ActiveRecord::Base
|
680
|
+
self.table_name = 'authors'
|
681
|
+
has_one :book, class_name: 'SpecialBook', foreign_key: 'author_id'
|
682
|
+
end
|
683
|
+
|
684
|
+
class SpecialSupscription < ActiveRecord::Base
|
685
|
+
self.table_name = "subscriptions"
|
686
|
+
belongs_to :book, class_name: "SpecialBook"
|
687
|
+
end
|
688
|
+
|
689
|
+
def test_assocation_enum_works_properly
|
690
|
+
author = SpecialAuthor.create!(name: 'Test')
|
691
|
+
book = SpecialBook.create!(status: 'published')
|
692
|
+
author.book = book
|
693
|
+
|
694
|
+
refute_equal 0, SpecialAuthor.joins(:book).where(books: { status: 'published' } ).count
|
695
|
+
end
|
696
|
+
|
697
|
+
def test_assocation_enum_works_properly_with_nested_join
|
698
|
+
author = SpecialAuthor.create!(name: "Test")
|
699
|
+
book = SpecialBook.create!(status: "published")
|
700
|
+
author.book = book
|
701
|
+
|
702
|
+
where_clause = { books: { subscriptions: { subscriber_id: nil } } }
|
703
|
+
assert_nothing_raised do
|
704
|
+
SpecialAuthor.joins(book: :subscription).where.not(where_clause)
|
705
|
+
end
|
706
|
+
end
|
610
707
|
end
|