Skip to content

Commit

Permalink
allow 127.0.0.1 in DATABASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
svenfuchs authored and etagwerker committed Apr 2, 2018
1 parent 303cfc8 commit 829befd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/database_cleaner/safeguard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def initialize(env)
end

class RemoteDatabaseUrl
LOCAL = %w(localhost 127.0.0.1)

def run
raise Error::RemoteDatabaseUrl if !skip? && given?
end
Expand All @@ -26,7 +28,7 @@ def given?
end

def remote?(url)
url && !url.include?('localhost')
url && !LOCAL.any? { |str| url.include?(str) }
end

def skip?
Expand Down
10 changes: 9 additions & 1 deletion spec/database_cleaner/safeguard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ module DatabaseCleaner
end
end

describe 'to a local url' do
describe 'to a localhost url' do
env DATABASE_URL: 'postgres://localhost'

it 'does not raise' do
expect { cleaner.start }.to_not raise_error
end
end

describe 'to a 127.0.0.1 url' do
env DATABASE_URL: 'postgres://127.0.0.1'

it 'does not raise' do
expect { cleaner.start }.to_not raise_error
end
end

describe 'DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL is set' do
env DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL: true

Expand Down

0 comments on commit 829befd

Please sign in to comment.