Permalink
Browse files

Fix writing mysql2 adapter to database.yml.

Change-Id: Ifee76eec8d3c6f17e22d21c3fe5ec279ff796388
  • Loading branch information...
1 parent 5f757b2 commit 547140fc6f951acbe24805535635c4628f8ac45e April Yu & Matthew Boedicker committed Feb 8, 2013
Showing with 24 additions and 1 deletion.
  1. +2 −1 lib/vcap/staging/plugin/rails3/database_support.rb
  2. +22 −0 spec/unit/rails3_spec.rb
@@ -50,12 +50,13 @@ def database_type
DATABASE_TO_ADAPTER_MAPPING = {
:mysql => 'mysql2',
+ :mysql2 => 'mysql2',
:postgres => 'postgresql'
}
def database_config
- { 'adapter' => DATABASE_TO_ADAPTER_MAPPING[database_type], 'encoding' => 'utf8', 'pool' => 5,
+ { 'adapter' => DATABASE_TO_ADAPTER_MAPPING.fetch(database_type), 'encoding' => 'utf8', 'pool' => 5,
'reconnect' => false }.merge(credentials)
end
View
@@ -298,6 +298,28 @@
lambda {stage(rails_staging_env([{:label=>"postgresql-9.0",
:name=> "myservice"}]))}.should raise_error RuntimeError
end
+
+ it 'raises an exception when the database adapter mapping is unknown' do
+ mock.instance_of(Rails3Plugin).database_type {:unknown_db}
+
+ expect {
+ stage(rails_staging_env([
+ {:label => "mysql-5.5", :name => "myservice", :credentials => {
+ :hostname => "thehost", :user => "auser", :port => 34567, :password => "testa", :name => "mydb23"}}
+ ]))
+ }.to raise_error(KeyError)
+ end
+
+ it 'sets the right adapter for mysql' do
+ stage(rails_staging_env([{:label => "mysql-5.5",
+ :credentials => {:hostname => "myhost", :user => "testuser", :port => 345, :password => "test",
+ :name => "mydb"}}])) do |staged_dir|
+ env = staged_dir.join('app', 'config', 'database.yml')
+ db_settings = YAML.load_file(env)
+ expect(db_settings['production']['adapter']).to eq 'mysql2'
+ end
+ end
+
end
describe "which has no database.yml" do

0 comments on commit 547140f

Please sign in to comment.