Skip to content
This repository
Browse code

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...
commit 046a87a85553173d02c2f349e05282235cea58a4 1 parent 9686dcd
David Heinemeier Hansson dhh authored
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *SVN*
2 2
  3 +* Fixed rename_column for SQLite when using symbols for the column names #8616 [drodriguez]
  4 +
3 5 * Added the possibility of using symbols in addition to concrete classes with ActiveRecord::Observer#observe #3998 [robbyrussell/tarmo]
4 6
5 7 * Added ActiveRecord::Base#to_json/from_json (currently does not support :include like to_xml) [DHH]
5 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -238,12 +238,13 @@ def change_column(table_name, column_name, type, options = {}) #:nodoc:
238 238 self.type = type
239 239 self.limit = options[:limit] if options.include?(:limit)
240 240 self.default = options[:default] if include_default
  241 + self.null = options[:null] if options.include?(:null)
241 242 end
242 243 end
243 244 end
244 245
245 246 def rename_column(table_name, column_name, new_column_name) #:nodoc:
246   - alter_table(table_name, :rename => {column_name => new_column_name})
  247 + alter_table(table_name, :rename => {column_name.to_s => new_column_name.to_s})
247 248 end
248 249
249 250
@@ -290,7 +291,7 @@ def copy_table(from, to, options = {}) #:nodoc:
290 291 (options[:rename][column.name] ||
291 292 options[:rename][column.name.to_sym] ||
292 293 column.name) : column.name
293   -
  294 +
294 295 @definition.column(column_name, column.type,
295 296 :limit => column.limit, :default => column.default,
296 297 :null => column.null)
11 activerecord/test/migration_test.rb
@@ -24,6 +24,8 @@ def puts(text="")
24 24
25 25 class MigrationTest < Test::Unit::TestCase
26 26 self.use_transactional_fixtures = false
  27 +
  28 + fixtures :people
27 29
28 30 def setup
29 31 ActiveRecord::Migration.verbose = true
@@ -277,6 +279,7 @@ def test_native_types
277 279 Person.connection.add_column "people", "favorite_day", :date
278 280 Person.connection.add_column "people", "moment_of_truth", :datetime
279 281 Person.connection.add_column "people", "male", :boolean
  282 + Person.reset_column_information
280 283
281 284 assert_nothing_raised do
282 285 Person.create :first_name => 'bob', :last_name => 'bobsen',
@@ -373,6 +376,7 @@ def test_add_rename
373 376
374 377 begin
375 378 Person.connection.add_column "people", "girlfriend", :string
  379 + Person.reset_column_information
376 380 Person.create :girlfriend => 'bobette'
377 381
378 382 Person.connection.rename_column "people", "girlfriend", "exgirlfriend"
@@ -390,9 +394,11 @@ def test_add_rename
390 394
391 395 def test_rename_column_using_symbol_arguments
392 396 begin
  397 + names_before = Person.find(:all).map(&:first_name)
393 398 Person.connection.rename_column :people, :first_name, :nick_name
394 399 Person.reset_column_information
395 400 assert Person.column_names.include?("nick_name")
  401 + assert_equal names_before, Person.find(:all).map(&:nick_name)
396 402 ensure
397 403 Person.connection.remove_column("people","nick_name")
398 404 Person.connection.add_column("people","first_name", :string)
@@ -401,9 +407,11 @@ def test_rename_column_using_symbol_arguments
401 407
402 408 def test_rename_column
403 409 begin
  410 + names_before = Person.find(:all).map(&:first_name)
404 411 Person.connection.rename_column "people", "first_name", "nick_name"
405 412 Person.reset_column_information
406 413 assert Person.column_names.include?("nick_name")
  414 + assert_equal names_before, Person.find(:all).map(&:nick_name)
407 415 ensure
408 416 Person.connection.remove_column("people","nick_name")
409 417 Person.connection.add_column("people","first_name", :string)
@@ -479,7 +487,7 @@ def test_change_column
479 487 old_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns")
480 488 assert old_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true }
481 489 assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => false }
482   - new_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns")
  490 + new_columns = Topic.connection.columns(Topic.table_name, "#{name} Columns")
483 491 assert_nil new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == true }
484 492 assert new_columns.find { |c| c.name == 'approved' and c.type == :boolean and c.default == false }
485 493 assert_nothing_raised { Topic.connection.change_column :topics, :approved, :boolean, :default => true }
@@ -781,6 +789,7 @@ def test_migrator_with_missing_version_numbers
781 789 assert_equal 4, ActiveRecord::Migrator.current_version
782 790
783 791 ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + '/fixtures/migrations_with_missing_versions/', 2)
  792 + Person.reset_column_information
784 793 assert !Reminder.table_exists?
785 794 assert Person.column_methods_hash.include?(:last_name)
786 795 assert_equal 2, ActiveRecord::Migrator.current_version

0 comments on commit 046a87a

Please sign in to comment.
Something went wrong with that request. Please try again.