diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-10-14 12:59:16 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2010-10-14 12:59:16 +0100 |
commit | bc821a56114ae6f6d0b595475ad9e71f01f46f35 (patch) | |
tree | 68f73c478155eec9c722c4cf7ab194938385ccc5 /activerecord/test | |
parent | 22782e2cc131863b72e457636f9a995a6ae50136 (diff) | |
download | rails-bc821a56114ae6f6d0b595475ad9e71f01f46f35.tar.gz rails-bc821a56114ae6f6d0b595475ad9e71f01f46f35.tar.bz2 rails-bc821a56114ae6f6d0b595475ad9e71f01f46f35.zip |
Added test_has_many_through_has_many_with_has_many_through_habtm_source_reflection and make it pass
Diffstat (limited to 'activerecord/test')
4 files changed, 24 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 4b7a8b494d..385505b109 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -304,7 +304,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_going_through_join_model_with_custom_foreign_key - assert_equal [], posts(:thinking).authors + assert_equal [authors(:bob)], posts(:thinking).authors assert_equal [authors(:mary)], posts(:authorless).authors end 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 4e7e766b14..26c31ef761 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 @@ -25,6 +25,7 @@ require 'models/sponsor' require 'models/club' require 'models/organization' require 'models/category' +require 'models/categorization' # NOTE: Some of these tests might not really test "nested" HMT associations, as opposed to ones which # are just one level deep. But it's all the same thing really, as the "nested" code is being @@ -34,7 +35,8 @@ require 'models/category' class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase fixtures :authors, :books, :posts, :subscriptions, :subscribers, :tags, :taggings, :people, :readers, :references, :jobs, :ratings, :comments, :members, :member_details, - :member_types, :sponsors, :clubs, :organizations, :categories, :categories_posts + :member_types, :sponsors, :clubs, :organizations, :categories, :categories_posts, + :categorizations # Through associations can either use the has_many or has_one macros. # @@ -183,6 +185,19 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase # assert_equal [comments(:greetings), comments(:more_greetings)], categories[1].post_comments end + # has_many through + # Source: has_many through a habtm + # Through: has_many through + def test_has_many_through_has_many_with_has_many_through_habtm_source_reflection + assert_equal [comments(:greetings), comments(:more_greetings)], authors(:bob).category_post_comments + + authors = Author.joins(:category_post_comments).where('comments.id' => comments(:does_it_hurt).id) + assert_equal [authors(:david), authors(:mary)], authors + + comments = Author.joins(:category_post_comments) + assert_equal [comments(:greetings), comments(:more_greetings)], comments[2].category_post_comments + end + # TODO: has_many through # Source: belongs_to # Through: has_many through diff --git a/activerecord/test/fixtures/categorizations.yml b/activerecord/test/fixtures/categorizations.yml index c5b6fc9a51..62e5bd111a 100644 --- a/activerecord/test/fixtures/categorizations.yml +++ b/activerecord/test/fixtures/categorizations.yml @@ -15,3 +15,9 @@ mary_thinking_general: author_id: 2 post_id: 2 category_id: 1 + +bob_misc_by_bob_technology: + id: 4 + author_id: 3 + post_id: 8 + category_id: 2 diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index 584164f19a..f2f373af8c 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -101,6 +101,7 @@ class Author < ActiveRecord::Base belongs_to :author_address_extra, :dependent => :delete, :class_name => "AuthorAddress" has_many :post_categories, :through => :posts, :source => :categories + has_many :category_post_comments, :through => :categories, :source => :post_comments scope :relation_include_posts, includes(:posts) scope :relation_include_tags, includes(:tags) |