@@ -503,6 +503,130 @@ module ConnectionAdapters
503
503
504
504
505
505
module ActiveRecord
506
+ # The original module is hardcoded for PostgreSQL/SQLite/MySQL tests.
507
+ module DatabaseTasksSetupper
508
+ def setup
509
+ @sqlserver_tasks =
510
+ Class . new do
511
+ def create ; end
512
+ def drop ; end
513
+ def purge ; end
514
+ def charset ; end
515
+ def collation ; end
516
+ def structure_dump ( *) ; end
517
+ def structure_load ( *) ; end
518
+ end . new
519
+
520
+ $stdout, @original_stdout = StringIO . new , $stdout
521
+ $stderr, @original_stderr = StringIO . new , $stderr
522
+ end
523
+
524
+ def with_stubbed_new
525
+ ActiveRecord ::Tasks ::SQLServerDatabaseTasks . stub ( :new , @sqlserver_tasks ) do
526
+ yield
527
+ end
528
+ end
529
+ end
530
+
531
+ class DatabaseTasksCreateTest < ActiveRecord ::TestCase
532
+ # Coerce PostgreSQL/SQLite/MySQL tests.
533
+ coerce_all_tests!
534
+
535
+ def test_sqlserver_create
536
+ with_stubbed_new do
537
+ assert_called ( eval ( "@sqlserver_tasks" ) , :create ) do
538
+ ActiveRecord ::Tasks ::DatabaseTasks . create "adapter" => :sqlserver
539
+ end
540
+ end
541
+ end
542
+ end
543
+
544
+ class DatabaseTasksDropTest < ActiveRecord ::TestCase
545
+ # Coerce PostgreSQL/SQLite/MySQL tests.
546
+ coerce_all_tests!
547
+
548
+ def test_sqlserver_drop
549
+ with_stubbed_new do
550
+ assert_called ( eval ( "@sqlserver_tasks" ) , :drop ) do
551
+ ActiveRecord ::Tasks ::DatabaseTasks . drop "adapter" => :sqlserver
552
+ end
553
+ end
554
+ end
555
+ end
556
+
557
+ class DatabaseTasksPurgeTest < ActiveRecord ::TestCase
558
+ # Coerce PostgreSQL/SQLite/MySQL tests.
559
+ coerce_all_tests!
560
+
561
+ def test_sqlserver_purge
562
+ with_stubbed_new do
563
+ assert_called ( eval ( "@sqlserver_tasks" ) , :purge ) do
564
+ ActiveRecord ::Tasks ::DatabaseTasks . purge "adapter" => :sqlserver
565
+ end
566
+ end
567
+ end
568
+ end
569
+
570
+ class DatabaseTasksCharsetTest < ActiveRecord ::TestCase
571
+ # Coerce PostgreSQL/SQLite/MySQL tests.
572
+ coerce_all_tests!
573
+
574
+ def test_sqlserver_charset
575
+ with_stubbed_new do
576
+ assert_called ( eval ( "@sqlserver_tasks" ) , :charset ) do
577
+ ActiveRecord ::Tasks ::DatabaseTasks . charset "adapter" => :sqlserver
578
+ end
579
+ end
580
+ end
581
+
582
+ end
583
+
584
+ class DatabaseTasksCollationTest < ActiveRecord ::TestCase
585
+ # Coerce PostgreSQL/SQLite/MySQL tests.
586
+ coerce_all_tests!
587
+
588
+ def test_sqlserver_collation
589
+ with_stubbed_new do
590
+ assert_called ( eval ( "@sqlserver_tasks" ) , :collation ) do
591
+ ActiveRecord ::Tasks ::DatabaseTasks . collation "adapter" => :sqlserver
592
+ end
593
+ end
594
+ end
595
+ end
596
+
597
+ class DatabaseTasksStructureDumpTest < ActiveRecord ::TestCase
598
+ # Coerce PostgreSQL/SQLite/MySQL tests.
599
+ coerce_all_tests!
600
+
601
+ def test_sqlserver_structure_dump
602
+ with_stubbed_new do
603
+ assert_called_with (
604
+ eval ( "@sqlserver_tasks" ) , :structure_dump ,
605
+ [ "awesome-file.sql" , nil ]
606
+ ) do
607
+ ActiveRecord ::Tasks ::DatabaseTasks . structure_dump ( { "adapter" => :sqlserver } , "awesome-file.sql" )
608
+ end
609
+ end
610
+ end
611
+ end
612
+
613
+ class DatabaseTasksStructureLoadTest < ActiveRecord ::TestCase
614
+ # Coerce PostgreSQL/SQLite/MySQL tests.
615
+ coerce_all_tests!
616
+
617
+ def test_sqlserver_structure_load
618
+ with_stubbed_new do
619
+ assert_called_with (
620
+ eval ( "@sqlserver_tasks" ) ,
621
+ :structure_load ,
622
+ [ "awesome-file.sql" , nil ]
623
+ ) do
624
+ ActiveRecord ::Tasks ::DatabaseTasks . structure_load ( { "adapter" => :sqlserver } , "awesome-file.sql" )
625
+ end
626
+ end
627
+ end
628
+ end
629
+
506
630
class DatabaseTasksDumpSchemaCacheTest < ActiveRecord ::TestCase
507
631
# Skip this test with /tmp/my_schema_cache.yml path on Windows.
508
632
coerce_tests! :test_dump_schema_cache if RbConfig ::CONFIG [ 'host_os' ] =~ /mswin|mingw/
0 commit comments