ibm_db 3.0.4 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +8 -1
- data/LICENSE +1 -1
- data/ParameterizedQueries README +6 -6
- data/README +38 -55
- data/ext/Makefile +266 -0
- data/ext/extconf.rb +34 -3
- data/ext/gil_release_version +3 -0
- data/ext/ibm_db.c +106 -111
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +103 -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 +911 -527
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
- data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
- data/test/cases/adapter_test.rb +148 -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 +176 -73
- data/test/cases/associations/extension_test.rb +7 -2
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +104 -32
- data/test/cases/associations/has_many_associations_test.rb +382 -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 +51 -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 +74 -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 +311 -236
- 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 +32 -44
- 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 +279 -151
- data/test/cases/fixture_set/file_test.rb +18 -0
- data/test/cases/fixtures_test.rb +123 -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 +118 -132
- 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 +68 -66
- 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 +114 -107
- 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 +18 -11
- data/test/cases/nested_attributes_test.rb +74 -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 +77 -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 +89 -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 +74 -8
- data/test/cases/tasks/mysql_rake_test.rb +143 -109
- data/test/cases/tasks/postgresql_rake_test.rb +71 -12
- 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 +47 -14
- 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 +150 -36
- data/test/cases/validations_repair_helper.rb +2 -6
- data/test/cases/validations_test.rb +36 -7
- data/test/cases/view_test.rb +108 -5
- data/test/cases/yaml_serialization_test.rb +36 -1
- 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 +5 -0
- data/test/models/club.rb +2 -0
- data/test/models/comment.rb +17 -5
- data/test/models/company.rb +7 -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 +22 -0
- data/test/models/face.rb +1 -1
- data/test/models/guitar.rb +4 -0
- data/test/models/hotel.rb +5 -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 +11 -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 +183 -64
- 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 +145 -26
- 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 -51
- 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
data/test/cases/helper.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require File.expand_path('../../../../load_paths', __FILE__)
|
2
|
-
|
3
1
|
require 'config'
|
4
2
|
|
5
3
|
require 'active_support/testing/autorun'
|
4
|
+
require 'active_support/testing/method_call_assertions'
|
6
5
|
require 'stringio'
|
7
6
|
|
8
7
|
require 'active_record'
|
@@ -24,15 +23,15 @@ ActiveSupport::Deprecation.debug = true
|
|
24
23
|
# Disable available locale checks to avoid warnings running the test suite.
|
25
24
|
I18n.enforce_available_locales = false
|
26
25
|
|
27
|
-
# Enable raise errors in after_commit and after_rollback.
|
28
|
-
ActiveRecord::Base.raise_in_transactional_callbacks = true
|
29
|
-
|
30
26
|
# Connect to the database
|
31
27
|
ARTest.connect
|
32
28
|
|
33
29
|
# Quote "type" if it's a reserved word for the current connection.
|
34
30
|
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
|
35
31
|
|
32
|
+
# FIXME: Remove this when the deprecation cycle on TZ aware types by default ends.
|
33
|
+
ActiveRecord::Base.time_zone_aware_types << :time
|
34
|
+
|
36
35
|
def current_adapter?(*types)
|
37
36
|
types.any? do |type|
|
38
37
|
ActiveRecord::ConnectionAdapters.const_defined?(type) &&
|
@@ -45,13 +44,12 @@ def in_memory_db?
|
|
45
44
|
ActiveRecord::Base.connection_pool.spec.config[:database] == ":memory:"
|
46
45
|
end
|
47
46
|
|
48
|
-
def
|
49
|
-
|
50
|
-
ActiveRecord::Base.connection.send(:version).join(".") >= "5.6.0"
|
47
|
+
def subsecond_precision_supported?
|
48
|
+
ActiveRecord::Base.connection.supports_datetime_with_precision?
|
51
49
|
end
|
52
50
|
|
53
51
|
def mysql_enforcing_gtid_consistency?
|
54
|
-
current_adapter?(:
|
52
|
+
current_adapter?(:Mysql2Adapter) && 'ON' == ActiveRecord::Base.connection.show_variable('enforce_gtid_consistency')
|
55
53
|
end
|
56
54
|
|
57
55
|
def supports_savepoints?
|
@@ -124,7 +122,7 @@ def enable_extension!(extension, connection)
|
|
124
122
|
return connection.reconnect! if connection.extension_enabled?(extension)
|
125
123
|
|
126
124
|
connection.enable_extension extension
|
127
|
-
connection.commit_db_transaction
|
125
|
+
connection.commit_db_transaction if connection.transaction_open?
|
128
126
|
connection.reconnect!
|
129
127
|
end
|
130
128
|
|
@@ -140,10 +138,11 @@ require "cases/validations_repair_helper"
|
|
140
138
|
class ActiveSupport::TestCase
|
141
139
|
include ActiveRecord::TestFixtures
|
142
140
|
include ActiveRecord::ValidationsRepairHelper
|
141
|
+
include ActiveSupport::Testing::MethodCallAssertions
|
143
142
|
|
144
143
|
self.fixture_path = FIXTURES_ROOT
|
145
144
|
self.use_instantiated_fixtures = false
|
146
|
-
self.
|
145
|
+
self.use_transactional_tests = true
|
147
146
|
|
148
147
|
def create_fixtures(*fixture_set_names, &block)
|
149
148
|
ActiveRecord::FixtureSet.create_fixtures(ActiveSupport::TestCase.fixture_path, fixture_set_names, fixture_class_names, &block)
|
@@ -203,8 +202,3 @@ module InTimeZone
|
|
203
202
|
end
|
204
203
|
|
205
204
|
require 'mocha/setup' # FIXME: stop using mocha
|
206
|
-
|
207
|
-
# FIXME: we have tests that depend on run order, we should fix that and
|
208
|
-
# remove this method call.
|
209
|
-
require 'active_support/test_case'
|
210
|
-
ActiveSupport::TestCase.test_order = :sorted
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'cases/helper'
|
2
|
+
require 'support/connection_helper'
|
2
3
|
|
3
4
|
class HotCompatibilityTest < ActiveRecord::TestCase
|
4
|
-
self.
|
5
|
+
self.use_transactional_tests = false
|
6
|
+
include ConnectionHelper
|
5
7
|
|
6
8
|
setup do
|
7
9
|
@klass = Class.new(ActiveRecord::Base) do
|
@@ -51,4 +53,90 @@ class HotCompatibilityTest < ActiveRecord::TestCase
|
|
51
53
|
record.reload
|
52
54
|
assert_equal 'bar', record.foo
|
53
55
|
end
|
56
|
+
|
57
|
+
if current_adapter?(:PostgreSQLAdapter)
|
58
|
+
test "cleans up after prepared statement failure in a transaction" do
|
59
|
+
with_two_connections do |original_connection, ddl_connection|
|
60
|
+
record = @klass.create! bar: 'bar'
|
61
|
+
|
62
|
+
# prepare the reload statement in a transaction
|
63
|
+
@klass.transaction do
|
64
|
+
record.reload
|
65
|
+
end
|
66
|
+
|
67
|
+
assert get_prepared_statement_cache(@klass.connection).any?,
|
68
|
+
"expected prepared statement cache to have something in it"
|
69
|
+
|
70
|
+
# add a new column
|
71
|
+
ddl_connection.add_column :hot_compatibilities, :baz, :string
|
72
|
+
|
73
|
+
assert_raise(ActiveRecord::PreparedStatementCacheExpired) do
|
74
|
+
@klass.transaction do
|
75
|
+
record.reload
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_empty get_prepared_statement_cache(@klass.connection),
|
80
|
+
"expected prepared statement cache to be empty but it wasn't"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test "cleans up after prepared statement failure in nested transactions" do
|
85
|
+
with_two_connections do |original_connection, ddl_connection|
|
86
|
+
record = @klass.create! bar: 'bar'
|
87
|
+
|
88
|
+
# prepare the reload statement in a transaction
|
89
|
+
@klass.transaction do
|
90
|
+
record.reload
|
91
|
+
end
|
92
|
+
|
93
|
+
assert get_prepared_statement_cache(@klass.connection).any?,
|
94
|
+
"expected prepared statement cache to have something in it"
|
95
|
+
|
96
|
+
# add a new column
|
97
|
+
ddl_connection.add_column :hot_compatibilities, :baz, :string
|
98
|
+
|
99
|
+
assert_raise(ActiveRecord::PreparedStatementCacheExpired) do
|
100
|
+
@klass.transaction do
|
101
|
+
@klass.transaction do
|
102
|
+
@klass.transaction do
|
103
|
+
record.reload
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
assert_empty get_prepared_statement_cache(@klass.connection),
|
110
|
+
"expected prepared statement cache to be empty but it wasn't"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def get_prepared_statement_cache(connection)
|
118
|
+
connection.instance_variable_get(:@statements)
|
119
|
+
.instance_variable_get(:@cache)[Process.pid]
|
120
|
+
end
|
121
|
+
|
122
|
+
# Rails will automatically clear the prepared statements on the connection
|
123
|
+
# that runs the migration, so we use two connections to simulate what would
|
124
|
+
# actually happen on a production system; we'd have one connection running the
|
125
|
+
# migration from the rake task ("ddl_connection" here), and we'd have another
|
126
|
+
# connection in a web worker.
|
127
|
+
def with_two_connections
|
128
|
+
run_without_connection do |original_connection|
|
129
|
+
ActiveRecord::Base.establish_connection(original_connection.merge(pool_size: 2))
|
130
|
+
begin
|
131
|
+
ddl_connection = ActiveRecord::Base.connection_pool.checkout
|
132
|
+
begin
|
133
|
+
yield original_connection, ddl_connection
|
134
|
+
ensure
|
135
|
+
ActiveRecord::Base.connection_pool.checkin ddl_connection
|
136
|
+
end
|
137
|
+
ensure
|
138
|
+
ActiveRecord::Base.clear_all_connections!
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
54
142
|
end
|
@@ -1,21 +1,41 @@
|
|
1
1
|
require 'cases/helper'
|
2
|
+
require 'models/author'
|
2
3
|
require 'models/company'
|
4
|
+
require 'models/membership'
|
3
5
|
require 'models/person'
|
4
6
|
require 'models/post'
|
5
7
|
require 'models/project'
|
6
8
|
require 'models/subscriber'
|
7
9
|
require 'models/vegetables'
|
8
10
|
require 'models/shop'
|
11
|
+
require 'models/sponsor'
|
12
|
+
|
13
|
+
module InheritanceTestHelper
|
14
|
+
def with_store_full_sti_class(&block)
|
15
|
+
assign_store_full_sti_class true, &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def without_store_full_sti_class(&block)
|
19
|
+
assign_store_full_sti_class false, &block
|
20
|
+
end
|
21
|
+
|
22
|
+
def assign_store_full_sti_class(flag)
|
23
|
+
old_store_full_sti_class = ActiveRecord::Base.store_full_sti_class
|
24
|
+
ActiveRecord::Base.store_full_sti_class = flag
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
ActiveRecord::Base.store_full_sti_class = old_store_full_sti_class
|
28
|
+
end
|
29
|
+
end
|
9
30
|
|
10
31
|
class InheritanceTest < ActiveRecord::TestCase
|
11
|
-
|
32
|
+
include InheritanceTestHelper
|
33
|
+
fixtures :companies, :projects, :subscribers, :accounts, :vegetables, :memberships
|
12
34
|
|
13
35
|
def test_class_with_store_full_sti_class_returns_full_name
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
ensure
|
18
|
-
ActiveRecord::Base.store_full_sti_class = old
|
36
|
+
with_store_full_sti_class do
|
37
|
+
assert_equal 'Namespaced::Company', Namespaced::Company.sti_name
|
38
|
+
end
|
19
39
|
end
|
20
40
|
|
21
41
|
def test_class_with_blank_sti_name
|
@@ -33,39 +53,104 @@ class InheritanceTest < ActiveRecord::TestCase
|
|
33
53
|
end
|
34
54
|
|
35
55
|
def test_class_without_store_full_sti_class_returns_demodulized_name
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
56
|
+
without_store_full_sti_class do
|
57
|
+
assert_equal 'Company', Namespaced::Company.sti_name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_compute_type_success
|
62
|
+
assert_equal Author, ActiveRecord::Base.send(:compute_type, 'Author')
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_compute_type_nonexistent_constant
|
66
|
+
e = assert_raises NameError do
|
67
|
+
ActiveRecord::Base.send :compute_type, 'NonexistentModel'
|
68
|
+
end
|
69
|
+
assert_equal 'uninitialized constant ActiveRecord::Base::NonexistentModel', e.message
|
70
|
+
assert_equal 'ActiveRecord::Base::NonexistentModel', e.name
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_compute_type_no_method_error
|
74
|
+
ActiveSupport::Dependencies.stub(:safe_constantize, proc{ raise NoMethodError }) do
|
75
|
+
assert_raises NoMethodError do
|
76
|
+
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_compute_type_on_undefined_method
|
82
|
+
error = nil
|
83
|
+
begin
|
84
|
+
Class.new(Author) do
|
85
|
+
alias_method :foo, :bar
|
86
|
+
end
|
87
|
+
rescue => e
|
88
|
+
error = e
|
89
|
+
end
|
90
|
+
|
91
|
+
ActiveSupport::Dependencies.stub(:safe_constantize, proc{ raise e }) do
|
92
|
+
|
93
|
+
exception = assert_raises NameError do
|
94
|
+
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
95
|
+
end
|
96
|
+
assert_equal error.message, exception.message
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_compute_type_argument_error
|
101
|
+
ActiveSupport::Dependencies.stub(:safe_constantize, proc{ raise ArgumentError }) do
|
102
|
+
assert_raises ArgumentError do
|
103
|
+
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
104
|
+
end
|
105
|
+
end
|
41
106
|
end
|
42
107
|
|
43
108
|
def test_should_store_demodulized_class_name_with_store_full_sti_class_option_disabled
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
ensure
|
49
|
-
ActiveRecord::Base.store_full_sti_class = old
|
109
|
+
without_store_full_sti_class do
|
110
|
+
item = Namespaced::Company.new
|
111
|
+
assert_equal 'Company', item[:type]
|
112
|
+
end
|
50
113
|
end
|
51
114
|
|
52
115
|
def test_should_store_full_class_name_with_store_full_sti_class_option_enabled
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
ensure
|
58
|
-
ActiveRecord::Base.store_full_sti_class = old
|
116
|
+
with_store_full_sti_class do
|
117
|
+
item = Namespaced::Company.new
|
118
|
+
assert_equal 'Namespaced::Company', item[:type]
|
119
|
+
end
|
59
120
|
end
|
60
121
|
|
61
122
|
def test_different_namespace_subclass_should_load_correctly_with_store_full_sti_class_option
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
123
|
+
with_store_full_sti_class do
|
124
|
+
item = Namespaced::Company.create name: "Wolverine 2"
|
125
|
+
assert_not_nil Company.find(item.id)
|
126
|
+
assert_not_nil Namespaced::Company.find(item.id)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_descends_from_active_record
|
131
|
+
assert !ActiveRecord::Base.descends_from_active_record?
|
132
|
+
|
133
|
+
# Abstract subclass of AR::Base.
|
134
|
+
assert LoosePerson.descends_from_active_record?
|
135
|
+
|
136
|
+
# Concrete subclass of an abstract class.
|
137
|
+
assert LooseDescendant.descends_from_active_record?
|
138
|
+
|
139
|
+
# Concrete subclass of AR::Base.
|
140
|
+
assert TightPerson.descends_from_active_record?
|
141
|
+
|
142
|
+
# Concrete subclass of a concrete class but has no type column.
|
143
|
+
assert TightDescendant.descends_from_active_record?
|
144
|
+
|
145
|
+
# Concrete subclass of AR::Base.
|
146
|
+
assert Post.descends_from_active_record?
|
147
|
+
|
148
|
+
# Abstract subclass of a concrete class which has a type column.
|
149
|
+
# This is pathological, as you'll never have Sub < Abstract < Concrete.
|
150
|
+
assert !StiPost.descends_from_active_record?
|
151
|
+
|
152
|
+
# Concrete subclasses an abstract class which has a type column.
|
153
|
+
assert !SubStiPost.descends_from_active_record?
|
69
154
|
end
|
70
155
|
|
71
156
|
def test_company_descends_from_active_record
|
@@ -75,6 +160,12 @@ class InheritanceTest < ActiveRecord::TestCase
|
|
75
160
|
assert !Class.new(Company).descends_from_active_record?, 'Company subclass should not descend from ActiveRecord::Base'
|
76
161
|
end
|
77
162
|
|
163
|
+
def test_abstract_class
|
164
|
+
assert !ActiveRecord::Base.abstract_class?
|
165
|
+
assert LoosePerson.abstract_class?
|
166
|
+
assert !LooseDescendant.abstract_class?
|
167
|
+
end
|
168
|
+
|
78
169
|
def test_inheritance_base_class
|
79
170
|
assert_equal Post, Post.base_class
|
80
171
|
assert_equal Post, SpecialPost.base_class
|
@@ -204,10 +295,27 @@ class InheritanceTest < ActiveRecord::TestCase
|
|
204
295
|
assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'Account') }
|
205
296
|
end
|
206
297
|
|
298
|
+
def test_new_with_unrelated_namespaced_type
|
299
|
+
without_store_full_sti_class do
|
300
|
+
e = assert_raises ActiveRecord::SubclassNotFound do
|
301
|
+
Namespaced::Company.new(type: 'Firm')
|
302
|
+
end
|
303
|
+
|
304
|
+
assert_equal "Invalid single-table inheritance type: Namespaced::Firm is not a subclass of Namespaced::Company", e.message
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
207
308
|
def test_new_with_complex_inheritance
|
208
309
|
assert_nothing_raised { Client.new(type: 'VerySpecialClient') }
|
209
310
|
end
|
210
311
|
|
312
|
+
def test_new_without_storing_full_sti_class
|
313
|
+
without_store_full_sti_class do
|
314
|
+
item = Company.new(type: 'SpecialCo')
|
315
|
+
assert_instance_of Company::SpecialCo, item
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
211
319
|
def test_new_with_autoload_paths
|
212
320
|
path = File.expand_path('../../models/autoloadable', __FILE__)
|
213
321
|
ActiveSupport::Dependencies.autoload_paths << path
|
@@ -310,7 +418,7 @@ class InheritanceTest < ActiveRecord::TestCase
|
|
310
418
|
|
311
419
|
def test_eager_load_belongs_to_primary_key_quoting
|
312
420
|
con = Account.connection
|
313
|
-
assert_sql(/#{con.quote_table_name('companies')}.#{con.quote_column_name('id')}
|
421
|
+
assert_sql(/#{con.quote_table_name('companies')}.#{con.quote_column_name('id')} = 1/) do
|
314
422
|
Account.all.merge!(:includes => :firm).find(1)
|
315
423
|
end
|
316
424
|
end
|
@@ -328,43 +436,42 @@ class InheritanceTest < ActiveRecord::TestCase
|
|
328
436
|
assert_nothing_raised { Company.of_first_firm }
|
329
437
|
assert_nothing_raised { Client.of_first_firm }
|
330
438
|
end
|
439
|
+
|
440
|
+
def test_inheritance_with_default_scope
|
441
|
+
assert_equal 1, SelectedMembership.count(:all)
|
442
|
+
end
|
331
443
|
end
|
332
444
|
|
333
445
|
class InheritanceComputeTypeTest < ActiveRecord::TestCase
|
446
|
+
include InheritanceTestHelper
|
334
447
|
fixtures :companies
|
335
448
|
|
336
|
-
def setup
|
337
|
-
ActiveSupport::Dependencies.log_activity = true
|
338
|
-
end
|
339
|
-
|
340
449
|
teardown do
|
341
|
-
ActiveSupport::Dependencies.log_activity = false
|
342
450
|
self.class.const_remove :FirmOnTheFly rescue nil
|
343
451
|
Firm.const_remove :FirmOnTheFly rescue nil
|
344
452
|
end
|
345
453
|
|
346
454
|
def test_instantiation_doesnt_try_to_require_corresponding_file
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
455
|
+
without_store_full_sti_class do
|
456
|
+
foo = Firm.first.clone
|
457
|
+
foo.type = 'FirmOnTheFly'
|
458
|
+
foo.save!
|
351
459
|
|
352
|
-
|
353
|
-
|
460
|
+
# Should fail without FirmOnTheFly in the type condition.
|
461
|
+
assert_raise(ActiveRecord::RecordNotFound) { Firm.find(foo.id) }
|
354
462
|
|
355
|
-
|
356
|
-
|
357
|
-
|
463
|
+
# Nest FirmOnTheFly in the test case where Dependencies won't see it.
|
464
|
+
self.class.const_set :FirmOnTheFly, Class.new(Firm)
|
465
|
+
assert_raise(ActiveRecord::SubclassNotFound) { Firm.find(foo.id) }
|
358
466
|
|
359
|
-
|
360
|
-
|
361
|
-
|
467
|
+
# Nest FirmOnTheFly in Firm where Dependencies will see it.
|
468
|
+
# This is analogous to nesting models in a migration.
|
469
|
+
Firm.const_set :FirmOnTheFly, Class.new(Firm)
|
362
470
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
ActiveRecord::Base.store_full_sti_class = true
|
471
|
+
# And instantiate will find the existing constant rather than trying
|
472
|
+
# to require firm_on_the_fly.
|
473
|
+
assert_nothing_raised { assert_kind_of Firm::FirmOnTheFly, Firm.find(foo.id) }
|
474
|
+
end
|
368
475
|
end
|
369
476
|
|
370
477
|
def test_sti_type_from_attributes_disabled_in_non_sti_class
|
@@ -372,4 +479,128 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase
|
|
372
479
|
product = Shop::Product.new(:type => phone)
|
373
480
|
assert product.save
|
374
481
|
end
|
482
|
+
|
483
|
+
def test_inheritance_new_with_subclass_as_default
|
484
|
+
original_type = Company.columns_hash["type"].default
|
485
|
+
ActiveRecord::Base.connection.change_column_default :companies, :type, 'Firm'
|
486
|
+
Company.reset_column_information
|
487
|
+
|
488
|
+
firm = Company.new # without arguments
|
489
|
+
assert_equal 'Firm', firm.type
|
490
|
+
assert_instance_of Firm, firm
|
491
|
+
|
492
|
+
firm = Company.new(firm_name: 'Shri Hans Plastic') # with arguments
|
493
|
+
assert_equal 'Firm', firm.type
|
494
|
+
assert_instance_of Firm, firm
|
495
|
+
|
496
|
+
client = Client.new
|
497
|
+
assert_equal 'Client', client.type
|
498
|
+
assert_instance_of Client, client
|
499
|
+
|
500
|
+
firm = Company.new(type: 'Client') # overwrite the default type
|
501
|
+
assert_equal 'Client', firm.type
|
502
|
+
assert_instance_of Client, firm
|
503
|
+
ensure
|
504
|
+
ActiveRecord::Base.connection.change_column_default :companies, :type, original_type
|
505
|
+
Company.reset_column_information
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
class InheritanceAttributeTest < ActiveRecord::TestCase
|
510
|
+
|
511
|
+
class Company < ActiveRecord::Base
|
512
|
+
self.table_name = 'companies'
|
513
|
+
attribute :type, :string, default: "InheritanceAttributeTest::Startup"
|
514
|
+
end
|
515
|
+
|
516
|
+
class Startup < Company
|
517
|
+
end
|
518
|
+
|
519
|
+
class Empire < Company
|
520
|
+
end
|
521
|
+
|
522
|
+
def test_inheritance_new_with_subclass_as_default
|
523
|
+
startup = Company.new # without arguments
|
524
|
+
assert_equal 'InheritanceAttributeTest::Startup', startup.type
|
525
|
+
assert_instance_of Startup, startup
|
526
|
+
|
527
|
+
empire = Company.new(type: 'InheritanceAttributeTest::Empire') # without arguments
|
528
|
+
assert_equal 'InheritanceAttributeTest::Empire', empire.type
|
529
|
+
assert_instance_of Empire, empire
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
class InheritanceAttributeMappingTest < ActiveRecord::TestCase
|
534
|
+
setup do
|
535
|
+
@old_registry = ActiveRecord::Type.registry
|
536
|
+
ActiveRecord::Type.registry = ActiveRecord::Type::AdapterSpecificRegistry.new
|
537
|
+
ActiveRecord::Type.register :omg_sti, InheritanceAttributeMappingTest::OmgStiType
|
538
|
+
Company.delete_all
|
539
|
+
Sponsor.delete_all
|
540
|
+
end
|
541
|
+
|
542
|
+
teardown do
|
543
|
+
ActiveRecord::Type.registry = @old_registry
|
544
|
+
end
|
545
|
+
|
546
|
+
class OmgStiType < ActiveRecord::Type::String
|
547
|
+
def cast_value(value)
|
548
|
+
if value =~ /\Aomg_(.+)\z/
|
549
|
+
$1.classify
|
550
|
+
else
|
551
|
+
value
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
def serialize(value)
|
556
|
+
if value
|
557
|
+
"omg_%s" % value.underscore
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
class Company < ActiveRecord::Base
|
563
|
+
self.table_name = 'companies'
|
564
|
+
attribute :type, :omg_sti
|
565
|
+
end
|
566
|
+
|
567
|
+
class Startup < Company; end
|
568
|
+
class Empire < Company; end
|
569
|
+
|
570
|
+
class Sponsor < ActiveRecord::Base
|
571
|
+
self.table_name = 'sponsors'
|
572
|
+
attribute :sponsorable_type, :omg_sti
|
573
|
+
|
574
|
+
belongs_to :sponsorable, polymorphic: true
|
575
|
+
end
|
576
|
+
|
577
|
+
def test_sti_with_custom_type
|
578
|
+
Startup.create! name: 'a Startup'
|
579
|
+
Empire.create! name: 'an Empire'
|
580
|
+
|
581
|
+
assert_equal [["a Startup", "omg_inheritance_attribute_mapping_test/startup"],
|
582
|
+
["an Empire", "omg_inheritance_attribute_mapping_test/empire"]], ActiveRecord::Base.connection.select_rows('SELECT name, type FROM companies').sort
|
583
|
+
assert_equal [["a Startup", "InheritanceAttributeMappingTest::Startup"],
|
584
|
+
["an Empire", "InheritanceAttributeMappingTest::Empire"]], Company.all.map { |a| [a.name, a.type] }.sort
|
585
|
+
|
586
|
+
startup = Startup.first
|
587
|
+
startup.becomes! Empire
|
588
|
+
startup.save!
|
589
|
+
|
590
|
+
assert_equal [["a Startup", "omg_inheritance_attribute_mapping_test/empire"],
|
591
|
+
["an Empire", "omg_inheritance_attribute_mapping_test/empire"]], ActiveRecord::Base.connection.select_rows('SELECT name, type FROM companies').sort
|
592
|
+
|
593
|
+
assert_equal [["a Startup", "InheritanceAttributeMappingTest::Empire"],
|
594
|
+
["an Empire", "InheritanceAttributeMappingTest::Empire"]], Company.all.map { |a| [a.name, a.type] }.sort
|
595
|
+
end
|
596
|
+
|
597
|
+
def test_polymorphic_associations_custom_type
|
598
|
+
startup = Startup.create! name: 'a Startup'
|
599
|
+
sponsor = Sponsor.create! sponsorable: startup
|
600
|
+
|
601
|
+
assert_equal ["omg_inheritance_attribute_mapping_test/company"], ActiveRecord::Base.connection.select_values('SELECT sponsorable_type FROM sponsors')
|
602
|
+
|
603
|
+
sponsor = Sponsor.first
|
604
|
+
assert_equal startup, sponsor.sponsorable
|
605
|
+
end
|
375
606
|
end
|