Skip to content
This repository
Browse code

Remove duplicated codes.

  • Loading branch information...
commit 30c84aababbd9411a0820e9e238f12b4c6054714 1 parent 1991195
Toshinori Kajihara authored June 21, 2012
52  activerecord/test/cases/database_tasks_test.rb
... ...
@@ -1,15 +1,17 @@
1 1
 require 'cases/helper'
2 2
 
3 3
 module ActiveRecord
4  
-  class DatabaseTasksCreateTest < ActiveRecord::TestCase
  4
+  module DatabaseTasksSetupper
5 5
     def setup
6 6
       @mysql_tasks, @postgresql_tasks, @sqlite_tasks = stub, stub, stub
7  
-
8 7
       ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
9  
-      ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).
10  
-        returns @postgresql_tasks
  8
+      ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).returns @postgresql_tasks
11 9
       ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks
12 10
     end
  11
+  end
  12
+
  13
+  class DatabaseTasksCreateTest < ActiveRecord::TestCase
  14
+    include DatabaseTasksSetupper
13 15
 
14 16
     def test_mysql_create
15 17
       @mysql_tasks.expects(:create)
@@ -137,14 +139,7 @@ def test_establishes_connection_for_the_given_environment
137 139
   end
138 140
 
139 141
   class DatabaseTasksDropTest < ActiveRecord::TestCase
140  
-    def setup
141  
-      @mysql_tasks, @postgresql_tasks, @sqlite_tasks = stub, stub, stub
142  
-
143  
-      ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
144  
-      ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).
145  
-        returns @postgresql_tasks
146  
-      ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks
147  
-    end
  142
+    include DatabaseTasksSetupper
148 143
 
149 144
     def test_mysql_create
150 145
       @mysql_tasks.expects(:drop)
@@ -261,14 +256,7 @@ def test_creates_test_database_when_environment_is_database
261 256
   end
262 257
 
263 258
   class DatabaseTasksPurgeTest < ActiveRecord::TestCase
264  
-    def setup
265  
-      @mysql_tasks, @postgresql_tasks, @sqlite_tasks = stub, stub, stub
266  
-
267  
-      ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
268  
-      ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).
269  
-        returns @postgresql_tasks
270  
-      ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks
271  
-    end
  259
+    include DatabaseTasksSetupper
272 260
 
273 261
     def test_mysql_create
274 262
       @mysql_tasks.expects(:purge)
@@ -296,13 +284,7 @@ def test_sqlite_create
296 284
   end
297 285
 
298 286
   class DatabaseTasksCharsetTest < ActiveRecord::TestCase
299  
-    def setup
300  
-      @mysql_tasks, @postgresql_tasks, @sqlite_tasks = stub, stub, stub
301  
-      ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
302  
-      ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).
303  
-        returns @postgresql_tasks
304  
-      ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks
305  
-    end
  287
+    include DatabaseTasksSetupper
306 288
  
307 289
     def test_mysql_charset
308 290
       @mysql_tasks.expects(:charset)
@@ -330,13 +312,7 @@ def test_sqlite_charset
330 312
   end
331 313
 
332 314
   class DatabaseTasksStructureDumpTest < ActiveRecord::TestCase
333  
-    def setup
334  
-      @mysql_tasks, @postgresql_tasks, @sqlite_tasks = stub, stub, stub
335  
-      ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
336  
-      ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).
337  
-        returns @postgresql_tasks
338  
-      ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks
339  
-    end
  315
+    include DatabaseTasksSetupper
340 316
 
341 317
     def test_mysql_structure_dump
342 318
       @mysql_tasks.expects(:structure_dump).with("awesome-file.sql")
@@ -364,13 +340,7 @@ def test_sqlite_structure_dump
364 340
   end
365 341
 
366 342
   class DatabaseTasksStructureLoadTest < ActiveRecord::TestCase
367  
-    def setup
368  
-      @mysql_tasks, @postgresql_tasks, @sqlite_tasks = stub, stub, stub
369  
-      ActiveRecord::Tasks::MySQLDatabaseTasks.stubs(:new).returns @mysql_tasks
370  
-      ActiveRecord::Tasks::PostgreSQLDatabaseTasks.stubs(:new).
371  
-        returns @postgresql_tasks
372  
-      ActiveRecord::Tasks::SQLiteDatabaseTasks.stubs(:new).returns @sqlite_tasks
373  
-    end
  343
+    include DatabaseTasksSetupper
374 344
 
375 345
     def test_mysql_structure_load
376 346
       @mysql_tasks.expects(:structure_load).with("awesome-file.sql")

0 notes on commit 30c84aa

Please sign in to comment.
Something went wrong with that request. Please try again.