diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-03 09:06:42 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-03 09:06:42 +0000 |
commit | 8c512a1caffa11d1522cef5d2a35e2888c608581 (patch) | |
tree | 4fc18e0b02824638eb87d815231f470b9523231a /activerecord/test | |
parent | f109bfb765fd54ef8bb94751c671a097089d7f53 (diff) | |
download | rails-8c512a1caffa11d1522cef5d2a35e2888c608581.tar.gz rails-8c512a1caffa11d1522cef5d2a35e2888c608581.tar.bz2 rails-8c512a1caffa11d1522cef5d2a35e2888c608581.zip |
Added extension capabilities to has_many and has_and_belongs_to_many proxies [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2861 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/associations_extensions_test.rb | 15 | ||||
-rw-r--r-- | activerecord/test/fixtures/developer.rb | 8 | ||||
-rw-r--r-- | activerecord/test/fixtures/post.rb | 16 |
3 files changed, 35 insertions, 4 deletions
diff --git a/activerecord/test/associations_extensions_test.rb b/activerecord/test/associations_extensions_test.rb new file mode 100644 index 0000000000..92bdb86eb5 --- /dev/null +++ b/activerecord/test/associations_extensions_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' +require 'fixtures/project' +require 'fixtures/developer' + +class AssociationsExtensionsTest < Test::Unit::TestCase + fixtures :projects, :developers + + def test_extension_on_habtm + assert_equal projects(:action_controller), developers(:david).projects.find_most_recent + end + + def test_extension_on_has_many + assert_equal comments(:more_greetings), posts(:welcome).comments.find_most_recent + end +end
\ No newline at end of file diff --git a/activerecord/test/fixtures/developer.rb b/activerecord/test/fixtures/developer.rb index 1a4f0648bb..336b48f087 100644 --- a/activerecord/test/fixtures/developer.rb +++ b/activerecord/test/fixtures/developer.rb @@ -1,5 +1,11 @@ class Developer < ActiveRecord::Base - has_and_belongs_to_many :projects + has_and_belongs_to_many :projects, :extend => Module.new { + def find_most_recent + find(:first, :order => "id DESC") + end + } + + has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id' validates_inclusion_of :salary, :in => 50000..200000 diff --git a/activerecord/test/fixtures/post.rb b/activerecord/test/fixtures/post.rb index f5adac41dc..6163ec90f8 100644 --- a/activerecord/test/fixtures/post.rb +++ b/activerecord/test/fixtures/post.rb @@ -1,7 +1,17 @@ class Post < ActiveRecord::Base - belongs_to :author - has_many :comments, :order => "body" - has_one :very_special_comment, :class_name => "VerySpecialComment" + belongs_to :author, :extend => Module.new { + def greeting + "hello" + end + } + + has_many :comments, :order => "body", :extend => Module.new { + def find_most_recent + find(:first, :order => "id DESC") + end + } + + has_many :special_comments, :class_name => "SpecialComment" has_and_belongs_to_many :categories has_and_belongs_to_many :special_categories, :join_table => "categories_posts" |