From 6bd9fac1e301d57765073e1f7a17e46972428205 Mon Sep 17 00:00:00 2001 From: Glenn Vanderburg Date: Fri, 28 Jan 2011 18:16:44 -0600 Subject: Propagate association extensions to scopes called on the association. Signed-off-by: Santiago Pastorino --- activerecord/test/cases/associations/extension_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/cases/associations/extension_test.rb') diff --git a/activerecord/test/cases/associations/extension_test.rb b/activerecord/test/cases/associations/extension_test.rb index efaab8569e..e1f5b16eca 100644 --- a/activerecord/test/cases/associations/extension_test.rb +++ b/activerecord/test/cases/associations/extension_test.rb @@ -29,6 +29,11 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase assert_equal projects(:action_controller), developers(:david).projects_extended_by_name_and_block.find_most_recent assert_equal projects(:active_record), developers(:david).projects_extended_by_name_and_block.find_least_recent end + + def test_extension_with_scopes + assert_equal comments(:greetings), posts(:welcome).comments.offset(1).find_most_recent + assert_equal comments(:greetings), posts(:welcome).comments.not_again.find_most_recent + end def test_marshalling_extensions david = developers(:david) -- cgit v1.2.3 From 52f8e4b9dae6137fcd95793dffc26ddff80b623e Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Mon, 21 Feb 2011 01:09:41 +0000 Subject: Use proper objects to do the work to build the associations (adding methods, callbacks etc) rather than calling a whole bunch of methods with rather long names. --- .../test/cases/associations/extension_test.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'activerecord/test/cases/associations/extension_test.rb') diff --git a/activerecord/test/cases/associations/extension_test.rb b/activerecord/test/cases/associations/extension_test.rb index e1f5b16eca..24830a661a 100644 --- a/activerecord/test/cases/associations/extension_test.rb +++ b/activerecord/test/cases/associations/extension_test.rb @@ -29,7 +29,7 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase assert_equal projects(:action_controller), developers(:david).projects_extended_by_name_and_block.find_most_recent assert_equal projects(:active_record), developers(:david).projects_extended_by_name_and_block.find_least_recent end - + def test_extension_with_scopes assert_equal comments(:greetings), posts(:welcome).comments.offset(1).find_most_recent assert_equal comments(:greetings), posts(:welcome).comments.not_again.find_most_recent @@ -52,12 +52,16 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase 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 + assert_equal 'DeveloperAssociationNameAssociationExtension', extension_name(Developer) + assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', extension_name(MyApplication::Business::Developer) + assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', extension_name(MyApplication::Business::Developer) end + + private + + def extension_name(model) + builder = ActiveRecord::Associations::Builder::HasMany.new(model, :association_name, {}) { } + builder.send(:wrap_block_extension) + builder.options[:extend].first.name + end end -- cgit v1.2.3