aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdeh DeSandies <adeh@yahoo.com>2008-09-12 18:02:40 +0800
committerrick <technoweenie@gmail.com>2008-09-20 13:46:09 -0700
commitde96a8666d8edc9be57f6146e587a71d23dbeb41 (patch)
tree641cb4fe91bab52207dc25ba16e91006c0044655
parent22e830f883af0b56de81186c184751b6398d0141 (diff)
downloadrails-de96a8666d8edc9be57f6146e587a71d23dbeb41.tar.gz
rails-de96a8666d8edc9be57f6146e587a71d23dbeb41.tar.bz2
rails-de96a8666d8edc9be57f6146e587a71d23dbeb41.zip
applied patch to fix the associations with blocks in modules bug from an old trac ticket
-rwxr-xr-xactiverecord/lib/active_record/associations.rb8
-rw-r--r--activerecord/test/cases/associations/extension_test.rb15
2 files changed, 19 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index d7aa4bfa98..e6491cebd6 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1026,7 +1026,7 @@ module ActiveRecord
# Create the callbacks to update counter cache
if options[:counter_cache]
cache_column = options[:counter_cache] == true ?
- "#{self.to_s.underscore.pluralize}_count" :
+ "#{self.to_s.demodulize.underscore.pluralize}_count" :
options[:counter_cache]
method_name = "belongs_to_counter_cache_after_create_for_#{reflection.name}".to_sym
@@ -1755,12 +1755,12 @@ module ActiveRecord
def create_extension_modules(association_id, block_extension, extensions)
if block_extension
- extension_module_name = "#{self.to_s}#{association_id.to_s.camelize}AssociationExtension"
+ extension_module_name = "#{self.to_s.demodulize}#{association_id.to_s.camelize}AssociationExtension"
silence_warnings do
- Object.const_set(extension_module_name, Module.new(&block_extension))
+ self.parent.const_set(extension_module_name, Module.new(&block_extension))
end
- Array(extensions).push(extension_module_name.constantize)
+ Array(extensions).push("#{self.parent}::#{extension_module_name}".constantize)
else
Array(extensions)
end
diff --git a/activerecord/test/cases/associations/extension_test.rb b/activerecord/test/cases/associations/extension_test.rb
index 5c01c3c1f5..9390633d5b 100644
--- a/activerecord/test/cases/associations/extension_test.rb
+++ b/activerecord/test/cases/associations/extension_test.rb
@@ -3,6 +3,7 @@ require 'models/post'
require 'models/comment'
require 'models/project'
require 'models/developer'
+require 'models/company_in_module'
class AssociationsExtensionsTest < ActiveRecord::TestCase
fixtures :projects, :developers, :developers_projects, :comments, :posts
@@ -44,4 +45,18 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
david = Marshal.load(Marshal.dump(david))
assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent
end
+
+
+ def test_extension_name
+ extension = Proc.new {}
+ name = :association_name
+
+ assert_equal 'DeveloperAssociationNameAssociationExtension', Developer.send(:create_extension_modules, name, extension, []).first.name
+ assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension',
+MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
+ assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
+ assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', MyApplication::Business::Developer.send(:create_extension_modules, name, extension, []).first.name
+ end
+
+
end