diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-12-18 23:37:36 -0500 |
---|---|---|
committer | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-12-21 13:54:50 -0500 |
commit | b045804c1e0430897677307333e9821a08b5bb13 (patch) | |
tree | 878a1b37c14d80a0582eb37e6cd9fdbbab3c8dd5 | |
parent | 95f5f8167ff86550d7fa9f5f7419cc9b38ef9704 (diff) | |
download | rails-b045804c1e0430897677307333e9821a08b5bb13.tar.gz rails-b045804c1e0430897677307333e9821a08b5bb13.tar.bz2 rails-b045804c1e0430897677307333e9821a08b5bb13.zip |
Simplify change_table and avoid duplicated logic
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 16 | ||||
-rw-r--r-- | activerecord/test/cases/migration/change_table_test.rb | 31 |
2 files changed, 7 insertions, 40 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 73012834c9..ade10081e3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -490,20 +490,8 @@ module ActiveRecord class_eval <<-EOV, __FILE__, __LINE__ + 1 def #{column_type}(*args) # def string(*args) options = args.extract_options! # options = args.extract_options! - column_names = args # column_names = args - type = :'#{column_type}' # type = :string - column_names.each do |name| # column_names.each do |name| - column = ColumnDefinition.new(@base, name.to_s, type) # column = ColumnDefinition.new(@base, name, type) - if options[:limit] # if options[:limit] - column.limit = options[:limit] # column.limit = options[:limit] - elsif native[type].is_a?(Hash) # elsif native[type].is_a?(Hash) - column.limit = native[type][:limit] # column.limit = native[type][:limit] - end # end - column.precision = options[:precision] # column.precision = options[:precision] - column.scale = options[:scale] # column.scale = options[:scale] - column.default = options[:default] # column.default = options[:default] - column.null = options[:null] # column.null = options[:null] - @base.add_column(@table_name, name, column.sql_type, options) # @base.add_column(@table_name, name, column.sql_type, options) + args.each do |name| # column_names.each do |name| + @base.add_column(@table_name, name, :#{column_type}, options) # @base.add_column(@table_name, name, :string, options) end # end end # end EOV diff --git a/activerecord/test/cases/migration/change_table_test.rb b/activerecord/test/cases/migration/change_table_test.rb index 8fb03cdee0..5800c46976 100644 --- a/activerecord/test/cases/migration/change_table_test.rb +++ b/activerecord/test/cases/migration/change_table_test.rb @@ -3,21 +3,8 @@ require "cases/migration/helper" module ActiveRecord class Migration class TableTest < ActiveRecord::TestCase - class MockConnection < MiniTest::Mock - def native_database_types - { - :string => 'varchar(255)', - :integer => 'integer', - } - end - - def type_to_sql(type, limit, precision, scale) - native_database_types[type] - end - end - def setup - @connection = MockConnection.new + @connection = MiniTest::Mock.new end def teardown @@ -98,26 +85,18 @@ module ActiveRecord end end - def string_column - @connection.native_database_types[:string] - end - - def integer_column - @connection.native_database_types[:integer] - end - def test_integer_creates_integer_column with_change_table do |t| - @connection.expect :add_column, nil, [:delete_me, :foo, integer_column, {}] - @connection.expect :add_column, nil, [:delete_me, :bar, integer_column, {}] + @connection.expect :add_column, nil, [:delete_me, :foo, :integer, {}] + @connection.expect :add_column, nil, [:delete_me, :bar, :integer, {}] t.integer :foo, :bar end end def test_string_creates_string_column with_change_table do |t| - @connection.expect :add_column, nil, [:delete_me, :foo, string_column, {}] - @connection.expect :add_column, nil, [:delete_me, :bar, string_column, {}] + @connection.expect :add_column, nil, [:delete_me, :foo, :string, {}] + @connection.expect :add_column, nil, [:delete_me, :bar, :string, {}] t.string :foo, :bar end end |