diff options
author | kennyj <kennyj@gmail.com> | 2012-06-20 01:28:44 +0900 |
---|---|---|
committer | kennyj <kennyj@gmail.com> | 2012-06-20 01:28:44 +0900 |
commit | d8dfcacd44a051b2c8bf0e940472b074e2c5dfb7 (patch) | |
tree | cda528d444d6ecbd357ee8ead18b4622ab76a77d /activerecord/test/cases | |
parent | 1aa052c6889bf5371ec92e5bfc461070d7d99761 (diff) | |
download | rails-d8dfcacd44a051b2c8bf0e940472b074e2c5dfb7.tar.gz rails-d8dfcacd44a051b2c8bf0e940472b074e2c5dfb7.tar.bz2 rails-d8dfcacd44a051b2c8bf0e940472b074e2c5dfb7.zip |
Refactor db:structure:dump task.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/database_tasks_test.rb | 36 | ||||
-rw-r--r-- | activerecord/test/cases/mysql_rake_test.rb | 24 | ||||
-rw-r--r-- | activerecord/test/cases/postgresql_rake_test.rb | 25 | ||||
-rw-r--r-- | activerecord/test/cases/sqlite_rake_test.rb | 22 |
4 files changed, 106 insertions, 1 deletions
diff --git a/activerecord/test/cases/database_tasks_test.rb b/activerecord/test/cases/database_tasks_test.rb index a5329073ed..41267c2df3 100644 --- a/activerecord/test/cases/database_tasks_test.rb +++ b/activerecord/test/cases/database_tasks_test.rb @@ -303,7 +303,7 @@ module ActiveRecord returns @postgresql_tasks ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks end - + def test_mysql_charset @mysql_tasks.expects(:charset) @@ -328,4 +328,38 @@ module ActiveRecord ActiveRecord::Tasks::DatabaseTasks.charset 'adapter' => 'sqlite3' end end + + class DatabaseTasksStructureDumpTest < ActiveRecord::TestCase + def setup + @mysql_tasks, @postgresql_tasks, @sqlite_tasks = stub, stub, stub + ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks + ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new). + returns @postgresql_tasks + ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks + end + + def test_mysql_structure_dump + @mysql_tasks.expects(:structure_dump).with("awesome-file.sql") + + ActiveRecord::Tasks::DatabaseTasks.structure_dump({'adapter' => 'mysql'}, "awesome-file.sql") + end + + def test_mysql2_structure_dump + @mysql_tasks.expects(:structure_dump).with("awesome-file.sql") + + ActiveRecord::Tasks::DatabaseTasks.structure_dump({'adapter' => 'mysql2'}, "awesome-file.sql") + end + + def test_postgresql_structure_dump + @postgresql_tasks.expects(:structure_dump).with("awesome-file.sql") + + ActiveRecord::Tasks::DatabaseTasks.structure_dump({'adapter' => 'postgresql'}, "awesome-file.sql") + end + + def test_sqlite_structure_dump + @sqlite_tasks.expects(:structure_dump).with("awesome-file.sql") + + ActiveRecord::Tasks::DatabaseTasks.structure_dump({'adapter' => 'sqlite3'}, "awesome-file.sql") + end + end end diff --git a/activerecord/test/cases/mysql_rake_test.rb b/activerecord/test/cases/mysql_rake_test.rb index 39d0ae428c..8255fe3aa5 100644 --- a/activerecord/test/cases/mysql_rake_test.rb +++ b/activerecord/test/cases/mysql_rake_test.rb @@ -194,4 +194,28 @@ module ActiveRecord ActiveRecord::Tasks::DatabaseTasks.charset @configuration end end + + class MySQLStructureDumpTest < ActiveRecord::TestCase + def setup + @connection = stub(:structure_dump => true) + @configuration = { + 'adapter' => 'mysql', + 'database' => 'test-db' + } + + ActiveRecord::Base.stubs(:connection).returns(@connection) + ActiveRecord::Base.stubs(:establish_connection).returns(true) + end + + def test_structure_dump + filename = "awesome-file.sql" + ActiveRecord::Base.expects(:establish_connection).with(@configuration) + @connection.expects(:structure_dump) + + ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename) + assert File.exists?(filename) + ensure + FileUtils.rm(filename) + end + end end diff --git a/activerecord/test/cases/postgresql_rake_test.rb b/activerecord/test/cases/postgresql_rake_test.rb index a9e0d913fa..b055762a24 100644 --- a/activerecord/test/cases/postgresql_rake_test.rb +++ b/activerecord/test/cases/postgresql_rake_test.rb @@ -150,4 +150,29 @@ module ActiveRecord ActiveRecord::Tasks::DatabaseTasks.charset @configuration end end + + class PostgreSQLStructureDumpTest < ActiveRecord::TestCase + def setup + @connection = stub(:structure_dump => true) + @configuration = { + 'adapter' => 'postgresql', + 'database' => 'my-app-db' + } + + ActiveRecord::Base.stubs(:connection).returns(@connection) + ActiveRecord::Base.stubs(:establish_connection).returns(true) + Kernel.stubs(:system) + end + + def test_structure_dump + filename = "awesome-file.sql" + Kernel.expects(:system).with("pg_dump -i -s -x -O -f #{filename} my-app-db").returns(true) + @connection.expects(:schema_search_path).returns("foo") + + ActiveRecord::Tasks::DatabaseTasks.structure_dump(@configuration, filename) + assert File.exists?(filename) + ensure + FileUtils.rm(filename) + end + end end diff --git a/activerecord/test/cases/sqlite_rake_test.rb b/activerecord/test/cases/sqlite_rake_test.rb index cfca937a24..69fb129326 100644 --- a/activerecord/test/cases/sqlite_rake_test.rb +++ b/activerecord/test/cases/sqlite_rake_test.rb @@ -123,4 +123,26 @@ module ActiveRecord ActiveRecord::Tasks::DatabaseTasks.charset @configuration, '/rails/root' end end + + class SqliteStructureDumpTest < ActiveRecord::TestCase + def setup + @database = "db_create.sqlite3" + @configuration = { + 'adapter' => 'sqlite3', + 'database' => @database + } + end + + def test_structure_dump + dbfile = @database + filename = "awesome-file.sql" + + ActiveRecord::Tasks::DatabaseTasks.structure_dump @configuration, filename, '/rails/root' + assert File.exists?(dbfile) + assert File.exists?(filename) + ensure + FileUtils.rm(filename) + FileUtils.rm(dbfile) + end + end end |