ibm_db 3.0.4 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +8 -1
- data/LICENSE +1 -1
- data/ParameterizedQueries README +6 -6
- data/README +38 -55
- data/ext/Makefile +266 -0
- data/ext/extconf.rb +34 -3
- data/ext/gil_release_version +3 -0
- data/ext/ibm_db.c +106 -111
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +103 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/ext/unicode_support_version +3 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +911 -527
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
- data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
- data/test/cases/adapter_test.rb +148 -58
- data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
- data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
- data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
- data/test/cases/adapters/mysql2/connection_test.rb +210 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
- data/test/cases/adapters/mysql2/enum_test.rb +26 -0
- data/test/cases/adapters/mysql2/explain_test.rb +21 -0
- data/test/cases/adapters/mysql2/json_test.rb +195 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
- data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
- data/test/cases/adapters/mysql2/schema_test.rb +126 -0
- data/test/cases/adapters/mysql2/sp_test.rb +36 -0
- data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
- data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
- data/test/cases/adapters/postgresql/array_test.rb +339 -0
- data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
- data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
- data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
- data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
- data/test/cases/adapters/postgresql/citext_test.rb +78 -0
- data/test/cases/adapters/postgresql/collation_test.rb +53 -0
- data/test/cases/adapters/postgresql/composite_test.rb +132 -0
- data/test/cases/adapters/postgresql/connection_test.rb +257 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
- data/test/cases/adapters/postgresql/domain_test.rb +47 -0
- data/test/cases/adapters/postgresql/enum_test.rb +91 -0
- data/test/cases/adapters/postgresql/explain_test.rb +20 -0
- data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
- data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
- data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
- data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
- data/test/cases/adapters/postgresql/integer_test.rb +25 -0
- data/test/cases/adapters/postgresql/json_test.rb +237 -0
- data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
- data/test/cases/adapters/postgresql/money_test.rb +96 -0
- data/test/cases/adapters/postgresql/network_test.rb +94 -0
- data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
- data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
- data/test/cases/adapters/postgresql/range_test.rb +343 -0
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
- data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
- data/test/cases/adapters/postgresql/schema_test.rb +597 -0
- data/test/cases/adapters/postgresql/serial_test.rb +154 -0
- data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
- data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
- data/test/cases/adapters/postgresql/utils_test.rb +62 -0
- data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
- data/test/cases/adapters/postgresql/xml_test.rb +54 -0
- data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
- data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
- data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
- data/test/cases/aggregations_test.rb +11 -1
- data/test/cases/ar_schema_test.rb +35 -50
- data/test/cases/associations/association_scope_test.rb +1 -6
- data/test/cases/associations/belongs_to_associations_test.rb +122 -10
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
- data/test/cases/associations/callbacks_test.rb +5 -7
- data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
- data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
- data/test/cases/associations/eager_test.rb +176 -73
- data/test/cases/associations/extension_test.rb +7 -2
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +104 -32
- data/test/cases/associations/has_many_associations_test.rb +382 -43
- data/test/cases/associations/has_many_through_associations_test.rb +108 -41
- data/test/cases/associations/has_one_associations_test.rb +105 -8
- data/test/cases/associations/has_one_through_associations_test.rb +6 -3
- data/test/cases/associations/inner_join_association_test.rb +3 -3
- data/test/cases/associations/inverse_associations_test.rb +51 -11
- data/test/cases/associations/join_model_test.rb +59 -36
- data/test/cases/associations/left_outer_join_association_test.rb +88 -0
- data/test/cases/associations/nested_through_associations_test.rb +2 -2
- data/test/cases/associations/required_test.rb +25 -5
- data/test/cases/associations_test.rb +39 -34
- data/test/cases/attribute_decorators_test.rb +9 -8
- data/test/cases/attribute_methods/read_test.rb +5 -5
- data/test/cases/attribute_methods_test.rb +97 -40
- data/test/cases/attribute_set_test.rb +74 -4
- data/test/cases/attribute_test.rb +84 -18
- data/test/cases/attributes_test.rb +151 -34
- data/test/cases/autosave_association_test.rb +149 -36
- data/test/cases/base_test.rb +311 -236
- data/test/cases/batches_test.rb +299 -22
- data/test/cases/binary_test.rb +2 -10
- data/test/cases/bind_parameter_test.rb +76 -66
- data/test/cases/cache_key_test.rb +26 -0
- data/test/cases/calculations_test.rb +167 -15
- data/test/cases/callbacks_test.rb +161 -68
- data/test/cases/coders/json_test.rb +15 -0
- data/test/cases/collection_cache_key_test.rb +115 -0
- data/test/cases/column_definition_test.rb +26 -57
- data/test/cases/comment_test.rb +145 -0
- data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
- data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
- data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
- data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
- data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
- data/test/cases/connection_management_test.rb +46 -56
- data/test/cases/connection_pool_test.rb +195 -20
- data/test/cases/connection_specification/resolver_test.rb +15 -0
- data/test/cases/counter_cache_test.rb +10 -5
- data/test/cases/custom_locking_test.rb +1 -1
- data/test/cases/database_statements_test.rb +18 -3
- data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
- data/test/cases/date_time_precision_test.rb +107 -0
- data/test/cases/defaults_test.rb +85 -89
- data/test/cases/dirty_test.rb +32 -44
- data/test/cases/disconnected_test.rb +4 -2
- data/test/cases/enum_test.rb +178 -24
- data/test/cases/errors_test.rb +16 -0
- data/test/cases/explain_test.rb +32 -21
- data/test/cases/finder_test.rb +279 -151
- data/test/cases/fixture_set/file_test.rb +18 -0
- data/test/cases/fixtures_test.rb +123 -32
- data/test/cases/forbidden_attributes_protection_test.rb +69 -3
- data/test/cases/helper.rb +10 -16
- data/test/cases/hot_compatibility_test.rb +89 -1
- data/test/cases/inheritance_test.rb +284 -53
- data/test/cases/integration_test.rb +23 -7
- data/test/cases/invalid_connection_test.rb +4 -2
- data/test/cases/invertible_migration_test.rb +124 -32
- data/test/cases/json_serialization_test.rb +11 -2
- data/test/cases/locking_test.rb +22 -6
- data/test/cases/log_subscriber_test.rb +106 -17
- data/test/cases/migration/change_schema_test.rb +118 -132
- data/test/cases/migration/change_table_test.rb +34 -2
- data/test/cases/migration/column_attributes_test.rb +7 -23
- data/test/cases/migration/column_positioning_test.rb +8 -8
- data/test/cases/migration/columns_test.rb +17 -11
- data/test/cases/migration/command_recorder_test.rb +47 -2
- data/test/cases/migration/compatibility_test.rb +118 -0
- data/test/cases/migration/create_join_table_test.rb +21 -12
- data/test/cases/migration/foreign_key_test.rb +68 -66
- data/test/cases/migration/index_test.rb +14 -12
- data/test/cases/migration/logger_test.rb +1 -1
- data/test/cases/migration/pending_migrations_test.rb +0 -1
- data/test/cases/migration/references_foreign_key_test.rb +114 -107
- data/test/cases/migration/references_index_test.rb +4 -4
- data/test/cases/migration/references_statements_test.rb +26 -6
- data/test/cases/migration/rename_table_test.rb +25 -25
- data/test/cases/migration_test.rb +279 -81
- data/test/cases/migrator_test.rb +91 -8
- data/test/cases/mixin_test.rb +0 -2
- data/test/cases/modules_test.rb +3 -4
- data/test/cases/multiparameter_attributes_test.rb +24 -2
- data/test/cases/multiple_db_test.rb +18 -11
- data/test/cases/nested_attributes_test.rb +74 -33
- data/test/cases/persistence_test.rb +102 -10
- data/test/cases/pooled_connections_test.rb +3 -3
- data/test/cases/primary_keys_test.rb +170 -31
- data/test/cases/query_cache_test.rb +216 -96
- data/test/cases/quoting_test.rb +65 -19
- data/test/cases/readonly_test.rb +2 -1
- data/test/cases/reflection_test.rb +77 -22
- data/test/cases/relation/delegation_test.rb +3 -8
- data/test/cases/relation/merging_test.rb +10 -14
- data/test/cases/relation/mutation_test.rb +42 -24
- data/test/cases/relation/or_test.rb +92 -0
- data/test/cases/relation/predicate_builder_test.rb +4 -2
- data/test/cases/relation/record_fetch_warning_test.rb +40 -0
- data/test/cases/relation/where_chain_test.rb +23 -99
- data/test/cases/relation/where_clause_test.rb +182 -0
- data/test/cases/relation/where_test.rb +45 -23
- data/test/cases/relation_test.rb +89 -58
- data/test/cases/relations_test.rb +249 -38
- data/test/cases/result_test.rb +10 -0
- data/test/cases/sanitize_test.rb +108 -15
- data/test/cases/schema_dumper_test.rb +119 -125
- data/test/cases/schema_loading_test.rb +52 -0
- data/test/cases/scoping/default_scoping_test.rb +113 -39
- data/test/cases/scoping/named_scoping_test.rb +46 -9
- data/test/cases/scoping/relation_scoping_test.rb +47 -4
- data/test/cases/secure_token_test.rb +32 -0
- data/test/cases/serialization_test.rb +1 -1
- data/test/cases/serialized_attribute_test.rb +93 -6
- data/test/cases/statement_cache_test.rb +38 -0
- data/test/cases/store_test.rb +2 -1
- data/test/cases/suppressor_test.rb +63 -0
- data/test/cases/tasks/database_tasks_test.rb +74 -8
- data/test/cases/tasks/mysql_rake_test.rb +143 -109
- data/test/cases/tasks/postgresql_rake_test.rb +71 -12
- data/test/cases/tasks/sqlite_rake_test.rb +30 -3
- data/test/cases/test_case.rb +28 -20
- data/test/cases/test_fixtures_test.rb +36 -0
- data/test/cases/time_precision_test.rb +103 -0
- data/test/cases/timestamp_test.rb +47 -14
- data/test/cases/touch_later_test.rb +121 -0
- data/test/cases/transaction_callbacks_test.rb +128 -62
- data/test/cases/transaction_isolation_test.rb +2 -2
- data/test/cases/transactions_test.rb +61 -43
- data/test/cases/type/adapter_specific_registry_test.rb +133 -0
- data/test/cases/type/date_time_test.rb +14 -0
- data/test/cases/type/integer_test.rb +2 -96
- data/test/cases/type/string_test.rb +0 -14
- data/test/cases/type_test.rb +39 -0
- data/test/cases/types_test.rb +1 -118
- data/test/cases/unconnected_test.rb +1 -1
- data/test/cases/validations/absence_validation_test.rb +73 -0
- data/test/cases/validations/association_validation_test.rb +13 -2
- data/test/cases/validations/i18n_validation_test.rb +6 -10
- data/test/cases/validations/length_validation_test.rb +62 -30
- data/test/cases/validations/presence_validation_test.rb +36 -1
- data/test/cases/validations/uniqueness_validation_test.rb +150 -36
- data/test/cases/validations_repair_helper.rb +2 -6
- data/test/cases/validations_test.rb +36 -7
- data/test/cases/view_test.rb +108 -5
- data/test/cases/yaml_serialization_test.rb +36 -1
- data/test/config.example.yml +97 -0
- data/test/fixtures/bad_posts.yml +9 -0
- data/test/fixtures/books.yml +20 -0
- data/test/fixtures/content.yml +3 -0
- data/test/fixtures/content_positions.yml +3 -0
- data/test/fixtures/dead_parrots.yml +5 -0
- data/test/fixtures/live_parrots.yml +4 -0
- data/test/fixtures/naked/yml/parrots.yml +2 -0
- data/test/fixtures/naked/yml/trees.yml +3 -0
- data/test/fixtures/nodes.yml +29 -0
- data/test/fixtures/other_comments.yml +6 -0
- data/test/fixtures/other_dogs.yml +2 -0
- data/test/fixtures/other_posts.yml +7 -0
- data/test/fixtures/price_estimates.yml +10 -1
- data/test/fixtures/trees.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +1 -1
- data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
- data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
- data/test/migrations/missing/1_people_have_last_names.rb +2 -2
- data/test/migrations/missing/3_we_need_reminders.rb +2 -2
- data/test/migrations/missing/4_innocent_jointable.rb +2 -2
- data/test/migrations/rename/1_we_need_things.rb +2 -2
- data/test/migrations/rename/2_rename_things.rb +2 -2
- data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy2/1_create_articles.rb +1 -1
- data/test/migrations/to_copy2/2_create_comments.rb +1 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
- data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
- data/test/models/admin/randomly_named_c1.rb +6 -2
- data/test/models/aircraft.rb +1 -0
- data/test/models/author.rb +4 -7
- data/test/models/bird.rb +1 -1
- data/test/models/book.rb +5 -0
- data/test/models/bulb.rb +2 -1
- data/test/models/car.rb +3 -0
- data/test/models/cat.rb +10 -0
- data/test/models/chef.rb +5 -0
- data/test/models/club.rb +2 -0
- data/test/models/comment.rb +17 -5
- data/test/models/company.rb +7 -2
- data/test/models/company_in_module.rb +1 -1
- data/test/models/contact.rb +1 -1
- data/test/models/content.rb +40 -0
- data/test/models/customer.rb +8 -2
- data/test/models/developer.rb +22 -0
- data/test/models/face.rb +1 -1
- data/test/models/guitar.rb +4 -0
- data/test/models/hotel.rb +5 -0
- data/test/models/member.rb +1 -0
- data/test/models/member_detail.rb +4 -3
- data/test/models/mentor.rb +3 -0
- data/test/models/mocktail_designer.rb +2 -0
- data/test/models/node.rb +5 -0
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +3 -0
- data/test/models/other_dog.rb +5 -0
- data/test/models/owner.rb +4 -1
- data/test/models/parrot.rb +6 -7
- data/test/models/person.rb +0 -1
- data/test/models/pet.rb +3 -0
- data/test/models/pet_treasure.rb +6 -0
- data/test/models/pirate.rb +3 -3
- data/test/models/post.rb +18 -9
- data/test/models/project.rb +11 -0
- data/test/models/randomly_named_c1.rb +1 -1
- data/test/models/recipe.rb +3 -0
- data/test/models/ship.rb +8 -2
- data/test/models/tag.rb +6 -0
- data/test/models/topic.rb +2 -8
- data/test/models/tree.rb +3 -0
- data/test/models/tuning_peg.rb +4 -0
- data/test/models/user.rb +14 -0
- data/test/models/uuid_item.rb +6 -0
- data/test/schema/mysql2_specific_schema.rb +33 -23
- data/test/schema/oracle_specific_schema.rb +1 -4
- data/test/schema/postgresql_specific_schema.rb +36 -124
- data/test/schema/schema.rb +183 -64
- data/test/schema/schema.rb.original +1057 -0
- data/test/schema/sqlite_specific_schema.rb +1 -5
- data/test/support/connection.rb +1 -0
- data/test/support/schema_dumping_helper.rb +1 -1
- data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
- data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
- metadata +145 -26
- data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
- data/test/cases/attribute_methods/serialization_test.rb +0 -29
- data/test/cases/migration/change_schema_test - Copy.rb +0 -448
- data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
- data/test/cases/migration/table_and_index_test.rb +0 -24
- data/test/cases/relation/where_test2.rb +0 -36
- data/test/cases/type/decimal_test.rb +0 -51
- data/test/cases/type/unsigned_integer_test.rb +0 -18
- data/test/cases/xml_serialization_test.rb +0 -457
- data/test/fixtures/naked/csv/accounts.csv +0 -1
- data/test/schema/mysql_specific_schema.rb +0 -70
data/test/cases/readonly_test.rb
CHANGED
@@ -7,9 +7,10 @@ require 'models/computer'
|
|
7
7
|
require 'models/project'
|
8
8
|
require 'models/reader'
|
9
9
|
require 'models/person'
|
10
|
+
require 'models/ship'
|
10
11
|
|
11
12
|
class ReadOnlyTest < ActiveRecord::TestCase
|
12
|
-
fixtures :authors, :posts, :comments, :developers, :projects, :developers_projects, :people, :readers
|
13
|
+
fixtures :authors, :posts, :comments, :developers, :projects, :developers_projects, :people, :readers
|
13
14
|
|
14
15
|
def test_cant_save_readonly_record
|
15
16
|
dev = Developer.find(1)
|
@@ -23,6 +23,8 @@ require 'models/chef'
|
|
23
23
|
require 'models/department'
|
24
24
|
require 'models/cake_designer'
|
25
25
|
require 'models/drink_designer'
|
26
|
+
require 'models/mocktail_designer'
|
27
|
+
require 'models/recipe'
|
26
28
|
|
27
29
|
class ReflectionTest < ActiveRecord::TestCase
|
28
30
|
include ActiveRecord::Reflection
|
@@ -50,13 +52,13 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def test_columns_are_returned_in_the_order_they_were_declared
|
53
|
-
column_names = Topic.columns.map
|
55
|
+
column_names = Topic.columns.map(&:name)
|
54
56
|
assert_equal %w(id title author_name author_email_address written_on bonus_time last_read content important approved replies_count unique_replies_count parent_id parent_title type group created_at updated_at), column_names
|
55
57
|
end
|
56
58
|
|
57
59
|
def test_content_columns
|
58
60
|
content_columns = Topic.content_columns
|
59
|
-
content_column_names = content_columns.map
|
61
|
+
content_column_names = content_columns.map(&:name)
|
60
62
|
assert_equal 13, content_columns.length
|
61
63
|
assert_equal %w(title author_name author_email_address written_on bonus_time last_read content important group approved parent_title created_at updated_at).sort, content_column_names.sort
|
62
64
|
end
|
@@ -80,10 +82,21 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
80
82
|
assert_equal :integer, @first.column_for_attribute("id").type
|
81
83
|
end
|
82
84
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def test_non_existent_columns_return_null_object
|
86
|
+
column = @first.column_for_attribute("attribute_that_doesnt_exist")
|
87
|
+
assert_instance_of ActiveRecord::ConnectionAdapters::NullColumn, column
|
88
|
+
assert_equal "attribute_that_doesnt_exist", column.name
|
89
|
+
assert_equal nil, column.sql_type
|
90
|
+
assert_equal nil, column.type
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_non_existent_types_are_identity_types
|
94
|
+
type = @first.type_for_attribute("attribute_that_doesnt_exist")
|
95
|
+
object = Object.new
|
96
|
+
|
97
|
+
assert_equal object, type.deserialize(object)
|
98
|
+
assert_equal object, type.cast(object)
|
99
|
+
assert_equal object, type.serialize(object)
|
87
100
|
end
|
88
101
|
|
89
102
|
def test_reflection_klass_for_nested_class_name
|
@@ -266,6 +279,31 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
266
279
|
assert_equal 2, @hotel.chefs.size
|
267
280
|
end
|
268
281
|
|
282
|
+
def test_scope_chain_does_not_interfere_with_hmt_with_polymorphic_case_and_sti
|
283
|
+
@hotel = Hotel.create!
|
284
|
+
@hotel.mocktail_designers << MocktailDesigner.create!
|
285
|
+
|
286
|
+
assert_equal 1, @hotel.mocktail_designers.size
|
287
|
+
assert_equal 1, @hotel.mocktail_designers.count
|
288
|
+
assert_equal 1, @hotel.chef_lists.size
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_scope_chain_of_polymorphic_association_does_not_leak_into_other_hmt_associations
|
292
|
+
hotel = Hotel.create!
|
293
|
+
department = hotel.departments.create!
|
294
|
+
drink = department.chefs.create!(employable: DrinkDesigner.create!)
|
295
|
+
Recipe.create!(chef_id: drink.id, hotel_id: hotel.id)
|
296
|
+
|
297
|
+
expected_sql = capture_sql { hotel.recipes.to_a }
|
298
|
+
|
299
|
+
Hotel.reflect_on_association(:recipes).clear_association_scope_cache
|
300
|
+
hotel.reload
|
301
|
+
hotel.drink_designers.to_a
|
302
|
+
loaded_sql = capture_sql { hotel.recipes.to_a }
|
303
|
+
|
304
|
+
assert_equal expected_sql, loaded_sql
|
305
|
+
end
|
306
|
+
|
269
307
|
def test_nested?
|
270
308
|
assert !Author.reflect_on_association(:comments).nested?
|
271
309
|
assert Author.reflect_on_association(:tags).nested?
|
@@ -287,6 +325,15 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
287
325
|
assert_equal "custom_primary_key", Author.reflect_on_association(:tags_with_primary_key).association_primary_key.to_s # nested
|
288
326
|
end
|
289
327
|
|
328
|
+
def test_association_primary_key_type
|
329
|
+
# Normal Association
|
330
|
+
assert_equal :integer, Author.reflect_on_association(:posts).association_primary_key_type.type
|
331
|
+
assert_equal :string, Author.reflect_on_association(:essay).association_primary_key_type.type
|
332
|
+
|
333
|
+
# Through Association
|
334
|
+
assert_equal :string, Author.reflect_on_association(:essay_category).association_primary_key_type.type
|
335
|
+
end
|
336
|
+
|
290
337
|
def test_association_primary_key_raises_when_missing_primary_key
|
291
338
|
reflection = ActiveRecord::Reflection.create(:has_many, :edge, nil, {}, Author)
|
292
339
|
assert_raises(ActiveRecord::UnknownPrimaryKey) { reflection.association_primary_key }
|
@@ -365,12 +412,14 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
365
412
|
product = Struct.new(:table_name, :pluralize_table_names).new('products', true)
|
366
413
|
|
367
414
|
reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, {}, product)
|
368
|
-
reflection.
|
369
|
-
|
415
|
+
reflection.stub(:klass, category) do
|
416
|
+
assert_equal 'categories_products', reflection.join_table
|
417
|
+
end
|
370
418
|
|
371
419
|
reflection = ActiveRecord::Reflection.create(:has_many, :products, nil, {}, category)
|
372
|
-
reflection.
|
373
|
-
|
420
|
+
reflection.stub(:klass, product) do
|
421
|
+
assert_equal 'categories_products', reflection.join_table
|
422
|
+
end
|
374
423
|
end
|
375
424
|
|
376
425
|
def test_join_table_with_common_prefix
|
@@ -378,12 +427,14 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
378
427
|
product = Struct.new(:table_name, :pluralize_table_names).new('catalog_products', true)
|
379
428
|
|
380
429
|
reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, {}, product)
|
381
|
-
reflection.
|
382
|
-
|
430
|
+
reflection.stub(:klass, category) do
|
431
|
+
assert_equal 'catalog_categories_products', reflection.join_table
|
432
|
+
end
|
383
433
|
|
384
434
|
reflection = ActiveRecord::Reflection.create(:has_many, :products, nil, {}, category)
|
385
|
-
reflection.
|
386
|
-
|
435
|
+
reflection.stub(:klass, product) do
|
436
|
+
assert_equal 'catalog_categories_products', reflection.join_table
|
437
|
+
end
|
387
438
|
end
|
388
439
|
|
389
440
|
def test_join_table_with_different_prefix
|
@@ -391,12 +442,14 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
391
442
|
page = Struct.new(:table_name, :pluralize_table_names).new('content_pages', true)
|
392
443
|
|
393
444
|
reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, {}, page)
|
394
|
-
reflection.
|
395
|
-
|
445
|
+
reflection.stub(:klass, category) do
|
446
|
+
assert_equal 'catalog_categories_content_pages', reflection.join_table
|
447
|
+
end
|
396
448
|
|
397
449
|
reflection = ActiveRecord::Reflection.create(:has_many, :pages, nil, {}, category)
|
398
|
-
reflection.
|
399
|
-
|
450
|
+
reflection.stub(:klass, page) do
|
451
|
+
assert_equal 'catalog_categories_content_pages', reflection.join_table
|
452
|
+
end
|
400
453
|
end
|
401
454
|
|
402
455
|
def test_join_table_can_be_overridden
|
@@ -404,12 +457,14 @@ class ReflectionTest < ActiveRecord::TestCase
|
|
404
457
|
product = Struct.new(:table_name, :pluralize_table_names).new('products', true)
|
405
458
|
|
406
459
|
reflection = ActiveRecord::Reflection.create(:has_many, :categories, nil, { :join_table => 'product_categories' }, product)
|
407
|
-
reflection.
|
408
|
-
|
460
|
+
reflection.stub(:klass, category) do
|
461
|
+
assert_equal 'product_categories', reflection.join_table
|
462
|
+
end
|
409
463
|
|
410
464
|
reflection = ActiveRecord::Reflection.create(:has_many, :products, nil, { :join_table => 'product_categories' }, category)
|
411
|
-
reflection.
|
412
|
-
|
465
|
+
reflection.stub(:klass, product) do
|
466
|
+
assert_equal 'product_categories', reflection.join_table
|
467
|
+
end
|
413
468
|
end
|
414
469
|
|
415
470
|
def test_includes_accepts_symbols
|
@@ -27,12 +27,13 @@ module ActiveRecord
|
|
27
27
|
|
28
28
|
module DelegationWhitelistBlacklistTests
|
29
29
|
ARRAY_DELEGATES = [
|
30
|
-
:+, :-, :|, :&, :[],
|
30
|
+
:+, :-, :|, :&, :[], :shuffle,
|
31
31
|
:all?, :collect, :compact, :detect, :each, :each_cons, :each_with_index,
|
32
32
|
:exclude?, :find_all, :flat_map, :group_by, :include?, :length,
|
33
33
|
:map, :none?, :one?, :partition, :reject, :reverse,
|
34
34
|
:sample, :second, :sort, :sort_by, :third,
|
35
|
-
:to_ary, :to_set, :to_xml, :to_yaml, :join
|
35
|
+
:to_ary, :to_set, :to_xml, :to_yaml, :join,
|
36
|
+
:in_groups, :in_groups_of, :to_sentence, :to_formatted_s
|
36
37
|
]
|
37
38
|
|
38
39
|
ARRAY_DELEGATES.each do |method|
|
@@ -40,12 +41,6 @@ module ActiveRecord
|
|
40
41
|
assert_respond_to target, method
|
41
42
|
end
|
42
43
|
end
|
43
|
-
|
44
|
-
ActiveRecord::Delegation::BLACKLISTED_ARRAY_METHODS.each do |method|
|
45
|
-
define_method "test_#{method}_is_not_delegated_to_Array" do
|
46
|
-
assert_raises(NoMethodError) { call_method(target, method) }
|
47
|
-
end
|
48
|
-
end
|
49
44
|
end
|
50
45
|
|
51
46
|
class DelegationAssociationTest < DelegationTest
|
@@ -8,7 +8,7 @@ require 'models/project'
|
|
8
8
|
require 'models/rating'
|
9
9
|
|
10
10
|
class RelationMergingTest < ActiveRecord::TestCase
|
11
|
-
fixtures :developers, :comments, :authors, :posts
|
11
|
+
fixtures :developers, :comments, :authors, :posts
|
12
12
|
|
13
13
|
def test_relation_merging
|
14
14
|
devs = Developer.where("salary >= 80000").merge(Developer.limit(2)).merge(Developer.order('id ASC').where("id < 3"))
|
@@ -82,26 +82,15 @@ class RelationMergingTest < ActiveRecord::TestCase
|
|
82
82
|
left = Post.where(title: "omg").where(comments_count: 1)
|
83
83
|
right = Post.where(title: "wtf").where(title: "bbq")
|
84
84
|
|
85
|
-
expected = [left.
|
85
|
+
expected = [left.bound_attributes[1]] + right.bound_attributes
|
86
86
|
merged = left.merge(right)
|
87
87
|
|
88
|
-
assert_equal expected, merged.
|
88
|
+
assert_equal expected, merged.bound_attributes
|
89
89
|
assert !merged.to_sql.include?("omg")
|
90
90
|
assert merged.to_sql.include?("wtf")
|
91
91
|
assert merged.to_sql.include?("bbq")
|
92
92
|
end
|
93
93
|
|
94
|
-
def test_merging_keeps_lhs_bind_parameters
|
95
|
-
column = Post.columns_hash['id']
|
96
|
-
binds = [[column, 20]]
|
97
|
-
|
98
|
-
right = Post.where(id: 20)
|
99
|
-
left = Post.where(id: 10)
|
100
|
-
|
101
|
-
merged = left.merge(right)
|
102
|
-
assert_equal binds, merged.bind_values
|
103
|
-
end
|
104
|
-
|
105
94
|
def test_merging_reorders_bind_params
|
106
95
|
post = Post.first
|
107
96
|
right = Post.where(id: 1)
|
@@ -115,6 +104,13 @@ class RelationMergingTest < ActiveRecord::TestCase
|
|
115
104
|
post = PostThatLoadsCommentsInAnAfterSaveHook.create!(title: "First Post", body: "Blah blah blah.")
|
116
105
|
assert_equal "First comment!", post.comments.where(body: "First comment!").first_or_create.body
|
117
106
|
end
|
107
|
+
|
108
|
+
def test_merging_with_from_clause
|
109
|
+
relation = Post.all
|
110
|
+
assert relation.from_clause.empty?
|
111
|
+
relation = relation.merge(Post.from("posts"))
|
112
|
+
refute relation.from_clause.empty?
|
113
|
+
end
|
118
114
|
end
|
119
115
|
|
120
116
|
class MergingDifferentRelationsTest < ActiveRecord::TestCase
|
@@ -22,13 +22,21 @@ module ActiveRecord
|
|
22
22
|
def sanitize_sql(sql)
|
23
23
|
sql
|
24
24
|
end
|
25
|
+
|
26
|
+
def sanitize_sql_for_order(sql)
|
27
|
+
sql
|
28
|
+
end
|
29
|
+
|
30
|
+
def arel_attribute(name, table)
|
31
|
+
table[name]
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
def relation
|
28
|
-
@relation ||= Relation.new FakeKlass.new('posts'), Post.arel_table
|
36
|
+
@relation ||= Relation.new FakeKlass.new('posts'), Post.arel_table, Post.predicate_builder
|
29
37
|
end
|
30
38
|
|
31
|
-
(Relation::MULTI_VALUE_METHODS - [:references, :extending, :order, :unscope, :select]).each do |method|
|
39
|
+
(Relation::MULTI_VALUE_METHODS - [:references, :extending, :order, :unscope, :select, :left_joins]).each do |method|
|
32
40
|
test "##{method}!" do
|
33
41
|
assert relation.public_send("#{method}!", :foo).equal?(relation)
|
34
42
|
assert_equal [:foo], relation.public_send("#{method}_values")
|
@@ -55,9 +63,10 @@ module ActiveRecord
|
|
55
63
|
|
56
64
|
test '#order! on non-string does not attempt regexp match for references' do
|
57
65
|
obj = Object.new
|
58
|
-
obj
|
59
|
-
|
60
|
-
|
66
|
+
assert_not_called(obj, :=~) do
|
67
|
+
assert relation.order!(obj)
|
68
|
+
assert_equal [obj], relation.order_values
|
69
|
+
end
|
61
70
|
end
|
62
71
|
|
63
72
|
test '#references!' do
|
@@ -81,7 +90,7 @@ module ActiveRecord
|
|
81
90
|
assert_equal [], relation.extending_values
|
82
91
|
end
|
83
92
|
|
84
|
-
(Relation::SINGLE_VALUE_METHODS - [:
|
93
|
+
(Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with, :uniq]).each do |method|
|
85
94
|
test "##{method}!" do
|
86
95
|
assert relation.public_send("#{method}!", :foo).equal?(relation)
|
87
96
|
assert_equal :foo, relation.public_send("#{method}_value")
|
@@ -90,7 +99,7 @@ module ActiveRecord
|
|
90
99
|
|
91
100
|
test '#from!' do
|
92
101
|
assert relation.from!('foo').equal?(relation)
|
93
|
-
assert_equal
|
102
|
+
assert_equal 'foo', relation.from_clause.value
|
94
103
|
end
|
95
104
|
|
96
105
|
test '#lock!' do
|
@@ -99,11 +108,11 @@ module ActiveRecord
|
|
99
108
|
end
|
100
109
|
|
101
110
|
test '#reorder!' do
|
102
|
-
|
111
|
+
@relation = self.relation.order('foo')
|
103
112
|
|
104
|
-
assert
|
105
|
-
assert_equal ['bar'],
|
106
|
-
assert
|
113
|
+
assert relation.reorder!('bar').equal?(relation)
|
114
|
+
assert_equal ['bar'], relation.order_values
|
115
|
+
assert relation.reordering_value
|
107
116
|
end
|
108
117
|
|
109
118
|
test '#reorder! with symbol prepends the table name' do
|
@@ -116,18 +125,18 @@ module ActiveRecord
|
|
116
125
|
end
|
117
126
|
|
118
127
|
test 'reverse_order!' do
|
119
|
-
|
128
|
+
@relation = Post.order('title ASC, comments_count DESC')
|
120
129
|
|
121
|
-
|
130
|
+
relation.reverse_order!
|
122
131
|
|
123
|
-
assert_equal 'title DESC',
|
124
|
-
assert_equal 'comments_count ASC',
|
132
|
+
assert_equal 'title DESC', relation.order_values.first
|
133
|
+
assert_equal 'comments_count ASC', relation.order_values.last
|
125
134
|
|
126
135
|
|
127
|
-
|
136
|
+
relation.reverse_order!
|
128
137
|
|
129
|
-
assert_equal 'title ASC',
|
130
|
-
assert_equal 'comments_count DESC',
|
138
|
+
assert_equal 'title ASC', relation.order_values.first
|
139
|
+
assert_equal 'comments_count DESC', relation.order_values.last
|
131
140
|
end
|
132
141
|
|
133
142
|
test 'create_with!' do
|
@@ -136,12 +145,12 @@ module ActiveRecord
|
|
136
145
|
end
|
137
146
|
|
138
147
|
test 'test_merge!' do
|
139
|
-
assert relation.merge!(
|
140
|
-
assert_equal [:foo], relation.
|
148
|
+
assert relation.merge!(select: :foo).equal?(relation)
|
149
|
+
assert_equal [:foo], relation.select_values
|
141
150
|
end
|
142
151
|
|
143
152
|
test 'merge with a proc' do
|
144
|
-
assert_equal [:foo], relation.merge(-> {
|
153
|
+
assert_equal [:foo], relation.merge(-> { select(:foo) }).select_values
|
145
154
|
end
|
146
155
|
|
147
156
|
test 'none!' do
|
@@ -153,13 +162,22 @@ module ActiveRecord
|
|
153
162
|
test 'distinct!' do
|
154
163
|
relation.distinct! :foo
|
155
164
|
assert_equal :foo, relation.distinct_value
|
156
|
-
|
165
|
+
|
166
|
+
assert_deprecated do
|
167
|
+
assert_equal :foo, relation.uniq_value # deprecated access
|
168
|
+
end
|
157
169
|
end
|
158
170
|
|
159
171
|
test 'uniq! was replaced by distinct!' do
|
160
|
-
|
172
|
+
assert_deprecated(/use distinct! instead/) do
|
173
|
+
relation.uniq! :foo
|
174
|
+
end
|
175
|
+
|
176
|
+
assert_deprecated(/use distinct_value instead/) do
|
177
|
+
assert_equal :foo, relation.uniq_value # deprecated access
|
178
|
+
end
|
179
|
+
|
161
180
|
assert_equal :foo, relation.distinct_value
|
162
|
-
assert_equal :foo, relation.uniq_value # deprecated access
|
163
181
|
end
|
164
182
|
end
|
165
183
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'models/post'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
class OrTest < ActiveRecord::TestCase
|
6
|
+
fixtures :posts
|
7
|
+
|
8
|
+
def test_or_with_relation
|
9
|
+
expected = Post.where('id = 1 or id = 2').to_a
|
10
|
+
assert_equal expected, Post.where('id = 1').or(Post.where('id = 2')).to_a
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_or_identity
|
14
|
+
expected = Post.where('id = 1').to_a
|
15
|
+
assert_equal expected, Post.where('id = 1').or(Post.where('id = 1')).to_a
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_or_with_null_left
|
19
|
+
expected = Post.where('id = 1').to_a
|
20
|
+
assert_equal expected, Post.none.or(Post.where('id = 1')).to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_or_with_null_right
|
24
|
+
expected = Post.where('id = 1').to_a
|
25
|
+
assert_equal expected, Post.where('id = 1').or(Post.none).to_a
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_or_with_bind_params
|
29
|
+
assert_equal Post.find([1, 2]), Post.where(id: 1).or(Post.where(id: 2)).to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_or_with_null_both
|
33
|
+
expected = Post.none.to_a
|
34
|
+
assert_equal expected, Post.none.or(Post.none).to_a
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_or_without_left_where
|
38
|
+
expected = Post.all
|
39
|
+
assert_equal expected, Post.or(Post.where('id = 1')).to_a
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_or_without_right_where
|
43
|
+
expected = Post.all
|
44
|
+
assert_equal expected, Post.where('id = 1').or(Post.all).to_a
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_or_preserves_other_querying_methods
|
48
|
+
expected = Post.where('id = 1 or id = 2 or id = 3').order('body asc').to_a
|
49
|
+
partial = Post.order('body asc')
|
50
|
+
assert_equal expected, partial.where('id = 1').or(partial.where(:id => [2, 3])).to_a
|
51
|
+
assert_equal expected, Post.order('body asc').where('id = 1').or(Post.order('body asc').where(:id => [2, 3])).to_a
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_or_with_incompatible_relations
|
55
|
+
error = assert_raises ArgumentError do
|
56
|
+
Post.order('body asc').where('id = 1').or(Post.order('id desc').where(:id => [2, 3])).to_a
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_equal "Relation passed to #or must be structurally compatible. Incompatible values: [:order]", error.message
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_or_when_grouping
|
63
|
+
groups = Post.where('id < 10').group('body').select('body, COUNT(*) AS c')
|
64
|
+
expected = groups.having("COUNT(*) > 1 OR body like 'Such%'").to_a.map {|o| [o.body, o.c] }
|
65
|
+
assert_equal expected, groups.having('COUNT(*) > 1').or(groups.having("body like 'Such%'")).to_a.map {|o| [o.body, o.c] }
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_or_with_named_scope
|
69
|
+
expected = Post.where("id = 1 or body LIKE '\%a\%'").to_a
|
70
|
+
assert_equal expected, Post.where('id = 1').or(Post.containing_the_letter_a)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_or_inside_named_scope
|
74
|
+
expected = Post.where("body LIKE '\%a\%' OR title LIKE ?", "%'%").order('id DESC').to_a
|
75
|
+
assert_equal expected, Post.order(id: :desc).typographically_interesting
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_or_on_loaded_relation
|
79
|
+
expected = Post.where('id = 1 or id = 2').to_a
|
80
|
+
p = Post.where('id = 1')
|
81
|
+
p.load
|
82
|
+
assert_equal p.loaded?, true
|
83
|
+
assert_equal expected, p.or(Post.where('id = 2')).to_a
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_or_with_non_relation_object_raises_error
|
87
|
+
assert_raises ArgumentError do
|
88
|
+
Post.where(id: [1, 2, 3]).or(title: 'Rails')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|