Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate ActiveRecord::Base#class_name [#379 state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit ac42e6951f0feb1a9890a3bbf5ebad87ebec08cc 1 parent d0d10f5
@dtrasbo dtrasbo authored josevalim committed
View
2  activerecord/lib/active_record/base.rb
@@ -1285,6 +1285,8 @@ def set_sequence_name(value = nil, &block)
# Turns the +table_name+ back into a class name following the reverse rules of +table_name+.
def class_name(table_name = table_name) # :nodoc:
+ ActiveSupport::Deprecation.warn("ActiveRecord::Base#class_name is deprecated and will be removed in Rails 2.3.9.", caller)
+
# remove any prefix and/or suffix from the table name
class_name = table_name[table_name_prefix.length..-(table_name_suffix.length + 1)].camelize
class_name = class_name.singularize if pluralize_table_names
View
34 activerecord/test/cases/base_test.rb
@@ -700,22 +700,24 @@ def test_attribute_keys_on_new_instance
end
def test_class_name
- assert_equal "Firm", ActiveRecord::Base.class_name("firms")
- assert_equal "Category", ActiveRecord::Base.class_name("categories")
- assert_equal "AccountHolder", ActiveRecord::Base.class_name("account_holder")
-
- ActiveRecord::Base.pluralize_table_names = false
- assert_equal "Firms", ActiveRecord::Base.class_name( "firms" )
- ActiveRecord::Base.pluralize_table_names = true
-
- ActiveRecord::Base.table_name_prefix = "test_"
- assert_equal "Firm", ActiveRecord::Base.class_name( "test_firms" )
- ActiveRecord::Base.table_name_suffix = "_tests"
- assert_equal "Firm", ActiveRecord::Base.class_name( "test_firms_tests" )
- ActiveRecord::Base.table_name_prefix = ""
- assert_equal "Firm", ActiveRecord::Base.class_name( "firms_tests" )
- ActiveRecord::Base.table_name_suffix = ""
- assert_equal "Firm", ActiveRecord::Base.class_name( "firms" )
+ ActiveSupport::Deprecation.silence do
+ assert_equal "Firm", ActiveRecord::Base.class_name("firms")
+ assert_equal "Category", ActiveRecord::Base.class_name("categories")
+ assert_equal "AccountHolder", ActiveRecord::Base.class_name("account_holder")
+
+ ActiveRecord::Base.pluralize_table_names = false
+ assert_equal "Firms", ActiveRecord::Base.class_name( "firms" )
+ ActiveRecord::Base.pluralize_table_names = true
+
+ ActiveRecord::Base.table_name_prefix = "test_"
+ assert_equal "Firm", ActiveRecord::Base.class_name( "test_firms" )
+ ActiveRecord::Base.table_name_suffix = "_tests"
+ assert_equal "Firm", ActiveRecord::Base.class_name( "test_firms_tests" )
+ ActiveRecord::Base.table_name_prefix = ""
+ assert_equal "Firm", ActiveRecord::Base.class_name( "firms_tests" )
+ ActiveRecord::Base.table_name_suffix = ""
+ assert_equal "Firm", ActiveRecord::Base.class_name( "firms" )
+ end
end
def test_null_fields
Please sign in to comment.
Something went wrong with that request. Please try again.