Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / lib / plugins / extension_patches / lib / .svn / text-base / fixture_loading_extension.rb.svn-base
blob1b70efe6c0d06cb9bcbe67bb826ff1cbb380506a
1 module Radiant
2   module FixtureLoadingExtension
3     def self.included(base)
4       class << base
5         include ClassMethods
6         alias_method_chain :create_fixtures, :multiple_paths
7       end
8     end\r 
9     module ClassMethods
10       def create_fixtures_with_multiple_paths(fixtures_directory, table_names, class_names = {})
11         table_names = [table_names].flatten.map { |n| n.to_s }
12         connection = block_given? ? yield : ActiveRecord::Base.connection
13         ActiveRecord::Base.silence do
14           fixtures_map = {}
15           fixtures = table_names.map do |table_name|
16             paths = fixtures_directory.dup
17             begin
18               directory = paths.pop
19               fixtures_map[table_name] = Fixtures.new(connection, File.split(table_name.to_s).last, class_names[table_name.to_sym], File.join(directory, table_name))
20             rescue SystemCallError => e
21               retry unless paths.empty?
22               raise e
23             end
24           end               
25           all_loaded_fixtures.merge! fixtures_map  
26     
27           connection.transaction(Thread.current['open_transactions'] == 0) do
28             fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures }
29             fixtures.each { |fixture| fixture.insert_fixtures }
30     
31             # Cap primary key sequences to max(pk).
32             if connection.respond_to?(:reset_pk_sequence!)
33               table_names.each do |table_name|
34                 connection.reset_pk_sequence!(table_name)
35               end
36             end
37           end
38     
39           return fixtures.size > 1 ? fixtures : fixtures.first
40         end
41       end  
42     end
43   end
44 end
46 require 'active_record/fixtures'
47 Fixtures.class_eval { include Radiant::FixtureLoadingExtension }
49 require 'action_controller/test_process'
50 module ActionController::TestProcess
51   def fixture_file_upload(path, mime_type = nil)
52     if Test::Unit::TestCase.respond_to?(:fixture_path)
53       fixture_path = Test::Unit::TestCase.fixture_path
54       if(fixture_path.respond_to? :to_str)
55         ActionController::TestUploadedFile.new(
56           fixture_path.to_str + path, 
57           mime_type
58         )
59       else
60         best_path = fixture_path.find { |x| File.exist? (x + path) }
61         best_path ||= fixture_path.last
62         ActionController::TestUploadedFile.new(
63           best_path + path, 
64           mime_type
65         )        
66       end
67     else
68       ActionController::TestUploadedFile.new(
69         path, 
70         mime_type
71       )
72     end
73   end
74 end