Permalink
Browse files

Merge pull request #7689 from cbarton/assume_migration_version_with_p…

…refix_fix

Fixing a schema:load when using a prefix and suffix on the tables [Reopen/backport]
  • Loading branch information...
tenderlove committed Nov 28, 2012
2 parents 9d97ef8 + 4325bec commit 66e87b714b406a25af60156a1fa15d1ebb99a0bd
Showing with 29 additions and 9 deletions.
  1. +1 −1 activerecord/lib/active_record/migration.rb
  2. +28 −8 activerecord/test/cases/ar_schema_test.rb
@@ -458,7 +458,7 @@ def method_missing(method, *arguments, &block)
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
@@ -11,23 +11,30 @@ def setup
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 @@ def test_schema_raises_an_error_for_invalid_column_type
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

0 comments on commit 66e87b7

Please sign in to comment.