mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fix the tests (I have actually verified that these are also the 'right' fixes, rather than just making the tests pass again)
This commit is contained in:
@@ -13,17 +13,17 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
|
||||
|
||||
def test_eager_association_loading_with_cascaded_two_levels
|
||||
authors = Author.find(:all, :include=>{:posts=>:comments}, :order=>"authors.id")
|
||||
assert_equal 2, authors.size
|
||||
assert_equal 3, authors.size
|
||||
assert_equal 5, authors[0].posts.size
|
||||
assert_equal 1, authors[1].posts.size
|
||||
assert_equal 2, authors[1].posts.size
|
||||
assert_equal 9, authors[0].posts.collect{|post| post.comments.size }.inject(0){|sum,i| sum+i}
|
||||
end
|
||||
|
||||
def test_eager_association_loading_with_cascaded_two_levels_and_one_level
|
||||
authors = Author.find(:all, :include=>[{:posts=>:comments}, :categorizations], :order=>"authors.id")
|
||||
assert_equal 2, authors.size
|
||||
assert_equal 3, authors.size
|
||||
assert_equal 5, authors[0].posts.size
|
||||
assert_equal 1, authors[1].posts.size
|
||||
assert_equal 2, 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 2, authors[1].categorizations.size
|
||||
@@ -54,15 +54,15 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
|
||||
|
||||
def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations
|
||||
authors = Author.find(:all, :include=>{:posts=>[:comments, :categorizations]}, :order=>"authors.id")
|
||||
assert_equal 2, authors.size
|
||||
assert_equal 3, authors.size
|
||||
assert_equal 5, authors[0].posts.size
|
||||
assert_equal 1, authors[1].posts.size
|
||||
assert_equal 2, authors[1].posts.size
|
||||
assert_equal 9, authors[0].posts.collect{|post| post.comments.size }.inject(0){|sum,i| sum+i}
|
||||
end
|
||||
|
||||
def test_eager_association_loading_with_cascaded_two_levels_and_self_table_reference
|
||||
authors = Author.find(:all, :include=>{:posts=>[:comments, :author]}, :order=>"authors.id")
|
||||
assert_equal 2, authors.size
|
||||
assert_equal 3, authors.size
|
||||
assert_equal 5, authors[0].posts.size
|
||||
assert_equal authors(:david).name, authors[0].name
|
||||
assert_equal [authors(:david).name], authors[0].posts.collect{|post| post.author.name}.uniq
|
||||
@@ -130,9 +130,9 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
|
||||
|
||||
def test_eager_association_loading_where_first_level_returns_nil
|
||||
authors = Author.find(:all, :include => {:post_about_thinking => :comments}, :order => 'authors.id DESC')
|
||||
assert_equal [authors(:mary), authors(:david)], authors
|
||||
assert_equal [authors(:bob), authors(:mary), authors(:david)], authors
|
||||
assert_no_queries do
|
||||
authors[1].post_about_thinking.comments.first
|
||||
authors[2].post_about_thinking.comments.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -53,8 +53,8 @@ class EagerAssociationTest < ActiveRecord::TestCase
|
||||
|
||||
def test_with_ordering
|
||||
list = Post.find(:all, :include => :comments, :order => "posts.id DESC")
|
||||
[:eager_other, :sti_habtm, :sti_post_and_comments, :sti_comments,
|
||||
:authorless, :thinking, :welcome
|
||||
[:misc_by_mary, :misc_by_bob, :eager_other, :sti_habtm, :sti_post_and_comments,
|
||||
:sti_comments, :authorless, :thinking, :welcome
|
||||
].each_with_index do |post, index|
|
||||
assert_equal posts(post), list[index]
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ class EachTest < ActiveRecord::TestCase
|
||||
end
|
||||
|
||||
def test_each_should_execute_if_id_is_in_select
|
||||
assert_queries(4) do
|
||||
assert_queries(5) do
|
||||
Post.find_each(:select => "id, title, type", :batch_size => 2) do |post|
|
||||
assert_kind_of Post, post
|
||||
end
|
||||
|
||||
@@ -127,7 +127,7 @@ class FinderTest < ActiveRecord::TestCase
|
||||
|
||||
assert_equal [[0,3],[1,1],[1,2]], first_three_posts.map { |p| [p.author_id, p.id] }
|
||||
assert_equal [[1,4],[1,5],[1,6]], second_three_posts.map { |p| [p.author_id, p.id] }
|
||||
assert_equal [[2,7]], last_posts.map { |p| [p.author_id, p.id] }
|
||||
assert_equal [[2,7],[2,9],[3,8]], last_posts.map { |p| [p.author_id, p.id] }
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
|
||||
)
|
||||
|
||||
['"name":"David"', '"posts":[', '{"id":1}', '{"id":2}', '{"id":4}',
|
||||
'{"id":5}', '{"id":6}', '"name":"Mary"', '"posts":[{"id":7}]'].each do |fragment|
|
||||
'{"id":5}', '{"id":6}', '"name":"Mary"', '"posts":[', '{"id":7}', '{"id":9}'].each do |fragment|
|
||||
assert json.include?(fragment), json
|
||||
end
|
||||
end
|
||||
|
||||
@@ -434,7 +434,7 @@ class RelationTest < ActiveRecord::TestCase
|
||||
|
||||
def test_last
|
||||
authors = Author.scoped
|
||||
assert_equal authors(:mary), authors.last
|
||||
assert_equal authors(:bob), authors.last
|
||||
end
|
||||
|
||||
def test_destroy_all
|
||||
@@ -507,22 +507,22 @@ class RelationTest < ActiveRecord::TestCase
|
||||
def test_count
|
||||
posts = Post.scoped
|
||||
|
||||
assert_equal 7, posts.count
|
||||
assert_equal 7, posts.count(:all)
|
||||
assert_equal 7, posts.count(:id)
|
||||
assert_equal 9, posts.count
|
||||
assert_equal 9, posts.count(:all)
|
||||
assert_equal 9, posts.count(:id)
|
||||
|
||||
assert_equal 1, posts.where('comments_count > 1').count
|
||||
assert_equal 5, posts.where(:comments_count => 0).count
|
||||
assert_equal 7, posts.where(:comments_count => 0).count
|
||||
end
|
||||
|
||||
def test_count_with_distinct
|
||||
posts = Post.scoped
|
||||
|
||||
assert_equal 3, posts.count(:comments_count, :distinct => true)
|
||||
assert_equal 7, posts.count(:comments_count, :distinct => false)
|
||||
assert_equal 9, posts.count(:comments_count, :distinct => false)
|
||||
|
||||
assert_equal 3, posts.select(:comments_count).count(:distinct => true)
|
||||
assert_equal 7, posts.select(:comments_count).count(:distinct => false)
|
||||
assert_equal 9, posts.select(:comments_count).count(:distinct => false)
|
||||
end
|
||||
|
||||
def test_count_explicit_columns
|
||||
@@ -532,7 +532,7 @@ class RelationTest < ActiveRecord::TestCase
|
||||
assert_equal [0], posts.select('comments_count').where('id is not null').group('id').order('id').count.values.uniq
|
||||
assert_equal 0, posts.where('id is not null').select('comments_count').count
|
||||
|
||||
assert_equal 7, posts.select('comments_count').count('id')
|
||||
assert_equal 9, posts.select('comments_count').count('id')
|
||||
assert_equal 0, posts.select('comments_count').count
|
||||
assert_equal 0, posts.count(:comments_count)
|
||||
assert_equal 0, posts.count('comments_count')
|
||||
@@ -547,12 +547,12 @@ class RelationTest < ActiveRecord::TestCase
|
||||
def test_size
|
||||
posts = Post.scoped
|
||||
|
||||
assert_queries(1) { assert_equal 7, posts.size }
|
||||
assert_queries(1) { assert_equal 9, posts.size }
|
||||
assert ! posts.loaded?
|
||||
|
||||
best_posts = posts.where(:comments_count => 0)
|
||||
best_posts.to_a # force load
|
||||
assert_no_queries { assert_equal 5, best_posts.size }
|
||||
assert_no_queries { assert_equal 7, best_posts.size }
|
||||
end
|
||||
|
||||
def test_count_complex_chained_relations
|
||||
|
||||
Reference in New Issue
Block a user