Allow local tld on safeguard check on DATABASE_URL

This commit is contained in:
Krzysztof Knapik 2018-05-02 11:31:35 +02:00
parent fa07bc064c
commit eece968212
3 changed files with 10 additions and 2 deletions

View file

@ -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.

View file

@ -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?

View file

@ -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' }