Class: TestData::DetectsDatabaseExistence

Inherits:
Object
  • Object
show all
Defined in:
lib/test_data/detects_database_existence.rb

Instance Method Summary collapse

Constructor Details

#initializeDetectsDatabaseExistence

Returns a new instance of DetectsDatabaseExistence.



3
4
5
# File 'lib/test_data/detects_database_existence.rb', line 3

def initialize
  @config = TestData.config
end

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/test_data/detects_database_existence.rb', line 7

def call
  rows = ActiveRecord::Base.connection.execute <<~SQL
    select datname database_name
    from pg_catalog.pg_database
  SQL
  rows.any? { |row|
    row["database_name"] == @config.database_name
  }
rescue ActiveRecord::NoDatabaseError
  false
end