public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Enable loading fixtures from arbitrary locations. [#586 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Jacek Becela (author)
Wed Jul 09 12:34:04 -0700 2008
lifo (committer)
Sun Jul 13 17:32:01 -0700 2008
commit  697ee1a50dea7580a7240535d3ad89d2d090721a
tree    154cce607d90477b6e901b8977c75ce8107cd952
parent  9783e66cade4d145389cca18fab822f44d03161a
...
179
180
181
182
 
183
184
185
186
187
 
 
 
 
 
 
188
189
190
...
179
180
181
 
182
183
184
 
 
 
185
186
187
188
189
190
191
192
193
0
@@ -179,12 +179,15 @@ namespace :db do
0
   end
0
 
0
   namespace :fixtures do
0
-    desc "Load fixtures into the current environment's database.  Load specific fixtures using FIXTURES=x,y"
0
+    desc "Load fixtures into the current environment's database.  Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
0
     task :load => :environment do
0
       require 'active_record/fixtures'
0
-      ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
0
-      (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
0
-        Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*'))
0
+      ActiveRecord::Base.establish_connection(Rails.env)
0
+      base_dir = File.join(Rails.root, 'test', 'fixtures')
0
+      fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
0
+
0
+      (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
0
+        Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
0
       end
0
     end
0
 

Comments