Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set counter caches to correct values in fixtures #25346

Merged
merged 1 commit into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_eager_association_loading_with_cascaded_two_levels_and_one_level

def test_eager_association_loading_with_hmt_does_not_table_name_collide_when_joining_associations
authors = Author.joins(:posts).eager_load(:comments).where(posts: { tags_count: 1 }).to_a
assert_equal 1, assert_no_queries { authors.size }
assert_equal 3, assert_no_queries { authors.size }
assert_equal 10, assert_no_queries { authors[0].comments.size }
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def test_find_scoped_grouped
end

def test_find_scoped_grouped_having
assert_equal 1, authors(:david).popular_grouped_posts.length
assert_equal 2, authors(:david).popular_grouped_posts.length
assert_equal 0, authors(:mary).popular_grouped_posts.length
end

Expand Down
18 changes: 9 additions & 9 deletions activerecord/test/cases/relations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -927,13 +927,13 @@ def test_count
assert_equal 11, posts.count(:all)
assert_equal 11, posts.count(:id)

assert_equal 1, posts.where("comments_count > 1").count
assert_equal 9, posts.where(comments_count: 0).count
assert_equal 3, posts.where("comments_count > 1").count
assert_equal 6, posts.where(comments_count: 0).count
end

def test_count_with_block
posts = Post.all
assert_equal 10, posts.count { |p| p.comments_count.even? }
assert_equal 8, posts.count { |p| p.comments_count.even? }
end

def test_count_on_association_relation
Expand All @@ -950,10 +950,10 @@ def test_count_on_association_relation
def test_count_with_distinct
posts = Post.all

assert_equal 3, posts.distinct(true).count(:comments_count)
assert_equal 4, posts.distinct(true).count(:comments_count)
assert_equal 11, posts.distinct(false).count(:comments_count)

assert_equal 3, posts.distinct(true).select(:comments_count).count
assert_equal 4, posts.distinct(true).select(:comments_count).count
assert_equal 11, posts.distinct(false).select(:comments_count).count
end

Expand Down Expand Up @@ -992,7 +992,7 @@ def test_size

best_posts = posts.where(comments_count: 0)
best_posts.load # force load
assert_no_queries { assert_equal 9, best_posts.size }
assert_no_queries { assert_equal 6, best_posts.size }
end

def test_size_with_limit
Expand All @@ -1003,7 +1003,7 @@ def test_size_with_limit

best_posts = posts.where(comments_count: 0)
best_posts.load # force load
assert_no_queries { assert_equal 9, best_posts.size }
assert_no_queries { assert_equal 6, best_posts.size }
end

def test_size_with_zero_limit
Expand All @@ -1026,7 +1026,7 @@ def test_empty_with_zero_limit
def test_count_complex_chained_relations
posts = Post.select("comments_count").where("id is not null").group("author_id").where("comments_count > 0")

expected = { 1 => 2 }
expected = { 1 => 4, 2 => 1 }
assert_equal expected, posts.count
end

Expand Down Expand Up @@ -1781,7 +1781,7 @@ def test_presence
end

test "arel_attribute respects a custom table" do
assert_equal [posts(:welcome)], custom_post_relation.ranked_by_comments.limit_by(1).to_a
assert_equal [posts(:sti_comments)], custom_post_relation.ranked_by_comments.limit_by(1).to_a
end

test "alias_tracker respects a custom table" do
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/fixtures/other_posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ second_welcome:
author_id: 1
title: Welcome to the another weblog
body: It's really nice today
comments_count: 1
8 changes: 8 additions & 0 deletions activerecord/test/fixtures/posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ sti_comments:
author_id: 1
title: sti comments
body: hello
comments_count: 5
type: Post

sti_post_and_comments:
id: 5
author_id: 1
title: sti me
body: hello
comments_count: 2
type: StiPost

sti_habtm:
Expand All @@ -50,31 +52,37 @@ eager_other:
title: eager loading with OR'd conditions
body: hello
type: Post
comments_count: 1
tags_count: 3

misc_by_bob:
id: 8
author_id: 3
title: misc post by bob
body: hello
type: Post
tags_count: 1

misc_by_mary:
id: 9
author_id: 2
title: misc post by mary
body: hello
type: Post
tags_count: 1

other_by_bob:
id: 10
author_id: 3
title: other post by bob
body: hello
type: Post
tags_count: 1

other_by_mary:
id: 11
author_id: 2
title: other post by mary
body: hello
type: Post
tags_count: 1