diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2013-08-23 16:48:44 -0700 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2013-08-23 16:48:44 -0700 |
commit | 3abeaf0e3bb97c435ce2acfd9cb97786f34f8319 (patch) | |
tree | e631e5139893c2dccc5e071f5b3d3999768ae069 /activerecord/test | |
parent | dc54dbe8f00138e8652438fe247f8c5792da7e24 (diff) | |
parent | 8c5d62f79669fcf67d106036177d731703f3aa44 (diff) | |
download | rails-3abeaf0e3bb97c435ce2acfd9cb97786f34f8319.tar.gz rails-3abeaf0e3bb97c435ce2acfd9cb97786f34f8319.tar.bz2 rails-3abeaf0e3bb97c435ce2acfd9cb97786f34f8319.zip |
Merge pull request #11984 from wangjohn/proper_table_name
Making proper_table_name take in options.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 29 |
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_' |