Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- desc 'Prepare the test database and load the schema'
- task :prepare_test_database => :environment do
- Rake::Task[prepare_test_database_task].invoke
- Rake::Task[:populate_test_database_with_fixtures].invoke
- end
- task :populate_test_database_with_fixtures => :environment do
- ENV["RAILS_ENV"] = "test"
- ActiveRecord::Base.establish_connection(:test)
- require File.dirname(__FILE__) + "/config/environment"
- require 'active_record/fixtures'
- table_names = Dir.glob(File.dirname(__FILE__) + '/test/fixtures/*.yml').map {|f| File.basename(f).split('.').first }
- Fixtures.create_fixtures(File.dirname(__FILE__) + '/test/fixtures', table_names)
- end
- task :setup_dedicated_test_database => :environment do
- require 'md5'
- require 'socket'
- config = YAML::load(File.open("#{RAILS_ROOT}/config/database.yml"))
- ip_address = IPSocket.getaddress(Socket.gethostname)
- full_path = File.expand_path(__FILE__)
- config['test']['database'] << "_#{MD5.hexdigest(ip_address + full_path)}"
- YAML.dump(config, File.open("#{RAILS_ROOT}/config/database.yml", "w"))
- ActiveRecord::Base.connection.recreate_database(config["test"]["database"])
- puts "Using '#{config['test']['database']}' as a dedicated test database"
- end
- task :drop_dedicated_test_database => :environment do
- abcs = ActiveRecord::Base.configurations
- ActiveRecord::Base.establish_connection(abcs['test'])
- ActiveRecord::Base.connection.drop_database(abcs['test']['database'])
- puts "Dropped the dedicated test database '#{abcs['test']['database']}'"
- end
- desc "Run the unit tests in test/unit"
- Rake::TestTask.new(:test_system => [ :prepare_test_database ]) do |t|
- t.libs << "test"
- t.pattern = 'test/system/**/*_test.rb'
- t.verbose = true
- end
Add Comment
Please, Sign In to add comment