Use DatabaseTasks.fixtures_path instead of FIXTURES_PATH in db.rake
This will allow to set fixtures path in global config easier, it should be not needed to use FIXTURES_PATH every time user wants to load fixtures.
This commit is contained in:
parent
d1d7c86d0c
commit
4522761c0a
@ -41,6 +41,7 @@ class Railtie < Rails::Railtie # :nodoc:
|
||||
ActiveRecord::Tasks::DatabaseTasks.seed_loader = Rails.application
|
||||
ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rails.application.config.database_configuration
|
||||
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
||||
ActiveRecord::Tasks::DatabaseTasks.fixtures_path = File.join Rails.root, 'test', 'fixtures'
|
||||
|
||||
if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
|
||||
if engine.paths['db/migrate'].existent
|
||||
|
@ -186,7 +186,15 @@ db_namespace = namespace :db do
|
||||
task :load => [:environment, :load_config] do
|
||||
require 'active_record/fixtures'
|
||||
|
||||
base_dir = File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
|
||||
base_dir = if ENV['FIXTURES_PATH']
|
||||
STDERR.puts "Using FIXTURES_PATH env variable is deprecated, please use " +
|
||||
"ActiveRecord::Tasks::DatabaseTasks.fixtures_path = '/path/to/fixtures' " +
|
||||
"instead."
|
||||
File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
|
||||
else
|
||||
ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
||||
end
|
||||
|
||||
fixtures_dir = File.join [base_dir, ENV['FIXTURES_DIR']].compact
|
||||
|
||||
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir["#{fixtures_dir}/**/*.yml"].map {|f| f[(fixtures_dir.size + 1)..-5] }).each do |fixture_file|
|
||||
@ -203,7 +211,16 @@ db_namespace = namespace :db do
|
||||
|
||||
puts %Q(The fixture ID for "#{label}" is #{ActiveRecord::FixtureSet.identify(label)}.) if label
|
||||
|
||||
base_dir = ENV['FIXTURES_PATH'] ? File.join(Rails.root, ENV['FIXTURES_PATH']) : File.join(Rails.root, 'test', 'fixtures')
|
||||
base_dir = if ENV['FIXTURES_PATH']
|
||||
STDERR.puts "Using FIXTURES_PATH env variable is deprecated, please use " +
|
||||
"ActiveRecord::Tasks::DatabaseTasks.fixtures_path = '/path/to/fixtures' " +
|
||||
"instead."
|
||||
File.join [Rails.root, ENV['FIXTURES_PATH'] || %w{test fixtures}].flatten
|
||||
else
|
||||
ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
||||
end
|
||||
|
||||
|
||||
Dir["#{base_dir}/**/*.yml"].each do |file|
|
||||
if data = YAML::load(ERB.new(IO.read(file)).result)
|
||||
data.keys.each do |key|
|
||||
|
@ -7,7 +7,8 @@ module DatabaseTasks # :nodoc:
|
||||
extend self
|
||||
|
||||
attr_writer :current_config
|
||||
attr_accessor :database_configuration, :migrations_paths, :seed_loader, :db_dir
|
||||
attr_accessor :database_configuration, :migrations_paths, :seed_loader, :db_dir,
|
||||
:fixtures_path
|
||||
|
||||
LOCAL_HOSTS = ['127.0.0.1', 'localhost']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user