Allow postgres:///dbname as a local url

This commit is contained in:
Will Leinweber 2018-11-06 16:14:01 -08:00
parent 14626296ef
commit cafe8d053e
2 changed files with 19 additions and 2 deletions

View File

@ -39,7 +39,7 @@ module DatabaseCleaner
class RemoteDatabaseUrl class RemoteDatabaseUrl
LOCAL = %w(localhost .local 127.0.0.1 sqlite3:) LOCAL = %w(localhost 127.0.0.1)
def run def run
raise Error::RemoteDatabaseUrl if !skip? && given? raise Error::RemoteDatabaseUrl if !skip? && given?
@ -52,7 +52,16 @@ module DatabaseCleaner
end end
def remote?(url) def remote?(url)
url && !LOCAL.any? { |str| url.include?(str) } return false unless url
parsed = URI.parse(url)
return false if parsed.scheme == 'sqlite3:'
host = parsed.host
return false unless host
return false if LOCAL.include?(host)
return false if host.end_with? '.local'
true
end end
def skip? def skip?

View File

@ -21,6 +21,14 @@ module DatabaseCleaner
end end
end end
describe 'to a local, empty-host url' do
let(:database_url) { 'postgres:///' }
it 'does not raise' do
expect { cleaner.start }.to_not raise_error
end
end
describe 'to a local tld url' do describe 'to a local tld url' do
let(:database_url) { 'postgres://postgres.local' } let(:database_url) { 'postgres://postgres.local' }