aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-13 01:29:09 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-13 01:29:09 +0100
commit781ad0f8fee209bcf10c5e52daae246477d49ea7 (patch)
treec4b1c714f96bd2e29079bb59f7ee848e4ec9915b /activerecord/test
parent199db8c8c006a5f3bcbbe2a32d39444a741c5843 (diff)
downloadrails-781ad0f8fee209bcf10c5e52daae246477d49ea7.tar.gz
rails-781ad0f8fee209bcf10c5e52daae246477d49ea7.tar.bz2
rails-781ad0f8fee209bcf10c5e52daae246477d49ea7.zip
First bit of support for habtm in through assocs - test_has_many_through_has_many_with_has_and_belongs_to_many_source_reflection now passes
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb2
-rw-r--r--activerecord/test/cases/associations/nested_has_many_through_associations_test.rb13
-rw-r--r--activerecord/test/fixtures/categories.yml5
-rw-r--r--activerecord/test/fixtures/categories_posts.yml4
4 files changed, 17 insertions, 7 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index e67cbcc1a8..c6777d0cb3 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -719,7 +719,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
def test_find_scoped_grouped
assert_equal 5, categories(:general).posts_grouped_by_title.size
- assert_equal 2, categories(:technology).posts_grouped_by_title.size
+ assert_equal 1, categories(:technology).posts_grouped_by_title.size
end
def test_find_scoped_grouped_having
diff --git a/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb b/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
index 835a573978..964112b006 100644
--- a/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/nested_has_many_through_associations_test.rb
@@ -159,10 +159,15 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
# has_many through
# Source: has_and_belongs_to_many
# Through: has_many
- # TODO: Enable and implement this, and finish off the test
- # def test_has_many_through_has_many_with_has_and_belongs_to_many_source_reflection
- # assert_equal [categories(:general), categories(:technology)], authors(:bob).post_categories
- # end
+ def test_has_many_through_has_many_with_has_and_belongs_to_many_source_reflection
+ assert_equal [categories(:general), categories(:cooking)], authors(:bob).post_categories
+
+ authors = Author.joins(:post_categories).where('categories.id' => categories(:cooking).id)
+ assert_equal [authors(:bob)], authors
+
+ authors = Author.includes(:post_categories)
+ assert_equal [categories(:general), categories(:cooking)], authors[2].post_categories
+ end
# TODO: has_many through
# Source: has_many
diff --git a/activerecord/test/fixtures/categories.yml b/activerecord/test/fixtures/categories.yml
index b0770a093d..3e75e733a6 100644
--- a/activerecord/test/fixtures/categories.yml
+++ b/activerecord/test/fixtures/categories.yml
@@ -12,3 +12,8 @@ sti_test:
id: 3
name: Special category
type: SpecialCategory
+
+cooking:
+ id: 4
+ name: Cooking
+ type: Category
diff --git a/activerecord/test/fixtures/categories_posts.yml b/activerecord/test/fixtures/categories_posts.yml
index 3b41510cb1..c6f0d885f5 100644
--- a/activerecord/test/fixtures/categories_posts.yml
+++ b/activerecord/test/fixtures/categories_posts.yml
@@ -26,6 +26,6 @@ general_misc_by_bob:
category_id: 1
post_id: 8
-technology_misc_by_bob:
- category_id: 2
+cooking_misc_by_bob:
+ category_id: 4
post_id: 8