Permalink
Browse files

Fixed rename_column for SQLite when using symbols for the column name…

…s (closes #8616) [drodriguez]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7563 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9686dcd commit 046a87a85553173d02c2f349e05282235cea58a4 @dhh dhh committed Sep 22, 2007
@@ -1,5 +1,7 @@
*SVN*
+* Fixed rename_column for SQLite when using symbols for the column names #8616 [drodriguez]
+
* Added the possibility of using symbols in addition to concrete classes with ActiveRecord::Observer#observe #3998 [robbyrussell/tarmo]
* Added ActiveRecord::Base#to_json/from_json (currently does not support :include like to_xml) [DHH]
@@ -238,12 +238,13 @@ def change_column(table_name, column_name, type, options = {}) #:nodoc:
self.type = type
self.limit = options[:limit] if options.include?(:limit)
self.default = options[:default] if include_default
+ self.null = options[:null] if options.include?(:null)
end
end
end
def rename_column(table_name, column_name, new_column_name) #:nodoc:
- alter_table(table_name, :rename => {column_name => new_column_name})
+ alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s})
end
@@ -290,7 +291,7 @@ def copy_table(from, to, options = {}) #:nodoc:
(options[:rename][column.name] ||
options[:rename][column.name.to_sym] ||
column.name) : column.name
-
+
@definition.column(column_name, column.type,
:limit => column.limit, :default => column.default,
:null => column.null)
@@ -24,6 +24,8 @@ def puts(text="")
class MigrationTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
+
+ fixtures :people
def setup
ActiveRecord::Migration.verbose = true
@@ -277,6 +279,7 @@ def test_native_types
Person.connection.add_column "people", "favorite_day", :date
Person.connection.add_column "people", "moment_of_truth", :datetime
Person.connection.add_column "people", "male", :boolean
+ Person.reset_column_information
assert_nothing_raised do
Person.create :first_name => 'bob', :last_name => 'bobsen',
@@ -373,6 +376,7 @@ def test_add_rename
begin
Person.connection.add_column "people", "girlfriend", :string
+ Person.reset_column_information
Person.create :girlfriend => 'bobette'
Person.connection.rename_column "people", "girlfriend", "exgirlfriend"
@@ -390,9 +394,11 @@ def test_add_rename
def test_rename_column_using_symbol_arguments
begin
+ names_before = Person.find(:all).map(&:first_name)
Person.connection.rename_column :people, :first_name, :nick_name
Person.reset_column_information
assert Person.column_names.include?("nick_name")
+ assert_equal names_before, Person.find(:all).map(&:nick_name)
ensure
Person.connection.remove_column("people","nick_name")
Person.connection.add_column("people","first_name", :string)
@@ -401,9 +407,11 @@ def test_rename_column_using_symbol_arguments
def test_rename_column
begin
+ names_before = Person.find(:all).map(&:first_name)
Person.connection.rename_column "people", "first_name", "nick_name"
Person.reset_column_information
assert Person.column_names.include?("nick_name")
+ assert_equal names_before, Person.find(:all).map(&:nick_name)
ensure
Person.connection.remove_column("people","nick_name")
Person.connection.add_column("people","first_name", :string)
@@ -479,7 +487,7 @@ def test_change_column
old_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns")
assert old_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true }
assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => false }
- new_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns")
+ new_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns")
assert_nil new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true }
assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false }
assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => true }
@@ -781,6 +789,7 @@ def test_migrator_with_missing_version_numbers
assert_equal 4, ActiveRecord::Migrator.current_version
ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_missing_versions/', 2)
+ Person.reset_column_information
assert !Reminder.table_exists?
assert Person.column_methods_hash.include?(:last_name)
assert_equal 2, ActiveRecord::Migrator.current_version

0 comments on commit 046a87a

Please sign in to comment.