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
@@ -0,0 +1,88 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/post'
|
3
|
+
require 'models/comment'
|
4
|
+
require 'models/author'
|
5
|
+
require 'models/essay'
|
6
|
+
require 'models/categorization'
|
7
|
+
require 'models/person'
|
8
|
+
|
9
|
+
class LeftOuterJoinAssociationTest < ActiveRecord::TestCase
|
10
|
+
fixtures :authors, :essays, :posts, :comments, :categorizations, :people
|
11
|
+
|
12
|
+
def test_construct_finder_sql_applies_aliases_tables_on_association_conditions
|
13
|
+
result = Author.left_outer_joins(:thinking_posts, :welcome_posts).to_a
|
14
|
+
assert_equal authors(:david), result.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_construct_finder_sql_does_not_table_name_collide_on_duplicate_associations
|
18
|
+
assert_nothing_raised do
|
19
|
+
queries = capture_sql do
|
20
|
+
Person.left_outer_joins(:agents => {:agents => :agents})
|
21
|
+
.left_outer_joins(:agents => {:agents => {:primary_contact => :agents}}).to_a
|
22
|
+
end
|
23
|
+
assert queries.any? { |sql| /agents_people_4/i =~ sql }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_left_outer_joins_count_is_same_as_size_of_loaded_results
|
28
|
+
assert_equal 17, Post.left_outer_joins(:comments).to_a.size
|
29
|
+
assert_equal 17, Post.left_outer_joins(:comments).count
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_left_joins_aliases_left_outer_joins
|
33
|
+
assert_equal Post.left_outer_joins(:comments).to_sql, Post.left_joins(:comments).to_sql
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_left_outer_joins_return_has_value_for_every_comment
|
37
|
+
all_post_ids = Post.pluck(:id)
|
38
|
+
assert_equal all_post_ids, all_post_ids & Post.left_outer_joins(:comments).pluck(:id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_left_outer_joins_actually_does_a_left_outer_join
|
42
|
+
queries = capture_sql { Author.left_outer_joins(:posts).to_a }
|
43
|
+
assert queries.any? { |sql| /LEFT OUTER JOIN/i =~ sql }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_construct_finder_sql_ignores_empty_left_outer_joins_hash
|
47
|
+
queries = capture_sql { Author.left_outer_joins({}).to_a }
|
48
|
+
assert queries.none? { |sql| /LEFT OUTER JOIN/i =~ sql }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_construct_finder_sql_ignores_empty_left_outer_joins_array
|
52
|
+
queries = capture_sql { Author.left_outer_joins([]).to_a }
|
53
|
+
assert queries.none? { |sql| /LEFT OUTER JOIN/i =~ sql }
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_left_outer_joins_forbids_to_use_string_as_argument
|
57
|
+
assert_raise(ArgumentError){ Author.left_outer_joins('LEFT OUTER JOIN "posts" ON "posts"."user_id" = "users"."id"').to_a }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_join_conditions_added_to_join_clause
|
61
|
+
queries = capture_sql { Author.left_outer_joins(:essays).to_a }
|
62
|
+
assert queries.any? { |sql| /writer_type.*?=.*?(Author|\?|\$1)/i =~ sql }
|
63
|
+
assert queries.none? { |sql| /WHERE/i =~ sql }
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_find_with_sti_join
|
67
|
+
scope = Post.left_outer_joins(:special_comments).where(:id => posts(:sti_comments).id)
|
68
|
+
|
69
|
+
# The join should match SpecialComment and its subclasses only
|
70
|
+
assert scope.where("comments.type" => "Comment").empty?
|
71
|
+
assert !scope.where("comments.type" => "SpecialComment").empty?
|
72
|
+
assert !scope.where("comments.type" => "SubSpecialComment").empty?
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_does_not_override_select
|
76
|
+
authors = Author.select("authors.name, #{%{(authors.author_address_id || ' ' || authors.author_address_extra_id) as addr_id}}").left_outer_joins(:posts)
|
77
|
+
assert authors.any?
|
78
|
+
assert authors.first.respond_to?(:addr_id)
|
79
|
+
end
|
80
|
+
|
81
|
+
test "the default scope of the target is applied when joining associations" do
|
82
|
+
author = Author.create! name: "Jon"
|
83
|
+
author.categorizations.create!
|
84
|
+
author.categorizations.create! special: true
|
85
|
+
|
86
|
+
assert_equal [author], Author.where(id: author).left_outer_joins(:special_categorizations)
|
87
|
+
end
|
88
|
+
end
|
@@ -27,7 +27,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase
|
|
27
27
|
fixtures :authors, :books, :posts, :subscriptions, :subscribers, :tags, :taggings,
|
28
28
|
:people, :readers, :references, :jobs, :ratings, :comments, :members, :member_details,
|
29
29
|
:member_types, :sponsors, :clubs, :organizations, :categories, :categories_posts,
|
30
|
-
:categorizations, :memberships, :essays
|
30
|
+
:categorizations, :memberships, :essays
|
31
31
|
|
32
32
|
# Through associations can either use the has_many or has_one macros.
|
33
33
|
#
|
@@ -495,7 +495,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase
|
|
495
495
|
groucho = members(:groucho)
|
496
496
|
founding = member_types(:founding)
|
497
497
|
|
498
|
-
assert_raises(ActiveRecord::
|
498
|
+
assert_raises(ActiveRecord::HasOneThroughNestedAssociationsAreReadonly) do
|
499
499
|
groucho.nested_member_type = founding
|
500
500
|
end
|
501
501
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require "cases/helper"
|
2
2
|
|
3
3
|
class RequiredAssociationsTest < ActiveRecord::TestCase
|
4
|
-
self.
|
4
|
+
self.use_transactional_tests = false
|
5
5
|
|
6
6
|
class Parent < ActiveRecord::Base
|
7
7
|
end
|
@@ -18,8 +18,8 @@ class RequiredAssociationsTest < ActiveRecord::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
teardown do
|
21
|
-
@connection.drop_table 'parents'
|
22
|
-
@connection.drop_table 'children'
|
21
|
+
@connection.drop_table 'parents', if_exists: true
|
22
|
+
@connection.drop_table 'children', if_exists: true
|
23
23
|
end
|
24
24
|
|
25
25
|
test "belongs_to associations are not required by default" do
|
@@ -40,7 +40,7 @@ class RequiredAssociationsTest < ActiveRecord::TestCase
|
|
40
40
|
|
41
41
|
record = model.new
|
42
42
|
assert_not record.save
|
43
|
-
assert_equal ["Parent
|
43
|
+
assert_equal ["Parent must exist"], record.errors.full_messages
|
44
44
|
|
45
45
|
record.parent = Parent.new
|
46
46
|
assert record.save
|
@@ -64,12 +64,32 @@ class RequiredAssociationsTest < ActiveRecord::TestCase
|
|
64
64
|
|
65
65
|
record = model.new
|
66
66
|
assert_not record.save
|
67
|
-
assert_equal ["Child
|
67
|
+
assert_equal ["Child must exist"], record.errors.full_messages
|
68
68
|
|
69
69
|
record.child = Child.new
|
70
70
|
assert record.save
|
71
71
|
end
|
72
72
|
|
73
|
+
test "required has_one associations have a correct error message" do
|
74
|
+
model = subclass_of(Parent) do
|
75
|
+
has_one :child, required: true, inverse_of: false,
|
76
|
+
class_name: "RequiredAssociationsTest::Child"
|
77
|
+
end
|
78
|
+
|
79
|
+
record = model.create
|
80
|
+
assert_equal ["Child must exist"], record.errors.full_messages
|
81
|
+
end
|
82
|
+
|
83
|
+
test "required belongs_to associations have a correct error message" do
|
84
|
+
model = subclass_of(Child) do
|
85
|
+
belongs_to :parent, required: true, inverse_of: false,
|
86
|
+
class_name: "RequiredAssociationsTest::Parent"
|
87
|
+
end
|
88
|
+
|
89
|
+
record = model.create
|
90
|
+
assert_equal ["Parent must exist"], record.errors.full_messages
|
91
|
+
end
|
92
|
+
|
73
93
|
private
|
74
94
|
|
75
95
|
def subclass_of(klass, &block)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "cases/helper"
|
2
2
|
require 'models/computer'
|
3
3
|
require 'models/developer'
|
4
|
-
require 'models/computer'
|
5
4
|
require 'models/project'
|
6
5
|
require 'models/company'
|
7
6
|
require 'models/categorization'
|
@@ -13,7 +12,6 @@ require 'models/tag'
|
|
13
12
|
require 'models/tagging'
|
14
13
|
require 'models/person'
|
15
14
|
require 'models/reader'
|
16
|
-
require 'models/parrot'
|
17
15
|
require 'models/ship_part'
|
18
16
|
require 'models/ship'
|
19
17
|
require 'models/liquid'
|
@@ -24,7 +22,7 @@ require 'models/interest'
|
|
24
22
|
|
25
23
|
class AssociationsTest < ActiveRecord::TestCase
|
26
24
|
fixtures :accounts, :companies, :developers, :projects, :developers_projects,
|
27
|
-
:computers, :people, :readers, :authors, :author_favorites
|
25
|
+
:computers, :people, :readers, :authors, :author_favorites
|
28
26
|
|
29
27
|
def test_eager_loading_should_not_change_count_of_children
|
30
28
|
liquid = Liquid.create(:name => 'salty')
|
@@ -43,28 +41,6 @@ class AssociationsTest < ActiveRecord::TestCase
|
|
43
41
|
assert_equal favs, fav2
|
44
42
|
end
|
45
43
|
|
46
|
-
def test_clear_association_cache_stored
|
47
|
-
firm = Firm.find(1)
|
48
|
-
assert_kind_of Firm, firm
|
49
|
-
|
50
|
-
firm.clear_association_cache
|
51
|
-
assert_equal Firm.find(1).clients.collect{ |x| x.name }.sort, firm.clients.collect{ |x| x.name }.sort
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_clear_association_cache_new_record
|
55
|
-
firm = Firm.new
|
56
|
-
client_stored = Client.find(3)
|
57
|
-
client_new = Client.new
|
58
|
-
client_new.name = "The Joneses"
|
59
|
-
clients = [ client_stored, client_new ]
|
60
|
-
|
61
|
-
firm.clients << clients
|
62
|
-
assert_equal clients.map(&:name).to_set, firm.clients.map(&:name).to_set
|
63
|
-
|
64
|
-
firm.clear_association_cache
|
65
|
-
assert_equal clients.map(&:name).to_set, firm.clients.map(&:name).to_set
|
66
|
-
end
|
67
|
-
|
68
44
|
def test_loading_the_association_target_should_keep_child_records_marked_for_destruction
|
69
45
|
ship = Ship.create!(:name => "The good ship Dollypop")
|
70
46
|
part = ship.parts.create!(:name => "Mast")
|
@@ -115,8 +91,10 @@ class AssociationsTest < ActiveRecord::TestCase
|
|
115
91
|
assert firm.clients.empty?, "New firm should have cached no client objects"
|
116
92
|
assert_equal 0, firm.clients.size, "New firm should have cached 0 clients count"
|
117
93
|
|
118
|
-
|
119
|
-
|
94
|
+
ActiveSupport::Deprecation.silence do
|
95
|
+
assert !firm.clients(true).empty?, "New firm should have reloaded client objects"
|
96
|
+
assert_equal 1, firm.clients(true).size, "New firm should have reloaded clients count"
|
97
|
+
end
|
120
98
|
end
|
121
99
|
|
122
100
|
def test_using_limitable_reflections_helper
|
@@ -132,16 +110,19 @@ class AssociationsTest < ActiveRecord::TestCase
|
|
132
110
|
def test_force_reload_is_uncached
|
133
111
|
firm = Firm.create!("name" => "A New Firm, Inc")
|
134
112
|
Client.create!("name" => "TheClient.com", :firm => firm)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
113
|
+
|
114
|
+
ActiveSupport::Deprecation.silence do
|
115
|
+
ActiveRecord::Base.cache do
|
116
|
+
firm.clients.each {}
|
117
|
+
assert_queries(0) { assert_not_nil firm.clients.each {} }
|
118
|
+
assert_queries(1) { assert_not_nil firm.clients(true).each {} }
|
119
|
+
end
|
139
120
|
end
|
140
121
|
end
|
141
122
|
|
142
123
|
def test_association_with_references
|
143
124
|
firm = companies(:first_firm)
|
144
|
-
|
125
|
+
assert_includes firm.association_with_references.references_values, 'foo'
|
145
126
|
end
|
146
127
|
|
147
128
|
end
|
@@ -202,6 +183,14 @@ class AssociationProxyTest < ActiveRecord::TestCase
|
|
202
183
|
assert !david.projects.loaded?
|
203
184
|
end
|
204
185
|
|
186
|
+
def test_load_does_load_target
|
187
|
+
david = developers(:david)
|
188
|
+
|
189
|
+
assert !david.projects.loaded?
|
190
|
+
david.projects.load
|
191
|
+
assert david.projects.loaded?
|
192
|
+
end
|
193
|
+
|
205
194
|
def test_inspect_does_not_reload_a_not_yet_loaded_target
|
206
195
|
andreas = Developer.new :name => 'Andreas', :log => 'new developer added'
|
207
196
|
assert !andreas.audit_logs.loaded?
|
@@ -238,7 +227,7 @@ class AssociationProxyTest < ActiveRecord::TestCase
|
|
238
227
|
end
|
239
228
|
|
240
229
|
def test_scoped_allows_conditions
|
241
|
-
assert developers(:david).projects.merge
|
230
|
+
assert developers(:david).projects.merge(where: 'foo').to_sql.include?('foo')
|
242
231
|
end
|
243
232
|
|
244
233
|
test "getting a scope from an association" do
|
@@ -250,7 +239,14 @@ class AssociationProxyTest < ActiveRecord::TestCase
|
|
250
239
|
|
251
240
|
test "proxy object is cached" do
|
252
241
|
david = developers(:david)
|
253
|
-
|
242
|
+
assert_same david.projects, david.projects
|
243
|
+
end
|
244
|
+
|
245
|
+
test "proxy object can be stubbed" do
|
246
|
+
david = developers(:david)
|
247
|
+
david.projects.define_singleton_method(:extra_method) { 42 }
|
248
|
+
|
249
|
+
assert_equal 42, david.projects.extra_method
|
254
250
|
end
|
255
251
|
|
256
252
|
test "inverses get set of subsets of the association" do
|
@@ -267,6 +263,15 @@ class AssociationProxyTest < ActiveRecord::TestCase
|
|
267
263
|
test "first! works on loaded associations" do
|
268
264
|
david = authors(:david)
|
269
265
|
assert_equal david.posts.first, david.posts.reload.first!
|
266
|
+
assert david.posts.loaded?
|
267
|
+
assert_no_queries { david.posts.first! }
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_pluck_uses_loaded_target
|
271
|
+
david = authors(:david)
|
272
|
+
assert_equal david.posts.pluck(:title), david.posts.load.pluck(:title)
|
273
|
+
assert david.posts.loaded?
|
274
|
+
assert_no_queries { david.posts.pluck(:title) }
|
270
275
|
end
|
271
276
|
|
272
277
|
def test_reset_unloads_target
|
@@ -12,11 +12,11 @@ module ActiveRecord
|
|
12
12
|
super(delegate)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def cast(value)
|
16
16
|
"#{super} #{@decoration}"
|
17
17
|
end
|
18
18
|
|
19
|
-
alias
|
19
|
+
alias deserialize cast
|
20
20
|
end
|
21
21
|
|
22
22
|
setup do
|
@@ -28,7 +28,8 @@ module ActiveRecord
|
|
28
28
|
|
29
29
|
teardown do
|
30
30
|
return unless @connection
|
31
|
-
@connection.drop_table 'attribute_decorators_model'
|
31
|
+
@connection.drop_table 'attribute_decorators_model'
|
32
|
+
#, if_exists: true
|
32
33
|
Model.attribute_type_decorations.clear
|
33
34
|
Model.reset_column_information
|
34
35
|
end
|
@@ -51,7 +52,7 @@ module ActiveRecord
|
|
51
52
|
end
|
52
53
|
|
53
54
|
test "undecorated columns are not touched" do
|
54
|
-
Model.attribute :another_string,
|
55
|
+
Model.attribute :another_string, :string, default: 'something or other'
|
55
56
|
Model.decorate_attribute_type(:a_string, :test) { |t| StringDecorator.new(t) }
|
56
57
|
|
57
58
|
assert_equal 'something or other', Model.new.another_string
|
@@ -86,7 +87,7 @@ module ActiveRecord
|
|
86
87
|
end
|
87
88
|
|
88
89
|
test "decorating attributes does not modify parent classes" do
|
89
|
-
Model.attribute :another_string,
|
90
|
+
Model.attribute :another_string, :string, default: 'whatever'
|
90
91
|
Model.decorate_attribute_type(:a_string, :test) { |t| StringDecorator.new(t) }
|
91
92
|
child_class = Class.new(Model)
|
92
93
|
child_class.decorate_attribute_type(:another_string, :test) { |t| StringDecorator.new(t) }
|
@@ -102,15 +103,15 @@ module ActiveRecord
|
|
102
103
|
end
|
103
104
|
|
104
105
|
class Multiplier < SimpleDelegator
|
105
|
-
def
|
106
|
+
def cast(value)
|
106
107
|
return if value.nil?
|
107
108
|
value * 2
|
108
109
|
end
|
109
|
-
alias
|
110
|
+
alias deserialize cast
|
110
111
|
end
|
111
112
|
|
112
113
|
test "decorating with a proc" do
|
113
|
-
Model.attribute :an_int,
|
114
|
+
Model.attribute :an_int, :integer
|
114
115
|
type_is_integer = proc { |_, type| type.type == :integer }
|
115
116
|
Model.decorate_matching_attribute_types type_is_integer, :multiplier do |type|
|
116
117
|
Multiplier.new(type)
|
@@ -17,7 +17,7 @@ module ActiveRecord
|
|
17
17
|
|
18
18
|
include ActiveRecord::AttributeMethods
|
19
19
|
|
20
|
-
def self.
|
20
|
+
def self.attribute_names
|
21
21
|
%w{ one two three }
|
22
22
|
end
|
23
23
|
|
@@ -25,11 +25,11 @@ module ActiveRecord
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.columns
|
28
|
-
|
28
|
+
attribute_names.map { FakeColumn.new(name) }
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.columns_hash
|
32
|
-
Hash[
|
32
|
+
Hash[attribute_names.map { |name|
|
33
33
|
[name, FakeColumn.new(name)]
|
34
34
|
}]
|
35
35
|
end
|
@@ -39,13 +39,13 @@ module ActiveRecord
|
|
39
39
|
def test_define_attribute_methods
|
40
40
|
instance = @klass.new
|
41
41
|
|
42
|
-
@klass.
|
42
|
+
@klass.attribute_names.each do |name|
|
43
43
|
assert !instance.methods.map(&:to_s).include?(name)
|
44
44
|
end
|
45
45
|
|
46
46
|
@klass.define_attribute_methods
|
47
47
|
|
48
|
-
@klass.
|
48
|
+
@klass.attribute_names.each do |name|
|
49
49
|
assert instance.methods.map(&:to_s).include?(name), "#{name} is not defined"
|
50
50
|
end
|
51
51
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require "cases/helper"
|
2
2
|
require 'models/minimalistic'
|
3
3
|
require 'models/developer'
|
4
|
-
require 'models/computer'
|
5
4
|
require 'models/auto_id'
|
6
5
|
require 'models/boolean'
|
7
6
|
require 'models/computer'
|
@@ -28,14 +27,33 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
28
27
|
ActiveRecord::Base.send(:attribute_method_matchers).concat(@old_matchers)
|
29
28
|
end
|
30
29
|
|
31
|
-
def
|
30
|
+
def test_attribute_for_inspect_string
|
32
31
|
t = topics(:first)
|
33
32
|
t.title = "The First Topic Now Has A Title With\nNewlines And More Than 50 Characters"
|
34
33
|
|
35
|
-
assert_equal %("#{t.written_on.to_s(:db)}"), t.attribute_for_inspect(:written_on)
|
36
34
|
assert_equal '"The First Topic Now Has A Title With\nNewlines And ..."', t.attribute_for_inspect(:title)
|
37
35
|
end
|
38
36
|
|
37
|
+
def test_attribute_for_inspect_date
|
38
|
+
t = topics(:first)
|
39
|
+
|
40
|
+
assert_equal %("#{t.written_on.to_s(:db)}"), t.attribute_for_inspect(:written_on)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_attribute_for_inspect_array
|
44
|
+
t = topics(:first)
|
45
|
+
t.content = [Object.new]
|
46
|
+
|
47
|
+
assert_match %r(\[#<Object:0x[0-9a-f]+>\]), t.attribute_for_inspect(:content)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_attribute_for_inspect_long_array
|
51
|
+
t = topics(:first)
|
52
|
+
t.content = (1..11).to_a
|
53
|
+
|
54
|
+
assert_equal "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]", t.attribute_for_inspect(:content)
|
55
|
+
end
|
56
|
+
|
39
57
|
def test_attribute_present
|
40
58
|
t = Topic.new
|
41
59
|
t.title = "hello there!"
|
@@ -67,8 +85,9 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
67
85
|
|
68
86
|
def test_caching_nil_primary_key
|
69
87
|
klass = Class.new(Minimalistic)
|
70
|
-
klass
|
71
|
-
|
88
|
+
assert_called(klass, :reset_primary_key, returns: nil) do
|
89
|
+
2.times { klass.primary_key }
|
90
|
+
end
|
72
91
|
end
|
73
92
|
|
74
93
|
def test_attribute_keys_on_new_instance
|
@@ -175,9 +194,9 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
175
194
|
assert_equal category_attrs , category.attributes_before_type_cast
|
176
195
|
end
|
177
196
|
|
178
|
-
if current_adapter?(:
|
197
|
+
if current_adapter?(:Mysql2Adapter)
|
179
198
|
def test_read_attributes_before_type_cast_on_boolean
|
180
|
-
bool = Boolean.create({ "value" => false })
|
199
|
+
bool = Boolean.create!({ "value" => false })
|
181
200
|
if RUBY_PLATFORM =~ /java/
|
182
201
|
# JRuby will return the value before typecast as string
|
183
202
|
assert_equal "0", bool.reload.attributes_before_type_cast["value"]
|
@@ -253,7 +272,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
253
272
|
|
254
273
|
def test_case_sensitive_attributes_hash
|
255
274
|
# DB2 is not case-sensitive
|
256
|
-
return true if current_adapter?(:DB2Adapter)
|
275
|
+
return true if current_adapter?(:DB2Adapter)
|
257
276
|
|
258
277
|
assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.first.attributes
|
259
278
|
end
|
@@ -502,7 +521,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
502
521
|
def test_typecast_attribute_from_select_to_false
|
503
522
|
Topic.create(:title => 'Budget')
|
504
523
|
# Oracle does not support boolean expressions in SELECT
|
505
|
-
if current_adapter?(:OracleAdapter
|
524
|
+
if current_adapter?(:OracleAdapter, :FbAdapter)
|
506
525
|
topic = Topic.all.merge!(:select => "topics.*, 0 as is_test").first
|
507
526
|
else
|
508
527
|
topic = Topic.all.merge!(:select => "topics.*, 1=2 as is_test").first
|
@@ -513,7 +532,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
513
532
|
def test_typecast_attribute_from_select_to_true
|
514
533
|
Topic.create(:title => 'Budget')
|
515
534
|
# Oracle does not support boolean expressions in SELECT
|
516
|
-
if current_adapter?(:OracleAdapter
|
535
|
+
if current_adapter?(:OracleAdapter, :FbAdapter)
|
517
536
|
topic = Topic.all.merge!(:select => "topics.*, 1 as is_test").first
|
518
537
|
else
|
519
538
|
topic = Topic.all.merge!(:select => "topics.*, 2=2 as is_test").first
|
@@ -531,20 +550,6 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
531
550
|
end
|
532
551
|
end
|
533
552
|
|
534
|
-
def test_deprecated_cache_attributes
|
535
|
-
assert_deprecated do
|
536
|
-
Topic.cache_attributes :replies_count
|
537
|
-
end
|
538
|
-
|
539
|
-
assert_deprecated do
|
540
|
-
Topic.cached_attributes
|
541
|
-
end
|
542
|
-
|
543
|
-
assert_deprecated do
|
544
|
-
Topic.cache_attribute? :replies_count
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
553
|
def test_converted_values_are_returned_after_assignment
|
549
554
|
developer = Developer.new(name: 1337, salary: "50000")
|
550
555
|
|
@@ -556,9 +561,6 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
556
561
|
|
557
562
|
developer.save!
|
558
563
|
|
559
|
-
assert_equal "50000", developer.salary_before_type_cast
|
560
|
-
assert_equal 1337, developer.name_before_type_cast
|
561
|
-
|
562
564
|
assert_equal 50000, developer.salary
|
563
565
|
assert_equal "1337", developer.name
|
564
566
|
end
|
@@ -671,7 +673,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
671
673
|
end
|
672
674
|
end
|
673
675
|
|
674
|
-
def
|
676
|
+
def test_setting_time_zone_aware_datetime_in_current_time_zone
|
675
677
|
utc_time = Time.utc(2008, 1, 1)
|
676
678
|
in_time_zone "Pacific Time (US & Canada)" do
|
677
679
|
record = @target.new
|
@@ -690,6 +692,54 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
690
692
|
end
|
691
693
|
end
|
692
694
|
|
695
|
+
def test_setting_time_zone_aware_time_in_current_time_zone
|
696
|
+
in_time_zone "Pacific Time (US & Canada)" do
|
697
|
+
record = @target.new
|
698
|
+
time_string = "10:00:00"
|
699
|
+
expected_time = Time.zone.parse("2000-01-01 #{time_string}")
|
700
|
+
|
701
|
+
record.bonus_time = time_string
|
702
|
+
assert_equal expected_time, record.bonus_time
|
703
|
+
assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.bonus_time.time_zone
|
704
|
+
|
705
|
+
record.bonus_time = ''
|
706
|
+
assert_nil record.bonus_time
|
707
|
+
end
|
708
|
+
end
|
709
|
+
|
710
|
+
def test_setting_time_zone_aware_time_with_dst
|
711
|
+
in_time_zone "Pacific Time (US & Canada)" do
|
712
|
+
current_time = Time.zone.local(2014, 06, 15, 10)
|
713
|
+
record = @target.new(bonus_time: current_time)
|
714
|
+
time_before_save = record.bonus_time
|
715
|
+
|
716
|
+
record.save
|
717
|
+
record.reload
|
718
|
+
|
719
|
+
assert_equal time_before_save, record.bonus_time
|
720
|
+
assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.bonus_time.time_zone
|
721
|
+
end
|
722
|
+
end
|
723
|
+
|
724
|
+
def test_removing_time_zone_aware_types
|
725
|
+
with_time_zone_aware_types(:datetime) do
|
726
|
+
in_time_zone "Pacific Time (US & Canada)" do
|
727
|
+
record = @target.new(bonus_time: "10:00:00")
|
728
|
+
expected_time = Time.utc(2000, 01, 01, 10)
|
729
|
+
|
730
|
+
assert_equal expected_time, record.bonus_time
|
731
|
+
assert record.bonus_time.utc?
|
732
|
+
end
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
def test_time_zone_aware_attributes_dont_recurse_infinitely_on_invalid_values
|
737
|
+
in_time_zone "Pacific Time (US & Canada)" do
|
738
|
+
record = @target.new(bonus_time: [])
|
739
|
+
assert_equal nil, record.bonus_time
|
740
|
+
end
|
741
|
+
end
|
742
|
+
|
693
743
|
def test_setting_time_zone_conversion_for_attributes_should_write_value_on_class_variable
|
694
744
|
Topic.skip_time_zone_conversion_for_attributes = [:field_a]
|
695
745
|
Minimalistic.skip_time_zone_conversion_for_attributes = [:field_b]
|
@@ -744,17 +794,6 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
744
794
|
assert_equal "unknown attribute 'hello' for Topic.", error.message
|
745
795
|
end
|
746
796
|
|
747
|
-
# This test is related to a bug in Ruby 2.2.1.
|
748
|
-
# It can be safely removed once that bug is fixed.
|
749
|
-
#
|
750
|
-
# xref: https://bugs.ruby-lang.org/issues/10969
|
751
|
-
def test_bulk_does_not_raise_name_error
|
752
|
-
nope rescue nil # necessary to trigger the bug
|
753
|
-
assert_raises(ActiveRecord::UnknownAttributeError) {
|
754
|
-
Topic.new(hello: "world")
|
755
|
-
}
|
756
|
-
end
|
757
|
-
|
758
797
|
def test_methods_override_in_multi_level_subclass
|
759
798
|
klass = Class.new(Developer) do
|
760
799
|
def name
|
@@ -778,7 +817,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
778
817
|
assert_nil computer.system
|
779
818
|
end
|
780
819
|
|
781
|
-
def
|
820
|
+
def test_global_methods_are_overwritten_when_subclassing
|
782
821
|
klass = Class.new(ActiveRecord::Base) { self.abstract_class = true }
|
783
822
|
|
784
823
|
subklass = Class.new(klass) do
|
@@ -921,6 +960,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
921
960
|
assert model.id_came_from_user?
|
922
961
|
end
|
923
962
|
|
963
|
+
def test_accessed_fields
|
964
|
+
model = @target.first
|
965
|
+
|
966
|
+
assert_equal [], model.accessed_fields
|
967
|
+
|
968
|
+
model.title
|
969
|
+
|
970
|
+
assert_equal ["title"], model.accessed_fields
|
971
|
+
end
|
972
|
+
|
924
973
|
private
|
925
974
|
|
926
975
|
def new_topic_like_ar_class(&block)
|
@@ -933,6 +982,14 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
933
982
|
klass
|
934
983
|
end
|
935
984
|
|
985
|
+
def with_time_zone_aware_types(*types)
|
986
|
+
old_types = ActiveRecord::Base.time_zone_aware_types
|
987
|
+
ActiveRecord::Base.time_zone_aware_types = types
|
988
|
+
yield
|
989
|
+
ensure
|
990
|
+
ActiveRecord::Base.time_zone_aware_types = old_types
|
991
|
+
end
|
992
|
+
|
936
993
|
def cached_columns
|
937
994
|
Topic.columns.map(&:name)
|
938
995
|
end
|