diff options
author | Jacek Becela <jacek.becela@gmail.com> | 2008-07-09 21:34:04 +0200 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-14 01:32:01 +0100 |
commit | 697ee1a50dea7580a7240535d3ad89d2d090721a (patch) | |
tree | 154cce607d90477b6e901b8977c75ce8107cd952 /railties | |
parent | 9783e66cade4d145389cca18fab822f44d03161a (diff) | |
download | rails-697ee1a50dea7580a7240535d3ad89d2d090721a.tar.gz rails-697ee1a50dea7580a7240535d3ad89d2d090721a.tar.bz2 rails-697ee1a50dea7580a7240535d3ad89d2d090721a.zip |
Enable loading fixtures from arbitrary locations. [#586 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/tasks/databases.rake | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 22b8459ce4..87934c295e 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -179,12 +179,15 @@ namespace :db do end namespace :fixtures do - desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y" + 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." task :load => :environment do require 'active_record/fixtures' - ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| - Fixtures.create_fixtures('test/fixtures', File.basename(fixture_file, '.*')) + ActiveRecord::Base.establish_connection(Rails.env) + base_dir = File.join(Rails.root, 'test', 'fixtures') + fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir + + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file| + Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*')) end end |