1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

decouple column definition from the database connection

This commit is contained in:
Aaron Patterson 2013-03-15 19:34:20 -07:00
parent 4b4c8bdc77
commit cd07f194dc
3 changed files with 11 additions and 11 deletions

View file

@ -15,7 +15,7 @@ module ActiveRecord
# are typically created by methods in TableDefinition, and added to the
# +columns+ attribute of said TableDefinition object, in order to be used
# for generating a number of table creation or table changing SQL statements.
class ColumnDefinition < Struct.new(:base, :name, :type, :limit, :precision, :scale, :default, :null) #:nodoc:
class ColumnDefinition < Struct.new(:name, :type, :limit, :precision, :scale, :default, :null) #:nodoc:
def string_to_binary(value)
value
end
@ -213,7 +213,7 @@ module ActiveRecord
raise ArgumentError, "you can't redefine the primary key column '#{name}'. To define a custom primary key, pass { id: false } to create_table."
end
column = self[name] || new_column_definition(@base, name, type)
column = self[name] || new_column_definition(name, type)
limit = options.fetch(:limit) do
native[type][:limit] if native[type].is_a?(Hash)
@ -272,12 +272,12 @@ module ActiveRecord
end
private
def create_column_definition(base, name, type)
ColumnDefinition.new base, name, type
def create_column_definition(name, type)
ColumnDefinition.new name, type
end
def new_column_definition(base, name, type)
definition = create_column_definition base, name, type
def new_column_definition(name, type)
definition = create_column_definition name, type
@columns << definition
@columns_hash[name] = definition
definition

View file

@ -344,8 +344,8 @@ module ActiveRecord
private
def create_column_definition(base, name, type)
ColumnDefinition.new base, name, type
def create_column_definition(name, type)
ColumnDefinition.new name, type
end
end

View file

@ -36,7 +36,7 @@ module ActiveRecord
def test_should_not_include_default_clause_when_default_is_null
column = Column.new("title", nil, "varchar(20)")
column_def = ColumnDefinition.new(
@adapter, column.name, "string",
column.name, "string",
column.limit, column.precision, column.scale, column.default, column.null)
assert_equal "title varchar(20)", @viz.accept(column_def)
end
@ -44,7 +44,7 @@ module ActiveRecord
def test_should_include_default_clause_when_default_is_present
column = Column.new("title", "Hello", "varchar(20)")
column_def = ColumnDefinition.new(
@adapter, column.name, "string",
column.name, "string",
column.limit, column.precision, column.scale, column.default, column.null)
assert_equal %Q{title varchar(20) DEFAULT 'Hello'}, @viz.accept(column_def)
end
@ -52,7 +52,7 @@ module ActiveRecord
def test_should_specify_not_null_if_null_option_is_false
column = Column.new("title", "Hello", "varchar(20)", false)
column_def = ColumnDefinition.new(
@adapter, column.name, "string",
column.name, "string",
column.limit, column.precision, column.scale, column.default, column.null)
assert_equal %Q{title varchar(20) DEFAULT 'Hello' NOT NULL}, @viz.accept(column_def)
end