public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
applied patch to fix the associations with blocks in modules bug from an old 
trac ticket
adevadeh (author)
Fri Sep 12 03:02:40 -0700 2008
technoweenie (committer)
Sat Sep 20 13:46:09 -0700 2008
commit  de96a8666d8edc9be57f6146e587a71d23dbeb41
tree    641cb4fe91bab52207dc25ba16e91006c0044655
parent  22e830f883af0b56de81186c184751b6398d0141
...
1026
1027
1028
1029
 
1030
1031
1032
...
1755
1756
1757
1758
 
1759
1760
1761
 
1762
1763
 
1764
1765
1766
...
1026
1027
1028
 
1029
1030
1031
1032
...
1755
1756
1757
 
1758
1759
1760
 
1761
1762
 
1763
1764
1765
1766
0
@@ -1026,7 +1026,7 @@ module ActiveRecord
0
         # Create the callbacks to update counter cache
0
         if options[:counter_cache]
0
           cache_column = options[:counter_cache] == true ?
0
-            "#{self.to_s.underscore.pluralize}_count" :
0
+            "#{self.to_s.demodulize.underscore.pluralize}_count" :
0
             options[:counter_cache]
0
 
0
           method_name = "belongs_to_counter_cache_after_create_for_#{reflection.name}".to_sym
0
@@ -1755,12 +1755,12 @@ module ActiveRecord
0
 
0
         def create_extension_modules(association_id, block_extension, extensions)
0
           if block_extension
0
-            extension_module_name = "#{self.to_s}#{association_id.to_s.camelize}AssociationExtension"
0
+            extension_module_name = "#{self.to_s.demodulize}#{association_id.to_s.camelize}AssociationExtension"
0
 
0
             silence_warnings do
0
-              Object.const_set(extension_module_name, Module.new(&block_extension))
0
+              self.parent.const_set(extension_module_name, Module.new(&block_extension))
0
             end
0
-            Array(extensions).push(extension_module_name.constantize)
0
+            Array(extensions).push("#{self.parent}::#{extension_module_name}".constantize)
0
           else
0
             Array(extensions)
0
           end
...
3
4
5
 
6
7
8
...
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
...
3
4
5
6
7
8
9
...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
0
@@ -3,6 +3,7 @@ require 'models/post'
0
 require 'models/comment'
0
 require 'models/project'
0
 require 'models/developer'
0
+require 'models/company_in_module'
0
 
0
 class AssociationsExtensionsTest < ActiveRecord::TestCase
0
   fixtures :projects, :developers, :developers_projects, :comments, :posts
0
@@ -44,4 +45,18 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
0
     david = Marshal.load(Marshal.dump(david))
0
     assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent
0
   end
0
+
0
+
0
+  def test_extension_name
0
+    extension = Proc.new {}
0
+    name = :association_name
0
+
0
+    assert_equal 'DeveloperAssociationNameAssociationExtension', Developer.send(:create_extension_modules, name, extension, []).first.name
0
+    assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension',
0
+MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
0
+    assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
0
+    assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
0
+  end
0
+
0
+
0
 end

Comments