Skip to content

Commit

Permalink
warning if database_url doesnt match any databases
Browse files Browse the repository at this point in the history
  • Loading branch information
will committed Mar 22, 2011
1 parent e445945 commit bb9a8ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pg.rb
Expand Up @@ -83,7 +83,7 @@ def resolve_db(options={})
def heroku_postgresql_client(url)
HerokuPostgresql::Client10.new(url)
end

def specified_db?
db_flag
end
Expand Down Expand Up @@ -248,10 +248,16 @@ def url_deprecation_check

def default_database_check
return unless @db_id == 'DATABASE'
@db_id = @dbs.find { |k,v|
dbs = @dbs.find { |k,v|
v == @dbs['DATABASE'] && k != 'DATABASE'
}.first
@messages << "using #{@db_id}"
}

if dbs
@db_id = dbs.first
@messages << "using #{@db_id}"
else
@messages << "DATABASE_URL does not match any of your databases"
end
end

def h_pg_color_check
Expand Down
5 changes: 5 additions & 0 deletions pg_spec.rb
Expand Up @@ -82,6 +82,11 @@
r.url.should == 'postgres://red'
end

it 'warns if DATABASE_URL is wrong' do
r = Pg::Resolver.new('DATABASE', config.merge!({"DATABASE_URL" => "foo"}))
r.message.should =~ /DATABASE_URL does not match/
end

it 'is able to get the non default database' do
r = Pg::Resolver.new('PERIWINKLE', config)
r.url.should == 'postgres://pari'
Expand Down

0 comments on commit bb9a8ce

Please sign in to comment.