Methods
S
T
Included Modules
Instance Public methods
setup()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 10
def setup
  @conn = ActiveRecord::Base.connection
end
test_bad_connection_mysql()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 14
def test_bad_connection_mysql
  assert_raise ActiveRecord::NoDatabaseError do
    configuration = ActiveRecord::Base.configurations['arunit'].merge(database: 'inexistent_activerecord_unittest')
    connection = ActiveRecord::Base.mysql_connection(configuration)
    connection.exec_query('drop table if exists ex')
  end
end
test_client_encoding()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 33
def test_client_encoding
  assert_equal Encoding::UTF_8, @conn.client_encoding
end
test_composite_primary_key()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 101
def test_composite_primary_key
  with_example_table '`id` INT(11), `number` INT(11), foo INT(11), PRIMARY KEY (`id`, `number`)' do
    assert_nil @conn.primary_key('ex')
  end
end
test_exec_insert_number()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 37
def test_exec_insert_number
  with_example_table do
    insert(@conn, 'number' => 10)

    result = @conn.exec_query('SELECT number FROM ex WHERE number = 10')

    assert_equal 1, result.rows.length
    # if there are no bind parameters, it will return a string (due to
    # the libmysql api)
    assert_equal '10', result.rows.last.last
  end
end
test_exec_insert_string()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 50
def test_exec_insert_string
  with_example_table do
    str = 'いただきます!'
    insert(@conn, 'number' => 10, 'data' => str)

    result = @conn.exec_query('SELECT number, data FROM ex WHERE number = 10')

    value = result.rows.last.last

    # FIXME: this should probably be inside the mysql AR adapter?
    value.force_encoding(@conn.client_encoding)

    # The strings in this file are utf-8, so transcode to utf-8
    value.encode!(Encoding::UTF_8)

    assert_equal str, value
  end
end
test_invalid_column()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 29
def test_invalid_column
  assert_not @conn.valid_type?(:foobar)
end
test_pk_and_sequence_for()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 77
def test_pk_and_sequence_for
  with_example_table do
    pk, seq = @conn.pk_and_sequence_for('ex')
    assert_equal 'id', pk
    assert_equal @conn.default_sequence_name('ex', 'id'), seq
  end
end
test_pk_and_sequence_for_with_custom_index_type_pk()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 93
def test_pk_and_sequence_for_with_custom_index_type_pk
  with_example_table '`id` INT(11) auto_increment, PRIMARY KEY USING BTREE (`id`)' do
    pk, seq = @conn.pk_and_sequence_for('ex')
    assert_equal 'id', pk
    assert_equal @conn.default_sequence_name('ex', 'id'), seq
  end
end
test_pk_and_sequence_for_with_non_standard_primary_key()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 85
def test_pk_and_sequence_for_with_non_standard_primary_key
  with_example_table '`code` INT(11) auto_increment, PRIMARY KEY (`code`)' do
    pk, seq = @conn.pk_and_sequence_for('ex')
    assert_equal 'code', pk
    assert_equal @conn.default_sequence_name('ex', 'code'), seq
  end
end
test_respond_to_disable_extension()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 125
def test_respond_to_disable_extension
  assert @conn.respond_to?(:disable_extension)
end
test_respond_to_enable_extension()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 121
def test_respond_to_enable_extension
  assert @conn.respond_to?(:enable_extension)
end
test_supports_extensions()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 117
def test_supports_extensions
  assert_not @conn.supports_extensions?, 'does not support extensions'
end
test_tables_quoting()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 69
def test_tables_quoting
  @conn.tables(nil, "foo-bar", nil)
  flunk
rescue => e
  # assertion for *quoted* database properly
  assert_match(/database 'foo-bar'/, e.inspect)
end
test_tinyint_integer_typecasting()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 107
def test_tinyint_integer_typecasting
  with_example_table '`status` TINYINT(4)' do
    insert(@conn, { 'status' => 2 }, 'ex')

    result = @conn.exec_query('SELECT status FROM ex')

    assert_equal 2, result.column_types['status'].type_cast_from_database(result.last['status'])
  end
end
test_valid_column()
# File activerecord/test/cases/adapters/mysql/mysql_adapter_test.rb, line 22
def test_valid_column
  with_example_table do
    column = @conn.columns('ex').find { |col| col.name == 'id' }
    assert @conn.valid_type?(column.type)
  end
end