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

Fixed rename_column for SQLite when using symbols for the column names (closes #8616) [drodriguez]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7563 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2007-09-22 18:23:30 +00:00
parent 9686dcdb5b
commit 046a87a855
3 changed files with 15 additions and 3 deletions

View file

@ -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]

View file

@ -238,12 +238,13 @@ module ActiveRecord
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

View file

@ -25,6 +25,8 @@ if ActiveRecord::Base.connection.supports_migrations?
class MigrationTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
fixtures :people
def setup
ActiveRecord::Migration.verbose = true
PeopleHaveLastNames.message_count = 0
@ -277,6 +279,7 @@ if ActiveRecord::Base.connection.supports_migrations?
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 @@ if ActiveRecord::Base.connection.supports_migrations?
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 @@ if ActiveRecord::Base.connection.supports_migrations?
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 @@ if ActiveRecord::Base.connection.supports_migrations?
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)
@ -781,6 +789,7 @@ if ActiveRecord::Base.connection.supports_migrations?
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