Merge pull request #547 from knapo/allow-local-tld-in-safeguards

Allow `local` tld on safeguard check on DATABASE_URL
This commit is contained in:
Ernesto Tagwerker 2018-05-02 09:21:12 -04:00 committed by GitHub
commit 868b991eae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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' }