Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column definition tests #122

Merged
merged 4 commits into from
Oct 10, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 20 additions & 19 deletions lib/arjdbc/mysql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ::ArJdbc
module MySQL
def self.column_selector
[/mysql/i, lambda {|cfg,col| col.extend(::ArJdbc::MySQL::Column)}]
[/mysql/i, lambda {|cfg,col| col.extend(::ArJdbc::MySQL::ColumnExtensions)}]
end

def self.extended(adapter)
Expand All @@ -18,7 +18,7 @@ def self.jdbc_connection_class
::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
end

module Column
module ColumnExtensions
def extract_default(default)
if sql_type =~ /blob/i || type == :text
if default.blank?
Expand Down Expand Up @@ -211,7 +211,7 @@ def structure_dump #:nodoc:
def jdbc_columns(table_name, name = nil)#:nodoc:
sql = "SHOW FIELDS FROM #{quote_table_name(table_name)}"
execute(sql, :skip_logging).map do |field|
::ActiveRecord::ConnectionAdapters::MysqlColumn.new(field["Field"], field["Default"], field["Type"], field["Null"] == "YES")
::ActiveRecord::ConnectionAdapters::MysqlAdapter::Column.new(field["Field"], field["Default"], field["Type"], field["Null"] == "YES")
end
end

Expand Down Expand Up @@ -394,21 +394,6 @@ module ActiveRecord::ConnectionAdapters
remove_const(:MysqlColumn) if const_defined?(:MysqlColumn)
remove_const(:MysqlAdapter) if const_defined?(:MysqlAdapter)

class MysqlColumn < JdbcColumn
include ArJdbc::MySQL::Column

def initialize(name, *args)
if Hash === name
super
else
super(nil, name, *args)
end
end

def call_discovered_column_callbacks(*)
end
end

class MysqlAdapter < JdbcAdapter
include ArJdbc::MySQL

Expand All @@ -422,11 +407,27 @@ def jdbc_connection_class(spec)
end

def jdbc_column_class
ActiveRecord::ConnectionAdapters::MysqlColumn
ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
end

alias_chained_method :columns, :query_cache, :jdbc_columns

remove_const(:Column) if const_defined?(:Column)
class Column < JdbcColumn
include ArJdbc::MySQL::ColumnExtensions

def initialize(name, *args)
if Hash === name
super
else
super(nil, name, *args)
end
end

def call_discovered_column_callbacks(*)
end
end

protected
def exec_insert(sql, name, binds)
binds = binds.dup
Expand Down
1 change: 1 addition & 0 deletions lib/arjdbc/postgresql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def simplified_type(field_type)
return :integer if field_type =~ /^(big|)serial/i
return :string if field_type =~ /\[\]$/i || field_type =~ /^interval/i
return :string if field_type =~ /^(?:point|lseg|box|"?path"?|polygon|circle)/i
return :string if field_type =~ /^uuid/i
return :datetime if field_type =~ /^timestamp/i
return :float if field_type =~ /^(?:real|double precision)$/i
return :binary if field_type =~ /^bytea/i
Expand Down
11 changes: 10 additions & 1 deletion test/mysql_simple_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ class MysqlSimpleTest < Test::Unit::TestCase
include ColumnNameQuotingTests

column_quote_char "`"


def test_column_class_instantiation
text_column = nil
assert_nothing_raised do
text_column = ActiveRecord::ConnectionAdapters::MysqlAdapter::Column.
new("title", nil, "text")
end
assert_not_nil text_column
end

def test_string_quoting_oddity
s = "0123456789a'a"
assert_equal "'0123456789a\\'a'", ActiveRecord::Base.connection.quote(s)
Expand Down
7 changes: 6 additions & 1 deletion test/postgres_native_type_mapping_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def self.up
real_should_be_float real,
bool_should_be_boolean bool,
interval_should_be_string interval,
bigint_should_be_integer bigint
bigint_should_be_integer bigint,
uuid_should_be_string uuid
)}
end

Expand All @@ -42,6 +43,10 @@ def column_type(column_name)
Customer.columns.detect { |c| c.name == column_name }.type
end

def test_uuid_column_should_map_to_string
assert_equal :string, column_type("uuid_should_be_string")
end

def test_bigint_serial_should_be_mapped_to_integer
assert_equal :integer, column_type("bigint_serial_should_be_integer")
end
Expand Down