Sha256: 8fb41b6432d70a6540bd529512ca8979bc3cc29307a62965ebdca7eda2ccb285
Contents?: true
Size: 1.54 KB
Versions: 3
Compression:
Stored size: 1.54 KB
Contents
require 'pathname' require 'active_record' require 'active_support/core_ext/logger' module ChronoTest extend self AR = ActiveRecord::Base log = ENV['VERBOSE'].present? ? $stderr : 'spec/debug.log'.tap{|f| File.truncate(f, 0)} AR.logger = ::Logger.new(log).tap do |l| l.level = 0 end def connect!(spec = self.config) unless ENV['VERBOSE'].present? spec = spec.merge(:min_messages => 'WARNING') end AR.establish_connection spec end def logger AR.logger end def connection AR.connection end def recreate_database! database = config.fetch(:database) connect! config.merge(:database => 'postgres') unless AR.supports_chrono? raise 'Your postgresql version is not supported. >= 9.0 is required.' end connection.drop_database database connection.create_database database ensure connect! logger.info "Connected to #{config}" end def config @config ||= YAML.load(config_file.read).tap do |conf| conf.symbolize_keys! conf.update(:adapter => 'postgresql') def conf.to_s 'pgsql://%s:%s@%s/%s' % [ self[:username], self[:password], self[:hostname], self[:database] ] end end rescue Errno::ENOENT $stderr.puts <<EOM Please define your AR database configuration in spec/config.yml or reference your own configuration file using the TEST_CONFIG environment variable EOM abort end def config_file Pathname(ENV['TEST_CONFIG'] || File.join(File.dirname(__FILE__), '..', 'config.yml') ) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
chrono_model-0.4.0 | spec/support/connection.rb |
chrono_model-0.3.1 | spec/support/connection.rb |
chrono_model-0.3.0 | spec/support/connection.rb |