diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-28 12:27:47 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-28 12:27:47 -0800 |
commit | 66e87b714b406a25af60156a1fa15d1ebb99a0bd (patch) | |
tree | 238ac027061c13226ab8995fc4b534afb6521ba3 /activerecord | |
parent | 9d97ef8f21ac583838230599fdbf812b27a5bc45 (diff) | |
parent | 4325bec1d46de4a7fbe094ae18e83648532e2ddf (diff) | |
download | rails-66e87b714b406a25af60156a1fa15d1ebb99a0bd.tar.gz rails-66e87b714b406a25af60156a1fa15d1ebb99a0bd.tar.bz2 rails-66e87b714b406a25af60156a1fa15d1ebb99a0bd.zip |
Merge pull request #7689 from cbarton/assume_migration_version_with_prefix_fix
Fixing a schema:load when using a prefix and suffix on the tables [Reopen/backport]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/ar_schema_test.rb | 36 |
2 files changed, 29 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index e6686597b7..6420f81347 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -458,7 +458,7 @@ module ActiveRecord say_with_time "#{method}(#{arg_list})" do unless reverting? unless arguments.empty? || method == :execute - arguments[0] = Migrator.proper_table_name(arguments.first) + arguments[0] = Migrator.proper_table_name(arguments.first) unless method == :assume_migrated_upto_version arguments[1] = Migrator.proper_table_name(arguments.second) if method == :rename_table end end diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb index 588adc38e3..ee338a3b99 100644 --- a/activerecord/test/cases/ar_schema_test.rb +++ b/activerecord/test/cases/ar_schema_test.rb @@ -11,23 +11,30 @@ if ActiveRecord::Base.connection.supports_migrations? def teardown @connection.drop_table :fruits rescue nil + @connection.drop_table :"_pre_fruits_suf_" rescue nil + @connection.drop_table :"_pre_schema_migrations_suf_" rescue nil end def test_schema_define - 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 + perform_schema_define! assert_nothing_raised { @connection.select_all "SELECT * FROM fruits" } assert_nothing_raised { @connection.select_all "SELECT * FROM schema_migrations" } assert_equal 7, ActiveRecord::Migrator::current_version end + def test_schema_define_with_table_prefix_and_suffix + ActiveRecord::Base.table_name_prefix = '_pre_' + ActiveRecord::Base.table_name_suffix = '_suf_' + + perform_schema_define! + + assert_equal 7, ActiveRecord::Migrator::current_version + ensure + ActiveRecord::Base.table_name_prefix = '' + ActiveRecord::Base.table_name_suffix = '' + end + def test_schema_raises_an_error_for_invalid_column_type assert_raise NoMethodError do ActiveRecord::Schema.define(:version => 8) do @@ -39,4 +46,17 @@ if ActiveRecord::Base.connection.supports_migrations? end end + private + + def perform_schema_define! + 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 + end + end |