ibm_db 3.0.4 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES +8 -1
- data/LICENSE +1 -1
- data/ParameterizedQueries README +6 -6
- data/README +38 -55
- data/ext/Makefile +266 -0
- data/ext/extconf.rb +34 -3
- data/ext/gil_release_version +3 -0
- data/ext/ibm_db.c +106 -111
- data/ext/ibm_db.o +0 -0
- data/ext/ibm_db.so +0 -0
- data/ext/mkmf.log +103 -0
- data/ext/ruby_ibm_db_cli.o +0 -0
- data/ext/unicode_support_version +3 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +911 -527
- data/lib/active_record/connection_adapters/ibmdb_adapter.rb +4 -1
- data/test/active_record/connection_adapters/fake_adapter.rb +8 -5
- data/test/cases/adapter_test.rb +148 -58
- data/test/cases/adapters/mysql2/active_schema_test.rb +193 -0
- data/test/cases/adapters/mysql2/bind_parameter_test.rb +50 -0
- data/test/cases/adapters/mysql2/boolean_test.rb +100 -0
- data/test/cases/adapters/mysql2/case_sensitivity_test.rb +63 -0
- data/test/cases/adapters/mysql2/charset_collation_test.rb +54 -0
- data/test/cases/adapters/mysql2/connection_test.rb +210 -0
- data/test/cases/adapters/mysql2/datetime_precision_quoting_test.rb +45 -0
- data/test/cases/adapters/mysql2/enum_test.rb +26 -0
- data/test/cases/adapters/mysql2/explain_test.rb +21 -0
- data/test/cases/adapters/mysql2/json_test.rb +195 -0
- data/test/cases/adapters/mysql2/mysql2_adapter_test.rb +83 -0
- data/test/cases/adapters/mysql2/reserved_word_test.rb +152 -0
- data/test/cases/adapters/mysql2/schema_migrations_test.rb +59 -0
- data/test/cases/adapters/mysql2/schema_test.rb +126 -0
- data/test/cases/adapters/mysql2/sp_test.rb +36 -0
- data/test/cases/adapters/mysql2/sql_types_test.rb +14 -0
- data/test/cases/adapters/mysql2/table_options_test.rb +42 -0
- data/test/cases/adapters/mysql2/unsigned_type_test.rb +66 -0
- data/test/cases/adapters/postgresql/active_schema_test.rb +98 -0
- data/test/cases/adapters/postgresql/array_test.rb +339 -0
- data/test/cases/adapters/postgresql/bit_string_test.rb +82 -0
- data/test/cases/adapters/postgresql/bytea_test.rb +134 -0
- data/test/cases/adapters/postgresql/case_insensitive_test.rb +26 -0
- data/test/cases/adapters/postgresql/change_schema_test.rb +38 -0
- data/test/cases/adapters/postgresql/cidr_test.rb +25 -0
- data/test/cases/adapters/postgresql/citext_test.rb +78 -0
- data/test/cases/adapters/postgresql/collation_test.rb +53 -0
- data/test/cases/adapters/postgresql/composite_test.rb +132 -0
- data/test/cases/adapters/postgresql/connection_test.rb +257 -0
- data/test/cases/adapters/postgresql/datatype_test.rb +92 -0
- data/test/cases/adapters/postgresql/domain_test.rb +47 -0
- data/test/cases/adapters/postgresql/enum_test.rb +91 -0
- data/test/cases/adapters/postgresql/explain_test.rb +20 -0
- data/test/cases/adapters/postgresql/extension_migration_test.rb +63 -0
- data/test/cases/adapters/postgresql/full_text_test.rb +44 -0
- data/test/cases/adapters/postgresql/geometric_test.rb +378 -0
- data/test/cases/adapters/postgresql/hstore_test.rb +382 -0
- data/test/cases/adapters/postgresql/infinity_test.rb +69 -0
- data/test/cases/adapters/postgresql/integer_test.rb +25 -0
- data/test/cases/adapters/postgresql/json_test.rb +237 -0
- data/test/cases/adapters/postgresql/ltree_test.rb +53 -0
- data/test/cases/adapters/postgresql/money_test.rb +96 -0
- data/test/cases/adapters/postgresql/network_test.rb +94 -0
- data/test/cases/adapters/postgresql/numbers_test.rb +49 -0
- data/test/cases/adapters/postgresql/postgresql_adapter_test.rb +405 -0
- data/test/cases/adapters/postgresql/prepared_statements_test.rb +22 -0
- data/test/cases/adapters/postgresql/quoting_test.rb +44 -0
- data/test/cases/adapters/postgresql/range_test.rb +343 -0
- data/test/cases/adapters/postgresql/referential_integrity_test.rb +111 -0
- data/test/cases/adapters/postgresql/rename_table_test.rb +34 -0
- data/test/cases/adapters/postgresql/schema_authorization_test.rb +119 -0
- data/test/cases/adapters/postgresql/schema_test.rb +597 -0
- data/test/cases/adapters/postgresql/serial_test.rb +154 -0
- data/test/cases/adapters/postgresql/statement_pool_test.rb +41 -0
- data/test/cases/adapters/postgresql/timestamp_test.rb +90 -0
- data/test/cases/adapters/postgresql/type_lookup_test.rb +33 -0
- data/test/cases/adapters/postgresql/utils_test.rb +62 -0
- data/test/cases/adapters/postgresql/uuid_test.rb +294 -0
- data/test/cases/adapters/postgresql/xml_test.rb +54 -0
- data/test/cases/adapters/sqlite3/collation_test.rb +53 -0
- data/test/cases/adapters/sqlite3/copy_table_test.rb +98 -0
- data/test/cases/adapters/sqlite3/explain_test.rb +21 -0
- data/test/cases/adapters/sqlite3/quoting_test.rb +101 -0
- data/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +441 -0
- data/test/cases/adapters/sqlite3/sqlite3_create_folder_test.rb +24 -0
- data/test/cases/adapters/sqlite3/statement_pool_test.rb +20 -0
- data/test/cases/aggregations_test.rb +11 -1
- data/test/cases/ar_schema_test.rb +35 -50
- data/test/cases/associations/association_scope_test.rb +1 -6
- data/test/cases/associations/belongs_to_associations_test.rb +122 -10
- data/test/cases/associations/bidirectional_destroy_dependencies_test.rb +41 -0
- data/test/cases/associations/callbacks_test.rb +5 -7
- data/test/cases/associations/cascaded_eager_loading_test.rb +1 -1
- data/test/cases/associations/eager_load_nested_include_test.rb +1 -3
- data/test/cases/associations/eager_test.rb +176 -73
- data/test/cases/associations/extension_test.rb +7 -2
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +104 -32
- data/test/cases/associations/has_many_associations_test.rb +382 -43
- data/test/cases/associations/has_many_through_associations_test.rb +108 -41
- data/test/cases/associations/has_one_associations_test.rb +105 -8
- data/test/cases/associations/has_one_through_associations_test.rb +6 -3
- data/test/cases/associations/inner_join_association_test.rb +3 -3
- data/test/cases/associations/inverse_associations_test.rb +51 -11
- data/test/cases/associations/join_model_test.rb +59 -36
- data/test/cases/associations/left_outer_join_association_test.rb +88 -0
- data/test/cases/associations/nested_through_associations_test.rb +2 -2
- data/test/cases/associations/required_test.rb +25 -5
- data/test/cases/associations_test.rb +39 -34
- data/test/cases/attribute_decorators_test.rb +9 -8
- data/test/cases/attribute_methods/read_test.rb +5 -5
- data/test/cases/attribute_methods_test.rb +97 -40
- data/test/cases/attribute_set_test.rb +74 -4
- data/test/cases/attribute_test.rb +84 -18
- data/test/cases/attributes_test.rb +151 -34
- data/test/cases/autosave_association_test.rb +149 -36
- data/test/cases/base_test.rb +311 -236
- data/test/cases/batches_test.rb +299 -22
- data/test/cases/binary_test.rb +2 -10
- data/test/cases/bind_parameter_test.rb +76 -66
- data/test/cases/cache_key_test.rb +26 -0
- data/test/cases/calculations_test.rb +167 -15
- data/test/cases/callbacks_test.rb +161 -68
- data/test/cases/coders/json_test.rb +15 -0
- data/test/cases/collection_cache_key_test.rb +115 -0
- data/test/cases/column_definition_test.rb +26 -57
- data/test/cases/comment_test.rb +145 -0
- data/test/cases/connection_adapters/adapter_leasing_test.rb +5 -3
- data/test/cases/connection_adapters/connection_handler_test.rb +128 -21
- data/test/cases/connection_adapters/connection_specification_test.rb +1 -1
- data/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb +0 -38
- data/test/cases/connection_adapters/mysql_type_lookup_test.rb +5 -1
- data/test/cases/connection_adapters/schema_cache_test.rb +8 -3
- data/test/cases/connection_adapters/type_lookup_test.rb +15 -7
- data/test/cases/connection_management_test.rb +46 -56
- data/test/cases/connection_pool_test.rb +195 -20
- data/test/cases/connection_specification/resolver_test.rb +15 -0
- data/test/cases/counter_cache_test.rb +10 -5
- data/test/cases/custom_locking_test.rb +1 -1
- data/test/cases/database_statements_test.rb +18 -3
- data/test/cases/{invalid_date_test.rb → date_test.rb} +13 -1
- data/test/cases/date_time_precision_test.rb +107 -0
- data/test/cases/defaults_test.rb +85 -89
- data/test/cases/dirty_test.rb +32 -44
- data/test/cases/disconnected_test.rb +4 -2
- data/test/cases/enum_test.rb +178 -24
- data/test/cases/errors_test.rb +16 -0
- data/test/cases/explain_test.rb +32 -21
- data/test/cases/finder_test.rb +279 -151
- data/test/cases/fixture_set/file_test.rb +18 -0
- data/test/cases/fixtures_test.rb +123 -32
- data/test/cases/forbidden_attributes_protection_test.rb +69 -3
- data/test/cases/helper.rb +10 -16
- data/test/cases/hot_compatibility_test.rb +89 -1
- data/test/cases/inheritance_test.rb +284 -53
- data/test/cases/integration_test.rb +23 -7
- data/test/cases/invalid_connection_test.rb +4 -2
- data/test/cases/invertible_migration_test.rb +124 -32
- data/test/cases/json_serialization_test.rb +11 -2
- data/test/cases/locking_test.rb +22 -6
- data/test/cases/log_subscriber_test.rb +106 -17
- data/test/cases/migration/change_schema_test.rb +118 -132
- data/test/cases/migration/change_table_test.rb +34 -2
- data/test/cases/migration/column_attributes_test.rb +7 -23
- data/test/cases/migration/column_positioning_test.rb +8 -8
- data/test/cases/migration/columns_test.rb +17 -11
- data/test/cases/migration/command_recorder_test.rb +47 -2
- data/test/cases/migration/compatibility_test.rb +118 -0
- data/test/cases/migration/create_join_table_test.rb +21 -12
- data/test/cases/migration/foreign_key_test.rb +68 -66
- data/test/cases/migration/index_test.rb +14 -12
- data/test/cases/migration/logger_test.rb +1 -1
- data/test/cases/migration/pending_migrations_test.rb +0 -1
- data/test/cases/migration/references_foreign_key_test.rb +114 -107
- data/test/cases/migration/references_index_test.rb +4 -4
- data/test/cases/migration/references_statements_test.rb +26 -6
- data/test/cases/migration/rename_table_test.rb +25 -25
- data/test/cases/migration_test.rb +279 -81
- data/test/cases/migrator_test.rb +91 -8
- data/test/cases/mixin_test.rb +0 -2
- data/test/cases/modules_test.rb +3 -4
- data/test/cases/multiparameter_attributes_test.rb +24 -2
- data/test/cases/multiple_db_test.rb +18 -11
- data/test/cases/nested_attributes_test.rb +74 -33
- data/test/cases/persistence_test.rb +102 -10
- data/test/cases/pooled_connections_test.rb +3 -3
- data/test/cases/primary_keys_test.rb +170 -31
- data/test/cases/query_cache_test.rb +216 -96
- data/test/cases/quoting_test.rb +65 -19
- data/test/cases/readonly_test.rb +2 -1
- data/test/cases/reflection_test.rb +77 -22
- data/test/cases/relation/delegation_test.rb +3 -8
- data/test/cases/relation/merging_test.rb +10 -14
- data/test/cases/relation/mutation_test.rb +42 -24
- data/test/cases/relation/or_test.rb +92 -0
- data/test/cases/relation/predicate_builder_test.rb +4 -2
- data/test/cases/relation/record_fetch_warning_test.rb +40 -0
- data/test/cases/relation/where_chain_test.rb +23 -99
- data/test/cases/relation/where_clause_test.rb +182 -0
- data/test/cases/relation/where_test.rb +45 -23
- data/test/cases/relation_test.rb +89 -58
- data/test/cases/relations_test.rb +249 -38
- data/test/cases/result_test.rb +10 -0
- data/test/cases/sanitize_test.rb +108 -15
- data/test/cases/schema_dumper_test.rb +119 -125
- data/test/cases/schema_loading_test.rb +52 -0
- data/test/cases/scoping/default_scoping_test.rb +113 -39
- data/test/cases/scoping/named_scoping_test.rb +46 -9
- data/test/cases/scoping/relation_scoping_test.rb +47 -4
- data/test/cases/secure_token_test.rb +32 -0
- data/test/cases/serialization_test.rb +1 -1
- data/test/cases/serialized_attribute_test.rb +93 -6
- data/test/cases/statement_cache_test.rb +38 -0
- data/test/cases/store_test.rb +2 -1
- data/test/cases/suppressor_test.rb +63 -0
- data/test/cases/tasks/database_tasks_test.rb +74 -8
- data/test/cases/tasks/mysql_rake_test.rb +143 -109
- data/test/cases/tasks/postgresql_rake_test.rb +71 -12
- data/test/cases/tasks/sqlite_rake_test.rb +30 -3
- data/test/cases/test_case.rb +28 -20
- data/test/cases/test_fixtures_test.rb +36 -0
- data/test/cases/time_precision_test.rb +103 -0
- data/test/cases/timestamp_test.rb +47 -14
- data/test/cases/touch_later_test.rb +121 -0
- data/test/cases/transaction_callbacks_test.rb +128 -62
- data/test/cases/transaction_isolation_test.rb +2 -2
- data/test/cases/transactions_test.rb +61 -43
- data/test/cases/type/adapter_specific_registry_test.rb +133 -0
- data/test/cases/type/date_time_test.rb +14 -0
- data/test/cases/type/integer_test.rb +2 -96
- data/test/cases/type/string_test.rb +0 -14
- data/test/cases/type_test.rb +39 -0
- data/test/cases/types_test.rb +1 -118
- data/test/cases/unconnected_test.rb +1 -1
- data/test/cases/validations/absence_validation_test.rb +73 -0
- data/test/cases/validations/association_validation_test.rb +13 -2
- data/test/cases/validations/i18n_validation_test.rb +6 -10
- data/test/cases/validations/length_validation_test.rb +62 -30
- data/test/cases/validations/presence_validation_test.rb +36 -1
- data/test/cases/validations/uniqueness_validation_test.rb +150 -36
- data/test/cases/validations_repair_helper.rb +2 -6
- data/test/cases/validations_test.rb +36 -7
- data/test/cases/view_test.rb +108 -5
- data/test/cases/yaml_serialization_test.rb +36 -1
- data/test/config.example.yml +97 -0
- data/test/fixtures/bad_posts.yml +9 -0
- data/test/fixtures/books.yml +20 -0
- data/test/fixtures/content.yml +3 -0
- data/test/fixtures/content_positions.yml +3 -0
- data/test/fixtures/dead_parrots.yml +5 -0
- data/test/fixtures/live_parrots.yml +4 -0
- data/test/fixtures/naked/yml/parrots.yml +2 -0
- data/test/fixtures/naked/yml/trees.yml +3 -0
- data/test/fixtures/nodes.yml +29 -0
- data/test/fixtures/other_comments.yml +6 -0
- data/test/fixtures/other_dogs.yml +2 -0
- data/test/fixtures/other_posts.yml +7 -0
- data/test/fixtures/price_estimates.yml +10 -1
- data/test/fixtures/trees.yml +3 -0
- data/test/migrations/10_urban/9_add_expressions.rb +1 -1
- data/test/migrations/decimal/1_give_me_big_numbers.rb +1 -1
- data/test/migrations/magic/1_currencies_have_symbols.rb +1 -1
- data/test/migrations/missing/1000_people_have_middle_names.rb +2 -2
- data/test/migrations/missing/1_people_have_last_names.rb +2 -2
- data/test/migrations/missing/3_we_need_reminders.rb +2 -2
- data/test/migrations/missing/4_innocent_jointable.rb +2 -2
- data/test/migrations/rename/1_we_need_things.rb +2 -2
- data/test/migrations/rename/2_rename_things.rb +2 -2
- data/test/migrations/to_copy/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy/2_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy2/1_create_articles.rb +1 -1
- data/test/migrations/to_copy2/2_create_comments.rb +1 -1
- data/test/migrations/to_copy_with_name_collision/1_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010101_people_have_hobbies.rb +1 -1
- data/test/migrations/to_copy_with_timestamps/20090101010202_people_have_descriptions.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010101_create_articles.rb +1 -1
- data/test/migrations/to_copy_with_timestamps2/20090101010202_create_comments.rb +1 -1
- data/test/migrations/valid/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_subdirectories/1_valid_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_subdirectories/sub/2_we_need_reminders.rb +2 -2
- data/test/migrations/valid_with_subdirectories/sub1/3_innocent_jointable.rb +2 -2
- data/test/migrations/valid_with_timestamps/20100101010101_valid_with_timestamps_people_have_last_names.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100201010101_valid_with_timestamps_we_need_reminders.rb +1 -1
- data/test/migrations/valid_with_timestamps/20100301010101_valid_with_timestamps_innocent_jointable.rb +1 -1
- data/test/migrations/version_check/20131219224947_migration_version_check.rb +1 -1
- data/test/models/admin/randomly_named_c1.rb +6 -2
- data/test/models/aircraft.rb +1 -0
- data/test/models/author.rb +4 -7
- data/test/models/bird.rb +1 -1
- data/test/models/book.rb +5 -0
- data/test/models/bulb.rb +2 -1
- data/test/models/car.rb +3 -0
- data/test/models/cat.rb +10 -0
- data/test/models/chef.rb +5 -0
- data/test/models/club.rb +2 -0
- data/test/models/comment.rb +17 -5
- data/test/models/company.rb +7 -2
- data/test/models/company_in_module.rb +1 -1
- data/test/models/contact.rb +1 -1
- data/test/models/content.rb +40 -0
- data/test/models/customer.rb +8 -2
- data/test/models/developer.rb +22 -0
- data/test/models/face.rb +1 -1
- data/test/models/guitar.rb +4 -0
- data/test/models/hotel.rb +5 -0
- data/test/models/member.rb +1 -0
- data/test/models/member_detail.rb +4 -3
- data/test/models/mentor.rb +3 -0
- data/test/models/mocktail_designer.rb +2 -0
- data/test/models/node.rb +5 -0
- data/test/models/non_primary_key.rb +2 -0
- data/test/models/notification.rb +3 -0
- data/test/models/other_dog.rb +5 -0
- data/test/models/owner.rb +4 -1
- data/test/models/parrot.rb +6 -7
- data/test/models/person.rb +0 -1
- data/test/models/pet.rb +3 -0
- data/test/models/pet_treasure.rb +6 -0
- data/test/models/pirate.rb +3 -3
- data/test/models/post.rb +18 -9
- data/test/models/project.rb +11 -0
- data/test/models/randomly_named_c1.rb +1 -1
- data/test/models/recipe.rb +3 -0
- data/test/models/ship.rb +8 -2
- data/test/models/tag.rb +6 -0
- data/test/models/topic.rb +2 -8
- data/test/models/tree.rb +3 -0
- data/test/models/tuning_peg.rb +4 -0
- data/test/models/user.rb +14 -0
- data/test/models/uuid_item.rb +6 -0
- data/test/schema/mysql2_specific_schema.rb +33 -23
- data/test/schema/oracle_specific_schema.rb +1 -4
- data/test/schema/postgresql_specific_schema.rb +36 -124
- data/test/schema/schema.rb +183 -64
- data/test/schema/schema.rb.original +1057 -0
- data/test/schema/sqlite_specific_schema.rb +1 -5
- data/test/support/connection.rb +1 -0
- data/test/support/schema_dumping_helper.rb +1 -1
- data/test/support/yaml_compatibility_fixtures/rails_4_1.yml +22 -0
- data/test/support/yaml_compatibility_fixtures/rails_4_2_0.yml +182 -0
- metadata +145 -26
- data/test/cases/associations/deprecated_counter_cache_on_has_many_through_test.rb +0 -26
- data/test/cases/attribute_methods/serialization_test.rb +0 -29
- data/test/cases/migration/change_schema_test - Copy.rb +0 -448
- data/test/cases/migration/foreign_key_test - Changed.rb +0 -325
- data/test/cases/migration/table_and_index_test.rb +0 -24
- data/test/cases/relation/where_test2.rb +0 -36
- data/test/cases/type/decimal_test.rb +0 -51
- data/test/cases/type/unsigned_integer_test.rb +0 -18
- data/test/cases/xml_serialization_test.rb +0 -457
- data/test/fixtures/naked/csv/accounts.csv +0 -1
- data/test/schema/mysql_specific_schema.rb +0 -70
data/test/cases/result_test.rb
CHANGED
@@ -22,6 +22,16 @@ module ActiveRecord
|
|
22
22
|
], result.to_hash
|
23
23
|
end
|
24
24
|
|
25
|
+
test "first returns first row as a hash" do
|
26
|
+
assert_equal(
|
27
|
+
{'col_1' => 'row 1 col 1', 'col_2' => 'row 1 col 2'}, result.first)
|
28
|
+
end
|
29
|
+
|
30
|
+
test "last returns last row as a hash" do
|
31
|
+
assert_equal(
|
32
|
+
{'col_1' => 'row 3 col 1', 'col_2' => 'row 3 col 2'}, result.last)
|
33
|
+
end
|
34
|
+
|
25
35
|
test "each with block returns row hashes" do
|
26
36
|
result.each do |row|
|
27
37
|
assert_equal ['col_1', 'col_2'], row.keys
|
data/test/cases/sanitize_test.rb
CHANGED
@@ -7,24 +7,13 @@ class SanitizeTest < ActiveRecord::TestCase
|
|
7
7
|
def setup
|
8
8
|
end
|
9
9
|
|
10
|
-
def test_sanitize_sql_hash_handles_associations
|
11
|
-
quoted_bambi = ActiveRecord::Base.connection.quote("Bambi")
|
12
|
-
quoted_column_name = ActiveRecord::Base.connection.quote_column_name("name")
|
13
|
-
quoted_table_name = ActiveRecord::Base.connection.quote_table_name("adorable_animals")
|
14
|
-
expected_value = "#{quoted_table_name}.#{quoted_column_name} = #{quoted_bambi}"
|
15
|
-
|
16
|
-
assert_deprecated do
|
17
|
-
assert_equal expected_value, Binary.send(:sanitize_sql_hash, {adorable_animals: {name: 'Bambi'}})
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
10
|
def test_sanitize_sql_array_handles_string_interpolation
|
22
11
|
quoted_bambi = ActiveRecord::Base.connection.quote_string("Bambi")
|
23
|
-
assert_equal "name
|
24
|
-
assert_equal "name
|
12
|
+
assert_equal "name='#{quoted_bambi}'", Binary.send(:sanitize_sql_array, ["name='%s'", "Bambi"])
|
13
|
+
assert_equal "name='#{quoted_bambi}'", Binary.send(:sanitize_sql_array, ["name='%s'", "Bambi".mb_chars])
|
25
14
|
quoted_bambi_and_thumper = ActiveRecord::Base.connection.quote_string("Bambi\nand\nThumper")
|
26
|
-
assert_equal "name
|
27
|
-
assert_equal "name
|
15
|
+
assert_equal "name='#{quoted_bambi_and_thumper}'",Binary.send(:sanitize_sql_array, ["name='%s'", "Bambi\nand\nThumper"])
|
16
|
+
assert_equal "name='#{quoted_bambi_and_thumper}'",Binary.send(:sanitize_sql_array, ["name='%s'", "Bambi\nand\nThumper".mb_chars])
|
28
17
|
end
|
29
18
|
|
30
19
|
def test_sanitize_sql_array_handles_bind_variables
|
@@ -36,6 +25,16 @@ class SanitizeTest < ActiveRecord::TestCase
|
|
36
25
|
assert_equal "name=#{quoted_bambi_and_thumper}", Binary.send(:sanitize_sql_array, ["name=?", "Bambi\nand\nThumper".mb_chars])
|
37
26
|
end
|
38
27
|
|
28
|
+
def test_sanitize_sql_array_handles_named_bind_variables
|
29
|
+
quoted_bambi = ActiveRecord::Base.connection.quote("Bambi")
|
30
|
+
assert_equal "name=#{quoted_bambi}", Binary.send(:sanitize_sql_array, ["name=:name", name: "Bambi"])
|
31
|
+
assert_equal "name=#{quoted_bambi} AND id=1", Binary.send(:sanitize_sql_array, ["name=:name AND id=:id", name: "Bambi", id: 1])
|
32
|
+
|
33
|
+
quoted_bambi_and_thumper = ActiveRecord::Base.connection.quote("Bambi\nand\nThumper")
|
34
|
+
assert_equal "name=#{quoted_bambi_and_thumper}", Binary.send(:sanitize_sql_array, ["name=:name", name: "Bambi\nand\nThumper"])
|
35
|
+
assert_equal "name=#{quoted_bambi_and_thumper} AND name2=#{quoted_bambi_and_thumper}", Binary.send(:sanitize_sql_array, ["name=:name AND name2=:name", name: "Bambi\nand\nThumper"])
|
36
|
+
end
|
37
|
+
|
39
38
|
def test_sanitize_sql_array_handles_relations
|
40
39
|
david = Author.create!(name: 'David')
|
41
40
|
david_posts = david.posts.select(:id)
|
@@ -80,4 +79,98 @@ class SanitizeTest < ActiveRecord::TestCase
|
|
80
79
|
searchable_post.search("20% _reduction_!").to_a
|
81
80
|
end
|
82
81
|
end
|
82
|
+
|
83
|
+
def test_bind_arity
|
84
|
+
assert_nothing_raised { bind '' }
|
85
|
+
assert_raise(ActiveRecord::PreparedStatementInvalid) { bind '', 1 }
|
86
|
+
|
87
|
+
assert_raise(ActiveRecord::PreparedStatementInvalid) { bind '?' }
|
88
|
+
assert_nothing_raised { bind '?', 1 }
|
89
|
+
assert_raise(ActiveRecord::PreparedStatementInvalid) { bind '?', 1, 1 }
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_named_bind_variables
|
93
|
+
assert_equal '1', bind(':a', :a => 1) # ' ruby-mode
|
94
|
+
assert_equal '1 1', bind(':a :a', :a => 1) # ' ruby-mode
|
95
|
+
|
96
|
+
assert_nothing_raised { bind("'+00:00'", :foo => "bar") }
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_named_bind_arity
|
100
|
+
assert_nothing_raised { bind "name = :name", { name: "37signals" } }
|
101
|
+
assert_nothing_raised { bind "name = :name", { name: "37signals", id: 1 } }
|
102
|
+
assert_raise(ActiveRecord::PreparedStatementInvalid) { bind "name = :name", { id: 1 } }
|
103
|
+
end
|
104
|
+
|
105
|
+
class SimpleEnumerable
|
106
|
+
include Enumerable
|
107
|
+
|
108
|
+
def initialize(ary)
|
109
|
+
@ary = ary
|
110
|
+
end
|
111
|
+
|
112
|
+
def each(&b)
|
113
|
+
@ary.each(&b)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_bind_enumerable
|
118
|
+
quoted_abc = %(#{ActiveRecord::Base.connection.quote('a')},#{ActiveRecord::Base.connection.quote('b')},#{ActiveRecord::Base.connection.quote('c')})
|
119
|
+
|
120
|
+
assert_equal '1,2,3', bind('?', [1, 2, 3])
|
121
|
+
assert_equal quoted_abc, bind('?', %w(a b c))
|
122
|
+
|
123
|
+
assert_equal '1,2,3', bind(':a', :a => [1, 2, 3])
|
124
|
+
assert_equal quoted_abc, bind(':a', :a => %w(a b c)) # '
|
125
|
+
|
126
|
+
assert_equal '1,2,3', bind('?', SimpleEnumerable.new([1, 2, 3]))
|
127
|
+
assert_equal quoted_abc, bind('?', SimpleEnumerable.new(%w(a b c)))
|
128
|
+
|
129
|
+
assert_equal '1,2,3', bind(':a', :a => SimpleEnumerable.new([1, 2, 3]))
|
130
|
+
assert_equal quoted_abc, bind(':a', :a => SimpleEnumerable.new(%w(a b c))) # '
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_bind_empty_enumerable
|
134
|
+
quoted_nil = ActiveRecord::Base.connection.quote(nil)
|
135
|
+
assert_equal quoted_nil, bind('?', [])
|
136
|
+
assert_equal " in (#{quoted_nil})", bind(' in (?)', [])
|
137
|
+
assert_equal "foo in (#{quoted_nil})", bind('foo in (?)', [])
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_bind_empty_string
|
141
|
+
quoted_empty = ActiveRecord::Base.connection.quote('')
|
142
|
+
assert_equal quoted_empty, bind('?', '')
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_bind_chars
|
146
|
+
quoted_bambi = ActiveRecord::Base.connection.quote("Bambi")
|
147
|
+
quoted_bambi_and_thumper = ActiveRecord::Base.connection.quote("Bambi\nand\nThumper")
|
148
|
+
assert_equal "name=#{quoted_bambi}", bind('name=?', "Bambi")
|
149
|
+
assert_equal "name=#{quoted_bambi_and_thumper}", bind('name=?', "Bambi\nand\nThumper")
|
150
|
+
assert_equal "name=#{quoted_bambi}", bind('name=?', "Bambi".mb_chars)
|
151
|
+
assert_equal "name=#{quoted_bambi_and_thumper}", bind('name=?', "Bambi\nand\nThumper".mb_chars)
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_bind_record
|
155
|
+
o = Struct.new(:quoted_id).new(1)
|
156
|
+
assert_equal '1', bind('?', o)
|
157
|
+
|
158
|
+
os = [o] * 3
|
159
|
+
assert_equal '1,1,1', bind('?', os)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_named_bind_with_postgresql_type_casts
|
163
|
+
l = Proc.new { bind(":a::integer '2009-01-01'::date", :a => '10') }
|
164
|
+
assert_nothing_raised(&l)
|
165
|
+
assert_equal "#{ActiveRecord::Base.connection.quote('10')}::integer '2009-01-01'::date", l.call
|
166
|
+
end
|
167
|
+
|
168
|
+
private
|
169
|
+
def bind(statement, *vars)
|
170
|
+
if vars.first.is_a?(Hash)
|
171
|
+
ActiveRecord::Base.send(:replace_named_bind_variables, statement, vars.first)
|
172
|
+
else
|
173
|
+
ActiveRecord::Base.send(:replace_bind_variables, statement, vars)
|
174
|
+
end
|
175
|
+
end
|
83
176
|
end
|
@@ -3,7 +3,7 @@ require 'support/schema_dumping_helper'
|
|
3
3
|
|
4
4
|
class SchemaDumperTest < ActiveRecord::TestCase
|
5
5
|
include SchemaDumpingHelper
|
6
|
-
self.
|
6
|
+
self.use_transactional_tests = false
|
7
7
|
|
8
8
|
setup do
|
9
9
|
ActiveRecord::SchemaMigration.create_table
|
@@ -17,6 +17,12 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
17
17
|
dump_all_table_schema []
|
18
18
|
end
|
19
19
|
|
20
|
+
def test_dump_schema_information_with_empty_versions
|
21
|
+
ActiveRecord::SchemaMigration.delete_all
|
22
|
+
schema_info = ActiveRecord::Base.connection.dump_schema_information
|
23
|
+
assert_no_match(/INSERT INTO/, schema_info)
|
24
|
+
end
|
25
|
+
|
20
26
|
def test_dump_schema_information_outputs_lexically_ordered_versions
|
21
27
|
versions = %w{ 20100101010101 20100201010101 20100301010101 }
|
22
28
|
versions.reverse_each do |v|
|
@@ -29,15 +35,31 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
29
35
|
ActiveRecord::SchemaMigration.delete_all
|
30
36
|
end
|
31
37
|
|
32
|
-
|
33
|
-
|
38
|
+
if current_adapter?(:SQLite3Adapter)
|
39
|
+
%w{3.7.8 3.7.11 3.7.12}.each do |version_string|
|
40
|
+
test "dumps schema version for sqlite version #{version_string}" do
|
41
|
+
version = ActiveRecord::ConnectionAdapters::SQLite3Adapter::Version.new(version_string)
|
42
|
+
ActiveRecord::Base.connection.stubs(:sqlite_version).returns(version)
|
43
|
+
|
44
|
+
versions = %w{ 20100101010101 20100201010101 20100301010101 }
|
45
|
+
versions.reverse_each do |v|
|
46
|
+
ActiveRecord::SchemaMigration.create!(:version => v)
|
47
|
+
end
|
48
|
+
|
49
|
+
schema_info = ActiveRecord::Base.connection.dump_schema_information
|
50
|
+
assert_match(/20100201010101.*20100301010101/m, schema_info)
|
51
|
+
ActiveRecord::SchemaMigration.delete_all
|
52
|
+
end
|
53
|
+
end
|
34
54
|
end
|
35
55
|
|
36
56
|
def test_schema_dump
|
37
57
|
output = standard_dump
|
38
58
|
assert_match %r{create_table "accounts"}, output
|
39
59
|
assert_match %r{create_table "authors"}, output
|
60
|
+
assert_no_match %r{(?<=, ) do \|t\|}, output
|
40
61
|
assert_no_match %r{create_table "schema_migrations"}, output
|
62
|
+
assert_no_match %r{create_table "ar_internal_metadata"}, output
|
41
63
|
end
|
42
64
|
|
43
65
|
def test_schema_dump_uses_force_cascade_on_create_table
|
@@ -78,10 +100,10 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
78
100
|
next if column_set.empty?
|
79
101
|
|
80
102
|
lengths = column_set.map do |column|
|
81
|
-
if match = column.match(
|
103
|
+
if match = column.match(/\bt\.\w+\s+(?="\w+?")/)
|
82
104
|
match[0].length
|
83
105
|
end
|
84
|
-
end
|
106
|
+
end.compact
|
85
107
|
|
86
108
|
assert_equal 1, lengths.uniq.length
|
87
109
|
end
|
@@ -122,8 +144,8 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
122
144
|
|
123
145
|
assert_match %r{c_int_4.*}, output
|
124
146
|
assert_no_match %r{c_int_4.*limit:}, output
|
125
|
-
elsif current_adapter?(:
|
126
|
-
assert_match %r{c_int_without_limit
|
147
|
+
elsif current_adapter?(:Mysql2Adapter)
|
148
|
+
assert_match %r{c_int_without_limit"$}, output
|
127
149
|
|
128
150
|
assert_match %r{c_int_1.*limit: 1}, output
|
129
151
|
assert_match %r{c_int_2.*limit: 2}, output
|
@@ -151,10 +173,10 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
151
173
|
assert_match %r{c_int_7.*limit: 7}, output
|
152
174
|
assert_match %r{c_int_8.*limit: 8}, output
|
153
175
|
else
|
154
|
-
assert_match %r{c_int_5
|
155
|
-
assert_match %r{c_int_6
|
156
|
-
assert_match %r{c_int_7
|
157
|
-
assert_match %r{c_int_8
|
176
|
+
assert_match %r{t\.bigint\s+"c_int_5"$}, output
|
177
|
+
assert_match %r{t\.bigint\s+"c_int_6"$}, output
|
178
|
+
assert_match %r{t\.bigint\s+"c_int_7"$}, output
|
179
|
+
assert_match %r{t\.bigint\s+"c_int_8"$}, output
|
158
180
|
end
|
159
181
|
end
|
160
182
|
|
@@ -163,6 +185,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
163
185
|
assert_no_match %r{create_table "accounts"}, output
|
164
186
|
assert_match %r{create_table "authors"}, output
|
165
187
|
assert_no_match %r{create_table "schema_migrations"}, output
|
188
|
+
assert_no_match %r{create_table "ar_internal_metadata"}, output
|
166
189
|
end
|
167
190
|
|
168
191
|
def test_schema_dump_with_regexp_ignored_table
|
@@ -170,27 +193,30 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
170
193
|
assert_no_match %r{create_table "accounts"}, output
|
171
194
|
assert_match %r{create_table "authors"}, output
|
172
195
|
assert_no_match %r{create_table "schema_migrations"}, output
|
196
|
+
assert_no_match %r{create_table "ar_internal_metadata"}, output
|
173
197
|
end
|
174
198
|
|
175
199
|
def test_schema_dumps_index_columns_in_right_order
|
176
|
-
index_definition = standard_dump.split(/\n/).grep(/
|
177
|
-
if current_adapter?(:
|
178
|
-
assert_equal '
|
200
|
+
index_definition = standard_dump.split(/\n/).grep(/t\.index.*company_index/).first.strip
|
201
|
+
if current_adapter?(:PostgreSQLAdapter)
|
202
|
+
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", order: { rating: :desc }, using: :btree', index_definition
|
203
|
+
elsif current_adapter?(:Mysql2Adapter)
|
204
|
+
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", length: { type: 10 }, using: :btree', index_definition
|
179
205
|
else
|
180
|
-
assert_equal '
|
206
|
+
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index"', index_definition
|
181
207
|
end
|
182
208
|
end
|
183
209
|
|
184
210
|
def test_schema_dumps_partial_indices
|
185
|
-
index_definition = standard_dump.split(/\n/).grep(/
|
211
|
+
index_definition = standard_dump.split(/\n/).grep(/t\.index.*company_partial_index/).first.strip
|
186
212
|
if current_adapter?(:PostgreSQLAdapter)
|
187
|
-
assert_equal '
|
188
|
-
elsif current_adapter?(:
|
189
|
-
assert_equal '
|
213
|
+
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index", where: "(rating > 10)", using: :btree', index_definition
|
214
|
+
elsif current_adapter?(:Mysql2Adapter)
|
215
|
+
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index", using: :btree', index_definition
|
190
216
|
elsif current_adapter?(:SQLite3Adapter) && ActiveRecord::Base.connection.supports_partial_index?
|
191
|
-
assert_equal '
|
217
|
+
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index", where: "rating > 10"', index_definition
|
192
218
|
else
|
193
|
-
assert_equal '
|
219
|
+
assert_equal 't.index ["firm_id", "type"], name: "company_partial_index"', index_definition
|
194
220
|
end
|
195
221
|
end
|
196
222
|
|
@@ -206,28 +232,28 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
206
232
|
assert_match %r{t\.boolean\s+"has_fun",.+default: false}, output
|
207
233
|
end
|
208
234
|
|
209
|
-
if current_adapter?(:
|
235
|
+
if current_adapter?(:Mysql2Adapter)
|
210
236
|
def test_schema_dump_should_add_default_value_for_mysql_text_field
|
211
237
|
output = standard_dump
|
212
|
-
assert_match %r{t
|
238
|
+
assert_match %r{t\.text\s+"body",\s+limit: 65535,\s+null: false$}, output
|
213
239
|
end
|
214
240
|
|
215
241
|
def test_schema_dump_includes_length_for_mysql_binary_fields
|
216
242
|
output = standard_dump
|
217
|
-
assert_match %r{t
|
218
|
-
assert_match %r{t
|
243
|
+
assert_match %r{t\.binary\s+"var_binary",\s+limit: 255$}, output
|
244
|
+
assert_match %r{t\.binary\s+"var_binary_large",\s+limit: 4095$}, output
|
219
245
|
end
|
220
246
|
|
221
247
|
def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
|
222
248
|
output = standard_dump
|
223
|
-
assert_match %r{t
|
224
|
-
assert_match %r{t
|
225
|
-
assert_match %r{t
|
226
|
-
assert_match %r{t
|
227
|
-
assert_match %r{t
|
228
|
-
assert_match %r{t
|
229
|
-
assert_match %r{t
|
230
|
-
assert_match %r{t
|
249
|
+
assert_match %r{t\.blob\s+"tiny_blob",\s+limit: 255$}, output
|
250
|
+
assert_match %r{t\.binary\s+"normal_blob",\s+limit: 65535$}, output
|
251
|
+
assert_match %r{t\.binary\s+"medium_blob",\s+limit: 16777215$}, output
|
252
|
+
assert_match %r{t\.binary\s+"long_blob",\s+limit: 4294967295$}, output
|
253
|
+
assert_match %r{t\.text\s+"tiny_text",\s+limit: 255$}, output
|
254
|
+
assert_match %r{t\.text\s+"normal_text",\s+limit: 65535$}, output
|
255
|
+
assert_match %r{t\.text\s+"medium_text",\s+limit: 16777215$}, output
|
256
|
+
assert_match %r{t\.text\s+"long_text",\s+limit: 4294967295$}, output
|
231
257
|
end
|
232
258
|
|
233
259
|
def test_schema_does_not_include_limit_for_emulated_mysql_boolean_fields
|
@@ -237,32 +263,35 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
237
263
|
|
238
264
|
def test_schema_dumps_index_type
|
239
265
|
output = standard_dump
|
240
|
-
assert_match %r{
|
241
|
-
assert_match %r{
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
if mysql_56?
|
246
|
-
def test_schema_dump_includes_datetime_precision
|
247
|
-
output = standard_dump
|
248
|
-
assert_match %r{t.datetime\s+"written_on",\s+precision: 6$}, output
|
266
|
+
assert_match %r{t\.index \["awesome"\], name: "index_key_tests_on_awesome", type: :fulltext}, output
|
267
|
+
assert_match %r{t\.index \["pizza"\], name: "index_key_tests_on_pizza", using: :btree}, output
|
249
268
|
end
|
250
269
|
end
|
251
270
|
|
252
271
|
def test_schema_dump_includes_decimal_options
|
253
272
|
output = dump_all_table_schema([/^[^n]/])
|
254
|
-
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: 2
|
273
|
+
assert_match %r{precision: 3,[[:space:]]+scale: 2,[[:space:]]+default: "2\.78"}, output
|
255
274
|
end
|
256
275
|
|
257
276
|
if current_adapter?(:PostgreSQLAdapter)
|
258
277
|
def test_schema_dump_includes_bigint_default
|
259
278
|
output = standard_dump
|
260
|
-
assert_match %r{t
|
279
|
+
assert_match %r{t\.bigint\s+"bigint_default",\s+default: 0}, output
|
261
280
|
end
|
262
281
|
|
263
282
|
def test_schema_dump_includes_limit_on_array_type
|
264
283
|
output = standard_dump
|
265
|
-
assert_match %r{t\.
|
284
|
+
assert_match %r{t\.bigint\s+"big_int_data_points\",\s+array: true}, output
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_schema_dump_allows_array_of_decimal_defaults
|
288
|
+
output = standard_dump
|
289
|
+
assert_match %r{t\.decimal\s+"decimal_array_default",\s+default: \["1.23", "3.45"\],\s+array: true}, output
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_schema_dump_expression_indices
|
293
|
+
index_definition = standard_dump.split(/\n/).grep(/t\.index.*company_expression_index/).first.strip
|
294
|
+
assert_equal 't.index "lower((name)::text)", name: "company_expression_index", using: :btree', index_definition
|
266
295
|
end
|
267
296
|
|
268
297
|
if ActiveRecord::Base.connection.supports_extensions?
|
@@ -280,89 +309,20 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
280
309
|
assert_no_match %r{enable_extension}, output
|
281
310
|
end
|
282
311
|
end
|
283
|
-
|
284
|
-
def test_schema_dump_includes_xml_shorthand_definition
|
285
|
-
output = standard_dump
|
286
|
-
if %r{create_table "postgresql_xml_data_type"} =~ output
|
287
|
-
assert_match %r{t.xml "data"}, output
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_schema_dump_includes_inet_shorthand_definition
|
292
|
-
output = standard_dump
|
293
|
-
if %r{create_table "postgresql_network_addresses"} =~ output
|
294
|
-
assert_match %r{t.inet\s+"inet_address",\s+default: "192.168.1.1"}, output
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
def test_schema_dump_includes_cidr_shorthand_definition
|
299
|
-
output = standard_dump
|
300
|
-
if %r{create_table "postgresql_network_addresses"} =~ output
|
301
|
-
assert_match %r{t.cidr\s+"cidr_address",\s+default: "192.168.1.0/24"}, output
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_schema_dump_includes_macaddr_shorthand_definition
|
306
|
-
output = standard_dump
|
307
|
-
if %r{create_table "postgresql_network_addresses"} =~ output
|
308
|
-
assert_match %r{t.macaddr\s+"mac_address",\s+default: "ff:ff:ff:ff:ff:ff"}, output
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_schema_dump_includes_uuid_shorthand_definition
|
313
|
-
output = standard_dump
|
314
|
-
if %r{create_table "postgresql_uuids"} =~ output
|
315
|
-
assert_match %r{t.uuid "guid"}, output
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
def test_schema_dump_includes_hstores_shorthand_definition
|
320
|
-
output = standard_dump
|
321
|
-
if %r{create_table "postgresql_hstores"} =~ output
|
322
|
-
assert_match %r[t.hstore "hash_store", default: {}], output
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
def test_schema_dump_includes_citext_shorthand_definition
|
327
|
-
output = standard_dump
|
328
|
-
if %r{create_table "postgresql_citext"} =~ output
|
329
|
-
assert_match %r[t.citext "text_citext"], output
|
330
|
-
end
|
331
|
-
end
|
332
|
-
|
333
|
-
def test_schema_dump_includes_ltrees_shorthand_definition
|
334
|
-
output = standard_dump
|
335
|
-
if %r{create_table "postgresql_ltrees"} =~ output
|
336
|
-
assert_match %r[t.ltree "path"], output
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
def test_schema_dump_includes_arrays_shorthand_definition
|
341
|
-
output = standard_dump
|
342
|
-
if %r{create_table "postgresql_arrays"} =~ output
|
343
|
-
assert_match %r[t.text\s+"nicknames",\s+array: true], output
|
344
|
-
assert_match %r[t.integer\s+"commission_by_quarter",\s+array: true], output
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
def test_schema_dump_includes_tsvector_shorthand_definition
|
349
|
-
output = standard_dump
|
350
|
-
if %r{create_table "postgresql_tsvectors"} =~ output
|
351
|
-
assert_match %r{t.tsvector "text_vector"}, output
|
352
|
-
end
|
353
|
-
end
|
354
312
|
end
|
355
313
|
|
356
314
|
def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
|
357
315
|
output = standard_dump
|
358
316
|
# Oracle supports precision up to 38 and it identifies decimals with scale 0 as integers
|
359
317
|
if current_adapter?(:OracleAdapter)
|
360
|
-
assert_match %r{t
|
361
|
-
|
318
|
+
assert_match %r{t\.integer\s+"atoms_in_universe",\s+precision: 38}, output
|
319
|
+
elsif current_adapter?(:IBM_DBAdapter)
|
362
320
|
# DB2 supports precision up to 31
|
363
|
-
assert_match %r{t.decimal\s+"atoms_in_universe",\s+precision: 31,\s+scale: 0}, output
|
321
|
+
assert_match %r{t.decimal\s+"atoms_in_universe",\s+precision: 31,\s+scale: 0}, output
|
322
|
+
elsif current_adapter?(:FbAdapter)
|
323
|
+
assert_match %r{t\.integer\s+"atoms_in_universe",\s+precision: 18}, output
|
364
324
|
else
|
365
|
-
assert_match %r{t
|
325
|
+
assert_match %r{t\.decimal\s+"atoms_in_universe",\s+precision: 55}, output
|
366
326
|
end
|
367
327
|
end
|
368
328
|
|
@@ -371,7 +331,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
371
331
|
match = output.match(%r{create_table "goofy_string_id"(.*)do.*\n(.*)\n})
|
372
332
|
assert_not_nil(match, "goofy_string_id table not found")
|
373
333
|
assert_match %r(id: false), match[1], "no table id not preserved"
|
374
|
-
assert_match %r{t
|
334
|
+
assert_match %r{t\.string\s+"id",.*?null: false$}, match[2], "non-primary key id column not preserved"
|
375
335
|
end
|
376
336
|
|
377
337
|
def test_schema_dump_keeps_id_false_when_id_is_false_and_unique_not_null_column_added
|
@@ -391,7 +351,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
391
351
|
end
|
392
352
|
end
|
393
353
|
|
394
|
-
class CreateDogMigration < ActiveRecord::Migration
|
354
|
+
class CreateDogMigration < ActiveRecord::Migration::Current
|
395
355
|
def up
|
396
356
|
create_table("dog_owners") do |t|
|
397
357
|
end
|
@@ -399,9 +359,9 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
399
359
|
create_table("dogs") do |t|
|
400
360
|
t.column :name, :string
|
401
361
|
t.column :owner_id, :integer
|
362
|
+
t.index [:name]
|
363
|
+
t.foreign_key :dog_owners, column: "owner_id" if supports_foreign_keys?
|
402
364
|
end
|
403
|
-
add_index "dogs", [:name]
|
404
|
-
add_foreign_key :dogs, :dog_owners, column: "owner_id" if supports_foreign_keys?
|
405
365
|
end
|
406
366
|
def down
|
407
367
|
drop_table("dogs")
|
@@ -421,6 +381,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
421
381
|
assert_no_match %r{create_table "foo_.+_bar"}, output
|
422
382
|
assert_no_match %r{add_index "foo_.+_bar"}, output
|
423
383
|
assert_no_match %r{create_table "schema_migrations"}, output
|
384
|
+
assert_no_match %r{create_table "ar_internal_metadata"}, output
|
424
385
|
|
425
386
|
if ActiveRecord::Base.connection.supports_foreign_keys?
|
426
387
|
assert_no_match %r{add_foreign_key "foo_.+_bar"}, output
|
@@ -432,6 +393,38 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
432
393
|
ActiveRecord::Base.table_name_suffix = ActiveRecord::Base.table_name_prefix = ''
|
433
394
|
$stdout = original
|
434
395
|
end
|
396
|
+
|
397
|
+
def test_schema_dump_with_table_name_prefix_and_ignoring_tables
|
398
|
+
original, $stdout = $stdout, StringIO.new
|
399
|
+
|
400
|
+
create_cat_migration = Class.new(ActiveRecord::Migration::Current) do
|
401
|
+
def change
|
402
|
+
create_table("cats") do |t|
|
403
|
+
end
|
404
|
+
create_table("omg_cats") do |t|
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
original_table_name_prefix = ActiveRecord::Base.table_name_prefix
|
410
|
+
original_schema_dumper_ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
|
411
|
+
ActiveRecord::Base.table_name_prefix = 'omg_'
|
412
|
+
ActiveRecord::SchemaDumper.ignore_tables = ["cats"]
|
413
|
+
migration = create_cat_migration.new
|
414
|
+
migration.migrate(:up)
|
415
|
+
|
416
|
+
stream = StringIO.new
|
417
|
+
output = ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream).string
|
418
|
+
|
419
|
+
assert_match %r{create_table "omg_cats"}, output
|
420
|
+
refute_match %r{create_table "cats"}, output
|
421
|
+
ensure
|
422
|
+
migration.migrate(:down)
|
423
|
+
ActiveRecord::Base.table_name_prefix = original_table_name_prefix
|
424
|
+
ActiveRecord::SchemaDumper.ignore_tables = original_schema_dumper_ignore_tables
|
425
|
+
|
426
|
+
$stdout = original
|
427
|
+
end
|
435
428
|
end
|
436
429
|
|
437
430
|
class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
@@ -449,7 +442,8 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
|
449
442
|
|
450
443
|
teardown do
|
451
444
|
return unless @connection
|
452
|
-
@connection.
|
445
|
+
@connection.drop_table 'defaults'
|
446
|
+
#, if_exists: true
|
453
447
|
end
|
454
448
|
|
455
449
|
def test_schema_dump_defaults_with_universally_supported_types
|