Class: DataMapper::Spec::Adapters::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-core/spec/setup.rb

Direct Known Subclasses

InMemoryAdapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Adapter



96
97
98
# File 'lib/dm-core/spec/setup.rb', line 96

def initialize(name)
  @name = name.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



94
95
96
# File 'lib/dm-core/spec/setup.rb', line 94

def name
  @name
end

Instance Method Details

#adapterObject Also known as: setup



100
101
102
# File 'lib/dm-core/spec/setup.rb', line 100

def adapter
  @adapter ||= setup!
end

#adapter_nameObject



114
115
116
# File 'lib/dm-core/spec/setup.rb', line 114

def adapter_name
  @adapter_name ||= infer_adapter_name
end

#alternate_storage_nameObject



130
131
132
# File 'lib/dm-core/spec/setup.rb', line 130

def alternate_storage_name
  "datamapper_alternate_tests"
end

#connection_uriObject



118
119
120
# File 'lib/dm-core/spec/setup.rb', line 118

def connection_uri
  "#{adapter_name}://#{username}:#{password}@#{host}/#{storage_name}"
end

#default_storage_nameObject



126
127
128
# File 'lib/dm-core/spec/setup.rb', line 126

def default_storage_name
  "datamapper_default_tests"
end

#hostObject



142
143
144
# File 'lib/dm-core/spec/setup.rb', line 142

def host
  ENV.fetch('DM_DB_HOST', 'localhost')
end

#passwordObject



138
139
140
# File 'lib/dm-core/spec/setup.rb', line 138

def password
  ENV.fetch('DM_DB_PASSWORD', 'datamapper')
end

#setup!Object



106
107
108
109
110
111
112
# File 'lib/dm-core/spec/setup.rb', line 106

def setup!
  adapter = DataMapper.setup(name, connection_uri)
  test_connection(adapter)
  adapter
rescue Exception => e
  puts "Could not connect to the database using '#{connection_uri}' because of: #{e.inspect}"
end

#storage_nameObject



122
123
124
# File 'lib/dm-core/spec/setup.rb', line 122

def storage_name
  send("#{name}_storage_name")
end

#test_connection(adapter) ⇒ Object

Test the connection

Overwrite this method if you need to perform custom connection testing

Raises:

  • (Exception)


151
152
153
154
155
# File 'lib/dm-core/spec/setup.rb', line 151

def test_connection(adapter)
  if adapter.respond_to?(:select)
    adapter.select('SELECT 1')
  end
end

#usernameObject



134
135
136
# File 'lib/dm-core/spec/setup.rb', line 134

def username
  ENV.fetch('DM_DB_USER', 'datamapper')
end