Ticket #4289: self_referential_has_many_through_tests.diff
| File self_referential_has_many_through_tests.diff, 4.7 kB (added by lmarlow@yahoo.com, 2 years ago) |
|---|
-
vendor/rails/activerecord/test/associations_join_model_test.rb
old new 2 2 require 'fixtures/tag' 3 3 require 'fixtures/tagging' 4 4 require 'fixtures/post' 5 require 'fixtures/related_post' 5 6 require 'fixtures/comment' 6 7 require 'fixtures/author' 7 8 require 'fixtures/category' … … 9 10 10 11 class AssociationsJoinModelTest < Test::Unit::TestCase 11 12 self.use_transactional_fixtures = false 12 fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings 13 fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings, :related_posts 13 14 14 15 def test_has_many 15 16 assert_equal categories(:general), authors(:david).categories.first … … 233 234 assert_equal [authors(:mary)], posts(:authorless).authors 234 235 end 235 236 237 def test_self_referential_has_many_going_through_join_model 238 assert_equal [], posts(:thinking).related_posts 239 assert_equal [posts(:thinking)], posts(:authorless).related_posts 240 assert_equal [posts(:thinking), posts(:authorless), posts(:sti_comments)], posts(:welcome).related_posts 241 end 242 236 243 def test_belongs_to_polymorphic_with_counter_cache 237 244 assert_equal 0, posts(:welcome)[:taggings_count] 238 245 tagging = posts(:welcome).taggings.create(:tag => tags(:general)) -
vendor/rails/activerecord/test/associations_go_eager_test.rb
old new 1 1 require 'abstract_unit' 2 2 require 'fixtures/post' 3 require 'fixtures/related_post' 3 4 require 'fixtures/comment' 4 5 require 'fixtures/author' 5 6 require 'fixtures/category' … … 9 10 10 11 class EagerAssociationTest < Test::Unit::TestCase 11 12 fixtures :posts, :comments, :authors, :categories, :categories_posts, 12 :companies, :accounts, :tags, :people, :readers 13 :companies, :accounts, :tags, :people, :readers, :related_posts 13 14 14 15 def test_loading_with_one_association 15 16 posts = Post.find(:all, :include => :comments) … … 111 112 assert_equal authors(:david), assert_no_queries { posts_with_author.first.author } 112 113 assert_equal authors(:david), assert_no_queries { posts_with_comments_and_author.first.author } 113 114 end 115 116 def test_eager_with_self_referential_has_many_through 117 related_posts_with_comments = posts(:welcome).related_posts.find(:all, :include => :comments) 118 assert_equal 3, related_posts_with_comments.size 119 related_posts_with_comments.each do |p| 120 assert_no_queries { p.comments } 121 end 122 end 114 123 115 124 def test_eager_with_has_many_and_limit 116 125 posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2) -
vendor/rails/activerecord/test/fixtures/db_definitions/mysql.sql
old new 181 181 PRIMARY KEY (`id`) 182 182 ) TYPE=InnoDB; 183 183 184 CREATE TABLE `related_posts` ( 185 `id` INTEGER NOT NULL auto_increment, 186 `post_id` INTEGER, 187 `related_post_id` INTEGER, 188 `position` INTEGER, 189 PRIMARY KEY (`id`) 190 ) TYPE=InnoDB; 191 184 192 CREATE TABLE `categories` ( 185 193 `id` int(11) NOT NULL auto_increment, 186 194 `name` VARCHAR(255) NOT NULL, -
vendor/rails/activerecord/test/fixtures/db_definitions/mysql.drop.sql
old new 22 22 DROP TABLE posts; 23 23 DROP TABLE comments; 24 24 DROP TABLE authors; 25 DROP TABLE related_posts; 25 26 DROP TABLE categories; 26 27 DROP TABLE categories_posts; 27 28 DROP TABLE fk_test_has_fk; -
vendor/rails/activerecord/test/fixtures/post.rb
old new 35 35 has_many :readers 36 36 has_many :people, :through => :readers 37 37 38 has_many :related_post_infos, :class_name => 'RelatedPost' 39 has_many :related_to_post_infos, :class_name => 'RelatedPost', :foreign_key => 'related_post_id' 40 has_many :related_posts, :class_name => 'Post', :through => :related_post_infos 41 38 42 def self.what_are_you 39 43 'a post...' 40 44 end