aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-04-06 16:06:38 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-04-06 16:06:38 +0000
commit64003677b7063aabc2a943e75e56b48cae6b15f7 (patch)
tree00bd7f2a6ab6ddf96f4a8026d41a20573431a094
parent9935a3561e0bc9f356b8c0213cec65fc853fd7d6 (diff)
downloadrails-64003677b7063aabc2a943e75e56b48cae6b15f7.tar.gz
rails-64003677b7063aabc2a943e75e56b48cae6b15f7.tar.bz2
rails-64003677b7063aabc2a943e75e56b48cae6b15f7.zip
Fix type_name_with_module to handle type names that begin with '::'. Closes #4614.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4187 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rwxr-xr-xactiverecord/test/base_test.rb5
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.