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

Returns a new instance of Adapter.



91
92
93
# File 'lib/dm-core/spec/setup.rb', line 91

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



89
90
91
# File 'lib/dm-core/spec/setup.rb', line 89

def name
  @name
end

Instance Method Details

#adapterObject Also known as: setup



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

def adapter
  @adapter ||= setup!
end

#adapter_nameObject



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

def adapter_name
  @adapter_name ||= infer_adapter_name
end

#alternate_storage_nameObject



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

def alternate_storage_name
  "datamapper_alternate_tests"
end

#connection_uriObject



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

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

#default_storage_nameObject



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

def default_storage_name
  "datamapper_default_tests"
end

#passwordObject



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

def password
  'datamapper'
end

#setup!Object



101
102
103
104
105
106
107
# File 'lib/dm-core/spec/setup.rb', line 101

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



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

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)


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

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

#usernameObject



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

def username
  'datamapper'
end