From 443f8dd5cdb273327a8b03a97c431de67c15ace6 Mon Sep 17 00:00:00 2001 From: Kyle Stevens Date: Sat, 11 May 2013 22:32:33 -0400 Subject: Call assume_migrated_upto_version on connection Call assume_migrated_upto_version on connection to prevent it from first being picked up in method_missing. In the base class, Migration, method_missing expects the argument to be a table name, and calls proper_table_name on the arguments before sending to connection. If table_name_prefix or table_name_suffix is used, the schema version changes to prefix_version_suffix, breaking `rake test:prepare`. Fixes #10411. --- activerecord/CHANGELOG.md | 11 +++++++++++ activerecord/lib/active_record/schema.rb | 2 +- activerecord/test/cases/ar_schema_test.rb | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f7c1937eff..6426730a8d 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,14 @@ +* Fix pending migrations error when loading schema and ActiveRecord::Base.table_name_prefix is not blank. + + Call assume_migrated_upto_version on connection to prevent it from first being picked up in method_missing. + In the base class, Migration, method_missing expects the argument to be a table name, and calls proper_table_name + on the arguments before sending to connection. If table_name_prefix or table_name_suffix is used, the schema + version changes to prefix_version_suffix, breaking `rake test:prepare`. + + Fixes #10411. + + *Kyle Stevens* + * Method read_attribute_before_type_cast should accept input as symbol. *Neeraj Singh* diff --git a/activerecord/lib/active_record/schema.rb b/activerecord/lib/active_record/schema.rb index 3259dbbd80..4bfd0167a4 100644 --- a/activerecord/lib/active_record/schema.rb +++ b/activerecord/lib/active_record/schema.rb @@ -43,7 +43,7 @@ module ActiveRecord unless info[:version].blank? initialize_schema_migrations_table - assume_migrated_upto_version(info[:version], migrations_paths) + connection.assume_migrated_upto_version(info[:version], migrations_paths) end end diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 244e0b7179..500df52cd8 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -12,6 +12,8 @@ if ActiveRecord::Base.connection.supports_migrations? def teardown @connection.drop_table :fruits rescue nil + @connection.drop_table :nep_fruits rescue nil + @connection.drop_table :nep_schema_migrations rescue nil ActiveRecord::SchemaMigration.delete_all rescue nil end @@ -30,6 +32,24 @@ if ActiveRecord::Base.connection.supports_migrations? assert_equal 7, ActiveRecord::Migrator::current_version end + def test_schema_define_w_table_name_prefix + table_name = ActiveRecord::SchemaMigration.table_name + ActiveRecord::Base.table_name_prefix = "nep_" + ActiveRecord::SchemaMigration.table_name = "nep_#{table_name}" + ActiveRecord::Schema.define(:version => 7) do + create_table :fruits do |t| + t.column :color, :string + t.column :fruit_size, :string # NOTE: "size" is reserved in Oracle + t.column :texture, :string + t.column :flavor, :string + end + end + assert_equal 7, ActiveRecord::Migrator::current_version + ensure + ActiveRecord::Base.table_name_prefix = "" + ActiveRecord::SchemaMigration.table_name = table_name + end + def test_schema_raises_an_error_for_invalid_column_type assert_raise NoMethodError do ActiveRecord::Schema.define(:version => 8) do -- cgit v1.2.3