Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Merge "Fix writing mysql2 adapter to database.yml."
Browse files Browse the repository at this point in the history
  • Loading branch information
April Yu & Matthew Boedicker authored and Gerrit Code Review committed Feb 8, 2013
2 parents fd58243 + 547140f commit 9f6cef7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/vcap/staging/plugin/rails3/database_support.rb
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions spec/unit/rails3_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 9f6cef7

Please sign in to comment.