Permalink
Browse files

Fix type_name_with_module to handle type names that begin with '::'. C…

…loses #4614.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4187 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9935a35 commit 64003677b7063aabc2a943e75e56b48cae6b15f7 @seckar seckar committed Apr 6, 2006
Showing with 8 additions and 1 deletion.
  1. +2 −0 activerecord/CHANGELOG
  2. +1 −1 activerecord/lib/active_record/base.rb
  3. +5 −0 activerecord/test/base_test.rb
View
@@ -1,3 +1,5 @@
+* Fix type_name_with_module to handle type names that begin with '::'. Closes #4614. [Nicholas Seckar]
+
*1.14.1* (April 6th, 2005)
* Enable Limit/Offset in Calculations (closes #4558) [lmarlow@yahoo.com]
@@ -1000,7 +1000,7 @@ def instantiate(record)
# Nest the type name in the same module as this class.
# Bar is "MyApp::Business::Bar" relative to MyApp::Business::Foo
def type_name_with_module(type_name)
- "#{self.name.sub(/(::)?[^:]+$/, '')}#{$1}#{type_name}"
+ (/^::/ =~ type_name) ? type_name : "#{parent.name}::#{type_name}"
end
def construct_finder_sql(options)
@@ -1257,6 +1257,11 @@ def test_include_attributes
assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys)
assert_equal(%w( title author_name type id approved ), topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys)
end
+
+ def test_type_name_with_module_should_handle_beginning
+ assert_equal 'ActiveRecord::Person', ActiveRecord::Base.send(:type_name_with_module, 'Person')
+ assert_equal '::Person', ActiveRecord::Base.send(:type_name_with_module, '::Person')
+ end
# FIXME: this test ought to run, but it needs to run sandboxed so that it
# doesn't b0rk the current test environment by undefing everything.

0 comments on commit 6400367

Please sign in to comment.