Permalink
Browse files

Making database configuration driven by rails-like .yml file instead …

…of being hard coded in spec_helper.rb
  • Loading branch information...
1 parent 626d31f commit 65c373e450ab8c8aeb9841242e9bdb6fed3487fd @mattconnolly committed Sep 9, 2012
Showing with 48 additions and 17 deletions.
  1. +31 −0 config/database.yml
  2. +17 −17 spec/spec_helper.rb
View
@@ -0,0 +1,31 @@
+# postgresql is the default if no ADAPTER environment variable is set when running specs.
+
+postgresql:
+ adapter: postgresql
+ database: postgres
+ host: localhost
+ username: rapns_test
+ password: ""
+
+jdbcpostgresql:
+ adapter: jdbcpostgresql
+ database: rapns_test
+ host: localhost
+ username: postgres
+ password: ""
+
+mysql:
+ adapter: mysql
+ database: rapns_test
+ host: localhost
+ username: rapns_test
+ password: ""
+ encoding: utf8
+
+mysql2:
+ adapter: mysql
+ database: rapns_test
+ host: localhost
+ username: rapns_test
+ password: ""
+ encoding: utf8
View
@@ -10,37 +10,37 @@
end
require 'active_record'
-adapters = ['mysql', 'mysql2', 'postgresql', 'jdbcpostgresql']
jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
-$adapter = if ENV['ADAPTER']
- ENV['ADAPTER']
-elsif jruby
- 'jdbcpostgresql'
-else
- 'postgresql'
+$adapter = ENV['ADAPTER'] ||
+ if jruby
+ 'jdbcpostgresql'
+ else
+ 'postgresql'
+ end
+
+DATABASE_CONFIG = YAML.load_file(File.expand_path("../config/database.yml", File.dirname(__FILE__)))
+db_config = DATABASE_CONFIG[$adapter]
+
+if db_config.nil?
+ puts "No such adapter '#{$adapter}'. Valid adapters are #{DATABASE_CONFIG.keys.join(', ')}."
+ exit 1
end
if jruby
if ENV['TRAVIS']
- username = 'postgres'
+ db_config['username'] = 'postgres'
else
require 'etc'
- username = Etc.getlogin
+ db_config['username'] = Etc.getlogin
end
-else
- username = nil
-end
-
-if !adapters.include?($adapter)
- puts "No such adapter '#{$adapter}'. Valid adapters are #{adapters.join(', ')}."
- exit 1
end
puts "Using #{$adapter} adapter."
-ActiveRecord::Base.establish_connection('username' => username, 'adapter' => $adapter, 'database' => 'rapns_test')
+ActiveRecord::Base.establish_connection(db_config)
+
require 'generators/templates/create_rapns_notifications'
require 'generators/templates/create_rapns_feedback'
require 'generators/templates/add_alert_is_json_to_rapns_notifications'

0 comments on commit 65c373e

Please sign in to comment.