Class: Cranium::TestFramework::DatabaseTable

Inherits:
DatabaseEntity show all
Defined in:
lib/cranium/test_framework/database_table.rb

Instance Attribute Summary

Attributes inherited from DatabaseEntity

#connection, #entity_name

Instance Method Summary collapse

Methods inherited from DatabaseEntity

cleanup, entities_created, #initialize

Constructor Details

This class inherits a constructor from Cranium::TestFramework::DatabaseEntity

Instance Method Details

#clearObject



35
36
37
# File 'lib/cranium/test_framework/database_table.rb', line 35

def clear
  connection[entity_name].truncate
end

#content(fields = ["*".to_sym]) ⇒ Object



23
24
25
# File 'lib/cranium/test_framework/database_table.rb', line 23

def content(fields = ["*".to_sym])
  connection[entity_name].select(*fields).all
end

#countObject



17
18
19
# File 'lib/cranium/test_framework/database_table.rb', line 17

def count
  connection[entity_name].count
end

#create(fields) ⇒ Object



4
5
6
7
# File 'lib/cranium/test_framework/database_table.rb', line 4

def create(fields)
  connection.run "CREATE TABLE #{entity_name} (#{fields.map { |field| "#{field[:field_name]} #{field[:field_type]}" }.join ", " })"
  self.class.entities_created << self
end

#destroyObject



11
12
13
# File 'lib/cranium/test_framework/database_table.rb', line 11

def destroy
  connection.run "DROP TABLE #{entity_name}"
end

#insert(data) ⇒ Object



29
30
31
# File 'lib/cranium/test_framework/database_table.rb', line 29

def insert(data)
  connection[entity_name].multi_insert data
end