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
@@ -4,11 +4,13 @@ require 'models/topic'
|
|
4
4
|
module ActiveRecord
|
5
5
|
class PredicateBuilderTest < ActiveRecord::TestCase
|
6
6
|
def test_registering_new_handlers
|
7
|
-
|
7
|
+
Topic.predicate_builder.register_handler(Regexp, proc do |column, value|
|
8
8
|
Arel::Nodes::InfixOperation.new('~', column, Arel.sql(value.source))
|
9
9
|
end)
|
10
10
|
|
11
|
-
assert_match %r{["`]topics["`]
|
11
|
+
assert_match %r{["`]topics["`]\.["`]title["`] ~ rails}i, Topic.where(title: /rails/).to_sql
|
12
|
+
ensure
|
13
|
+
Topic.reset_column_information
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
require 'models/post'
|
3
|
+
require 'active_record/relation/record_fetch_warning'
|
4
|
+
|
5
|
+
module ActiveRecord
|
6
|
+
class RecordFetchWarningTest < ActiveRecord::TestCase
|
7
|
+
fixtures :posts
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@original_logger = ActiveRecord::Base.logger
|
11
|
+
@original_warn_on_records_fetched_greater_than = ActiveRecord::Base.warn_on_records_fetched_greater_than
|
12
|
+
@log = StringIO.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
ActiveRecord::Base.logger = @original_logger
|
17
|
+
ActiveRecord::Base.warn_on_records_fetched_greater_than = @original_warn_on_records_fetched_greater_than
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_warn_on_records_fetched_greater_than_allowed_limit
|
21
|
+
ActiveRecord::Base.logger = ActiveSupport::Logger.new(@log)
|
22
|
+
ActiveRecord::Base.logger.level = Logger::WARN
|
23
|
+
ActiveRecord::Base.warn_on_records_fetched_greater_than = 1
|
24
|
+
|
25
|
+
Post.all.to_a
|
26
|
+
|
27
|
+
assert_match(/Query fetched/, @log.string)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_does_not_warn_on_records_fetched_less_than_allowed_limit
|
31
|
+
ActiveRecord::Base.logger = ActiveSupport::Logger.new(@log)
|
32
|
+
ActiveRecord::Base.logger.level = Logger::WARN
|
33
|
+
ActiveRecord::Base.warn_on_records_fetched_greater_than = 100
|
34
|
+
|
35
|
+
Post.all.to_a
|
36
|
+
|
37
|
+
assert_no_match(/Query fetched/, @log.string)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -11,22 +11,11 @@ module ActiveRecord
|
|
11
11
|
@name = 'title'
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def test_not_inverts_where_clause
|
15
15
|
relation = Post.where.not(title: 'hello')
|
16
|
+
expected_where_clause = Post.where(title: 'hello').where_clause.invert
|
16
17
|
|
17
|
-
assert_equal
|
18
|
-
|
19
|
-
value = relation.where_values.first
|
20
|
-
bind = relation.bind_values.first
|
21
|
-
|
22
|
-
assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual
|
23
|
-
assert_equal 'hello', bind.last
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_not_null
|
27
|
-
expected = Post.arel_table[@name].not_eq(nil)
|
28
|
-
relation = Post.where.not(title: nil)
|
29
|
-
assert_equal([expected], relation.where_values)
|
18
|
+
assert_equal expected_where_clause, relation.where_clause
|
30
19
|
end
|
31
20
|
|
32
21
|
def test_not_with_nil
|
@@ -35,146 +24,81 @@ module ActiveRecord
|
|
35
24
|
end
|
36
25
|
end
|
37
26
|
|
38
|
-
def test_not_in
|
39
|
-
expected = Post.arel_table[@name].not_in(%w[hello goodbye])
|
40
|
-
relation = Post.where.not(title: %w[hello goodbye])
|
41
|
-
assert_equal([expected], relation.where_values)
|
42
|
-
end
|
43
|
-
|
44
27
|
def test_association_not_eq
|
45
|
-
expected = Comment.arel_table[@name].not_eq(
|
28
|
+
expected = Arel::Nodes::Grouping.new(Comment.arel_table[@name].not_eq(Arel::Nodes::BindParam.new))
|
46
29
|
relation = Post.joins(:comments).where.not(comments: {title: 'hello'})
|
47
|
-
assert_equal(expected.to_sql, relation.
|
30
|
+
assert_equal(expected.to_sql, relation.where_clause.ast.to_sql)
|
48
31
|
end
|
49
32
|
|
50
33
|
def test_not_eq_with_preceding_where
|
51
34
|
relation = Post.where(title: 'hello').where.not(title: 'world')
|
35
|
+
expected_where_clause =
|
36
|
+
Post.where(title: 'hello').where_clause +
|
37
|
+
Post.where(title: 'world').where_clause.invert
|
52
38
|
|
53
|
-
|
54
|
-
bind = relation.bind_values.first
|
55
|
-
assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::Equality
|
56
|
-
assert_equal 'hello', bind.last
|
57
|
-
|
58
|
-
value = relation.where_values.last
|
59
|
-
bind = relation.bind_values.last
|
60
|
-
assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual
|
61
|
-
assert_equal 'world', bind.last
|
39
|
+
assert_equal expected_where_clause, relation.where_clause
|
62
40
|
end
|
63
41
|
|
64
42
|
def test_not_eq_with_succeeding_where
|
65
43
|
relation = Post.where.not(title: 'hello').where(title: 'world')
|
44
|
+
expected_where_clause =
|
45
|
+
Post.where(title: 'hello').where_clause.invert +
|
46
|
+
Post.where(title: 'world').where_clause
|
66
47
|
|
67
|
-
|
68
|
-
bind = relation.bind_values.first
|
69
|
-
assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual
|
70
|
-
assert_equal 'hello', bind.last
|
71
|
-
|
72
|
-
value = relation.where_values.last
|
73
|
-
bind = relation.bind_values.last
|
74
|
-
assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::Equality
|
75
|
-
assert_equal 'world', bind.last
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_not_eq_with_string_parameter
|
79
|
-
expected = Arel::Nodes::Not.new("title = 'hello'")
|
80
|
-
relation = Post.where.not("title = 'hello'")
|
81
|
-
assert_equal([expected], relation.where_values)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_not_eq_with_array_parameter
|
85
|
-
expected = Arel::Nodes::Not.new("title = 'hello'")
|
86
|
-
relation = Post.where.not(['title = ?', 'hello'])
|
87
|
-
assert_equal([expected], relation.where_values)
|
48
|
+
assert_equal expected_where_clause, relation.where_clause
|
88
49
|
end
|
89
50
|
|
90
51
|
def test_chaining_multiple
|
91
52
|
relation = Post.where.not(author_id: [1, 2]).where.not(title: 'ruby on rails')
|
53
|
+
expected_where_clause =
|
54
|
+
Post.where(author_id: [1, 2]).where_clause.invert +
|
55
|
+
Post.where(title: 'ruby on rails').where_clause.invert
|
92
56
|
|
93
|
-
|
94
|
-
assert_equal(expected, relation.where_values[0])
|
95
|
-
|
96
|
-
value = relation.where_values[1]
|
97
|
-
bind = relation.bind_values.first
|
98
|
-
|
99
|
-
assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::NotEqual
|
100
|
-
assert_equal 'ruby on rails', bind.last
|
57
|
+
assert_equal expected_where_clause, relation.where_clause
|
101
58
|
end
|
102
59
|
|
103
60
|
def test_rewhere_with_one_condition
|
104
61
|
relation = Post.where(title: 'hello').where(title: 'world').rewhere(title: 'alone')
|
62
|
+
expected = Post.where(title: 'alone')
|
105
63
|
|
106
|
-
assert_equal
|
107
|
-
value = relation.where_values.first
|
108
|
-
bind = relation.bind_values.first
|
109
|
-
assert_bound_ast value, Post.arel_table[@name], Arel::Nodes::Equality
|
110
|
-
assert_equal 'alone', bind.last
|
64
|
+
assert_equal expected.where_clause, relation.where_clause
|
111
65
|
end
|
112
66
|
|
113
67
|
def test_rewhere_with_multiple_overwriting_conditions
|
114
68
|
relation = Post.where(title: 'hello').where(body: 'world').rewhere(title: 'alone', body: 'again')
|
69
|
+
expected = Post.where(title: 'alone', body: 'again')
|
115
70
|
|
116
|
-
assert_equal
|
117
|
-
|
118
|
-
value = relation.where_values.first
|
119
|
-
bind = relation.bind_values.first
|
120
|
-
assert_bound_ast value, Post.arel_table['title'], Arel::Nodes::Equality
|
121
|
-
assert_equal 'alone', bind.last
|
122
|
-
|
123
|
-
value = relation.where_values[1]
|
124
|
-
bind = relation.bind_values[1]
|
125
|
-
assert_bound_ast value, Post.arel_table['body'], Arel::Nodes::Equality
|
126
|
-
assert_equal 'again', bind.last
|
127
|
-
end
|
128
|
-
|
129
|
-
def assert_bound_ast value, table, type
|
130
|
-
assert_equal table, value.left
|
131
|
-
assert_kind_of type, value
|
132
|
-
assert_kind_of Arel::Nodes::BindParam, value.right
|
71
|
+
assert_equal expected.where_clause, relation.where_clause
|
133
72
|
end
|
134
73
|
|
135
74
|
def test_rewhere_with_one_overwriting_condition_and_one_unrelated
|
136
75
|
relation = Post.where(title: 'hello').where(body: 'world').rewhere(title: 'alone')
|
76
|
+
expected = Post.where(body: 'world', title: 'alone')
|
137
77
|
|
138
|
-
assert_equal
|
139
|
-
|
140
|
-
value = relation.where_values.first
|
141
|
-
bind = relation.bind_values.first
|
142
|
-
|
143
|
-
assert_bound_ast value, Post.arel_table['body'], Arel::Nodes::Equality
|
144
|
-
assert_equal 'world', bind.last
|
145
|
-
|
146
|
-
value = relation.where_values.second
|
147
|
-
bind = relation.bind_values.second
|
148
|
-
|
149
|
-
assert_bound_ast value, Post.arel_table['title'], Arel::Nodes::Equality
|
150
|
-
assert_equal 'alone', bind.last
|
78
|
+
assert_equal expected.where_clause, relation.where_clause
|
151
79
|
end
|
152
80
|
|
153
81
|
def test_rewhere_with_range
|
154
82
|
relation = Post.where(comments_count: 1..3).rewhere(comments_count: 3..5)
|
155
83
|
|
156
|
-
assert_equal 1, relation.where_values.size
|
157
84
|
assert_equal Post.where(comments_count: 3..5), relation
|
158
85
|
end
|
159
86
|
|
160
87
|
def test_rewhere_with_infinite_upper_bound_range
|
161
88
|
relation = Post.where(comments_count: 1..Float::INFINITY).rewhere(comments_count: 3..5)
|
162
89
|
|
163
|
-
assert_equal 1, relation.where_values.size
|
164
90
|
assert_equal Post.where(comments_count: 3..5), relation
|
165
91
|
end
|
166
92
|
|
167
93
|
def test_rewhere_with_infinite_lower_bound_range
|
168
94
|
relation = Post.where(comments_count: -Float::INFINITY..1).rewhere(comments_count: 3..5)
|
169
95
|
|
170
|
-
assert_equal 1, relation.where_values.size
|
171
96
|
assert_equal Post.where(comments_count: 3..5), relation
|
172
97
|
end
|
173
98
|
|
174
99
|
def test_rewhere_with_infinite_range
|
175
100
|
relation = Post.where(comments_count: -Float::INFINITY..Float::INFINITY).rewhere(comments_count: 3..5)
|
176
101
|
|
177
|
-
assert_equal 1, relation.where_values.size
|
178
102
|
assert_equal Post.where(comments_count: 3..5), relation
|
179
103
|
end
|
180
104
|
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
|
3
|
+
class ActiveRecord::Relation
|
4
|
+
class WhereClauseTest < ActiveRecord::TestCase
|
5
|
+
test "+ combines two where clauses" do
|
6
|
+
first_clause = WhereClause.new([table["id"].eq(bind_param)], [["id", 1]])
|
7
|
+
second_clause = WhereClause.new([table["name"].eq(bind_param)], [["name", "Sean"]])
|
8
|
+
combined = WhereClause.new(
|
9
|
+
[table["id"].eq(bind_param), table["name"].eq(bind_param)],
|
10
|
+
[["id", 1], ["name", "Sean"]],
|
11
|
+
)
|
12
|
+
|
13
|
+
assert_equal combined, first_clause + second_clause
|
14
|
+
end
|
15
|
+
|
16
|
+
test "+ is associative, but not commutative" do
|
17
|
+
a = WhereClause.new(["a"], ["bind a"])
|
18
|
+
b = WhereClause.new(["b"], ["bind b"])
|
19
|
+
c = WhereClause.new(["c"], ["bind c"])
|
20
|
+
|
21
|
+
assert_equal a + (b + c), (a + b) + c
|
22
|
+
assert_not_equal a + b, b + a
|
23
|
+
end
|
24
|
+
|
25
|
+
test "an empty where clause is the identity value for +" do
|
26
|
+
clause = WhereClause.new([table["id"].eq(bind_param)], [["id", 1]])
|
27
|
+
|
28
|
+
assert_equal clause, clause + WhereClause.empty
|
29
|
+
end
|
30
|
+
|
31
|
+
test "merge combines two where clauses" do
|
32
|
+
a = WhereClause.new([table["id"].eq(1)], [])
|
33
|
+
b = WhereClause.new([table["name"].eq("Sean")], [])
|
34
|
+
expected = WhereClause.new([table["id"].eq(1), table["name"].eq("Sean")], [])
|
35
|
+
|
36
|
+
assert_equal expected, a.merge(b)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "merge keeps the right side, when two equality clauses reference the same column" do
|
40
|
+
a = WhereClause.new([table["id"].eq(1), table["name"].eq("Sean")], [])
|
41
|
+
b = WhereClause.new([table["name"].eq("Jim")], [])
|
42
|
+
expected = WhereClause.new([table["id"].eq(1), table["name"].eq("Jim")], [])
|
43
|
+
|
44
|
+
assert_equal expected, a.merge(b)
|
45
|
+
end
|
46
|
+
|
47
|
+
test "merge removes bind parameters matching overlapping equality clauses" do
|
48
|
+
a = WhereClause.new(
|
49
|
+
[table["id"].eq(bind_param), table["name"].eq(bind_param)],
|
50
|
+
[attribute("id", 1), attribute("name", "Sean")],
|
51
|
+
)
|
52
|
+
b = WhereClause.new(
|
53
|
+
[table["name"].eq(bind_param)],
|
54
|
+
[attribute("name", "Jim")]
|
55
|
+
)
|
56
|
+
expected = WhereClause.new(
|
57
|
+
[table["id"].eq(bind_param), table["name"].eq(bind_param)],
|
58
|
+
[attribute("id", 1), attribute("name", "Jim")],
|
59
|
+
)
|
60
|
+
|
61
|
+
assert_equal expected, a.merge(b)
|
62
|
+
end
|
63
|
+
|
64
|
+
test "merge allows for columns with the same name from different tables" do
|
65
|
+
skip "This is not possible as of 4.2, and the binds do not yet contain sufficient information for this to happen"
|
66
|
+
# We might be able to change the implementation to remove conflicts by index, rather than column name
|
67
|
+
end
|
68
|
+
|
69
|
+
test "a clause knows if it is empty" do
|
70
|
+
assert WhereClause.empty.empty?
|
71
|
+
assert_not WhereClause.new(["anything"], []).empty?
|
72
|
+
end
|
73
|
+
|
74
|
+
test "invert cannot handle nil" do
|
75
|
+
where_clause = WhereClause.new([nil], [])
|
76
|
+
|
77
|
+
assert_raises ArgumentError do
|
78
|
+
where_clause.invert
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
test "invert replaces each part of the predicate with its inverse" do
|
83
|
+
random_object = Object.new
|
84
|
+
original = WhereClause.new([
|
85
|
+
table["id"].in([1, 2, 3]),
|
86
|
+
table["id"].eq(1),
|
87
|
+
"sql literal",
|
88
|
+
random_object
|
89
|
+
], [])
|
90
|
+
expected = WhereClause.new([
|
91
|
+
table["id"].not_in([1, 2, 3]),
|
92
|
+
table["id"].not_eq(1),
|
93
|
+
Arel::Nodes::Not.new(Arel::Nodes::SqlLiteral.new("sql literal")),
|
94
|
+
Arel::Nodes::Not.new(random_object)
|
95
|
+
], [])
|
96
|
+
|
97
|
+
assert_equal expected, original.invert
|
98
|
+
end
|
99
|
+
|
100
|
+
test "accept removes binary predicates referencing a given column" do
|
101
|
+
where_clause = WhereClause.new([
|
102
|
+
table["id"].in([1, 2, 3]),
|
103
|
+
table["name"].eq(bind_param),
|
104
|
+
table["age"].gteq(bind_param),
|
105
|
+
], [
|
106
|
+
attribute("name", "Sean"),
|
107
|
+
attribute("age", 30),
|
108
|
+
])
|
109
|
+
expected = WhereClause.new([table["age"].gteq(bind_param)], [attribute("age", 30)])
|
110
|
+
|
111
|
+
assert_equal expected, where_clause.except("id", "name")
|
112
|
+
end
|
113
|
+
|
114
|
+
test "ast groups its predicates with AND" do
|
115
|
+
predicates = [
|
116
|
+
table["id"].in([1, 2, 3]),
|
117
|
+
table["name"].eq(bind_param),
|
118
|
+
]
|
119
|
+
where_clause = WhereClause.new(predicates, [])
|
120
|
+
expected = Arel::Nodes::And.new(predicates)
|
121
|
+
|
122
|
+
assert_equal expected, where_clause.ast
|
123
|
+
end
|
124
|
+
|
125
|
+
test "ast wraps any SQL literals in parenthesis" do
|
126
|
+
random_object = Object.new
|
127
|
+
where_clause = WhereClause.new([
|
128
|
+
table["id"].in([1, 2, 3]),
|
129
|
+
"foo = bar",
|
130
|
+
random_object,
|
131
|
+
], [])
|
132
|
+
expected = Arel::Nodes::And.new([
|
133
|
+
table["id"].in([1, 2, 3]),
|
134
|
+
Arel::Nodes::Grouping.new(Arel.sql("foo = bar")),
|
135
|
+
Arel::Nodes::Grouping.new(random_object),
|
136
|
+
])
|
137
|
+
|
138
|
+
assert_equal expected, where_clause.ast
|
139
|
+
end
|
140
|
+
|
141
|
+
test "ast removes any empty strings" do
|
142
|
+
where_clause = WhereClause.new([table["id"].in([1, 2, 3])], [])
|
143
|
+
where_clause_with_empty = WhereClause.new([table["id"].in([1, 2, 3]), ''], [])
|
144
|
+
|
145
|
+
assert_equal where_clause.ast, where_clause_with_empty.ast
|
146
|
+
end
|
147
|
+
|
148
|
+
test "or joins the two clauses using OR" do
|
149
|
+
where_clause = WhereClause.new([table["id"].eq(bind_param)], [attribute("id", 1)])
|
150
|
+
other_clause = WhereClause.new([table["name"].eq(bind_param)], [attribute("name", "Sean")])
|
151
|
+
expected_ast =
|
152
|
+
Arel::Nodes::Grouping.new(
|
153
|
+
Arel::Nodes::Or.new(table["id"].eq(bind_param), table["name"].eq(bind_param))
|
154
|
+
)
|
155
|
+
expected_binds = where_clause.binds + other_clause.binds
|
156
|
+
|
157
|
+
assert_equal expected_ast.to_sql, where_clause.or(other_clause).ast.to_sql
|
158
|
+
assert_equal expected_binds, where_clause.or(other_clause).binds
|
159
|
+
end
|
160
|
+
|
161
|
+
test "or returns an empty where clause when either side is empty" do
|
162
|
+
where_clause = WhereClause.new([table["id"].eq(bind_param)], [attribute("id", 1)])
|
163
|
+
|
164
|
+
assert_equal WhereClause.empty, where_clause.or(WhereClause.empty)
|
165
|
+
assert_equal WhereClause.empty, WhereClause.empty.or(where_clause)
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
|
170
|
+
def table
|
171
|
+
Arel::Table.new("table")
|
172
|
+
end
|
173
|
+
|
174
|
+
def bind_param
|
175
|
+
Arel::Nodes::BindParam.new
|
176
|
+
end
|
177
|
+
|
178
|
+
def attribute(name, value)
|
179
|
+
ActiveRecord::Attribute.with_cast_value(name, value, ActiveRecord::Type::Value.new)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -2,7 +2,7 @@ require "cases/helper"
|
|
2
2
|
require "models/author"
|
3
3
|
require "models/binary"
|
4
4
|
require "models/cake_designer"
|
5
|
-
require "models/
|
5
|
+
require "models/car"
|
6
6
|
require "models/chef"
|
7
7
|
require "models/comment"
|
8
8
|
require "models/edge"
|
@@ -15,7 +15,7 @@ require "models/vertex"
|
|
15
15
|
|
16
16
|
module ActiveRecord
|
17
17
|
class WhereTest < ActiveRecord::TestCase
|
18
|
-
fixtures :posts, :edges, :authors, :binaries, :essays, :
|
18
|
+
fixtures :posts, :edges, :authors, :binaries, :essays, :cars, :treasures, :price_estimates
|
19
19
|
|
20
20
|
def test_where_copies_bind_params
|
21
21
|
author = authors(:david)
|
@@ -30,6 +30,14 @@ module ActiveRecord
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_where_copies_bind_params_in_the_right_order
|
34
|
+
author = authors(:david)
|
35
|
+
posts = author.posts.where.not(id: 1)
|
36
|
+
joined = Post.where(id: posts, title: posts.first.title)
|
37
|
+
|
38
|
+
assert_equal joined, [posts.first]
|
39
|
+
end
|
40
|
+
|
33
41
|
def test_where_copies_arel_bind_params
|
34
42
|
chef = Chef.create!
|
35
43
|
CakeDesigner.create!(chef: chef)
|
@@ -107,16 +115,15 @@ module ActiveRecord
|
|
107
115
|
assert_equal expected.to_sql, actual.to_sql
|
108
116
|
end
|
109
117
|
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
hidden.id = 2
|
118
|
+
def test_polymorphic_array_where_multiple_types
|
119
|
+
treasure_1 = treasures(:diamond)
|
120
|
+
treasure_2 = treasures(:sapphire)
|
121
|
+
car = cars(:honda)
|
115
122
|
|
116
|
-
expected =
|
117
|
-
actual = PriceEstimate.where(estimate_of: [])
|
123
|
+
expected = [price_estimates(:diamond), price_estimates(:sapphire_1), price_estimates(:sapphire_2), price_estimates(:honda)].sort
|
124
|
+
actual = PriceEstimate.where(estimate_of: [treasure_1, treasure_2, car]).to_a.sort
|
118
125
|
|
119
|
-
assert_equal expected
|
126
|
+
assert_equal expected, actual
|
120
127
|
end
|
121
128
|
|
122
129
|
def test_polymorphic_nested_relation_where
|
@@ -207,12 +214,6 @@ module ActiveRecord
|
|
207
214
|
assert_equal 0, Post.where(:id => []).count
|
208
215
|
end
|
209
216
|
|
210
|
-
def test_where_with_table_name_and_nested_empty_array
|
211
|
-
assert_deprecated do
|
212
|
-
assert_equal [], Post.where(:id => [[]]).to_a
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
217
|
def test_where_with_empty_hash_and_no_foreign_key
|
217
218
|
assert_equal 0, Edge.where(:sink => {}).count
|
218
219
|
end
|
@@ -233,12 +234,10 @@ module ActiveRecord
|
|
233
234
|
assert_equal 0, count
|
234
235
|
end
|
235
236
|
|
236
|
-
unless current_adapter?(:IBM_DBAdapter)
|
237
237
|
def test_where_with_boolean_for_string_column
|
238
238
|
count = Post.where(:title => false).count
|
239
239
|
assert_equal 0, count
|
240
240
|
end
|
241
|
-
end
|
242
241
|
|
243
242
|
def test_where_with_decimal_for_string_column
|
244
243
|
count = Post.where(:title => BigDecimal.new(0)).count
|
@@ -249,12 +248,11 @@ module ActiveRecord
|
|
249
248
|
count = Post.where(:title => 0.seconds).count
|
250
249
|
assert_equal 0, count
|
251
250
|
end
|
252
|
-
|
251
|
+
|
253
252
|
def test_where_with_integer_for_binary_column
|
254
253
|
count = Binary.where(:data => 0).count
|
255
254
|
assert_equal 0, count
|
256
255
|
end
|
257
|
-
end
|
258
256
|
|
259
257
|
def test_where_on_association_with_custom_primary_key
|
260
258
|
author = authors(:david)
|
@@ -291,10 +289,34 @@ module ActiveRecord
|
|
291
289
|
assert_equal essays(:david_modest_proposal), essay
|
292
290
|
end
|
293
291
|
|
294
|
-
def
|
295
|
-
|
292
|
+
def test_where_with_strong_parameters
|
293
|
+
protected_params = Class.new do
|
294
|
+
attr_reader :permitted
|
295
|
+
alias :permitted? :permitted
|
296
296
|
|
297
|
-
|
297
|
+
def initialize(parameters)
|
298
|
+
@parameters = parameters
|
299
|
+
@permitted = false
|
300
|
+
end
|
301
|
+
|
302
|
+
def to_h
|
303
|
+
@parameters
|
304
|
+
end
|
305
|
+
|
306
|
+
def permit!
|
307
|
+
@permitted = true
|
308
|
+
self
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
author = authors(:david)
|
313
|
+
params = protected_params.new(name: author.name)
|
314
|
+
assert_raises(ActiveModel::ForbiddenAttributesError) { Author.where(params) }
|
315
|
+
assert_equal author, Author.where(params.permit!).first
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_where_with_unsupported_arguments
|
319
|
+
assert_raises(ArgumentError) { Author.where(42) }
|
298
320
|
end
|
299
321
|
end
|
300
322
|
end
|