diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-06 19:05:42 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-06 19:05:42 +0000 |
commit | c8dd66fdcdc2170982fea8a1782c1728f79e3d41 (patch) | |
tree | bd7c1141fe7c23511080661cb723894858a2c3cd /activerecord/test | |
parent | 0073a759f14c406316062ef6e27f1de5f9ad6cdc (diff) | |
download | rails-c8dd66fdcdc2170982fea8a1782c1728f79e3d41.tar.gz rails-c8dd66fdcdc2170982fea8a1782c1728f79e3d41.tar.bz2 rails-c8dd66fdcdc2170982fea8a1782c1728f79e3d41.zip |
Made association extensions use simpler block syntax
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2895 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/associations_extensions_test.rb | 24 | ||||
-rw-r--r-- | activerecord/test/fixtures/developer.rb | 17 | ||||
-rw-r--r-- | activerecord/test/fixtures/post.rb | 8 |
3 files changed, 40 insertions, 9 deletions
diff --git a/activerecord/test/associations_extensions_test.rb b/activerecord/test/associations_extensions_test.rb index fa9674a149..320432bc28 100644 --- a/activerecord/test/associations_extensions_test.rb +++ b/activerecord/test/associations_extensions_test.rb @@ -7,11 +7,31 @@ require 'fixtures/developer' class AssociationsExtensionsTest < Test::Unit::TestCase fixtures :projects, :developers, :comments, :posts + def test_extension_on_has_many + assert_equal comments(:more_greetings), posts(:welcome).comments.find_most_recent + end + def test_extension_on_habtm assert_equal projects(:action_controller), developers(:david).projects.find_most_recent end + + def test_named_extension_on_habtm + assert_equal projects(:action_controller), developers(:david).projects_extended_by_name.find_most_recent + end - def test_extension_on_has_many - assert_equal comments(:more_greetings), posts(:welcome).comments.find_most_recent + def test_marshalling_extensions + david = developers(:david) + assert_equal projects(:action_controller), david.projects.find_most_recent + + david = Marshal.load(Marshal.dump(david)) + assert_equal projects(:action_controller), david.projects.find_most_recent + end + + def test_marshalling_named_extensions + david = developers(:david) + assert_equal projects(:action_controller), david.projects_extended_by_name.find_most_recent + + david = Marshal.load(Marshal.dump(david)) + assert_equal projects(:action_controller), david.projects_extended_by_name.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 336b48f087..ce65ff78c0 100644 --- a/activerecord/test/fixtures/developer.rb +++ b/activerecord/test/fixtures/developer.rb @@ -1,10 +1,21 @@ +module DeveloperProjectsAssociationExtension + def find_most_recent + find(:first, :order => "id DESC") + end +end + class Developer < ActiveRecord::Base - has_and_belongs_to_many :projects, :extend => Module.new { + has_and_belongs_to_many :projects do def find_most_recent find(:first, :order => "id DESC") end - } - + end + + has_and_belongs_to_many :projects_extended_by_name, + :class_name => "Project", + :join_table => "developers_projects", + :association_foreign_key => "project_id", + :extend => DeveloperProjectsAssociationExtension has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id' diff --git a/activerecord/test/fixtures/post.rb b/activerecord/test/fixtures/post.rb index 1a34823ca0..1697f0a599 100644 --- a/activerecord/test/fixtures/post.rb +++ b/activerecord/test/fixtures/post.rb @@ -1,15 +1,15 @@ class Post < ActiveRecord::Base - belongs_to :author, :extend => Module.new { + belongs_to :author do def greeting "hello" end - } + end - has_many :comments, :order => "body", :extend => Module.new { + has_many :comments, :order => "body" do def find_most_recent find(:first, :order => "id DESC") end - } + end has_one :very_special_comment has_many :special_comments |