ibm_db 3.0.5-x86-mingw32 → 5.0.5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/test/cases/relation_test.rb
CHANGED
@@ -6,7 +6,7 @@ require 'models/rating'
|
|
6
6
|
|
7
7
|
module ActiveRecord
|
8
8
|
class RelationTest < ActiveRecord::TestCase
|
9
|
-
fixtures :posts, :comments, :authors
|
9
|
+
fixtures :posts, :comments, :authors
|
10
10
|
|
11
11
|
class FakeKlass < Struct.new(:table_name, :name)
|
12
12
|
extend ActiveRecord::Delegation::DelegateCache
|
@@ -20,62 +20,67 @@ module ActiveRecord
|
|
20
20
|
def self.table_name
|
21
21
|
'fake_table'
|
22
22
|
end
|
23
|
+
|
24
|
+
def self.sanitize_sql_for_order(sql)
|
25
|
+
sql
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
def test_construction
|
26
|
-
relation = Relation.new
|
30
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
27
31
|
assert_equal FakeKlass, relation.klass
|
28
32
|
assert_equal :b, relation.table
|
29
33
|
assert !relation.loaded, 'relation is not loaded'
|
30
34
|
end
|
31
35
|
|
32
36
|
def test_responds_to_model_and_returns_klass
|
33
|
-
relation = Relation.new
|
37
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
34
38
|
assert_equal FakeKlass, relation.model
|
35
39
|
end
|
36
40
|
|
37
41
|
def test_initialize_single_values
|
38
|
-
relation = Relation.new
|
42
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
39
43
|
(Relation::SINGLE_VALUE_METHODS - [:create_with]).each do |method|
|
40
44
|
assert_nil relation.send("#{method}_value"), method.to_s
|
41
45
|
end
|
42
|
-
|
46
|
+
value = relation.create_with_value
|
47
|
+
assert_equal({}, value)
|
48
|
+
assert_predicate value, :frozen?
|
43
49
|
end
|
44
50
|
|
45
51
|
def test_multi_value_initialize
|
46
|
-
relation = Relation.new
|
52
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
47
53
|
Relation::MULTI_VALUE_METHODS.each do |method|
|
48
|
-
|
54
|
+
values = relation.send("#{method}_values")
|
55
|
+
assert_equal [], values, method.to_s
|
56
|
+
assert_predicate values, :frozen?, method.to_s
|
49
57
|
end
|
50
58
|
end
|
51
59
|
|
52
60
|
def test_extensions
|
53
|
-
relation = Relation.new
|
61
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
54
62
|
assert_equal [], relation.extensions
|
55
63
|
end
|
56
64
|
|
57
65
|
def test_empty_where_values_hash
|
58
|
-
relation = Relation.new
|
59
|
-
assert_equal({}, relation.where_values_hash)
|
60
|
-
|
61
|
-
relation.where! :hello
|
66
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
62
67
|
assert_equal({}, relation.where_values_hash)
|
63
68
|
end
|
64
69
|
|
65
70
|
def test_has_values
|
66
|
-
relation = Relation.new Post, Post.
|
71
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
67
72
|
relation.where! relation.table[:id].eq(10)
|
68
73
|
assert_equal({:id => 10}, relation.where_values_hash)
|
69
74
|
end
|
70
75
|
|
71
76
|
def test_values_wrong_table
|
72
|
-
relation = Relation.new Post, Post.
|
77
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
73
78
|
relation.where! Comment.arel_table[:id].eq(10)
|
74
79
|
assert_equal({}, relation.where_values_hash)
|
75
80
|
end
|
76
81
|
|
77
82
|
def test_tree_is_not_traversed
|
78
|
-
relation = Relation.new Post, Post.
|
83
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
79
84
|
left = relation.table[:id].eq(10)
|
80
85
|
right = relation.table[:id].eq(10)
|
81
86
|
combine = left.and right
|
@@ -84,24 +89,24 @@ module ActiveRecord
|
|
84
89
|
end
|
85
90
|
|
86
91
|
def test_table_name_delegates_to_klass
|
87
|
-
relation = Relation.new
|
92
|
+
relation = Relation.new(FakeKlass.new('posts'), :b, Post.predicate_builder)
|
88
93
|
assert_equal 'posts', relation.table_name
|
89
94
|
end
|
90
95
|
|
91
96
|
def test_scope_for_create
|
92
|
-
relation = Relation.new
|
97
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
93
98
|
assert_equal({}, relation.scope_for_create)
|
94
99
|
end
|
95
100
|
|
96
101
|
def test_create_with_value
|
97
|
-
relation = Relation.new Post, Post.
|
102
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
98
103
|
hash = { :hello => 'world' }
|
99
104
|
relation.create_with_value = hash
|
100
105
|
assert_equal hash, relation.scope_for_create
|
101
106
|
end
|
102
107
|
|
103
108
|
def test_create_with_value_with_wheres
|
104
|
-
relation = Relation.new Post, Post.
|
109
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
105
110
|
relation.where! relation.table[:id].eq(10)
|
106
111
|
relation.create_with_value = {:hello => 'world'}
|
107
112
|
assert_equal({:hello => 'world', :id => 10}, relation.scope_for_create)
|
@@ -109,7 +114,7 @@ module ActiveRecord
|
|
109
114
|
|
110
115
|
# FIXME: is this really wanted or expected behavior?
|
111
116
|
def test_scope_for_create_is_cached
|
112
|
-
relation = Relation.new Post, Post.
|
117
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
113
118
|
assert_equal({}, relation.scope_for_create)
|
114
119
|
|
115
120
|
relation.where! relation.table[:id].eq(10)
|
@@ -126,62 +131,72 @@ module ActiveRecord
|
|
126
131
|
end
|
127
132
|
|
128
133
|
def test_empty_eager_loading?
|
129
|
-
relation = Relation.new
|
134
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
130
135
|
assert !relation.eager_loading?
|
131
136
|
end
|
132
137
|
|
133
138
|
def test_eager_load_values
|
134
|
-
relation = Relation.new
|
139
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
135
140
|
relation.eager_load! :b
|
136
141
|
assert relation.eager_loading?
|
137
142
|
end
|
138
143
|
|
139
144
|
def test_references_values
|
140
|
-
relation = Relation.new
|
145
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
141
146
|
assert_equal [], relation.references_values
|
142
147
|
relation = relation.references(:foo).references(:omg, :lol)
|
143
148
|
assert_equal ['foo', 'omg', 'lol'], relation.references_values
|
144
149
|
end
|
145
150
|
|
146
151
|
def test_references_values_dont_duplicate
|
147
|
-
relation = Relation.new
|
152
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
148
153
|
relation = relation.references(:foo).references(:foo)
|
149
154
|
assert_equal ['foo'], relation.references_values
|
150
155
|
end
|
151
156
|
|
152
157
|
test 'merging a hash into a relation' do
|
153
|
-
relation = Relation.new
|
154
|
-
relation = relation.merge where: :lol, readonly: true
|
158
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
159
|
+
relation = relation.merge where: {name: :lol}, readonly: true
|
155
160
|
|
156
|
-
assert_equal
|
161
|
+
assert_equal({"name"=>:lol}, relation.where_clause.to_h)
|
157
162
|
assert_equal true, relation.readonly_value
|
158
163
|
end
|
159
164
|
|
160
165
|
test 'merging an empty hash into a relation' do
|
161
|
-
assert_equal
|
166
|
+
assert_equal Relation::WhereClause.empty, Relation.new(FakeKlass, :b, nil).merge({}).where_clause
|
162
167
|
end
|
163
168
|
|
164
169
|
test 'merging a hash with unknown keys raises' do
|
165
170
|
assert_raises(ArgumentError) { Relation::HashMerger.new(nil, omg: 'lol') }
|
166
171
|
end
|
167
172
|
|
173
|
+
test 'merging nil or false raises' do
|
174
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
175
|
+
|
176
|
+
e = assert_raises(ArgumentError) do
|
177
|
+
relation = relation.merge nil
|
178
|
+
end
|
179
|
+
|
180
|
+
assert_equal 'invalid argument: nil.', e.message
|
181
|
+
|
182
|
+
e = assert_raises(ArgumentError) do
|
183
|
+
relation = relation.merge false
|
184
|
+
end
|
185
|
+
|
186
|
+
assert_equal 'invalid argument: false.', e.message
|
187
|
+
end
|
188
|
+
|
168
189
|
test '#values returns a dup of the values' do
|
169
|
-
relation = Relation.new(
|
190
|
+
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder).where!(name: :foo)
|
170
191
|
values = relation.values
|
171
192
|
|
172
193
|
values[:where] = nil
|
173
|
-
assert_not_nil relation.
|
194
|
+
assert_not_nil relation.where_clause
|
174
195
|
end
|
175
196
|
|
176
197
|
test 'relations can be created with a values hash' do
|
177
|
-
relation = Relation.new(FakeKlass, :b,
|
178
|
-
assert_equal [:foo], relation.
|
179
|
-
end
|
180
|
-
|
181
|
-
test 'merging a single where value' do
|
182
|
-
relation = Relation.new(FakeKlass, :b)
|
183
|
-
relation.merge!(where: :foo)
|
184
|
-
assert_equal [:foo], relation.where_values
|
198
|
+
relation = Relation.new(FakeKlass, :b, nil, select: [:foo])
|
199
|
+
assert_equal [:foo], relation.select_values
|
185
200
|
end
|
186
201
|
|
187
202
|
test 'merging a hash interpolates conditions' do
|
@@ -192,13 +207,13 @@ module ActiveRecord
|
|
192
207
|
end
|
193
208
|
end
|
194
209
|
|
195
|
-
relation = Relation.new(klass, :b)
|
210
|
+
relation = Relation.new(klass, :b, nil)
|
196
211
|
relation.merge!(where: ['foo = ?', 'bar'])
|
197
|
-
assert_equal ['foo = bar'], relation.
|
212
|
+
assert_equal Relation::WhereClause.new(['foo = bar'], []), relation.where_clause
|
198
213
|
end
|
199
214
|
|
200
215
|
def test_merging_readonly_false
|
201
|
-
relation = Relation.new
|
216
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
202
217
|
readonly_false_relation = relation.readonly(false)
|
203
218
|
# test merging in both directions
|
204
219
|
assert_equal false, relation.merge(readonly_false_relation).readonly_value
|
@@ -208,13 +223,7 @@ module ActiveRecord
|
|
208
223
|
def test_relation_merging_with_merged_joins_as_symbols
|
209
224
|
special_comments_with_ratings = SpecialComment.joins(:ratings)
|
210
225
|
posts_with_special_comments_with_ratings = Post.group("posts.id").joins(:special_comments).merge(special_comments_with_ratings)
|
211
|
-
assert_equal 3, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_conflicting_bind_values
|
215
|
-
assert_nothing_raised do
|
216
|
-
CommentWithConflictingDefaultScope.joins(:post_with_conflicting_default_scope).delete_all
|
217
|
-
end
|
226
|
+
assert_equal({ 2=>1, 4=>3, 5=>1 }, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count)
|
218
227
|
end
|
219
228
|
|
220
229
|
def test_relation_merging_with_joins_as_join_dependency_pick_proper_parent
|
@@ -227,6 +236,13 @@ module ActiveRecord
|
|
227
236
|
assert_equal 3, relation.where(id: post.id).pluck(:id).size
|
228
237
|
end
|
229
238
|
|
239
|
+
def test_merge_raises_with_invalid_argument
|
240
|
+
assert_raises ArgumentError do
|
241
|
+
relation = Relation.new(FakeKlass, :b, nil)
|
242
|
+
relation.merge(true)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
230
246
|
def test_respond_to_for_non_selected_element
|
231
247
|
post = Post.select(:title).first
|
232
248
|
assert_equal false, post.respond_to?(:body), "post should not respond_to?(:body) since invoking it raises exception"
|
@@ -257,14 +273,7 @@ module ActiveRecord
|
|
257
273
|
join_string = "LEFT OUTER JOIN #{Rating.quoted_table_name} ON #{SpecialComment.quoted_table_name}.id = #{Rating.quoted_table_name}.comment_id"
|
258
274
|
special_comments_with_ratings = SpecialComment.joins join_string
|
259
275
|
posts_with_special_comments_with_ratings = Post.group("posts.id").joins(:special_comments).merge(special_comments_with_ratings)
|
260
|
-
assert_equal 3, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_merge_raises_with_invalid_argument
|
264
|
-
assert_raises ArgumentError do
|
265
|
-
relation = Relation.new(FakeKlass, :b)
|
266
|
-
relation.merge(true)
|
267
|
-
end
|
276
|
+
assert_equal({ 2=>1, 4=>3, 5=>1 }, authors(:david).posts.merge(posts_with_special_comments_with_ratings).count)
|
268
277
|
end
|
269
278
|
|
270
279
|
class EnsureRoundTripTypeCasting < ActiveRecord::Type::Value
|
@@ -272,12 +281,12 @@ module ActiveRecord
|
|
272
281
|
:string
|
273
282
|
end
|
274
283
|
|
275
|
-
def
|
284
|
+
def deserialize(value)
|
276
285
|
raise value unless value == "type cast for database"
|
277
286
|
"type cast from database"
|
278
287
|
end
|
279
288
|
|
280
|
-
def
|
289
|
+
def serialize(value)
|
281
290
|
raise value unless value == "value from user"
|
282
291
|
"type cast for database"
|
283
292
|
end
|
@@ -18,10 +18,17 @@ require 'models/minivan'
|
|
18
18
|
require 'models/aircraft'
|
19
19
|
require "models/possession"
|
20
20
|
require "models/reader"
|
21
|
+
require "models/categorization"
|
22
|
+
require "models/edge"
|
21
23
|
|
22
24
|
class RelationTest < ActiveRecord::TestCase
|
23
25
|
fixtures :authors, :topics, :entrants, :developers, :companies, :developers_projects, :accounts, :categories, :categorizations, :posts, :comments,
|
24
|
-
:tags, :taggings, :cars, :minivans
|
26
|
+
:tags, :taggings, :cars, :minivans
|
27
|
+
|
28
|
+
class TopicWithCallbacks < ActiveRecord::Base
|
29
|
+
self.table_name = :topics
|
30
|
+
before_update { |topic| topic.author_name = 'David' if topic.author_name.blank? }
|
31
|
+
end
|
25
32
|
|
26
33
|
def test_do_not_double_quote_string_id
|
27
34
|
van = Minivan.last
|
@@ -35,15 +42,6 @@ class RelationTest < ActiveRecord::TestCase
|
|
35
42
|
assert_equal van, Minivan.where(:minivan_id => [van]).to_a.first
|
36
43
|
end
|
37
44
|
|
38
|
-
def test_bind_values
|
39
|
-
relation = Post.all
|
40
|
-
assert_equal [], relation.bind_values
|
41
|
-
|
42
|
-
relation2 = relation.bind 'foo'
|
43
|
-
assert_equal %w{ foo }, relation2.bind_values
|
44
|
-
assert_equal [], relation.bind_values
|
45
|
-
end
|
46
|
-
|
47
45
|
def test_two_scopes_with_includes_should_not_drop_any_include
|
48
46
|
# heat habtm cache
|
49
47
|
car = Car.incl_engines.incl_tyres.first
|
@@ -114,15 +112,38 @@ class RelationTest < ActiveRecord::TestCase
|
|
114
112
|
|
115
113
|
def test_loaded_first
|
116
114
|
topics = Topic.all.order('id ASC')
|
115
|
+
topics.to_a # force load
|
117
116
|
|
118
|
-
|
119
|
-
|
120
|
-
2.times { assert_equal "The First Topic", topics.first.title }
|
117
|
+
assert_no_queries do
|
118
|
+
assert_equal "The First Topic", topics.first.title
|
121
119
|
end
|
122
120
|
|
123
121
|
assert topics.loaded?
|
124
122
|
end
|
125
123
|
|
124
|
+
def test_loaded_first_with_limit
|
125
|
+
topics = Topic.all.order('id ASC')
|
126
|
+
topics.to_a # force load
|
127
|
+
|
128
|
+
assert_no_queries do
|
129
|
+
assert_equal ["The First Topic",
|
130
|
+
"The Second Topic of the day"], topics.first(2).map(&:title)
|
131
|
+
end
|
132
|
+
|
133
|
+
assert topics.loaded?
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_first_get_more_than_available
|
137
|
+
topics = Topic.all.order('id ASC')
|
138
|
+
unloaded_first = topics.first(10)
|
139
|
+
topics.to_a # force load
|
140
|
+
|
141
|
+
assert_no_queries do
|
142
|
+
loaded_first = topics.first(10)
|
143
|
+
assert_equal unloaded_first, loaded_first
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
126
147
|
def test_reload
|
127
148
|
topics = Topic.all
|
128
149
|
|
@@ -203,6 +224,48 @@ class RelationTest < ActiveRecord::TestCase
|
|
203
224
|
assert_equal topics(:fifth).title, topics.first.title
|
204
225
|
end
|
205
226
|
|
227
|
+
def test_reverse_order_with_function
|
228
|
+
topics = Topic.order("length(title)").reverse_order
|
229
|
+
assert_equal topics(:second).title, topics.first.title
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_reverse_order_with_function_other_predicates
|
233
|
+
topics = Topic.order("author_name, length(title), id").reverse_order
|
234
|
+
assert_equal topics(:second).title, topics.first.title
|
235
|
+
topics = Topic.order("length(author_name), id, length(title)").reverse_order
|
236
|
+
assert_equal topics(:fifth).title, topics.first.title
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_reverse_order_with_multiargument_function
|
240
|
+
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
241
|
+
Topic.order("concat(author_name, title)").reverse_order
|
242
|
+
end
|
243
|
+
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
244
|
+
Topic.order("concat(lower(author_name), title)").reverse_order
|
245
|
+
end
|
246
|
+
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
247
|
+
Topic.order("concat(author_name, lower(title))").reverse_order
|
248
|
+
end
|
249
|
+
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
250
|
+
Topic.order("concat(lower(author_name), title, length(title)").reverse_order
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_reverse_order_with_nulls_first_or_last
|
255
|
+
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
256
|
+
Topic.order("title NULLS FIRST").reverse_order
|
257
|
+
end
|
258
|
+
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
259
|
+
Topic.order("title nulls last").reverse_order
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_default_reverse_order_on_table_without_primary_key
|
264
|
+
assert_raises(ActiveRecord::IrreversibleOrderError) do
|
265
|
+
Edge.all.reverse_order
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
206
269
|
def test_order_with_hash_and_symbol_generates_the_same_sql
|
207
270
|
assert_equal Topic.order(:id).to_sql, Topic.order(:id => :asc).to_sql
|
208
271
|
end
|
@@ -261,7 +324,7 @@ class RelationTest < ActiveRecord::TestCase
|
|
261
324
|
|
262
325
|
def test_finding_with_reorder
|
263
326
|
topics = Topic.order('author_name').order('title').reorder('id').to_a
|
264
|
-
topics_titles = topics.map
|
327
|
+
topics_titles = topics.map(&:title)
|
265
328
|
assert_equal ['The First Topic', 'The Second Topic of the day', 'The Third Topic of the day', 'The Fourth Topic of the day', 'The Fifth Topic of the day'], topics_titles
|
266
329
|
end
|
267
330
|
|
@@ -301,6 +364,17 @@ class RelationTest < ActiveRecord::TestCase
|
|
301
364
|
assert_equal 3, tags.length
|
302
365
|
end
|
303
366
|
|
367
|
+
def test_finding_with_sanitized_order
|
368
|
+
query = Tag.order(["field(id, ?)", [1,3,2]]).to_sql
|
369
|
+
assert_match(/field\(id, 1,3,2\)/, query)
|
370
|
+
|
371
|
+
query = Tag.order(["field(id, ?)", []]).to_sql
|
372
|
+
assert_match(/field\(id, NULL\)/, query)
|
373
|
+
|
374
|
+
query = Tag.order(["field(id, ?)", nil]).to_sql
|
375
|
+
assert_match(/field\(id, NULL\)/, query)
|
376
|
+
end
|
377
|
+
|
304
378
|
def test_finding_with_order_limit_and_offset
|
305
379
|
entrants = Entrant.order("id ASC").limit(2).offset(1)
|
306
380
|
|
@@ -357,7 +431,9 @@ class RelationTest < ActiveRecord::TestCase
|
|
357
431
|
assert_equal 0, Developer.none.size
|
358
432
|
assert_equal 0, Developer.none.count
|
359
433
|
assert_equal true, Developer.none.empty?
|
434
|
+
assert_equal true, Developer.none.none?
|
360
435
|
assert_equal false, Developer.none.any?
|
436
|
+
assert_equal false, Developer.none.one?
|
361
437
|
assert_equal false, Developer.none.many?
|
362
438
|
end
|
363
439
|
end
|
@@ -365,7 +441,7 @@ class RelationTest < ActiveRecord::TestCase
|
|
365
441
|
def test_null_relation_calculations_methods
|
366
442
|
assert_no_queries(ignore_none: false) do
|
367
443
|
assert_equal 0, Developer.none.count
|
368
|
-
assert_equal 0, Developer.none.calculate(:count, nil
|
444
|
+
assert_equal 0, Developer.none.calculate(:count, nil)
|
369
445
|
assert_equal nil, Developer.none.calculate(:average, 'salary')
|
370
446
|
end
|
371
447
|
end
|
@@ -453,7 +529,7 @@ class RelationTest < ActiveRecord::TestCase
|
|
453
529
|
where('project_id=1').to_a
|
454
530
|
|
455
531
|
assert_equal 3, developers_on_project_one.length
|
456
|
-
developer_names = developers_on_project_one.map
|
532
|
+
developer_names = developers_on_project_one.map(&:name)
|
457
533
|
assert developer_names.include?('David')
|
458
534
|
assert developer_names.include?('Jamis')
|
459
535
|
end
|
@@ -709,8 +785,8 @@ class RelationTest < ActiveRecord::TestCase
|
|
709
785
|
expected_taggings = taggings(:welcome_general, :thinking_general)
|
710
786
|
|
711
787
|
assert_no_queries do
|
712
|
-
assert_equal expected_taggings, author.taggings.distinct.sort_by
|
713
|
-
assert_equal expected_taggings, author.taggings.uniq.sort_by
|
788
|
+
assert_equal expected_taggings, author.taggings.distinct.sort_by(&:id)
|
789
|
+
assert_equal expected_taggings, author.taggings.uniq.sort_by(&:id)
|
714
790
|
end
|
715
791
|
|
716
792
|
authors = Author.all
|
@@ -769,7 +845,9 @@ class RelationTest < ActiveRecord::TestCase
|
|
769
845
|
|
770
846
|
def test_find_by_classname
|
771
847
|
Author.create!(:name => Mary.name)
|
772
|
-
|
848
|
+
assert_deprecated do
|
849
|
+
assert_equal 1, Author.where(:name => Mary).size
|
850
|
+
end
|
773
851
|
end
|
774
852
|
|
775
853
|
def test_find_by_id_with_list_of_ar
|
@@ -913,6 +991,12 @@ class RelationTest < ActiveRecord::TestCase
|
|
913
991
|
assert authors.exists?(authors(:david).id)
|
914
992
|
end
|
915
993
|
|
994
|
+
def test_any_with_scope_on_hash_includes
|
995
|
+
post = authors(:david).posts.first
|
996
|
+
categories = Categorization.includes(author: :posts).where(posts: { id: post.id })
|
997
|
+
assert categories.exists?
|
998
|
+
end
|
999
|
+
|
916
1000
|
def test_last
|
917
1001
|
authors = Author.all
|
918
1002
|
assert_equal authors(:bob), authors.last
|
@@ -931,6 +1015,12 @@ class RelationTest < ActiveRecord::TestCase
|
|
931
1015
|
assert davids.loaded?
|
932
1016
|
end
|
933
1017
|
|
1018
|
+
def test_destroy_all_with_conditions_is_deprecated
|
1019
|
+
assert_deprecated do
|
1020
|
+
assert_difference('Author.count', -1) { Author.destroy_all(name: 'David') }
|
1021
|
+
end
|
1022
|
+
end
|
1023
|
+
|
934
1024
|
def test_delete_all
|
935
1025
|
davids = Author.where(:name => 'David')
|
936
1026
|
|
@@ -938,6 +1028,12 @@ class RelationTest < ActiveRecord::TestCase
|
|
938
1028
|
assert ! davids.loaded?
|
939
1029
|
end
|
940
1030
|
|
1031
|
+
def test_delete_all_with_conditions_is_deprecated
|
1032
|
+
assert_deprecated do
|
1033
|
+
assert_difference('Author.count', -1) { Author.delete_all(name: 'David') }
|
1034
|
+
end
|
1035
|
+
end
|
1036
|
+
|
941
1037
|
def test_delete_all_loaded
|
942
1038
|
davids = Author.where(:name => 'David')
|
943
1039
|
|
@@ -953,7 +1049,7 @@ class RelationTest < ActiveRecord::TestCase
|
|
953
1049
|
|
954
1050
|
def test_delete_all_with_unpermitted_relation_raises_error
|
955
1051
|
assert_raises(ActiveRecord::ActiveRecordError) { Author.limit(10).delete_all }
|
956
|
-
assert_raises(ActiveRecord::ActiveRecordError) { Author.
|
1052
|
+
assert_raises(ActiveRecord::ActiveRecordError) { Author.distinct.delete_all }
|
957
1053
|
assert_raises(ActiveRecord::ActiveRecordError) { Author.group(:name).delete_all }
|
958
1054
|
assert_raises(ActiveRecord::ActiveRecordError) { Author.having('SUM(id) < 3').delete_all }
|
959
1055
|
assert_raises(ActiveRecord::ActiveRecordError) { Author.offset(10).delete_all }
|
@@ -1160,6 +1256,48 @@ class RelationTest < ActiveRecord::TestCase
|
|
1160
1256
|
assert ! posts.limit(1).many?
|
1161
1257
|
end
|
1162
1258
|
|
1259
|
+
def test_none?
|
1260
|
+
posts = Post.all
|
1261
|
+
assert_queries(1) do
|
1262
|
+
assert ! posts.none? # Uses COUNT()
|
1263
|
+
end
|
1264
|
+
|
1265
|
+
assert ! posts.loaded?
|
1266
|
+
|
1267
|
+
assert_queries(1) do
|
1268
|
+
assert posts.none? {|p| p.id < 0 }
|
1269
|
+
assert ! posts.none? {|p| p.id == 1 }
|
1270
|
+
end
|
1271
|
+
|
1272
|
+
assert posts.loaded?
|
1273
|
+
end
|
1274
|
+
|
1275
|
+
def test_one
|
1276
|
+
posts = Post.all
|
1277
|
+
assert_queries(1) do
|
1278
|
+
assert ! posts.one? # Uses COUNT()
|
1279
|
+
end
|
1280
|
+
|
1281
|
+
assert ! posts.loaded?
|
1282
|
+
|
1283
|
+
assert_queries(1) do
|
1284
|
+
assert ! posts.one? {|p| p.id < 3 }
|
1285
|
+
assert posts.one? {|p| p.id == 1 }
|
1286
|
+
end
|
1287
|
+
|
1288
|
+
assert posts.loaded?
|
1289
|
+
end
|
1290
|
+
|
1291
|
+
def test_to_a_should_dup_target
|
1292
|
+
posts = Post.all
|
1293
|
+
|
1294
|
+
original_size = posts.size
|
1295
|
+
removed = posts.to_a.pop
|
1296
|
+
|
1297
|
+
assert_equal original_size, posts.size
|
1298
|
+
assert_includes posts.to_a, removed
|
1299
|
+
end
|
1300
|
+
|
1163
1301
|
def test_build
|
1164
1302
|
posts = Post.all
|
1165
1303
|
|
@@ -1438,12 +1576,6 @@ class RelationTest < ActiveRecord::TestCase
|
|
1438
1576
|
assert_equal "id", Post.all.primary_key
|
1439
1577
|
end
|
1440
1578
|
|
1441
|
-
def test_disable_implicit_join_references_is_deprecated
|
1442
|
-
assert_deprecated do
|
1443
|
-
ActiveRecord::Base.disable_implicit_join_references = true
|
1444
|
-
end
|
1445
|
-
end
|
1446
|
-
|
1447
1579
|
def test_ordering_with_extra_spaces
|
1448
1580
|
assert_equal authors(:david), Author.order('id DESC , name DESC').last
|
1449
1581
|
end
|
@@ -1472,8 +1604,6 @@ class RelationTest < ActiveRecord::TestCase
|
|
1472
1604
|
assert_equal posts(:welcome), comments(:more_greetings).post
|
1473
1605
|
end
|
1474
1606
|
|
1475
|
-
unless current_adapter?(:IBM_DBAdapter)
|
1476
|
-
#IBM_DB does not support offset on subselect of the update statement
|
1477
1607
|
def test_update_all_with_joins_and_offset
|
1478
1608
|
all_comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id)
|
1479
1609
|
count = all_comments.count
|
@@ -1491,7 +1621,26 @@ unless current_adapter?(:IBM_DBAdapter)
|
|
1491
1621
|
assert_equal posts(:thinking), comments(:more_greetings).post
|
1492
1622
|
assert_equal posts(:welcome), comments(:greetings).post
|
1493
1623
|
end
|
1494
|
-
|
1624
|
+
|
1625
|
+
def test_update_on_relation
|
1626
|
+
topic1 = TopicWithCallbacks.create! title: 'arel', author_name: nil
|
1627
|
+
topic2 = TopicWithCallbacks.create! title: 'activerecord', author_name: nil
|
1628
|
+
topics = TopicWithCallbacks.where(id: [topic1.id, topic2.id])
|
1629
|
+
topics.update(title: 'adequaterecord')
|
1630
|
+
|
1631
|
+
assert_equal 'adequaterecord', topic1.reload.title
|
1632
|
+
assert_equal 'adequaterecord', topic2.reload.title
|
1633
|
+
# Testing that the before_update callbacks have run
|
1634
|
+
assert_equal 'David', topic1.reload.author_name
|
1635
|
+
assert_equal 'David', topic2.reload.author_name
|
1636
|
+
end
|
1637
|
+
|
1638
|
+
def test_update_on_relation_passing_active_record_object_is_deprecated
|
1639
|
+
topic = Topic.create!(title: 'Foo', author_name: nil)
|
1640
|
+
assert_deprecated(/update/) do
|
1641
|
+
Topic.where(id: topic.id).update(topic, title: 'Bar')
|
1642
|
+
end
|
1643
|
+
end
|
1495
1644
|
|
1496
1645
|
def test_distinct
|
1497
1646
|
tag1 = Tag.create(:name => 'Foo')
|
@@ -1502,22 +1651,42 @@ end
|
|
1502
1651
|
assert_equal ['Foo', 'Foo'], query.map(&:name)
|
1503
1652
|
assert_sql(/DISTINCT/) do
|
1504
1653
|
assert_equal ['Foo'], query.distinct.map(&:name)
|
1505
|
-
assert_equal ['Foo'], query.uniq.map(&:name)
|
1654
|
+
assert_deprecated { assert_equal ['Foo'], query.uniq.map(&:name) }
|
1506
1655
|
end
|
1507
1656
|
assert_sql(/DISTINCT/) do
|
1508
1657
|
assert_equal ['Foo'], query.distinct(true).map(&:name)
|
1509
|
-
assert_equal ['Foo'], query.uniq(true).map(&:name)
|
1658
|
+
assert_deprecated { assert_equal ['Foo'], query.uniq(true).map(&:name) }
|
1510
1659
|
end
|
1511
1660
|
assert_equal ['Foo', 'Foo'], query.distinct(true).distinct(false).map(&:name)
|
1512
|
-
|
1661
|
+
|
1662
|
+
assert_deprecated do
|
1663
|
+
assert_equal ['Foo', 'Foo'], query.uniq(true).uniq(false).map(&:name)
|
1664
|
+
end
|
1513
1665
|
end
|
1514
1666
|
|
1515
1667
|
def test_doesnt_add_having_values_if_options_are_blank
|
1516
1668
|
scope = Post.having('')
|
1517
|
-
|
1669
|
+
assert scope.having_clause.empty?
|
1518
1670
|
|
1519
1671
|
scope = Post.having([])
|
1520
|
-
|
1672
|
+
assert scope.having_clause.empty?
|
1673
|
+
end
|
1674
|
+
|
1675
|
+
def test_having_with_binds_for_both_where_and_having
|
1676
|
+
post = Post.first
|
1677
|
+
having_then_where = Post.having(id: post.id).where(title: post.title).group(:id)
|
1678
|
+
where_then_having = Post.where(title: post.title).having(id: post.id).group(:id)
|
1679
|
+
|
1680
|
+
assert_equal [post], having_then_where
|
1681
|
+
assert_equal [post], where_then_having
|
1682
|
+
end
|
1683
|
+
|
1684
|
+
def test_multiple_where_and_having_clauses
|
1685
|
+
post = Post.first
|
1686
|
+
having_then_where = Post.having(id: post.id).where(title: post.title)
|
1687
|
+
.having(id: post.id).where(title: post.title).group(:id)
|
1688
|
+
|
1689
|
+
assert_equal [post], having_then_where
|
1521
1690
|
end
|
1522
1691
|
|
1523
1692
|
def test_grouping_by_column_with_reserved_name
|
@@ -1649,6 +1818,10 @@ end
|
|
1649
1818
|
assert_sql(/^((?!ORDER).)*$/) { Post.all.find_by(author_id: 2) }
|
1650
1819
|
end
|
1651
1820
|
|
1821
|
+
test "find_by requires at least one argument" do
|
1822
|
+
assert_raises(ArgumentError) { Post.all.find_by }
|
1823
|
+
end
|
1824
|
+
|
1652
1825
|
test "find_by! with hash conditions returns the first matching record" do
|
1653
1826
|
assert_equal posts(:eager_other), Post.order(:id).find_by!(author_id: 2)
|
1654
1827
|
end
|
@@ -1671,6 +1844,10 @@ end
|
|
1671
1844
|
end
|
1672
1845
|
end
|
1673
1846
|
|
1847
|
+
test "find_by! requires at least one argument" do
|
1848
|
+
assert_raises(ArgumentError) { Post.all.find_by! }
|
1849
|
+
end
|
1850
|
+
|
1674
1851
|
test "loaded relations cannot be mutated by multi value methods" do
|
1675
1852
|
relation = Post.all
|
1676
1853
|
relation.to_a
|
@@ -1707,6 +1884,14 @@ end
|
|
1707
1884
|
end
|
1708
1885
|
end
|
1709
1886
|
|
1887
|
+
test "relations with cached arel can't be mutated [internal API]" do
|
1888
|
+
relation = Post.all
|
1889
|
+
relation.count
|
1890
|
+
|
1891
|
+
assert_raises(ActiveRecord::ImmutableRelation) { relation.limit!(5) }
|
1892
|
+
assert_raises(ActiveRecord::ImmutableRelation) { relation.where!("1 = 2") }
|
1893
|
+
end
|
1894
|
+
|
1710
1895
|
test "relations show the records in #inspect" do
|
1711
1896
|
relation = Post.limit(2)
|
1712
1897
|
assert_equal "#<ActiveRecord::Relation [#{Post.limit(2).map(&:inspect).join(', ')}]>", relation.inspect
|
@@ -1731,7 +1916,9 @@ end
|
|
1731
1916
|
test 'using a custom table affects the wheres' do
|
1732
1917
|
table_alias = Post.arel_table.alias('omg_posts')
|
1733
1918
|
|
1734
|
-
|
1919
|
+
table_metadata = ActiveRecord::TableMetadata.new(Post, table_alias)
|
1920
|
+
predicate_builder = ActiveRecord::PredicateBuilder.new(table_metadata)
|
1921
|
+
relation = ActiveRecord::Relation.new(Post, table_alias, predicate_builder)
|
1735
1922
|
relation.where!(:foo => "bar")
|
1736
1923
|
|
1737
1924
|
node = relation.arel.constraints.first.grep(Arel::Attributes::Attribute).first
|
@@ -1790,14 +1977,13 @@ end
|
|
1790
1977
|
end
|
1791
1978
|
|
1792
1979
|
def test_merging_keeps_lhs_bind_parameters
|
1793
|
-
|
1794
|
-
binds = [[column, 20]]
|
1980
|
+
binds = [ActiveRecord::Relation::QueryAttribute.new("id", 20, Post.type_for_attribute("id"))]
|
1795
1981
|
|
1796
1982
|
right = Post.where(id: 20)
|
1797
1983
|
left = Post.where(id: 10)
|
1798
1984
|
|
1799
1985
|
merged = left.merge(right)
|
1800
|
-
assert_equal binds, merged.
|
1986
|
+
assert_equal binds, merged.bound_attributes
|
1801
1987
|
end
|
1802
1988
|
|
1803
1989
|
def test_merging_reorders_bind_params
|
@@ -1812,4 +1998,29 @@ end
|
|
1812
1998
|
def test_relation_join_method
|
1813
1999
|
assert_equal 'Thank you for the welcome,Thank you again for the welcome', Post.first.comments.join(",")
|
1814
2000
|
end
|
2001
|
+
|
2002
|
+
def test_connection_adapters_can_reorder_binds
|
2003
|
+
posts = Post.limit(1).offset(2)
|
2004
|
+
|
2005
|
+
stubbed_connection = Post.connection.dup
|
2006
|
+
def stubbed_connection.combine_bind_parameters(**kwargs)
|
2007
|
+
offset = kwargs[:offset]
|
2008
|
+
kwargs[:offset] = kwargs[:limit]
|
2009
|
+
kwargs[:limit] = offset
|
2010
|
+
super(**kwargs)
|
2011
|
+
end
|
2012
|
+
|
2013
|
+
posts.define_singleton_method(:connection) do
|
2014
|
+
stubbed_connection
|
2015
|
+
end
|
2016
|
+
|
2017
|
+
assert_equal 2, posts.to_a.length
|
2018
|
+
end
|
2019
|
+
|
2020
|
+
def test_update_all_can_receive_active_record_objects
|
2021
|
+
assert_deprecated do
|
2022
|
+
Comment.update_all(post_id: Post.first)
|
2023
|
+
assert(Comment.all.all? { |c| c.post_id == Post.first.id })
|
2024
|
+
end
|
2025
|
+
end
|
1815
2026
|
end
|