aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration_test.rb
diff options
context:
space:
mode:
authorwangjohn <wangjohn@mit.edu>2013-08-22 16:15:11 -0400
committerwangjohn <wangjohn@mit.edu>2013-08-22 18:06:56 -0400
commit8c5d62f79669fcf67d106036177d731703f3aa44 (patch)
tree773f3b60495e00a439da0a69434d3e0cd141a95e /activerecord/test/cases/migration_test.rb
parent744ed5c39381cb3e58eba6fab21f42b3408dce53 (diff)
downloadrails-8c5d62f79669fcf67d106036177d731703f3aa44.tar.gz
rails-8c5d62f79669fcf67d106036177d731703f3aa44.tar.bz2
rails-8c5d62f79669fcf67d106036177d731703f3aa44.zip
Making proper_table_name take in options.
The options will specify the prefix and the suffix. Also, I'm moving the method to be an instance method on the +Migration+ instance. This makes more sense than being a class method on the +Migrator+ class because the only place that uses it is on a +Migration+ instance (in a method_missing hook). The logic for the Migrator shouldn't be doing any work to calculate the table name, it should be the Migration itself. Also made some small indentation fixes.
Diffstat (limited to 'activerecord/test/cases/migration_test.rb')
-rw-r--r--activerecord/test/cases/migration_test.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb
index ed080b2995..cbc9e96473 100644
--- a/activerecord/test/cases/migration_test.rb
+++ b/activerecord/test/cases/migration_test.rb
@@ -321,7 +321,7 @@ class MigrationTest < ActiveRecord::TestCase
assert_equal "schema_migrations", ActiveRecord::Migrator.schema_migrations_table_name
end
- def test_proper_table_name
+ def test_proper_table_name_on_migrator
assert_equal "table", ActiveRecord::Migrator.proper_table_name('table')
assert_equal "table", ActiveRecord::Migrator.proper_table_name(:table)
assert_equal "reminders", ActiveRecord::Migrator.proper_table_name(Reminder)
@@ -347,6 +347,33 @@ class MigrationTest < ActiveRecord::TestCase
assert_equal "prefix_table_suffix", ActiveRecord::Migrator.proper_table_name(:table)
end
+ def test_proper_table_name_on_migration
+ migration = ActiveRecord::Migration.new
+ assert_equal "table", migration.proper_table_name('table')
+ assert_equal "table", migration.proper_table_name(:table)
+ assert_equal "reminders", migration.proper_table_name(Reminder)
+ Reminder.reset_table_name
+ assert_equal Reminder.table_name, migration.proper_table_name(Reminder)
+
+ # Use the model's own prefix/suffix if a model is given
+ ActiveRecord::Base.table_name_prefix = "ARprefix_"
+ ActiveRecord::Base.table_name_suffix = "_ARsuffix"
+ Reminder.table_name_prefix = 'prefix_'
+ Reminder.table_name_suffix = '_suffix'
+ Reminder.reset_table_name
+ assert_equal "prefix_reminders_suffix", migration.proper_table_name(Reminder)
+ Reminder.table_name_prefix = ''
+ Reminder.table_name_suffix = ''
+ Reminder.reset_table_name
+
+ # Use AR::Base's prefix/suffix if string or symbol is given
+ ActiveRecord::Base.table_name_prefix = "prefix_"
+ ActiveRecord::Base.table_name_suffix = "_suffix"
+ Reminder.reset_table_name
+ assert_equal "prefix_table_suffix", migration.proper_table_name('table', migration.table_name_options)
+ assert_equal "prefix_table_suffix", migration.proper_table_name(:table, migration.table_name_options)
+ end
+
def test_rename_table_with_prefix_and_suffix
assert !Thing.table_exists?
ActiveRecord::Base.table_name_prefix = 'p_'