Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

89 lines (68 sloc) 2.985 kb
require File.dirname(__FILE__) + '/helper.rb'
class Test_ActiveRecord_ConnectionAdapters_DbslayerAdapter < Test::Unit::TestCase
def setup
@config = { :host => 'localhost', :port => 9090 }
@adapter = ActiveRecord::Base.dbslayer_connection(@config)
end
def test_adapter_name
assert_equal 'DBSlayer (MySQL)', @adapter.adapter_name
end
def test_active?
@adapter.raw_connection.expects(:mysql_stats).returns("STAT_REPLY")
assert @adapter.active?
end
def test_active_fail?
@adapter.raw_connection.expects(:mysql_stats).raises(RuntimeError)
assert_equal false, @adapter.active?
end
def test_select_rows
select_query = "select * from cities limit 10"
select_name = 'foo'
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash(select_query)).returns(CITY_RESULTS)
rows = @adapter.select_rows(select_query, select_name)
assert_equal CITY_ROWS, rows
end
def test_insert_returns_id
insert_sql = "insert into cities(name) values(\"Seattle\")"
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash(insert_sql)).returns(INSERT_ID_RESULT)
id = @adapter.insert_sql(insert_sql)
assert_equal 1, id
end
def test_update_affected_rows
update_sql = "update cities set urban=1"
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash(update_sql)).returns(UPDATE_RESULT)
affected_rows = @adapter.send :update_sql, update_sql
assert_equal 42, affected_rows
end
def test_tables
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash("SHOW TABLES")).returns(SHOW_TABLES_REPLY)
tables = @adapter.tables
assert_equal ["table1", "table2"], tables
end
def test_columns
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash("SHOW FIELDS FROM `places`")).returns(SHOW_COLUMNS_REPLY)
columns = @adapter.columns('places')
assert_equal 4, columns.size
assert_equal %w(id zipcode terms md5hash), columns.map {|c| c.name }
columns.each do |c|
assert_kind_of ActiveRecord::ConnectionAdapters::DbslayerColumn, c
end
end
def test_indexes
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash("SHOW KEYS FROM `places`")).returns(SHOW_KEYS_REPLY)
indexes = @adapter.indexes('places')
assert_equal 2, indexes.size
indexes.each do |i|
assert_kind_of ActiveRecord::ConnectionAdapters::IndexDefinition, i
end
end
def test_pk_and_sequence_for
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash("describe `places`")).returns(DESCRIBE_REPLY)
assert_equal ['id', nil], @adapter.pk_and_sequence_for('places')
end
def test_show_variable
@adapter.raw_connection.expects(:cmd_execute).with(:db, sql_hash("SHOW VARIABLES LIKE 'character_set_database'")).returns(VARIABLE_REPLY)
variable = @adapter.show_variable('character_set_database')
assert_equal 'utf8', variable
end
end
Jump to Line
Something went wrong with that request. Please try again.