class ActiveRecord::PostgreSQLDBCreateTest
Public Instance Methods
setup()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 9 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) $stdout, @original_stdout = StringIO.new, $stdout $stderr, @original_stderr = StringIO.new, $stderr end
teardown()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 23 def teardown $stdout, $stderr = @original_stdout, @original_stderr end
test_create_when_database_exists_outputs_info_to_stderr()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 82 def test_create_when_database_exists_outputs_info_to_stderr ActiveRecord::Base.connection.stubs(:create_database).raises( ActiveRecord::Tasks::DatabaseAlreadyExists ) ActiveRecord::Tasks::DatabaseTasks.create @configuration assert_equal "Database 'my-app-db' already exists\n", $stderr.string end
test_creates_database_with_default_encoding()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 37 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
test_creates_database_with_given_collation_and_ctype()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 52 def test_creates_database_with_given_collation_and_ctype @connection.expects(:create_database). with("my-app-db", @configuration.merge("encoding" => "utf8", "collation" => "ja_JP.UTF8", "ctype" => "ja_JP.UTF8")) ActiveRecord::Tasks::DatabaseTasks.create @configuration. merge("collation" => "ja_JP.UTF8", "ctype" => "ja_JP.UTF8") end
test_creates_database_with_given_encoding()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 44 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
test_db_create_with_error_prints_message()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 66 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}") assert_raises(Exception) { ActiveRecord::Tasks::DatabaseTasks.create @configuration } end
test_establishes_connection_to_new_database()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 60 def test_establishes_connection_to_new_database ActiveRecord::Base.expects(:establish_connection).with(@configuration) ActiveRecord::Tasks::DatabaseTasks.create @configuration end
test_establishes_connection_to_postgresql_database()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 27 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
test_when_database_created_successfully_outputs_info_to_stdout()
click to toggle source
# File activerecord/test/cases/tasks/postgresql_rake_test.rb, line 76 def test_when_database_created_successfully_outputs_info_to_stdout ActiveRecord::Tasks::DatabaseTasks.create @configuration assert_equal "Created database 'my-app-db'\n", $stdout.string end