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
@@ -0,0 +1,154 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'support/schema_dumping_helper'
|
3
|
+
|
4
|
+
class PostgresqlSerialTest < ActiveRecord::PostgreSQLTestCase
|
5
|
+
include SchemaDumpingHelper
|
6
|
+
|
7
|
+
class PostgresqlSerial < ActiveRecord::Base; end
|
8
|
+
|
9
|
+
setup do
|
10
|
+
@connection = ActiveRecord::Base.connection
|
11
|
+
@connection.create_table "postgresql_serials", force: true do |t|
|
12
|
+
t.serial :seq
|
13
|
+
t.integer :serials_id, default: -> { "nextval('postgresql_serials_id_seq')" }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
teardown do
|
18
|
+
@connection.drop_table "postgresql_serials", if_exists: true
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_serial_column
|
22
|
+
column = PostgresqlSerial.columns_hash["seq"]
|
23
|
+
assert_equal :integer, column.type
|
24
|
+
assert_equal "integer", column.sql_type
|
25
|
+
assert column.serial?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_not_serial_column
|
29
|
+
column = PostgresqlSerial.columns_hash["serials_id"]
|
30
|
+
assert_equal :integer, column.type
|
31
|
+
assert_equal "integer", column.sql_type
|
32
|
+
assert_not column.serial?
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_schema_dump_with_shorthand
|
36
|
+
output = dump_table_schema "postgresql_serials"
|
37
|
+
assert_match %r{t\.serial\s+"seq",\s+null: false$}, output
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_schema_dump_with_not_serial
|
41
|
+
output = dump_table_schema "postgresql_serials"
|
42
|
+
assert_match %r{t\.integer\s+"serials_id",\s+default: -> \{ "nextval\('postgresql_serials_id_seq'::regclass\)" \}$}, output
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class PostgresqlBigSerialTest < ActiveRecord::PostgreSQLTestCase
|
47
|
+
include SchemaDumpingHelper
|
48
|
+
|
49
|
+
class PostgresqlBigSerial < ActiveRecord::Base; end
|
50
|
+
|
51
|
+
setup do
|
52
|
+
@connection = ActiveRecord::Base.connection
|
53
|
+
@connection.create_table "postgresql_big_serials", force: true do |t|
|
54
|
+
t.bigserial :seq
|
55
|
+
t.bigint :serials_id, default: -> { "nextval('postgresql_big_serials_id_seq')" }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
teardown do
|
60
|
+
@connection.drop_table "postgresql_big_serials", if_exists: true
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_bigserial_column
|
64
|
+
column = PostgresqlBigSerial.columns_hash["seq"]
|
65
|
+
assert_equal :integer, column.type
|
66
|
+
assert_equal "bigint", column.sql_type
|
67
|
+
assert column.serial?
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_not_bigserial_column
|
71
|
+
column = PostgresqlBigSerial.columns_hash["serials_id"]
|
72
|
+
assert_equal :integer, column.type
|
73
|
+
assert_equal "bigint", column.sql_type
|
74
|
+
assert_not column.serial?
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_schema_dump_with_shorthand
|
78
|
+
output = dump_table_schema "postgresql_big_serials"
|
79
|
+
assert_match %r{t\.bigserial\s+"seq",\s+null: false$}, output
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_schema_dump_with_not_bigserial
|
83
|
+
output = dump_table_schema "postgresql_big_serials"
|
84
|
+
assert_match %r{t\.bigint\s+"serials_id",\s+default: -> \{ "nextval\('postgresql_big_serials_id_seq'::regclass\)" \}$}, output
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
module SequenceNameDetectionTestCases
|
89
|
+
class CollidedSequenceNameTest < ActiveRecord::PostgreSQLTestCase
|
90
|
+
include SchemaDumpingHelper
|
91
|
+
|
92
|
+
def setup
|
93
|
+
@connection = ActiveRecord::Base.connection
|
94
|
+
@connection.create_table :foo_bar, force: true do |t|
|
95
|
+
t.serial :baz_id
|
96
|
+
end
|
97
|
+
@connection.create_table :foo, force: true do |t|
|
98
|
+
t.serial :bar_id
|
99
|
+
t.bigserial :bar_baz_id
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def teardown
|
104
|
+
@connection.drop_table :foo_bar, if_exists: true
|
105
|
+
@connection.drop_table :foo, if_exists: true
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_serial_columns
|
109
|
+
columns = @connection.columns(:foo)
|
110
|
+
columns.each do |column|
|
111
|
+
assert_equal :integer, column.type
|
112
|
+
assert column.serial?
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_schema_dump_with_collided_sequence_name
|
117
|
+
output = dump_table_schema "foo"
|
118
|
+
assert_match %r{t\.serial\s+"bar_id",\s+null: false$}, output
|
119
|
+
assert_match %r{t\.bigserial\s+"bar_baz_id",\s+null: false$}, output
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class LongerSequenceNameDetectionTest < ActiveRecord::PostgreSQLTestCase
|
124
|
+
include SchemaDumpingHelper
|
125
|
+
|
126
|
+
def setup
|
127
|
+
@table_name = "long_table_name_to_test_sequence_name_detection_for_serial_cols"
|
128
|
+
@connection = ActiveRecord::Base.connection
|
129
|
+
@connection.create_table @table_name, force: true do |t|
|
130
|
+
t.serial :seq
|
131
|
+
t.bigserial :bigseq
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def teardown
|
136
|
+
@connection.drop_table @table_name, if_exists: true
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_serial_columns
|
140
|
+
columns = @connection.columns(@table_name)
|
141
|
+
columns.each do |column|
|
142
|
+
assert_equal :integer, column.type
|
143
|
+
assert column.serial?
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_schema_dump_with_long_table_name
|
148
|
+
output = dump_table_schema @table_name
|
149
|
+
assert_match %r{create_table "#{@table_name}", force: :cascade}, output
|
150
|
+
assert_match %r{t\.serial\s+"seq",\s+null: false$}, output
|
151
|
+
assert_match %r{t\.bigserial\s+"bigseq",\s+null: false$}, output
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
class PostgreSQLAdapter < AbstractAdapter
|
6
|
+
class InactivePgConnection
|
7
|
+
def query(*args)
|
8
|
+
raise PG::Error
|
9
|
+
end
|
10
|
+
|
11
|
+
def status
|
12
|
+
PG::CONNECTION_BAD
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class StatementPoolTest < ActiveRecord::PostgreSQLTestCase
|
17
|
+
if Process.respond_to?(:fork)
|
18
|
+
def test_cache_is_per_pid
|
19
|
+
cache = StatementPool.new nil, 10
|
20
|
+
cache['foo'] = 'bar'
|
21
|
+
assert_equal 'bar', cache['foo']
|
22
|
+
|
23
|
+
pid = fork {
|
24
|
+
lookup = cache['foo'];
|
25
|
+
exit!(!lookup)
|
26
|
+
}
|
27
|
+
|
28
|
+
Process.waitpid pid
|
29
|
+
assert $?.success?, 'process should exit successfully'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_dealloc_does_not_raise_on_inactive_connection
|
34
|
+
cache = StatementPool.new InactivePgConnection.new, 10
|
35
|
+
cache['foo'] = 'bar'
|
36
|
+
assert_nothing_raised { cache.clear }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
require 'models/developer'
|
3
|
+
require 'models/topic'
|
4
|
+
|
5
|
+
class PostgresqlTimestampTest < ActiveRecord::PostgreSQLTestCase
|
6
|
+
class PostgresqlTimestampWithZone < ActiveRecord::Base; end
|
7
|
+
|
8
|
+
self.use_transactional_tests = false
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@connection = ActiveRecord::Base.connection
|
12
|
+
@connection.execute("INSERT INTO postgresql_timestamp_with_zones (id, time) VALUES (1, '2010-01-01 10:00:00-1')")
|
13
|
+
end
|
14
|
+
|
15
|
+
teardown do
|
16
|
+
PostgresqlTimestampWithZone.delete_all
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_timestamp_with_zone_values_with_rails_time_zone_support
|
20
|
+
with_timezone_config default: :utc, aware_attributes: true do
|
21
|
+
@connection.reconnect!
|
22
|
+
|
23
|
+
timestamp = PostgresqlTimestampWithZone.find(1)
|
24
|
+
assert_equal Time.utc(2010,1,1, 11,0,0), timestamp.time
|
25
|
+
assert_instance_of Time, timestamp.time
|
26
|
+
end
|
27
|
+
ensure
|
28
|
+
@connection.reconnect!
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_timestamp_with_zone_values_without_rails_time_zone_support
|
32
|
+
with_timezone_config default: :local, aware_attributes: false do
|
33
|
+
@connection.reconnect!
|
34
|
+
# make sure to use a non-UTC time zone
|
35
|
+
@connection.execute("SET time zone 'America/Jamaica'", 'SCHEMA')
|
36
|
+
|
37
|
+
timestamp = PostgresqlTimestampWithZone.find(1)
|
38
|
+
assert_equal Time.utc(2010,1,1, 11,0,0), timestamp.time
|
39
|
+
assert_instance_of Time, timestamp.time
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
@connection.reconnect!
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class PostgresqlTimestampFixtureTest < ActiveRecord::PostgreSQLTestCase
|
47
|
+
fixtures :topics
|
48
|
+
|
49
|
+
def test_group_by_date
|
50
|
+
keys = Topic.group("date_trunc('month', created_at)").count.keys
|
51
|
+
assert_operator keys.length, :>, 0
|
52
|
+
keys.each { |k| assert_kind_of Time, k }
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_load_infinity_and_beyond
|
56
|
+
d = Developer.find_by_sql("select 'infinity'::timestamp as updated_at")
|
57
|
+
assert d.first.updated_at.infinite?, 'timestamp should be infinite'
|
58
|
+
|
59
|
+
d = Developer.find_by_sql("select '-infinity'::timestamp as updated_at")
|
60
|
+
time = d.first.updated_at
|
61
|
+
assert time.infinite?, 'timestamp should be infinite'
|
62
|
+
assert_operator time, :<, 0
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_save_infinity_and_beyond
|
66
|
+
d = Developer.create!(:name => 'aaron', :updated_at => 1.0 / 0.0)
|
67
|
+
assert_equal(1.0 / 0.0, d.updated_at)
|
68
|
+
|
69
|
+
d = Developer.create!(:name => 'aaron', :updated_at => -1.0 / 0.0)
|
70
|
+
assert_equal(-1.0 / 0.0, d.updated_at)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_bc_timestamp
|
74
|
+
date = Date.new(0) - 1.week
|
75
|
+
Developer.create!(:name => "aaron", :updated_at => date)
|
76
|
+
assert_equal date, Developer.find_by_name("aaron").updated_at
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_bc_timestamp_leap_year
|
80
|
+
date = Time.utc(-4, 2, 29)
|
81
|
+
Developer.create!(:name => "taihou", :updated_at => date)
|
82
|
+
assert_equal date, Developer.find_by_name("taihou").updated_at
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_bc_timestamp_year_zero
|
86
|
+
date = Time.utc(0, 4, 7)
|
87
|
+
Developer.create!(:name => "yahagi", :updated_at => date)
|
88
|
+
assert_equal date, Developer.find_by_name("yahagi").updated_at
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
|
3
|
+
class PostgresqlTypeLookupTest < ActiveRecord::PostgreSQLTestCase
|
4
|
+
setup do
|
5
|
+
@connection = ActiveRecord::Base.connection
|
6
|
+
end
|
7
|
+
|
8
|
+
test "array delimiters are looked up correctly" do
|
9
|
+
box_array = @connection.type_map.lookup(1020)
|
10
|
+
int_array = @connection.type_map.lookup(1007)
|
11
|
+
|
12
|
+
assert_equal ';', box_array.delimiter
|
13
|
+
assert_equal ',', int_array.delimiter
|
14
|
+
end
|
15
|
+
|
16
|
+
test "array types correctly respect registration of subtypes" do
|
17
|
+
int_array = @connection.type_map.lookup(1007, -1, "integer[]")
|
18
|
+
bigint_array = @connection.type_map.lookup(1016, -1, "bigint[]")
|
19
|
+
big_array = [123456789123456789]
|
20
|
+
|
21
|
+
assert_raises(ActiveModel::RangeError) { int_array.serialize(big_array) }
|
22
|
+
assert_equal "{123456789123456789}", @connection.type_cast(bigint_array.serialize(big_array))
|
23
|
+
end
|
24
|
+
|
25
|
+
test "range types correctly respect registration of subtypes" do
|
26
|
+
int_range = @connection.type_map.lookup(3904, -1, "int4range")
|
27
|
+
bigint_range = @connection.type_map.lookup(3926, -1, "int8range")
|
28
|
+
big_range = 0..123456789123456789
|
29
|
+
|
30
|
+
assert_raises(ActiveModel::RangeError) { int_range.serialize(big_range) }
|
31
|
+
assert_equal "[0,123456789123456789]", bigint_range.serialize(big_range)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'cases/helper'
|
2
|
+
require 'active_record/connection_adapters/postgresql/utils'
|
3
|
+
|
4
|
+
class PostgreSQLUtilsTest < ActiveRecord::PostgreSQLTestCase
|
5
|
+
Name = ActiveRecord::ConnectionAdapters::PostgreSQL::Name
|
6
|
+
include ActiveRecord::ConnectionAdapters::PostgreSQL::Utils
|
7
|
+
|
8
|
+
def test_extract_schema_qualified_name
|
9
|
+
{
|
10
|
+
%(table_name) => [nil,'table_name'],
|
11
|
+
%("table.name") => [nil,'table.name'],
|
12
|
+
%(schema.table_name) => %w{schema table_name},
|
13
|
+
%("schema".table_name) => %w{schema table_name},
|
14
|
+
%(schema."table_name") => %w{schema table_name},
|
15
|
+
%("schema"."table_name") => %w{schema table_name},
|
16
|
+
%("even spaces".table) => ['even spaces','table'],
|
17
|
+
%(schema."table.name") => ['schema', 'table.name']
|
18
|
+
}.each do |given, expect|
|
19
|
+
assert_equal Name.new(*expect), extract_schema_qualified_name(given)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class PostgreSQLNameTest < ActiveRecord::PostgreSQLTestCase
|
25
|
+
Name = ActiveRecord::ConnectionAdapters::PostgreSQL::Name
|
26
|
+
|
27
|
+
test "represents itself as schema.name" do
|
28
|
+
obj = Name.new("public", "articles")
|
29
|
+
assert_equal "public.articles", obj.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
test "without schema, represents itself as name only" do
|
33
|
+
obj = Name.new(nil, "articles")
|
34
|
+
assert_equal "articles", obj.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
test "quoted returns a string representation usable in a query" do
|
38
|
+
assert_equal %("articles"), Name.new(nil, "articles").quoted
|
39
|
+
assert_equal %("public"."articles"), Name.new("public", "articles").quoted
|
40
|
+
end
|
41
|
+
|
42
|
+
test "prevents double quoting" do
|
43
|
+
name = Name.new('"quoted_schema"', '"quoted_table"')
|
44
|
+
assert_equal "quoted_schema.quoted_table", name.to_s
|
45
|
+
assert_equal %("quoted_schema"."quoted_table"), name.quoted
|
46
|
+
end
|
47
|
+
|
48
|
+
test "equality based on state" do
|
49
|
+
assert_equal Name.new("access", "users"), Name.new("access", "users")
|
50
|
+
assert_equal Name.new(nil, "users"), Name.new(nil, "users")
|
51
|
+
assert_not_equal Name.new(nil, "users"), Name.new("access", "users")
|
52
|
+
assert_not_equal Name.new("access", "users"), Name.new("public", "users")
|
53
|
+
assert_not_equal Name.new("public", "users"), Name.new("public", "articles")
|
54
|
+
end
|
55
|
+
|
56
|
+
test "can be used as hash key" do
|
57
|
+
hash = {Name.new("schema", "article_seq") => "success"}
|
58
|
+
assert_equal "success", hash[Name.new("schema", "article_seq")]
|
59
|
+
assert_equal nil, hash[Name.new("schema", "articles")]
|
60
|
+
assert_equal nil, hash[Name.new("public", "article_seq")]
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
require "cases/helper"
|
2
|
+
require 'support/schema_dumping_helper'
|
3
|
+
|
4
|
+
module PostgresqlUUIDHelper
|
5
|
+
def connection
|
6
|
+
@connection ||= ActiveRecord::Base.connection
|
7
|
+
end
|
8
|
+
|
9
|
+
def drop_table(name)
|
10
|
+
connection.drop_table name, if_exists: true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class PostgresqlUUIDTest < ActiveRecord::PostgreSQLTestCase
|
15
|
+
include PostgresqlUUIDHelper
|
16
|
+
include SchemaDumpingHelper
|
17
|
+
|
18
|
+
class UUIDType < ActiveRecord::Base
|
19
|
+
self.table_name = "uuid_data_type"
|
20
|
+
end
|
21
|
+
|
22
|
+
setup do
|
23
|
+
enable_extension!('uuid-ossp', connection)
|
24
|
+
|
25
|
+
connection.create_table "uuid_data_type" do |t|
|
26
|
+
t.uuid 'guid'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
teardown do
|
31
|
+
drop_table "uuid_data_type"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_change_column_default
|
35
|
+
@connection.add_column :uuid_data_type, :thingy, :uuid, null: false, default: "uuid_generate_v1()"
|
36
|
+
UUIDType.reset_column_information
|
37
|
+
column = UUIDType.columns_hash['thingy']
|
38
|
+
assert_equal "uuid_generate_v1()", column.default_function
|
39
|
+
|
40
|
+
@connection.change_column :uuid_data_type, :thingy, :uuid, null: false, default: "uuid_generate_v4()"
|
41
|
+
|
42
|
+
UUIDType.reset_column_information
|
43
|
+
column = UUIDType.columns_hash['thingy']
|
44
|
+
assert_equal "uuid_generate_v4()", column.default_function
|
45
|
+
ensure
|
46
|
+
UUIDType.reset_column_information
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_data_type_of_uuid_types
|
50
|
+
column = UUIDType.columns_hash["guid"]
|
51
|
+
assert_equal :uuid, column.type
|
52
|
+
assert_equal "uuid", column.sql_type
|
53
|
+
assert_not column.array?
|
54
|
+
|
55
|
+
type = UUIDType.type_for_attribute("guid")
|
56
|
+
assert_not type.binary?
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_treat_blank_uuid_as_nil
|
60
|
+
UUIDType.create! guid: ''
|
61
|
+
assert_equal(nil, UUIDType.last.guid)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_treat_invalid_uuid_as_nil
|
65
|
+
uuid = UUIDType.create! guid: 'foobar'
|
66
|
+
assert_equal(nil, uuid.guid)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_invalid_uuid_dont_modify_before_type_cast
|
70
|
+
uuid = UUIDType.new guid: 'foobar'
|
71
|
+
assert_equal 'foobar', uuid.guid_before_type_cast
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_acceptable_uuid_regex
|
75
|
+
# Valid uuids
|
76
|
+
['A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11',
|
77
|
+
'{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}',
|
78
|
+
'a0eebc999c0b4ef8bb6d6bb9bd380a11',
|
79
|
+
'a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11',
|
80
|
+
'{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}',
|
81
|
+
# The following is not a valid RFC 4122 UUID, but PG doesn't seem to care,
|
82
|
+
# so we shouldn't block it either. (Pay attention to "fb6d" – the "f" here
|
83
|
+
# is invalid – it must be one of 8, 9, A, B, a, b according to the spec.)
|
84
|
+
'{a0eebc99-9c0b-4ef8-fb6d-6bb9bd380a11}',
|
85
|
+
].each do |valid_uuid|
|
86
|
+
uuid = UUIDType.new guid: valid_uuid
|
87
|
+
assert_not_nil uuid.guid
|
88
|
+
end
|
89
|
+
|
90
|
+
# Invalid uuids
|
91
|
+
[['A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11'],
|
92
|
+
Hash.new,
|
93
|
+
0,
|
94
|
+
0.0,
|
95
|
+
true,
|
96
|
+
'Z0000C99-9C0B-4EF8-BB6D-6BB9BD380A11',
|
97
|
+
'a0eebc999r0b4ef8ab6d6bb9bd380a11',
|
98
|
+
'a0ee-bc99------4ef8-bb6d-6bb9-bd38-0a11',
|
99
|
+
'{a0eebc99-bb6d6bb9-bd380a11}'].each do |invalid_uuid|
|
100
|
+
uuid = UUIDType.new guid: invalid_uuid
|
101
|
+
assert_nil uuid.guid
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_uuid_formats
|
106
|
+
["A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11",
|
107
|
+
"{a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11}",
|
108
|
+
"a0eebc999c0b4ef8bb6d6bb9bd380a11",
|
109
|
+
"a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11",
|
110
|
+
"{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}"].each do |valid_uuid|
|
111
|
+
UUIDType.create(guid: valid_uuid)
|
112
|
+
uuid = UUIDType.last
|
113
|
+
assert_equal "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", uuid.guid
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_schema_dump_with_shorthand
|
118
|
+
output = dump_table_schema "uuid_data_type"
|
119
|
+
assert_match %r{t\.uuid "guid"}, output
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_uniqueness_validation_ignores_uuid
|
123
|
+
klass = Class.new(ActiveRecord::Base) do
|
124
|
+
self.table_name = "uuid_data_type"
|
125
|
+
validates :guid, uniqueness: { case_sensitive: false }
|
126
|
+
|
127
|
+
def self.name
|
128
|
+
"UUIDType"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
record = klass.create!(guid: "a0ee-bc99-9c0b-4ef8-bb6d-6bb9-bd38-0a11")
|
133
|
+
duplicate = klass.new(guid: record.guid)
|
134
|
+
|
135
|
+
assert record.guid.present? # Ensure we actually are testing a UUID
|
136
|
+
assert_not duplicate.valid?
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class PostgresqlUUIDGenerationTest < ActiveRecord::PostgreSQLTestCase
|
141
|
+
include PostgresqlUUIDHelper
|
142
|
+
include SchemaDumpingHelper
|
143
|
+
|
144
|
+
class UUID < ActiveRecord::Base
|
145
|
+
self.table_name = 'pg_uuids'
|
146
|
+
end
|
147
|
+
|
148
|
+
setup do
|
149
|
+
connection.create_table('pg_uuids', id: :uuid, default: 'uuid_generate_v1()') do |t|
|
150
|
+
t.string 'name'
|
151
|
+
t.uuid 'other_uuid', default: 'uuid_generate_v4()'
|
152
|
+
end
|
153
|
+
|
154
|
+
# Create custom PostgreSQL function to generate UUIDs
|
155
|
+
# to test dumping tables which columns have defaults with custom functions
|
156
|
+
connection.execute <<-SQL
|
157
|
+
CREATE OR REPLACE FUNCTION my_uuid_generator() RETURNS uuid
|
158
|
+
AS $$ SELECT * FROM uuid_generate_v4() $$
|
159
|
+
LANGUAGE SQL VOLATILE;
|
160
|
+
SQL
|
161
|
+
|
162
|
+
# Create such a table with custom function as default value generator
|
163
|
+
connection.create_table('pg_uuids_2', id: :uuid, default: 'my_uuid_generator()') do |t|
|
164
|
+
t.string 'name'
|
165
|
+
t.uuid 'other_uuid_2', default: 'my_uuid_generator()'
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
teardown do
|
170
|
+
drop_table "pg_uuids"
|
171
|
+
drop_table 'pg_uuids_2'
|
172
|
+
connection.execute 'DROP FUNCTION IF EXISTS my_uuid_generator();'
|
173
|
+
end
|
174
|
+
|
175
|
+
if ActiveRecord::Base.connection.supports_extensions?
|
176
|
+
def test_id_is_uuid
|
177
|
+
assert_equal :uuid, UUID.columns_hash['id'].type
|
178
|
+
assert UUID.primary_key
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_id_has_a_default
|
182
|
+
u = UUID.create
|
183
|
+
assert_not_nil u.id
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_auto_create_uuid
|
187
|
+
u = UUID.create
|
188
|
+
u.reload
|
189
|
+
assert_not_nil u.other_uuid
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_pk_and_sequence_for_uuid_primary_key
|
193
|
+
pk, seq = connection.pk_and_sequence_for('pg_uuids')
|
194
|
+
assert_equal 'id', pk
|
195
|
+
assert_equal nil, seq
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_schema_dumper_for_uuid_primary_key
|
199
|
+
schema = dump_table_schema "pg_uuids"
|
200
|
+
assert_match(/\bcreate_table "pg_uuids", id: :uuid, default: -> { "uuid_generate_v1\(\)" }/, schema)
|
201
|
+
assert_match(/t\.uuid "other_uuid", default: -> { "uuid_generate_v4\(\)" }/, schema)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_schema_dumper_for_uuid_primary_key_with_custom_default
|
205
|
+
schema = dump_table_schema "pg_uuids_2"
|
206
|
+
assert_match(/\bcreate_table "pg_uuids_2", id: :uuid, default: -> { "my_uuid_generator\(\)" }/, schema)
|
207
|
+
assert_match(/t\.uuid "other_uuid_2", default: -> { "my_uuid_generator\(\)" }/, schema)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class PostgresqlUUIDTestNilDefault < ActiveRecord::PostgreSQLTestCase
|
213
|
+
include PostgresqlUUIDHelper
|
214
|
+
include SchemaDumpingHelper
|
215
|
+
|
216
|
+
setup do
|
217
|
+
connection.create_table('pg_uuids', id: false) do |t|
|
218
|
+
t.primary_key :id, :uuid, default: nil
|
219
|
+
t.string 'name'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
teardown do
|
224
|
+
drop_table "pg_uuids"
|
225
|
+
end
|
226
|
+
|
227
|
+
if ActiveRecord::Base.connection.supports_extensions?
|
228
|
+
def test_id_allows_default_override_via_nil
|
229
|
+
col_desc = connection.execute("SELECT pg_get_expr(d.adbin, d.adrelid) as default
|
230
|
+
FROM pg_attribute a
|
231
|
+
LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
232
|
+
WHERE a.attname='id' AND a.attrelid = 'pg_uuids'::regclass").first
|
233
|
+
assert_nil col_desc["default"]
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_schema_dumper_for_uuid_primary_key_with_default_override_via_nil
|
237
|
+
schema = dump_table_schema "pg_uuids"
|
238
|
+
assert_match(/\bcreate_table "pg_uuids", id: :uuid, default: nil/, schema)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class PostgresqlUUIDTestInverseOf < ActiveRecord::PostgreSQLTestCase
|
244
|
+
include PostgresqlUUIDHelper
|
245
|
+
|
246
|
+
class UuidPost < ActiveRecord::Base
|
247
|
+
self.table_name = 'pg_uuid_posts'
|
248
|
+
has_many :uuid_comments, inverse_of: :uuid_post
|
249
|
+
end
|
250
|
+
|
251
|
+
class UuidComment < ActiveRecord::Base
|
252
|
+
self.table_name = 'pg_uuid_comments'
|
253
|
+
belongs_to :uuid_post
|
254
|
+
end
|
255
|
+
|
256
|
+
setup do
|
257
|
+
connection.transaction do
|
258
|
+
connection.create_table('pg_uuid_posts', id: :uuid) do |t|
|
259
|
+
t.string 'title'
|
260
|
+
end
|
261
|
+
connection.create_table('pg_uuid_comments', id: :uuid) do |t|
|
262
|
+
t.references :uuid_post, type: :uuid
|
263
|
+
t.string 'content'
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
teardown do
|
269
|
+
drop_table "pg_uuid_comments"
|
270
|
+
drop_table "pg_uuid_posts"
|
271
|
+
end
|
272
|
+
|
273
|
+
if ActiveRecord::Base.connection.supports_extensions?
|
274
|
+
def test_collection_association_with_uuid
|
275
|
+
post = UuidPost.create!
|
276
|
+
comment = post.uuid_comments.create!
|
277
|
+
assert post.uuid_comments.find(comment.id)
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_find_with_uuid
|
281
|
+
UuidPost.create!
|
282
|
+
assert_raise ActiveRecord::RecordNotFound do
|
283
|
+
UuidPost.find(123456)
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_find_by_with_uuid
|
289
|
+
UuidPost.create!
|
290
|
+
assert_nil UuidPost.find_by(id: 789)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
end
|