ibm_db 3.0.5-x86-mingw32 → 5.0.5-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/batches_test.rb
    CHANGED
    
    | 
         @@ -37,9 +37,9 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
              if Enumerator.method_defined? :size
         
     | 
| 
       39 
39 
     | 
    
         
             
                def test_each_should_return_a_sized_enumerator
         
     | 
| 
       40 
     | 
    
         
            -
                  assert_equal 11, Post.find_each(: 
     | 
| 
       41 
     | 
    
         
            -
                  assert_equal 5, Post.find_each(: 
     | 
| 
       42 
     | 
    
         
            -
                  assert_equal 11, Post.find_each(: 
     | 
| 
      
 40 
     | 
    
         
            +
                  assert_equal 11, Post.find_each(batch_size: 1).size
         
     | 
| 
      
 41 
     | 
    
         
            +
                  assert_equal 5, Post.find_each(batch_size:  2, start: 7).size
         
     | 
| 
      
 42 
     | 
    
         
            +
                  assert_equal 11, Post.find_each(batch_size: 10_000).size
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
       44 
44 
     | 
    
         
             
              end
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
         @@ -53,7 +53,7 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       53 
53 
     | 
    
         
             
              end
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
              def test_each_should_raise_if_select_is_set_without_id
         
     | 
| 
       56 
     | 
    
         
            -
                assert_raise( 
     | 
| 
      
 56 
     | 
    
         
            +
                assert_raise(ArgumentError) do
         
     | 
| 
       57 
57 
     | 
    
         
             
                  Post.select(:title).find_each(batch_size: 1) { |post|
         
     | 
| 
       58 
58 
     | 
    
         
             
                    flunk "should not call this block"
         
     | 
| 
       59 
59 
     | 
    
         
             
                  }
         
     | 
| 
         @@ -69,13 +69,15 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       69 
69 
     | 
    
         
             
              end
         
     | 
| 
       70 
70 
     | 
    
         | 
| 
       71 
71 
     | 
    
         
             
              def test_warn_if_limit_scope_is_set
         
     | 
| 
       72 
     | 
    
         
            -
                ActiveRecord::Base.logger 
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
                assert_called(ActiveRecord::Base.logger, :warn) do
         
     | 
| 
      
 73 
     | 
    
         
            +
                  Post.limit(1).find_each { |post| post }
         
     | 
| 
      
 74 
     | 
    
         
            +
                end
         
     | 
| 
       74 
75 
     | 
    
         
             
              end
         
     | 
| 
       75 
76 
     | 
    
         | 
| 
       76 
77 
     | 
    
         
             
              def test_warn_if_order_scope_is_set
         
     | 
| 
       77 
     | 
    
         
            -
                ActiveRecord::Base.logger 
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 78 
     | 
    
         
            +
                assert_called(ActiveRecord::Base.logger, :warn) do
         
     | 
| 
      
 79 
     | 
    
         
            +
                  Post.order("title").find_each { |post| post }
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
       79 
81 
     | 
    
         
             
              end
         
     | 
| 
       80 
82 
     | 
    
         | 
| 
       81 
83 
     | 
    
         
             
              def test_logger_not_required
         
     | 
| 
         @@ -99,7 +101,16 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       99 
101 
     | 
    
         | 
| 
       100 
102 
     | 
    
         
             
              def test_find_in_batches_should_start_from_the_start_option
         
     | 
| 
       101 
103 
     | 
    
         
             
                assert_queries(@total) do
         
     | 
| 
       102 
     | 
    
         
            -
                  Post.find_in_batches(: 
     | 
| 
      
 104 
     | 
    
         
            +
                  Post.find_in_batches(batch_size: 1, start: 2) do |batch|
         
     | 
| 
      
 105 
     | 
    
         
            +
                    assert_kind_of Array, batch
         
     | 
| 
      
 106 
     | 
    
         
            +
                    assert_kind_of Post, batch.first
         
     | 
| 
      
 107 
     | 
    
         
            +
                  end
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
              def test_find_in_batches_should_end_at_the_finish_option
         
     | 
| 
      
 112 
     | 
    
         
            +
                assert_queries(6) do
         
     | 
| 
      
 113 
     | 
    
         
            +
                  Post.find_in_batches(batch_size: 1, finish: 5) do |batch|
         
     | 
| 
       103 
114 
     | 
    
         
             
                    assert_kind_of Array, batch
         
     | 
| 
       104 
115 
     | 
    
         
             
                    assert_kind_of Post, batch.first
         
     | 
| 
       105 
116 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -128,14 +139,15 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       128 
139 
     | 
    
         | 
| 
       129 
140 
     | 
    
         
             
              def test_find_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified
         
     | 
| 
       130 
141 
     | 
    
         
             
                not_a_post = "not a post"
         
     | 
| 
       131 
     | 
    
         
            -
                not_a_post. 
     | 
| 
      
 142 
     | 
    
         
            +
                def not_a_post.id; end
         
     | 
| 
      
 143 
     | 
    
         
            +
                not_a_post.stub(:id, ->{ raise StandardError.new("not_a_post had #id called on it") }) do
         
     | 
| 
      
 144 
     | 
    
         
            +
                  assert_nothing_raised do
         
     | 
| 
      
 145 
     | 
    
         
            +
                    Post.find_in_batches(:batch_size => 1) do |batch|
         
     | 
| 
      
 146 
     | 
    
         
            +
                      assert_kind_of Array, batch
         
     | 
| 
      
 147 
     | 
    
         
            +
                      assert_kind_of Post, batch.first
         
     | 
| 
       132 
148 
     | 
    
         | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
                    assert_kind_of Array, batch
         
     | 
| 
       136 
     | 
    
         
            -
                    assert_kind_of Post, batch.first
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
                    batch.map! { not_a_post }
         
     | 
| 
      
 149 
     | 
    
         
            +
                      batch.map! { not_a_post }
         
     | 
| 
      
 150 
     | 
    
         
            +
                    end
         
     | 
| 
       139 
151 
     | 
    
         
             
                  end
         
     | 
| 
       140 
152 
     | 
    
         
             
                end
         
     | 
| 
       141 
153 
     | 
    
         
             
              end
         
     | 
| 
         @@ -149,7 +161,43 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       149 
161 
     | 
    
         
             
                end
         
     | 
| 
       150 
162 
     | 
    
         
             
                # posts.first will be ordered using id only. Title order scope should not apply here
         
     | 
| 
       151 
163 
     | 
    
         
             
                assert_not_equal first_post, posts.first
         
     | 
| 
       152 
     | 
    
         
            -
                assert_equal posts(:welcome), posts.first
         
     | 
| 
      
 164 
     | 
    
         
            +
                assert_equal posts(:welcome).id, posts.first.id
         
     | 
| 
      
 165 
     | 
    
         
            +
              end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
              def test_find_in_batches_should_error_on_ignore_the_order
         
     | 
| 
      
 168 
     | 
    
         
            +
                assert_raise(ArgumentError) do
         
     | 
| 
      
 169 
     | 
    
         
            +
                  PostWithDefaultScope.find_in_batches(error_on_ignore: true){}
         
     | 
| 
      
 170 
     | 
    
         
            +
                end
         
     | 
| 
      
 171 
     | 
    
         
            +
              end
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
              def test_find_in_batches_should_not_error_if_config_overriden
         
     | 
| 
      
 174 
     | 
    
         
            +
                # Set the config option which will be overriden
         
     | 
| 
      
 175 
     | 
    
         
            +
                prev = ActiveRecord::Base.error_on_ignored_order_or_limit
         
     | 
| 
      
 176 
     | 
    
         
            +
                ActiveRecord::Base.error_on_ignored_order_or_limit = true
         
     | 
| 
      
 177 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 178 
     | 
    
         
            +
                  PostWithDefaultScope.find_in_batches(error_on_ignore: false){}
         
     | 
| 
      
 179 
     | 
    
         
            +
                end
         
     | 
| 
      
 180 
     | 
    
         
            +
              ensure
         
     | 
| 
      
 181 
     | 
    
         
            +
                # Set back to default
         
     | 
| 
      
 182 
     | 
    
         
            +
                ActiveRecord::Base.error_on_ignored_order_or_limit = prev
         
     | 
| 
      
 183 
     | 
    
         
            +
              end
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
      
 185 
     | 
    
         
            +
              def test_find_in_batches_should_error_on_config_specified_to_error
         
     | 
| 
      
 186 
     | 
    
         
            +
                # Set the config option
         
     | 
| 
      
 187 
     | 
    
         
            +
                prev = ActiveRecord::Base.error_on_ignored_order_or_limit
         
     | 
| 
      
 188 
     | 
    
         
            +
                ActiveRecord::Base.error_on_ignored_order_or_limit = true
         
     | 
| 
      
 189 
     | 
    
         
            +
                assert_raise(ArgumentError) do
         
     | 
| 
      
 190 
     | 
    
         
            +
                  PostWithDefaultScope.find_in_batches(){}
         
     | 
| 
      
 191 
     | 
    
         
            +
                end
         
     | 
| 
      
 192 
     | 
    
         
            +
              ensure
         
     | 
| 
      
 193 
     | 
    
         
            +
                # Set back to default
         
     | 
| 
      
 194 
     | 
    
         
            +
                ActiveRecord::Base.error_on_ignored_order_or_limit = prev
         
     | 
| 
      
 195 
     | 
    
         
            +
              end
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
              def test_find_in_batches_should_not_error_by_default
         
     | 
| 
      
 198 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 199 
     | 
    
         
            +
                  PostWithDefaultScope.find_in_batches(){}
         
     | 
| 
      
 200 
     | 
    
         
            +
                end
         
     | 
| 
       153 
201 
     | 
    
         
             
              end
         
     | 
| 
       154 
202 
     | 
    
         | 
| 
       155 
203 
     | 
    
         
             
              def test_find_in_batches_should_not_ignore_the_default_scope_if_it_is_other_then_order
         
     | 
| 
         @@ -172,7 +220,7 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       172 
220 
     | 
    
         
             
                start_nick = nick_order_subscribers.second.nick
         
     | 
| 
       173 
221 
     | 
    
         | 
| 
       174 
222 
     | 
    
         
             
                subscribers = []
         
     | 
| 
       175 
     | 
    
         
            -
                Subscriber.find_in_batches(: 
     | 
| 
      
 223 
     | 
    
         
            +
                Subscriber.find_in_batches(batch_size: 1, start: start_nick) do |batch|
         
     | 
| 
       176 
224 
     | 
    
         
             
                  subscribers.concat(batch)
         
     | 
| 
       177 
225 
     | 
    
         
             
                end
         
     | 
| 
       178 
226 
     | 
    
         | 
| 
         @@ -181,15 +229,16 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       181 
229 
     | 
    
         | 
| 
       182 
230 
     | 
    
         
             
              def test_find_in_batches_should_use_any_column_as_primary_key_when_start_is_not_specified
         
     | 
| 
       183 
231 
     | 
    
         
             
                assert_queries(Subscriber.count + 1) do
         
     | 
| 
       184 
     | 
    
         
            -
                  Subscriber. 
     | 
| 
       185 
     | 
    
         
            -
                    assert_kind_of  
     | 
| 
      
 232 
     | 
    
         
            +
                  Subscriber.find_in_batches(batch_size: 1) do |batch|
         
     | 
| 
      
 233 
     | 
    
         
            +
                    assert_kind_of Array, batch
         
     | 
| 
      
 234 
     | 
    
         
            +
                    assert_kind_of Subscriber, batch.first
         
     | 
| 
       186 
235 
     | 
    
         
             
                  end
         
     | 
| 
       187 
236 
     | 
    
         
             
                end
         
     | 
| 
       188 
237 
     | 
    
         
             
              end
         
     | 
| 
       189 
238 
     | 
    
         | 
| 
       190 
239 
     | 
    
         
             
              def test_find_in_batches_should_return_an_enumerator
         
     | 
| 
       191 
240 
     | 
    
         
             
                enum = nil
         
     | 
| 
       192 
     | 
    
         
            -
                 
     | 
| 
      
 241 
     | 
    
         
            +
                assert_no_queries do
         
     | 
| 
       193 
242 
     | 
    
         
             
                  enum = Post.find_in_batches(:batch_size => 1)
         
     | 
| 
       194 
243 
     | 
    
         
             
                end
         
     | 
| 
       195 
244 
     | 
    
         
             
                assert_queries(4) do
         
     | 
| 
         @@ -200,11 +249,239 @@ class EachTest < ActiveRecord::TestCase 
     | 
|
| 
       200 
249 
     | 
    
         
             
                end
         
     | 
| 
       201 
250 
     | 
    
         
             
              end
         
     | 
| 
       202 
251 
     | 
    
         | 
| 
      
 252 
     | 
    
         
            +
              def test_in_batches_should_not_execute_any_query
         
     | 
| 
      
 253 
     | 
    
         
            +
                assert_no_queries do
         
     | 
| 
      
 254 
     | 
    
         
            +
                  assert_kind_of ActiveRecord::Batches::BatchEnumerator, Post.in_batches(of: 2)
         
     | 
| 
      
 255 
     | 
    
         
            +
                end
         
     | 
| 
      
 256 
     | 
    
         
            +
              end
         
     | 
| 
      
 257 
     | 
    
         
            +
             
     | 
| 
      
 258 
     | 
    
         
            +
              def test_in_batches_should_yield_relation_if_block_given
         
     | 
| 
      
 259 
     | 
    
         
            +
                assert_queries(6) do
         
     | 
| 
      
 260 
     | 
    
         
            +
                  Post.in_batches(of: 2) do |relation|
         
     | 
| 
      
 261 
     | 
    
         
            +
                    assert_kind_of ActiveRecord::Relation, relation
         
     | 
| 
      
 262 
     | 
    
         
            +
                  end
         
     | 
| 
      
 263 
     | 
    
         
            +
                end
         
     | 
| 
      
 264 
     | 
    
         
            +
              end
         
     | 
| 
      
 265 
     | 
    
         
            +
             
     | 
| 
      
 266 
     | 
    
         
            +
              def test_in_batches_should_be_enumerable_if_no_block_given
         
     | 
| 
      
 267 
     | 
    
         
            +
                assert_queries(6) do
         
     | 
| 
      
 268 
     | 
    
         
            +
                  Post.in_batches(of: 2).each do |relation|
         
     | 
| 
      
 269 
     | 
    
         
            +
                    assert_kind_of ActiveRecord::Relation, relation
         
     | 
| 
      
 270 
     | 
    
         
            +
                  end
         
     | 
| 
      
 271 
     | 
    
         
            +
                end
         
     | 
| 
      
 272 
     | 
    
         
            +
              end
         
     | 
| 
      
 273 
     | 
    
         
            +
             
     | 
| 
      
 274 
     | 
    
         
            +
              def test_in_batches_each_record_should_yield_record_if_block_is_given
         
     | 
| 
      
 275 
     | 
    
         
            +
                assert_queries(6) do
         
     | 
| 
      
 276 
     | 
    
         
            +
                  Post.in_batches(of: 2).each_record do |post|
         
     | 
| 
      
 277 
     | 
    
         
            +
                    assert post.title.present?
         
     | 
| 
      
 278 
     | 
    
         
            +
                    assert_kind_of Post, post
         
     | 
| 
      
 279 
     | 
    
         
            +
                  end
         
     | 
| 
      
 280 
     | 
    
         
            +
                end
         
     | 
| 
      
 281 
     | 
    
         
            +
              end
         
     | 
| 
      
 282 
     | 
    
         
            +
             
     | 
| 
      
 283 
     | 
    
         
            +
              def test_in_batches_each_record_should_return_enumerator_if_no_block_given
         
     | 
| 
      
 284 
     | 
    
         
            +
                assert_queries(6) do
         
     | 
| 
      
 285 
     | 
    
         
            +
                  Post.in_batches(of: 2).each_record.with_index do |post, i|
         
     | 
| 
      
 286 
     | 
    
         
            +
                    assert post.title.present?
         
     | 
| 
      
 287 
     | 
    
         
            +
                    assert_kind_of Post, post
         
     | 
| 
      
 288 
     | 
    
         
            +
                  end
         
     | 
| 
      
 289 
     | 
    
         
            +
                end
         
     | 
| 
      
 290 
     | 
    
         
            +
              end
         
     | 
| 
      
 291 
     | 
    
         
            +
             
     | 
| 
      
 292 
     | 
    
         
            +
              def test_in_batches_each_record_should_be_ordered_by_id
         
     | 
| 
      
 293 
     | 
    
         
            +
                ids = Post.order('id ASC').pluck(:id)
         
     | 
| 
      
 294 
     | 
    
         
            +
                assert_queries(6) do
         
     | 
| 
      
 295 
     | 
    
         
            +
                  Post.in_batches(of: 2).each_record.with_index do |post, i|
         
     | 
| 
      
 296 
     | 
    
         
            +
                    assert_equal ids[i], post.id
         
     | 
| 
      
 297 
     | 
    
         
            +
                  end
         
     | 
| 
      
 298 
     | 
    
         
            +
                end
         
     | 
| 
      
 299 
     | 
    
         
            +
              end
         
     | 
| 
      
 300 
     | 
    
         
            +
             
     | 
| 
      
 301 
     | 
    
         
            +
              def test_in_batches_update_all_affect_all_records
         
     | 
| 
      
 302 
     | 
    
         
            +
                assert_queries(6 + 6) do # 6 selects, 6 updates
         
     | 
| 
      
 303 
     | 
    
         
            +
                  Post.in_batches(of: 2).update_all(title: "updated-title")
         
     | 
| 
      
 304 
     | 
    
         
            +
                end
         
     | 
| 
      
 305 
     | 
    
         
            +
                assert_equal Post.all.pluck(:title), ["updated-title"] * Post.count
         
     | 
| 
      
 306 
     | 
    
         
            +
              end
         
     | 
| 
      
 307 
     | 
    
         
            +
             
     | 
| 
      
 308 
     | 
    
         
            +
              def test_in_batches_delete_all_should_not_delete_records_in_other_batches
         
     | 
| 
      
 309 
     | 
    
         
            +
                not_deleted_count = Post.where('id <= 2').count
         
     | 
| 
      
 310 
     | 
    
         
            +
                Post.where('id > 2').in_batches(of: 2).delete_all
         
     | 
| 
      
 311 
     | 
    
         
            +
                assert_equal 0, Post.where('id > 2').count
         
     | 
| 
      
 312 
     | 
    
         
            +
                assert_equal not_deleted_count, Post.count
         
     | 
| 
      
 313 
     | 
    
         
            +
              end
         
     | 
| 
      
 314 
     | 
    
         
            +
             
     | 
| 
      
 315 
     | 
    
         
            +
              def test_in_batches_should_not_be_loaded
         
     | 
| 
      
 316 
     | 
    
         
            +
                Post.in_batches(of: 1) do |relation|
         
     | 
| 
      
 317 
     | 
    
         
            +
                  assert_not relation.loaded?
         
     | 
| 
      
 318 
     | 
    
         
            +
                end
         
     | 
| 
      
 319 
     | 
    
         
            +
             
     | 
| 
      
 320 
     | 
    
         
            +
                Post.in_batches(of: 1, load: false) do |relation|
         
     | 
| 
      
 321 
     | 
    
         
            +
                  assert_not relation.loaded?
         
     | 
| 
      
 322 
     | 
    
         
            +
                end
         
     | 
| 
      
 323 
     | 
    
         
            +
              end
         
     | 
| 
      
 324 
     | 
    
         
            +
             
     | 
| 
      
 325 
     | 
    
         
            +
              def test_in_batches_should_be_loaded
         
     | 
| 
      
 326 
     | 
    
         
            +
                Post.in_batches(of: 1, load: true) do |relation|
         
     | 
| 
      
 327 
     | 
    
         
            +
                  assert relation.loaded?
         
     | 
| 
      
 328 
     | 
    
         
            +
                end
         
     | 
| 
      
 329 
     | 
    
         
            +
              end
         
     | 
| 
      
 330 
     | 
    
         
            +
             
     | 
| 
      
 331 
     | 
    
         
            +
              def test_in_batches_if_not_loaded_executes_more_queries
         
     | 
| 
      
 332 
     | 
    
         
            +
                assert_queries(@total + 1) do
         
     | 
| 
      
 333 
     | 
    
         
            +
                  Post.in_batches(of: 1, load: false) do |relation|
         
     | 
| 
      
 334 
     | 
    
         
            +
                    assert_not relation.loaded?
         
     | 
| 
      
 335 
     | 
    
         
            +
                  end
         
     | 
| 
      
 336 
     | 
    
         
            +
                end
         
     | 
| 
      
 337 
     | 
    
         
            +
              end
         
     | 
| 
      
 338 
     | 
    
         
            +
             
     | 
| 
      
 339 
     | 
    
         
            +
              def test_in_batches_should_return_relations
         
     | 
| 
      
 340 
     | 
    
         
            +
                assert_queries(@total + 1) do
         
     | 
| 
      
 341 
     | 
    
         
            +
                  Post.in_batches(of: 1) do |relation|
         
     | 
| 
      
 342 
     | 
    
         
            +
                    assert_kind_of ActiveRecord::Relation, relation
         
     | 
| 
      
 343 
     | 
    
         
            +
                  end
         
     | 
| 
      
 344 
     | 
    
         
            +
                end
         
     | 
| 
      
 345 
     | 
    
         
            +
              end
         
     | 
| 
      
 346 
     | 
    
         
            +
             
     | 
| 
      
 347 
     | 
    
         
            +
              def test_in_batches_should_start_from_the_start_option
         
     | 
| 
      
 348 
     | 
    
         
            +
                post = Post.order('id ASC').where('id >= ?', 2).first
         
     | 
| 
      
 349 
     | 
    
         
            +
                assert_queries(2) do
         
     | 
| 
      
 350 
     | 
    
         
            +
                  relation = Post.in_batches(of: 1, start: 2).first
         
     | 
| 
      
 351 
     | 
    
         
            +
                  assert_equal post, relation.first
         
     | 
| 
      
 352 
     | 
    
         
            +
                end
         
     | 
| 
      
 353 
     | 
    
         
            +
              end
         
     | 
| 
      
 354 
     | 
    
         
            +
             
     | 
| 
      
 355 
     | 
    
         
            +
              def test_in_batches_should_end_at_the_finish_option
         
     | 
| 
      
 356 
     | 
    
         
            +
                post = Post.order('id DESC').where('id <= ?', 5).first
         
     | 
| 
      
 357 
     | 
    
         
            +
                assert_queries(7) do
         
     | 
| 
      
 358 
     | 
    
         
            +
                  relation = Post.in_batches(of: 1, finish: 5, load: true).reverse_each.first
         
     | 
| 
      
 359 
     | 
    
         
            +
                  assert_equal post, relation.last
         
     | 
| 
      
 360 
     | 
    
         
            +
                end
         
     | 
| 
      
 361 
     | 
    
         
            +
              end
         
     | 
| 
      
 362 
     | 
    
         
            +
             
     | 
| 
      
 363 
     | 
    
         
            +
              def test_in_batches_shouldnt_execute_query_unless_needed
         
     | 
| 
      
 364 
     | 
    
         
            +
                assert_queries(2) do
         
     | 
| 
      
 365 
     | 
    
         
            +
                  Post.in_batches(of: @total) { |relation| assert_kind_of ActiveRecord::Relation, relation }
         
     | 
| 
      
 366 
     | 
    
         
            +
                end
         
     | 
| 
      
 367 
     | 
    
         
            +
             
     | 
| 
      
 368 
     | 
    
         
            +
                assert_queries(1) do
         
     | 
| 
      
 369 
     | 
    
         
            +
                  Post.in_batches(of: @total + 1) { |relation| assert_kind_of ActiveRecord::Relation, relation }
         
     | 
| 
      
 370 
     | 
    
         
            +
                end
         
     | 
| 
      
 371 
     | 
    
         
            +
              end
         
     | 
| 
      
 372 
     | 
    
         
            +
             
     | 
| 
      
 373 
     | 
    
         
            +
              def test_in_batches_should_quote_batch_order
         
     | 
| 
      
 374 
     | 
    
         
            +
                c = Post.connection
         
     | 
| 
      
 375 
     | 
    
         
            +
                assert_sql(/ORDER BY #{c.quote_table_name('posts')}.#{c.quote_column_name('id')}/) do
         
     | 
| 
      
 376 
     | 
    
         
            +
                  Post.in_batches(of: 1) do |relation|
         
     | 
| 
      
 377 
     | 
    
         
            +
                    assert_kind_of ActiveRecord::Relation, relation
         
     | 
| 
      
 378 
     | 
    
         
            +
                    assert_kind_of Post, relation.first
         
     | 
| 
      
 379 
     | 
    
         
            +
                  end
         
     | 
| 
      
 380 
     | 
    
         
            +
                end
         
     | 
| 
      
 381 
     | 
    
         
            +
              end
         
     | 
| 
      
 382 
     | 
    
         
            +
             
     | 
| 
      
 383 
     | 
    
         
            +
              def test_in_batches_should_not_use_records_after_yielding_them_in_case_original_array_is_modified
         
     | 
| 
      
 384 
     | 
    
         
            +
                not_a_post = "not a post"
         
     | 
| 
      
 385 
     | 
    
         
            +
                def not_a_post.id
         
     | 
| 
      
 386 
     | 
    
         
            +
                  raise StandardError.new("not_a_post had #id called on it")
         
     | 
| 
      
 387 
     | 
    
         
            +
                end
         
     | 
| 
      
 388 
     | 
    
         
            +
             
     | 
| 
      
 389 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 390 
     | 
    
         
            +
                  Post.in_batches(of: 1) do |relation|
         
     | 
| 
      
 391 
     | 
    
         
            +
                    assert_kind_of ActiveRecord::Relation, relation
         
     | 
| 
      
 392 
     | 
    
         
            +
                    assert_kind_of Post, relation.first
         
     | 
| 
      
 393 
     | 
    
         
            +
             
     | 
| 
      
 394 
     | 
    
         
            +
                    relation = [not_a_post] * relation.count
         
     | 
| 
      
 395 
     | 
    
         
            +
                  end
         
     | 
| 
      
 396 
     | 
    
         
            +
                end
         
     | 
| 
      
 397 
     | 
    
         
            +
              end
         
     | 
| 
      
 398 
     | 
    
         
            +
             
     | 
| 
      
 399 
     | 
    
         
            +
              def test_in_batches_should_not_ignore_default_scope_without_order_statements
         
     | 
| 
      
 400 
     | 
    
         
            +
                special_posts_ids = SpecialPostWithDefaultScope.all.map(&:id).sort
         
     | 
| 
      
 401 
     | 
    
         
            +
                posts = []
         
     | 
| 
      
 402 
     | 
    
         
            +
                SpecialPostWithDefaultScope.in_batches do |relation|
         
     | 
| 
      
 403 
     | 
    
         
            +
                  posts.concat(relation)
         
     | 
| 
      
 404 
     | 
    
         
            +
                end
         
     | 
| 
      
 405 
     | 
    
         
            +
                assert_equal special_posts_ids, posts.map(&:id)
         
     | 
| 
      
 406 
     | 
    
         
            +
              end
         
     | 
| 
      
 407 
     | 
    
         
            +
             
     | 
| 
      
 408 
     | 
    
         
            +
              def test_in_batches_should_not_modify_passed_options
         
     | 
| 
      
 409 
     | 
    
         
            +
                assert_nothing_raised do
         
     | 
| 
      
 410 
     | 
    
         
            +
                  Post.in_batches({ of: 42, start: 1 }.freeze){}
         
     | 
| 
      
 411 
     | 
    
         
            +
                end
         
     | 
| 
      
 412 
     | 
    
         
            +
              end
         
     | 
| 
      
 413 
     | 
    
         
            +
             
     | 
| 
      
 414 
     | 
    
         
            +
              def test_in_batches_should_use_any_column_as_primary_key
         
     | 
| 
      
 415 
     | 
    
         
            +
                nick_order_subscribers = Subscriber.order('nick asc')
         
     | 
| 
      
 416 
     | 
    
         
            +
                start_nick = nick_order_subscribers.second.nick
         
     | 
| 
      
 417 
     | 
    
         
            +
             
     | 
| 
      
 418 
     | 
    
         
            +
                subscribers = []
         
     | 
| 
      
 419 
     | 
    
         
            +
                Subscriber.in_batches(of: 1, start: start_nick) do |relation|
         
     | 
| 
      
 420 
     | 
    
         
            +
                  subscribers.concat(relation)
         
     | 
| 
      
 421 
     | 
    
         
            +
                end
         
     | 
| 
      
 422 
     | 
    
         
            +
             
     | 
| 
      
 423 
     | 
    
         
            +
                assert_equal nick_order_subscribers[1..-1].map(&:id), subscribers.map(&:id)
         
     | 
| 
      
 424 
     | 
    
         
            +
              end
         
     | 
| 
      
 425 
     | 
    
         
            +
             
     | 
| 
      
 426 
     | 
    
         
            +
              def test_in_batches_should_use_any_column_as_primary_key_when_start_is_not_specified
         
     | 
| 
      
 427 
     | 
    
         
            +
                assert_queries(Subscriber.count + 1) do
         
     | 
| 
      
 428 
     | 
    
         
            +
                  Subscriber.in_batches(of: 1, load: true) do |relation|
         
     | 
| 
      
 429 
     | 
    
         
            +
                    assert_kind_of ActiveRecord::Relation, relation
         
     | 
| 
      
 430 
     | 
    
         
            +
                    assert_kind_of Subscriber, relation.first
         
     | 
| 
      
 431 
     | 
    
         
            +
                  end
         
     | 
| 
      
 432 
     | 
    
         
            +
                end
         
     | 
| 
      
 433 
     | 
    
         
            +
              end
         
     | 
| 
      
 434 
     | 
    
         
            +
             
     | 
| 
      
 435 
     | 
    
         
            +
              def test_in_batches_should_return_an_enumerator
         
     | 
| 
      
 436 
     | 
    
         
            +
                enum = nil
         
     | 
| 
      
 437 
     | 
    
         
            +
                assert_no_queries do
         
     | 
| 
      
 438 
     | 
    
         
            +
                  enum = Post.in_batches(of: 1)
         
     | 
| 
      
 439 
     | 
    
         
            +
                end
         
     | 
| 
      
 440 
     | 
    
         
            +
                assert_queries(4) do
         
     | 
| 
      
 441 
     | 
    
         
            +
                  enum.first(4) do |relation|
         
     | 
| 
      
 442 
     | 
    
         
            +
                    assert_kind_of ActiveRecord::Relation, relation
         
     | 
| 
      
 443 
     | 
    
         
            +
                    assert_kind_of Post, relation.first
         
     | 
| 
      
 444 
     | 
    
         
            +
                  end
         
     | 
| 
      
 445 
     | 
    
         
            +
                end
         
     | 
| 
      
 446 
     | 
    
         
            +
              end
         
     | 
| 
      
 447 
     | 
    
         
            +
             
     | 
| 
      
 448 
     | 
    
         
            +
              def test_in_batches_relations_should_not_overlap_with_each_other
         
     | 
| 
      
 449 
     | 
    
         
            +
                seen_posts = []
         
     | 
| 
      
 450 
     | 
    
         
            +
                Post.in_batches(of: 2, load: true) do |relation|
         
     | 
| 
      
 451 
     | 
    
         
            +
                  relation.to_a.each do |post|
         
     | 
| 
      
 452 
     | 
    
         
            +
                    assert_not seen_posts.include?(post)
         
     | 
| 
      
 453 
     | 
    
         
            +
                    seen_posts << post
         
     | 
| 
      
 454 
     | 
    
         
            +
                  end
         
     | 
| 
      
 455 
     | 
    
         
            +
                end
         
     | 
| 
      
 456 
     | 
    
         
            +
              end
         
     | 
| 
      
 457 
     | 
    
         
            +
             
     | 
| 
      
 458 
     | 
    
         
            +
              def test_in_batches_relations_with_condition_should_not_overlap_with_each_other
         
     | 
| 
      
 459 
     | 
    
         
            +
                seen_posts = []
         
     | 
| 
      
 460 
     | 
    
         
            +
                author_id = Post.first.author_id
         
     | 
| 
      
 461 
     | 
    
         
            +
                posts_by_author = Post.where(author_id: author_id)
         
     | 
| 
      
 462 
     | 
    
         
            +
                Post.in_batches(of: 2) do |batch|
         
     | 
| 
      
 463 
     | 
    
         
            +
                  seen_posts += batch.where(author_id: author_id)
         
     | 
| 
      
 464 
     | 
    
         
            +
                end
         
     | 
| 
      
 465 
     | 
    
         
            +
             
     | 
| 
      
 466 
     | 
    
         
            +
                assert_equal posts_by_author.pluck(:id).sort, seen_posts.map(&:id).sort
         
     | 
| 
      
 467 
     | 
    
         
            +
              end
         
     | 
| 
      
 468 
     | 
    
         
            +
             
     | 
| 
      
 469 
     | 
    
         
            +
              def test_in_batches_relations_update_all_should_not_affect_matching_records_in_other_batches
         
     | 
| 
      
 470 
     | 
    
         
            +
                Post.update_all(author_id: 0)
         
     | 
| 
      
 471 
     | 
    
         
            +
                person = Post.last
         
     | 
| 
      
 472 
     | 
    
         
            +
                person.update_attributes(author_id: 1)
         
     | 
| 
      
 473 
     | 
    
         
            +
             
     | 
| 
      
 474 
     | 
    
         
            +
                Post.in_batches(of: 2) do |batch|
         
     | 
| 
      
 475 
     | 
    
         
            +
                  batch.where('author_id >= 1').update_all('author_id = author_id + 1')
         
     | 
| 
      
 476 
     | 
    
         
            +
                end
         
     | 
| 
      
 477 
     | 
    
         
            +
                assert_equal 2, person.reload.author_id # incremented only once
         
     | 
| 
      
 478 
     | 
    
         
            +
              end
         
     | 
| 
      
 479 
     | 
    
         
            +
             
     | 
| 
       203 
480 
     | 
    
         
             
              if Enumerator.method_defined? :size
         
     | 
| 
       204 
481 
     | 
    
         
             
                def test_find_in_batches_should_return_a_sized_enumerator
         
     | 
| 
       205 
482 
     | 
    
         
             
                  assert_equal 11, Post.find_in_batches(:batch_size => 1).size
         
     | 
| 
       206 
483 
     | 
    
         
             
                  assert_equal 6, Post.find_in_batches(:batch_size => 2).size
         
     | 
| 
       207 
     | 
    
         
            -
                  assert_equal 4, Post.find_in_batches(: 
     | 
| 
      
 484 
     | 
    
         
            +
                  assert_equal 4, Post.find_in_batches(batch_size: 2, start: 4).size
         
     | 
| 
       208 
485 
     | 
    
         
             
                  assert_equal 4, Post.find_in_batches(:batch_size => 3).size
         
     | 
| 
       209 
486 
     | 
    
         
             
                  assert_equal 1, Post.find_in_batches(:batch_size => 10_000).size
         
     | 
| 
       210 
487 
     | 
    
         
             
                end
         
     | 
    
        data/test/cases/binary_test.rb
    CHANGED
    
    | 
         @@ -1,4 +1,3 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # encoding: utf-8
         
     | 
| 
       2 
1 
     | 
    
         
             
            require "cases/helper"
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
3 
     | 
    
         
             
            # Without using prepared statements, it makes no sense to test
         
     | 
| 
         @@ -21,10 +20,6 @@ unless current_adapter?(:DB2Adapter) 
     | 
|
| 
       21 
20 
     | 
    
         | 
| 
       22 
21 
     | 
    
         
             
                  name = binary.name
         
     | 
| 
       23 
22 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                  # MySQL adapter doesn't properly encode things, so we have to do it
         
     | 
| 
       25 
     | 
    
         
            -
                  if current_adapter?(:MysqlAdapter, :DB2Adapter)
         
     | 
| 
       26 
     | 
    
         
            -
                    name.force_encoding(Encoding::UTF_8)
         
     | 
| 
       27 
     | 
    
         
            -
                  end
         
     | 
| 
       28 
23 
     | 
    
         
             
                  assert_equal 'いただきます!', name
         
     | 
| 
       29 
24 
     | 
    
         
             
                end
         
     | 
| 
       30 
25 
     | 
    
         | 
| 
         @@ -32,11 +27,8 @@ unless current_adapter?(:DB2Adapter) 
     | 
|
| 
       32 
27 
     | 
    
         
             
                  Binary.delete_all
         
     | 
| 
       33 
28 
     | 
    
         | 
| 
       34 
29 
     | 
    
         
             
                  FIXTURES.each do |filename|
         
     | 
| 
       35 
     | 
    
         
            -
                    data = File.read(ASSETS_ROOT + "/#{filename}") 
     | 
| 
      
 30 
     | 
    
         
            +
                    data = File.read(ASSETS_ROOT + "/#{filename}")
         
     | 
| 
       36 
31 
     | 
    
         
             
                    data.force_encoding('ASCII-8BIT')
         
     | 
| 
       37 
     | 
    
         
            -
            		if current_adapter?(:DB2Adapter)
         
     | 
| 
       38 
     | 
    
         
            -
            			data.force_encoding(Encoding::UTF_8)
         
     | 
| 
       39 
     | 
    
         
            -
            		end
         
     | 
| 
       40 
32 
     | 
    
         
             
                    data.freeze
         
     | 
| 
       41 
33 
     | 
    
         | 
| 
       42 
34 
     | 
    
         
             
                    bin = Binary.new(:data => data)
         
     | 
| 
         @@ -44,7 +36,7 @@ unless current_adapter?(:DB2Adapter) 
     | 
|
| 
       44 
36 
     | 
    
         | 
| 
       45 
37 
     | 
    
         
             
                    bin.save!
         
     | 
| 
       46 
38 
     | 
    
         
             
                    assert_equal data, bin.data, 'Data differs from original after save'
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       48 
40 
     | 
    
         
             
                    assert_equal data, bin.reload.data, 'Reloaded data differs from original'
         
     | 
| 
       49 
41 
     | 
    
         
             
                  end
         
     | 
| 
       50 
42 
     | 
    
         
             
                end
         
     | 
| 
         @@ -3,44 +3,49 @@ require 'models/topic' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'models/author'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'models/post'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
            if ActiveRecord::Base.connection.supports_statement_cache? &&
         
     | 
| 
      
 7 
     | 
    
         
            +
               ActiveRecord::Base.connection.prepared_statements
         
     | 
| 
      
 8 
     | 
    
         
            +
              module ActiveRecord
         
     | 
| 
      
 9 
     | 
    
         
            +
                class BindParameterTest < ActiveRecord::TestCase
         
     | 
| 
      
 10 
     | 
    
         
            +
                  fixtures :topics, :authors, :posts
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  class LogListener
         
     | 
| 
      
 13 
     | 
    
         
            +
                    attr_accessor :calls
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    def initialize
         
     | 
| 
      
 16 
     | 
    
         
            +
                      @calls = []
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                    def call(*args)
         
     | 
| 
      
 20 
     | 
    
         
            +
                      calls << args
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
       15 
22 
     | 
    
         
             
                  end
         
     | 
| 
       16 
23 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                  def  
     | 
| 
       18 
     | 
    
         
            -
                     
     | 
| 
      
 24 
     | 
    
         
            +
                  def setup
         
     | 
| 
      
 25 
     | 
    
         
            +
                    super
         
     | 
| 
      
 26 
     | 
    
         
            +
            		puts "BindParameterTest - setup"
         
     | 
| 
      
 27 
     | 
    
         
            +
                    @connection = ActiveRecord::Base.connection
         
     | 
| 
      
 28 
     | 
    
         
            +
                    @subscriber = LogListener.new
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @pk = Topic.columns_hash[Topic.primary_key]
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @subscription = ActiveSupport::Notifications.subscribe("sql.active_record", @subscriber)
         
     | 
| 
       19 
31 
     | 
    
         
             
                  end
         
     | 
| 
       20 
     | 
    
         
            -
                end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                def setup
         
     | 
| 
       23 
     | 
    
         
            -
                  super
         
     | 
| 
       24 
     | 
    
         
            -
                  @connection = ActiveRecord::Base.connection
         
     | 
| 
       25 
     | 
    
         
            -
                  @subscriber   = LogListener.new
         
     | 
| 
       26 
     | 
    
         
            -
                  @pk         = Topic.columns_hash[Topic.primary_key]
         
     | 
| 
       27 
     | 
    
         
            -
                  @subscription = ActiveSupport::Notifications.subscribe('sql.active_record', @subscriber)
         
     | 
| 
       28 
     | 
    
         
            -
                end
         
     | 
| 
       29 
32 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 33 
     | 
    
         
            +
                  def teardown
         
     | 
| 
      
 34 
     | 
    
         
            +
            	    puts "BindParameterTest - teardown"
         
     | 
| 
      
 35 
     | 
    
         
            +
                    ActiveSupport::Notifications.unsubscribe(@subscription)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
       33 
37 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                if ActiveRecord::Base.connection.supports_statement_cache?
         
     | 
| 
       35 
38 
     | 
    
         
             
                  def test_bind_from_join_in_subquery
         
     | 
| 
      
 39 
     | 
    
         
            +
            	    puts "BindParameterTest - test_bind_from_join_in_subquery"
         
     | 
| 
       36 
40 
     | 
    
         
             
                    subquery = Author.joins(:thinking_posts).where(name: 'David')
         
     | 
| 
       37 
41 
     | 
    
         
             
                    scope = Author.from(subquery, 'authors').where(id: 1)
         
     | 
| 
       38 
42 
     | 
    
         
             
                    assert_equal 1, scope.count
         
     | 
| 
       39 
43 
     | 
    
         
             
                  end
         
     | 
| 
       40 
44 
     | 
    
         | 
| 
       41 
45 
     | 
    
         
             
                  def test_binds_are_logged
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                     
     | 
| 
      
 46 
     | 
    
         
            +
            	    puts "BindParameterTest - test_binds_are_logged"
         
     | 
| 
      
 47 
     | 
    
         
            +
                    sub   = Arel::Nodes::BindParam.new
         
     | 
| 
      
 48 
     | 
    
         
            +
                    binds = [Relation::QueryAttribute.new("id", 1, Type::Value.new)]
         
     | 
| 
       44 
49 
     | 
    
         
             
                    sql   = "select * from topics where id = #{sub.to_sql}"
         
     | 
| 
       45 
50 
     | 
    
         | 
| 
       46 
51 
     | 
    
         
             
                    @connection.exec_query(sql, 'SQL', binds)
         
     | 
| 
         @@ -49,52 +54,57 @@ module ActiveRecord 
     | 
|
| 
       49 
54 
     | 
    
         
             
                    assert_equal binds, message[4][:binds]
         
     | 
| 
       50 
55 
     | 
    
         
             
                  end
         
     | 
| 
       51 
56 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
                  def test_binds_are_logged_after_type_cast
         
     | 
| 
       53 
     | 
    
         
            -
                    sub   = @connection.substitute_at(@pk)
         
     | 
| 
       54 
     | 
    
         
            -
                    binds = [[@pk, "3"]]
         
     | 
| 
       55 
     | 
    
         
            -
                    sql   = "select * from topics where id = #{sub.to_sql}"
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                    @connection.exec_query(sql, 'SQL', binds)
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                    message = @subscriber.calls.find { |args| args[4][:sql] == sql }
         
     | 
| 
       60 
     | 
    
         
            -
                    assert_equal [[@pk, 3]], message[4][:binds]
         
     | 
| 
       61 
     | 
    
         
            -
                  end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
57 
     | 
    
         
             
                  def test_find_one_uses_binds
         
     | 
| 
      
 58 
     | 
    
         
            +
            	    puts "BindParameterTest - test_find_one_uses_binds"
         
     | 
| 
       64 
59 
     | 
    
         
             
                    Topic.find(1)
         
     | 
| 
       65 
     | 
    
         
            -
                     
     | 
| 
       66 
     | 
    
         
            -
                    message = @subscriber.calls.find { |args| args[4][:binds] == binds }
         
     | 
| 
      
 60 
     | 
    
         
            +
                    message = @subscriber.calls.find { |args| args[4][:binds].any? { |attr| attr.value == 1 } }
         
     | 
| 
       67 
61 
     | 
    
         
             
                    assert message, 'expected a message with binds'
         
     | 
| 
       68 
62 
     | 
    
         
             
                  end
         
     | 
| 
       69 
63 
     | 
    
         | 
| 
       70 
     | 
    
         
            -
                  def  
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
                      123,
         
     | 
| 
       81 
     | 
    
         
            -
                      payload)
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                    logger = Class.new(ActiveRecord::LogSubscriber) {
         
     | 
| 
       84 
     | 
    
         
            -
                      attr_reader :debugs
         
     | 
| 
       85 
     | 
    
         
            -
                      def initialize
         
     | 
| 
       86 
     | 
    
         
            -
                        super
         
     | 
| 
       87 
     | 
    
         
            -
                        @debugs = []
         
     | 
| 
       88 
     | 
    
         
            -
                      end
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                      def debug str
         
     | 
| 
       91 
     | 
    
         
            -
                        @debugs << str
         
     | 
| 
       92 
     | 
    
         
            -
                      end
         
     | 
| 
       93 
     | 
    
         
            -
                    }.new
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                    logger.sql event
         
     | 
| 
       96 
     | 
    
         
            -
                    assert_match([[@pk.name, 10]].inspect, logger.debugs.first)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  def test_logs_binds_after_type_cast
         
     | 
| 
      
 65 
     | 
    
         
            +
            	    puts "BindParameterTest - test_logs_binds_after_type_cast"
         
     | 
| 
      
 66 
     | 
    
         
            +
                    binds = [Relation::QueryAttribute.new("id", "10", Type::Integer.new)]
         
     | 
| 
      
 67 
     | 
    
         
            +
                    assert_logs_binds(binds)
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                  def test_logs_legacy_binds_after_type_cast
         
     | 
| 
      
 71 
     | 
    
         
            +
            	    puts "BindParameterTest - test_logs_legacy_binds_after_type_cast"
         
     | 
| 
      
 72 
     | 
    
         
            +
                    binds = [[@pk, "10"]]
         
     | 
| 
      
 73 
     | 
    
         
            +
                    assert_logs_binds(binds)
         
     | 
| 
       97 
74 
     | 
    
         
             
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                  private
         
     | 
| 
      
 77 
     | 
    
         
            +
                    def assert_logs_binds(binds)
         
     | 
| 
      
 78 
     | 
    
         
            +
                      payload = {
         
     | 
| 
      
 79 
     | 
    
         
            +
                        name: "SQL",
         
     | 
| 
      
 80 
     | 
    
         
            +
                        sql: "select * from topics where id = ?",
         
     | 
| 
      
 81 
     | 
    
         
            +
                        binds: binds,
         
     | 
| 
      
 82 
     | 
    
         
            +
                        type_casted_binds: @connection.type_casted_binds(binds)
         
     | 
| 
      
 83 
     | 
    
         
            +
                      }
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                      event = ActiveSupport::Notifications::Event.new(
         
     | 
| 
      
 86 
     | 
    
         
            +
                        "foo",
         
     | 
| 
      
 87 
     | 
    
         
            +
                        Time.now,
         
     | 
| 
      
 88 
     | 
    
         
            +
                        Time.now,
         
     | 
| 
      
 89 
     | 
    
         
            +
                        123,
         
     | 
| 
      
 90 
     | 
    
         
            +
                        payload)
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                      logger = Class.new(ActiveRecord::LogSubscriber) {
         
     | 
| 
      
 93 
     | 
    
         
            +
                        attr_reader :debugs
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                        def initialize
         
     | 
| 
      
 96 
     | 
    
         
            +
                          super
         
     | 
| 
      
 97 
     | 
    
         
            +
                          @debugs = []
         
     | 
| 
      
 98 
     | 
    
         
            +
                        end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                        def debug(str)
         
     | 
| 
      
 101 
     | 
    
         
            +
                          @debugs << str
         
     | 
| 
      
 102 
     | 
    
         
            +
                        end
         
     | 
| 
      
 103 
     | 
    
         
            +
                      }.new
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                      logger.sql(event)
         
     | 
| 
      
 106 
     | 
    
         
            +
                      assert_match([[@pk.name, 10]].inspect, logger.debugs.first)
         
     | 
| 
      
 107 
     | 
    
         
            +
                    end
         
     | 
| 
       98 
108 
     | 
    
         
             
                end
         
     | 
| 
       99 
109 
     | 
    
         
             
              end
         
     | 
| 
       100 
110 
     | 
    
         
             
            end
         
     |