mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Allow postgres:///dbname as a local url
This commit is contained in:
parent
14626296ef
commit
cafe8d053e
2 changed files with 19 additions and 2 deletions
|
@ -39,7 +39,7 @@ module DatabaseCleaner
|
|||
|
||||
|
||||
class RemoteDatabaseUrl
|
||||
LOCAL = %w(localhost .local 127.0.0.1 sqlite3:)
|
||||
LOCAL = %w(localhost 127.0.0.1)
|
||||
|
||||
def run
|
||||
raise Error::RemoteDatabaseUrl if !skip? && given?
|
||||
|
@ -52,7 +52,16 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def skip?
|
||||
|
|
|
@ -21,6 +21,14 @@ module DatabaseCleaner
|
|||
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
|
||||
let(:database_url) { 'postgres://postgres.local' }
|
||||
|
||||
|
|
Loading…
Reference in a new issue