aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-04-11 01:10:42 +0000
committerRick Olson <technoweenie@gmail.com>2006-04-11 01:10:42 +0000
commit7e76740d2a5ee14b308c7e40f9c95354d19f6189 (patch)
tree83a89c7dec2b409749a0728aaa7897662ba11dc9 /activerecord/test
parent98634e776191123294f644b0b8444f50df2677e9 (diff)
downloadrails-7e76740d2a5ee14b308c7e40f9c95354d19f6189.tar.gz
rails-7e76740d2a5ee14b308c7e40f9c95354d19f6189.tar.bz2
rails-7e76740d2a5ee14b308c7e40f9c95354d19f6189.zip
Allow multiple association extensions with :extend option (closes #4666) [Josh Susser]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4206 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations_extensions_test.rb5
-rw-r--r--activerecord/test/fixtures/developer.rb12
2 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/associations_extensions_test.rb b/activerecord/test/associations_extensions_test.rb
index 915056c529..e80a2b9fb9 100644
--- a/activerecord/test/associations_extensions_test.rb
+++ b/activerecord/test/associations_extensions_test.rb
@@ -18,6 +18,11 @@ class AssociationsExtensionsTest < Test::Unit::TestCase
def test_named_extension_on_habtm
assert_equal projects(:action_controller), developers(:david).projects_extended_by_name.find_most_recent
end
+
+ def test_named_two_extensions_on_habtm
+ assert_equal projects(:action_controller), developers(:david).projects_extended_by_name_twice.find_most_recent
+ assert_equal projects(:active_record), developers(:david).projects_extended_by_name_twice.find_least_recent
+ end
def test_marshalling_extensions
david = developers(:david)
diff --git a/activerecord/test/fixtures/developer.rb b/activerecord/test/fixtures/developer.rb
index 29555d926a..75fb307b19 100644
--- a/activerecord/test/fixtures/developer.rb
+++ b/activerecord/test/fixtures/developer.rb
@@ -4,6 +4,12 @@ module DeveloperProjectsAssociationExtension
end
end
+module DeveloperProjectsAssociationExtension2
+ def find_least_recent
+ find(:first, :order => "id ASC")
+ end
+end
+
class Developer < ActiveRecord::Base
has_and_belongs_to_many :projects do
def find_most_recent
@@ -17,6 +23,12 @@ class Developer < ActiveRecord::Base
:association_foreign_key => "project_id",
:extend => DeveloperProjectsAssociationExtension
+ has_and_belongs_to_many :projects_extended_by_name_twice,
+ :class_name => "Project",
+ :join_table => "developers_projects",
+ :association_foreign_key => "project_id",
+ :extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2]
+
has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'
validates_inclusion_of :salary, :in => 50000..200000