Permalink
Browse files

create databases for specs if dbs are missed

  • Loading branch information...
1 parent e578517 commit 20599f0801c2921f5a09c9d00c0e17fb8003176c @artemk artemk committed Aug 3, 2011
Showing with 20 additions and 2 deletions.
  1. +3 −1 spec/database.yml.sample
  2. +17 −1 spec/spec_helper.rb
View
@@ -8,10 +8,12 @@ mysql:
username: root
password:
database: acts_as_taggable_on
-
+ charset: utf8
+
postgresql:
adapter: postgresql
hostname: localhost
username: postgres
password:
database: acts_as_taggable_on
+ encoding: utf8
View
@@ -37,8 +37,24 @@ def freq
active_record_configuration = YAML.load_file(database_yml)
ActiveRecord::Base.configurations = active_record_configuration
+ config = ActiveRecord::Base.configurations[db_name]
- ActiveRecord::Base.establish_connection(db_name)
+ begin
+ ActiveRecord::Base.establish_connection(db_name)
+ ActiveRecord::Base.connection
+ rescue
+ case db_name
+ when /mysql/
+ ActiveRecord::Base.establish_connection(config.merge('database' => nil))
+ ActiveRecord::Base.connection.create_database(config['database'], {:charset => 'utf8', :collation => 'utf8_unicode_ci'})
+ when 'postgresql'
+ ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
+ ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
+ end
+
+ ActiveRecord::Base.establish_connection(config)
+ end
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
ActiveRecord::Base.default_timezone = :utc

0 comments on commit 20599f0

Please sign in to comment.