public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
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
Nicholas Seckar (author)
Thu Apr 06 09:06:38 -0700 2006
commit  64003677b7063aabc2a943e75e56b48cae6b15f7
tree    00bd7f2a6ab6ddf96f4a8026d41a20573431a094
parent  9935a3561e0bc9f356b8c0213cec65fc853fd7d6
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+* Fix type_name_with_module to handle type names that begin with '::'. Closes #4614. [Nicholas Seckar]
0
+
0
 *1.14.1* (April 6th, 2005)
0
 
0
 * Enable Limit/Offset in Calculations (closes #4558) [lmarlow@yahoo.com]
...
1000
1001
1002
1003
 
1004
1005
1006
...
1000
1001
1002
 
1003
1004
1005
1006
0
@@ -1000,7 +1000,7 @@
0
         # Nest the type name in the same module as this class.
0
         # Bar is "MyApp::Business::Bar" relative to MyApp::Business::Foo
0
         def type_name_with_module(type_name)
0
- "#{self.name.sub(/(::)?[^:]+$/, '')}#{$1}#{type_name}"
0
+ (/^::/ =~ type_name) ? type_name : "#{parent.name}::#{type_name}"
0
         end
0
 
0
         def construct_finder_sql(options)
...
1257
1258
1259
 
 
 
 
 
1260
1261
1262
...
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
0
@@ -1257,6 +1257,11 @@
0
     assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys)
0
     assert_equal(%w( title author_name type id approved ), topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys)
0
   end
0
+
0
+ def test_type_name_with_module_should_handle_beginning
0
+ assert_equal 'ActiveRecord::Person', ActiveRecord::Base.send(:type_name_with_module, 'Person')
0
+ assert_equal '::Person', ActiveRecord::Base.send(:type_name_with_module, '::Person')
0
+ end
0
 
0
   # FIXME: this test ought to run, but it needs to run sandboxed so that it
0
   # doesn't b0rk the current test environment by undefing everything.

Comments

    No one has commented yet.