Sha256: 471ecfb9c1597d8eafc2b56bd672852760c55748005f56172768578b5c4d903c
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
require 'rubygems' require 'bundler' Bundler.setup Bundler.require(:default, :development) if defined?(Debugger) ::Debugger.start ::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings) end $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'active_record_shards' require 'models' require 'logger' RAILS_ENV = "test" ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/test.log") ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) ActiveRecord::Base.configurations.each do |name, conf| puts "Setting up the #{conf['database']} db" begin ActiveRecord::Base.establish_connection(name) ActiveRecord::Base.connection rescue Mysql::Error => e `echo "create DATABASE #{conf['database']}" | mysql --user=#{conf['username']}` ActiveRecord::Base.establish_connection(name) end load(File.dirname(__FILE__) + "/schema.rb") end require 'active_support/test_case' class ActiveSupport::TestCase def clear_databases ActiveRecord::Base.configurations.each do |name, conf| ActiveRecord::Base.establish_connection(name) ActiveRecord::Base.connection.execute("DELETE FROM accounts") ActiveRecord::Base.connection.execute("DELETE FROM tickets") end ActiveRecord::Base.establish_connection(RAILS_ENV) end setup :clear_databases def assert_using_master_db assert_using_database('ars_test') end def assert_using_slave_db assert_using_database('ars_test_slave') end def assert_using_database(db_name, model = ActiveRecord::Base) assert_equal(db_name, model.connection.current_database) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_record_shards-2.2.0 | test/helper.rb |