diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 5 |
3 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e6f923d2c2..8a68f37d12 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ecad32ebe2..b91ebafee5 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1000,7 +1000,7 @@ module ActiveRecord #:nodoc: # 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) diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 69665098af..391ee57632 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -1257,6 +1257,11 @@ class BasicsTest < Test::Unit::TestCase 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. |