diff options
author | Pat Allan <pat@freelancing-gods.com> | 2012-06-17 14:03:32 +0200 |
---|---|---|
committer | Pat Allan <pat@freelancing-gods.com> | 2012-06-17 14:03:32 +0200 |
commit | e678d413bc14e9a38cd9818c7cf727339b2db9e7 (patch) | |
tree | bdf048cf453d84415366460eda59f939b8cbbf85 /activerecord/test/cases | |
parent | d29727235ae967e1ae4880ddfa5fd37d726f779d (diff) | |
download | rails-e678d413bc14e9a38cd9818c7cf727339b2db9e7.tar.gz rails-e678d413bc14e9a38cd9818c7cf727339b2db9e7.tar.bz2 rails-e678d413bc14e9a38cd9818c7cf727339b2db9e7.zip |
db:create for PostgreSQL pulled out into a class.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/postgresql_rake_test.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/activerecord/test/cases/postgresql_rake_test.rb b/activerecord/test/cases/postgresql_rake_test.rb new file mode 100644 index 0000000000..b2f7c2e8ba --- /dev/null +++ b/activerecord/test/cases/postgresql_rake_test.rb @@ -0,0 +1,57 @@ +require 'cases/helper' + +module ActiveRecord + class PostgreSQLDBCreateTest < ActiveRecord::TestCase + def setup + @connection = stub(:create_database => true) + @configuration = { + 'adapter' => 'postgresql', + 'database' => 'my-app-db' + } + + ActiveRecord::Base.stubs(:connection).returns(@connection) + ActiveRecord::Base.stubs(:establish_connection).returns(true) + end + + def test_establishes_connection_to_postgresql_database + ActiveRecord::Base.expects(:establish_connection).with( + 'adapter' => 'postgresql', + 'database' => 'postgres', + 'schema_search_path' => 'public' + ) + + ActiveRecord::Tasks::DatabaseTasks.create @configuration + end + + def test_creates_database_with_default_encoding + @connection.expects(:create_database). + with('my-app-db', @configuration.merge('encoding' => 'utf8')) + + ActiveRecord::Tasks::DatabaseTasks.create @configuration + end + + def test_creates_database_with_given_encoding + @connection.expects(:create_database). + with('my-app-db', @configuration.merge('encoding' => 'latin')) + + ActiveRecord::Tasks::DatabaseTasks.create @configuration. + merge('encoding' => 'latin') + end + + def test_establishes_connection_to_new_database + ActiveRecord::Base.expects(:establish_connection).with(@configuration) + + ActiveRecord::Tasks::DatabaseTasks.create @configuration + end + + def test_db_create_with_error_prints_message + ActiveRecord::Base.stubs(:establish_connection).raises(Exception) + + $stderr.stubs(:puts).returns(true) + $stderr.expects(:puts). + with("Couldn't create database for #{@configuration.inspect}") + + ActiveRecord::Tasks::DatabaseTasks.create @configuration + end + end +end |