@@ -553,24 +553,24 @@ def reset_cache
553
553
@@all_cached_fixtures . clear
554
554
end
555
555
556
- def cache_for_connection ( connection )
557
- @@all_cached_fixtures [ connection ]
556
+ def cache_for_connection_pool ( connection_pool )
557
+ @@all_cached_fixtures [ connection_pool ]
558
558
end
559
559
560
- def fixture_is_cached? ( connection , table_name )
561
- cache_for_connection ( connection ) [ table_name ]
560
+ def fixture_is_cached? ( connection_pool , table_name )
561
+ cache_for_connection_pool ( connection_pool ) [ table_name ]
562
562
end
563
563
564
- def cached_fixtures ( connection , keys_to_fetch = nil )
564
+ def cached_fixtures ( connection_pool , keys_to_fetch = nil )
565
565
if keys_to_fetch
566
- cache_for_connection ( connection ) . values_at ( *keys_to_fetch )
566
+ cache_for_connection_pool ( connection_pool ) . values_at ( *keys_to_fetch )
567
567
else
568
- cache_for_connection ( connection ) . values
568
+ cache_for_connection_pool ( connection_pool ) . values
569
569
end
570
570
end
571
571
572
- def cache_fixtures ( connection , fixtures_map )
573
- cache_for_connection ( connection ) . update ( fixtures_map )
572
+ def cache_fixtures ( connection_pool , fixtures_map )
573
+ cache_for_connection_pool ( connection_pool ) . update ( fixtures_map )
574
574
end
575
575
576
576
def instantiate_fixtures ( object , fixture_set , load_instances = true )
@@ -588,27 +588,25 @@ def instantiate_all_loaded_fixtures(object, load_instances = true)
588
588
end
589
589
end
590
590
591
- def create_fixtures ( fixtures_directories , fixture_set_names , class_names = { } , config = ActiveRecord ::Base , & block )
591
+ def create_fixtures ( fixtures_directories , fixture_set_names , class_names = { } , config = ActiveRecord ::Base )
592
592
fixture_set_names = Array ( fixture_set_names ) . map ( &:to_s )
593
593
class_names . stringify_keys!
594
594
595
- # FIXME: Apparently JK uses this.
596
- connection = block_given? ? block : lambda { ActiveRecord ::Base . connection }
597
-
595
+ connection_pool = config . connection_pool
598
596
fixture_files_to_read = fixture_set_names . reject do |fs_name |
599
- fixture_is_cached? ( connection . call , fs_name )
597
+ fixture_is_cached? ( connection_pool , fs_name )
600
598
end
601
599
602
600
if fixture_files_to_read . any?
603
601
fixtures_map = read_and_insert (
604
602
Array ( fixtures_directories ) ,
605
603
fixture_files_to_read ,
606
604
class_names ,
607
- connection ,
605
+ connection_pool ,
608
606
)
609
- cache_fixtures ( connection . call , fixtures_map )
607
+ cache_fixtures ( connection_pool , fixtures_map )
610
608
end
611
- cached_fixtures ( connection . call , fixture_set_names )
609
+ cached_fixtures ( connection_pool , fixture_set_names )
612
610
end
613
611
614
612
# Returns a consistent, platform-independent identifier for +label+.
@@ -641,7 +639,7 @@ def context_class
641
639
end
642
640
643
641
private
644
- def read_and_insert ( fixtures_directories , fixture_files , class_names , connection ) # :nodoc:
642
+ def read_and_insert ( fixtures_directories , fixture_files , class_names , connection_pool ) # :nodoc:
645
643
fixtures_map = { }
646
644
directory_glob = "{#{ fixtures_directories . join ( "," ) } }"
647
645
fixture_sets = fixture_files . map do |fixture_set_name |
@@ -655,21 +653,21 @@ def read_and_insert(fixtures_directories, fixture_files, class_names, connection
655
653
end
656
654
update_all_loaded_fixtures ( fixtures_map )
657
655
658
- insert ( fixture_sets , connection )
656
+ insert ( fixture_sets , connection_pool )
659
657
660
658
fixtures_map
661
659
end
662
660
663
- def insert ( fixture_sets , connection ) # :nodoc:
664
- fixture_sets_by_connection = fixture_sets . group_by do |fixture_set |
661
+ def insert ( fixture_sets , connection_pool ) # :nodoc:
662
+ fixture_sets_by_pool = fixture_sets . group_by do |fixture_set |
665
663
if fixture_set . model_class
666
- fixture_set . model_class . connection
664
+ fixture_set . model_class . connection_pool
667
665
else
668
- connection . call
666
+ connection_pool
669
667
end
670
668
end
671
669
672
- fixture_sets_by_connection . each do |conn , set |
670
+ fixture_sets_by_pool . each do |pool , set |
673
671
table_rows_for_connection = Hash . new { |h , k | h [ k ] = [ ] }
674
672
675
673
set . each do |fixture_set |
@@ -678,13 +676,15 @@ def insert(fixture_sets, connection) # :nodoc:
678
676
end
679
677
end
680
678
681
- conn . insert_fixtures_set ( table_rows_for_connection , table_rows_for_connection . keys )
679
+ pool . with_connection do |conn |
680
+ conn . insert_fixtures_set ( table_rows_for_connection , table_rows_for_connection . keys )
682
681
683
- check_all_foreign_keys_valid! ( conn )
682
+ check_all_foreign_keys_valid! ( conn )
684
683
685
- # Cap primary key sequences to max(pk).
686
- if conn . respond_to? ( :reset_pk_sequence! )
687
- set . each { |fs | conn . reset_pk_sequence! ( fs . table_name ) }
684
+ # Cap primary key sequences to max(pk).
685
+ if conn . respond_to? ( :reset_pk_sequence! )
686
+ set . each { |fs | conn . reset_pk_sequence! ( fs . table_name ) }
687
+ end
688
688
end
689
689
end
690
690
end
0 commit comments