Class: DeploymentTest::Postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/deployment_test/postgres.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Postgres

Returns a new instance of Postgres.



6
7
8
9
10
11
12
13
# File 'lib/deployment_test/postgres.rb', line 6

def initialize(options = {})
  @options = {
    :host => "127.0.0.1",
    :dbname => 'postgres',
    :user => 'postgres',
    :password => 'postgres'
  }.merge(options)
end

Instance Method Details

#database_exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/deployment_test/postgres.rb', line 28

def database_exist?(name)
  database_count(name).entries[0]['count'] != '0'
end

#user_can_login?(name, password) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/deployment_test/postgres.rb', line 19

def user_can_login?(name, password)
  begin
    PGconn.connect(@options.merge(:user=>name, :password => password))
    true
  rescue PGError
    false
  end
end

#user_exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/deployment_test/postgres.rb', line 15

def user_exist?(name)
  user_count(name).entries[0]['count'] != '0'
end