diff options
author | Guilherme Mansur <guilherme.mansur@shopify.com> | 2019-06-10 16:22:29 -0400 |
---|---|---|
committer | Guilherme Mansur <guilherme.mansur@shopify.com> | 2019-06-17 14:00:53 -0400 |
commit | fe30211574648fa21bff958a3cf952fd0c20c3b1 (patch) | |
tree | d0f4c8b65fadf52ea0b0474c7b646b216e5b4a9f /activerecord/test/cases/adapters/postgresql | |
parent | c65acad0df6b332324c24e725c7d581bd76f9760 (diff) | |
download | rails-fe30211574648fa21bff958a3cf952fd0c20c3b1.tar.gz rails-fe30211574648fa21bff958a3cf952fd0c20c3b1.tar.bz2 rails-fe30211574648fa21bff958a3cf952fd0c20c3b1.zip |
Add database_exists? method to connection adapters
When SQLite connects it will silently create a database if the database does not
exist. This behaviour causes different issues because of inconsistent behaviour
between adapters: #36383, #32914. This commit adds a `database_exists?` method
as a way to check the database without creating it. This is a stepping stone to
fully resolving the above issues.
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index 68bc87eaf8..d99593817a 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -24,6 +24,18 @@ module ActiveRecord end end + def test_database_exists_returns_false_when_the_database_does_not_exist + config = { database: "non_extant_database", adapter: "postgresql" } + assert_not ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.database_exists?(config), + "expected database #{config[:database]} to not exist" + end + + def test_database_exists_returns_true_when_the_database_exists + config = ActiveRecord::Base.configurations["arunit"] + assert ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.database_exists?(config), + "expected database #{config[:database]} to exist" + end + def test_primary_key with_example_table do assert_equal "id", @connection.primary_key("ex") |