aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-05-06 23:37:56 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-05-06 23:37:56 +0000
commit50f538b72bbe6657627c9efe55b65d167956d1b7 (patch)
treea3fd7a90a3d205ffd05f20ed4127c426e73cbbc4 /activerecord/test
parente0123041750b724daa1e5fb4e7e66b233b2b1bed (diff)
downloadrails-50f538b72bbe6657627c9efe55b65d167956d1b7.tar.gz
rails-50f538b72bbe6657627c9efe55b65d167956d1b7.tar.bz2
rails-50f538b72bbe6657627c9efe55b65d167956d1b7.zip
Allow :uniq => true with has_many :through associations.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4325 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/associations_cascaded_eager_loading_test.rb2
-rw-r--r--activerecord/test/associations_join_model_test.rb19
-rw-r--r--activerecord/test/fixtures/author.rb5
-rw-r--r--activerecord/test/fixtures/categorizations.yml10
4 files changed, 25 insertions, 11 deletions
diff --git a/activerecord/test/associations_cascaded_eager_loading_test.rb b/activerecord/test/associations_cascaded_eager_loading_test.rb
index dd12d529a2..642e4fa433 100644
--- a/activerecord/test/associations_cascaded_eager_loading_test.rb
+++ b/activerecord/test/associations_cascaded_eager_loading_test.rb
@@ -28,7 +28,7 @@ class CascadedEagerLoadingTest < Test::Unit::TestCase
assert_equal 1, authors[1].posts.size
assert_equal 9, authors[0].posts.collect{|post| post.comments.size }.inject(0){|sum,i| sum+i}
assert_equal 1, authors[0].categorizations.size
- assert_equal 1, authors[1].categorizations.size
+ assert_equal 2, authors[1].categorizations.size
end
def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations
diff --git a/activerecord/test/associations_join_model_test.rb b/activerecord/test/associations_join_model_test.rb
index 9bacbfc717..be04df9c00 100644
--- a/activerecord/test/associations_join_model_test.rb
+++ b/activerecord/test/associations_join_model_test.rb
@@ -12,21 +12,26 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :author_favorites
def test_has_many
- assert_equal categories(:general), authors(:david).categories.first
+ assert authors(:david).categories.include?(categories(:general))
end
-
+
def test_has_many_inherited
- assert_equal categories(:sti_test), authors(:mary).categories.first
+ assert authors(:mary).categories.include?(categories(:sti_test))
end
def test_inherited_has_many
- assert_equal authors(:mary), categories(:sti_test).authors.first
+ assert categories(:sti_test).authors.include?(authors(:mary))
end
-
+
+ def test_has_many_uniq_through_join_model
+ assert_equal 2, authors(:mary).categorized_posts.size
+ assert_equal 1, authors(:mary).unique_categorized_posts.size
+ end
+
def test_polymorphic_has_many
- assert_equal taggings(:welcome_general), posts(:welcome).taggings.first
+ assert posts(:welcome).taggings.include?(taggings(:welcome_general))
end
-
+
def test_polymorphic_has_one
assert_equal taggings(:welcome_general), posts(:welcome).tagging
end
diff --git a/activerecord/test/fixtures/author.rb b/activerecord/test/fixtures/author.rb
index 99142f6621..ec844f6238 100644
--- a/activerecord/test/fixtures/author.rb
+++ b/activerecord/test/fixtures/author.rb
@@ -26,6 +26,9 @@ class Author < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
+ has_many :categorized_posts, :through => :categorizations, :source => :post
+ has_many :unique_categorized_posts, :through => :categorizations, :source => :post, :uniq => true
+
has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
has_many :author_favorites
@@ -73,4 +76,4 @@ end
class AuthorFavorite < ActiveRecord::Base
belongs_to :author
belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id'
-end \ No newline at end of file
+end
diff --git a/activerecord/test/fixtures/categorizations.yml b/activerecord/test/fixtures/categorizations.yml
index f8701fbde0..c5b6fc9a51 100644
--- a/activerecord/test/fixtures/categorizations.yml
+++ b/activerecord/test/fixtures/categorizations.yml
@@ -3,9 +3,15 @@ david_welcome_general:
author_id: 1
post_id: 1
category_id: 1
-
+
mary_thinking_sti:
id: 2
author_id: 2
post_id: 2
- category_id: 3 \ No newline at end of file
+ category_id: 3
+
+mary_thinking_general:
+ id: 3
+ author_id: 2
+ post_id: 2
+ category_id: 1