Guest User

Untitled

a guest
Feb 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. desc 'Prepare the test database and load the schema'
  2. task :prepare_test_database => :environment do
  3. Rake::Task[prepare_test_database_task].invoke
  4. Rake::Task[:populate_test_database_with_fixtures].invoke
  5. end
  6.  
  7.  
  8. task :populate_test_database_with_fixtures => :environment do
  9. ENV["RAILS_ENV"] = "test"
  10. ActiveRecord::Base.establish_connection(:test)
  11. require File.dirname(__FILE__) + "/config/environment"
  12. require 'active_record/fixtures'
  13.  
  14. table_names = Dir.glob(File.dirname(__FILE__) + '/test/fixtures/*.yml').map {|f| File.basename(f).split('.').first }
  15. Fixtures.create_fixtures(File.dirname(__FILE__) + '/test/fixtures', table_names)
  16. end
  17.  
  18. task :setup_dedicated_test_database => :environment do
  19. require 'md5'
  20. require 'socket'
  21.  
  22. config = YAML::load(File.open("#{RAILS_ROOT}/config/database.yml"))
  23. ip_address = IPSocket.getaddress(Socket.gethostname)
  24. full_path = File.expand_path(__FILE__)
  25. config['test']['database'] << "_#{MD5.hexdigest(ip_address + full_path)}"
  26. YAML.dump(config, File.open("#{RAILS_ROOT}/config/database.yml", "w"))
  27. ActiveRecord::Base.connection.recreate_database(config["test"]["database"])
  28.  
  29. puts "Using '#{config['test']['database']}' as a dedicated test database"
  30. end
  31.  
  32. task :drop_dedicated_test_database => :environment do
  33. abcs = ActiveRecord::Base.configurations
  34. ActiveRecord::Base.establish_connection(abcs['test'])
  35. ActiveRecord::Base.connection.drop_database(abcs['test']['database'])
  36.  
  37. puts "Dropped the dedicated test database '#{abcs['test']['database']}'"
  38. end
  39.  
  40.  
  41. desc "Run the unit tests in test/unit"
  42. Rake::TestTask.new(:test_system => [ :prepare_test_database ]) do |t|
  43. t.libs << "test"
  44. t.pattern = 'test/system/**/*_test.rb'
  45. t.verbose = true
  46. end
Add Comment
Please, Sign In to add comment