Skip to content

Commit

Permalink
rake db:fixtures:load and db:fixtures:identify now accept a FIXTURES_…
Browse files Browse the repository at this point in the history
…PATH option eg. "rake db:fixtures:load FIXTURES_PATH=spec/fixtures"

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#792 state:committed]
  • Loading branch information
matthewrudy authored and NZKoz committed Aug 9, 2008
1 parent b263050 commit eb4668b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions railties/lib/tasks/databases.rake
Expand Up @@ -182,19 +182,19 @@ namespace :db do
end

namespace :fixtures do
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."
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. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
task :load => :environment do
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(Rails.env)
base_dir = File.join(Rails.root, 'test', 'fixtures')
base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : 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

desc "Search for a fixture given a LABEL or ID."
desc "Search for a fixture given a LABEL or ID. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
task :identify => :environment do
require "active_record/fixtures"

Expand All @@ -203,7 +203,8 @@ namespace :db do

puts %Q(The fixture ID for "#{label}" is #{Fixtures.identify(label)}.) if label

Dir["#{RAILS_ROOT}/test/fixtures/**/*.yml"].each do |file|
base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
Dir["#{base_dir}/**/*.yml"].each do |file|
if data = YAML::load(ERB.new(IO.read(file)).result)
data.keys.each do |key|
key_id = Fixtures.identify(key)
Expand Down

0 comments on commit eb4668b

Please sign in to comment.