From eece968212fd966bdd6a6684ab7f9e1af822fce7 Mon Sep 17 00:00:00 2001 From: Krzysztof Knapik Date: Wed, 2 May 2018 11:31:35 +0200 Subject: [PATCH] Allow local tld on safeguard check on DATABASE_URL --- README.markdown | 2 +- lib/database_cleaner/safeguard.rb | 2 +- spec/database_cleaner/safeguard_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 6dce964..d674dd3 100644 --- a/README.markdown +++ b/README.markdown @@ -507,7 +507,7 @@ end DatabaseCleaner comes with safeguards against: * Running in production (checking for `ENV`, `RACK_ENV`, and `RAILS_ENV`) -* Running against a remote database (checking for a `DATABASE_URL` that does not include `localhost`) +* Running against a remote database (checking for a `DATABASE_URL` that does not include `localhost`, `.local` or `127.0.0.1`) Both safeguards can be disabled separately as follows. diff --git a/lib/database_cleaner/safeguard.rb b/lib/database_cleaner/safeguard.rb index 0c5e73d..55d04eb 100644 --- a/lib/database_cleaner/safeguard.rb +++ b/lib/database_cleaner/safeguard.rb @@ -15,7 +15,7 @@ module DatabaseCleaner end class RemoteDatabaseUrl - LOCAL = %w(localhost 127.0.0.1 sqlite3:) + LOCAL = %w(localhost .local 127.0.0.1 sqlite3:) def run raise Error::RemoteDatabaseUrl if !skip? && given? diff --git a/spec/database_cleaner/safeguard_spec.rb b/spec/database_cleaner/safeguard_spec.rb index fa280a8..c2de148 100644 --- a/spec/database_cleaner/safeguard_spec.rb +++ b/spec/database_cleaner/safeguard_spec.rb @@ -28,6 +28,14 @@ module DatabaseCleaner end end + describe 'to a local tld url' do + let(:database_url) { 'postgres://postgres.local' } + + it 'does not raise' do + expect { cleaner.start }.to_not raise_error + end + end + describe 'to a 127.0.0.1 url' do let(:database_url) { 'postgres://127.0.0.1' }