Skip to content

Commit 05f8809

Browse files
committed
Fix nondeterministic behavior in DeprecatedHasAndBelongsToManyAssociationsTest
This commit addresses intermittent failures like: https://buildkite.com/rails/rails/builds/121865#019970b4-ac11-4f90-9c65-7e39198536a8/1295-1306 https://buildkite.com/rails/rails/builds/121622#01995272-5209-4eda-bab1-fbdce04a5762/1223-1234 ```sql Failure: DeprecatedHasAndBelongsToManyAssociationsTest#test_<association> [test/cases/associations/has_and_belongs_to_many_associations_test.rb:1016]: --- expected +++ actual @@ -1 +1 @@ -#<ActiveRecord::Associations::CollectionProxy [#<DATS::Post id: 1, author_id: 1, title: "Welcome to the weblog", body: "Such a lovely day", type: "Post", legacy_comments_count: 2, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 1, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 2, author_id: 1, title: "So I was thinking", body: "Like I hopefully always am", type: "SpecialPost", legacy_comments_count: 1, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 1, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 6, author_id: 1, title: "habtm sti test", body: "hello", type: "Post", legacy_comments_count: 0, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 0, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 4, author_id: 1, title: "sti comments", body: "hello", type: "Post", legacy_comments_count: 5, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 0, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 8, author_id: 3, title: "misc post by bob", body: "hello", type: "Post", legacy_comments_count: 0, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 1, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>]> +#<ActiveRecord::Associations::CollectionProxy [#<DATS::Post id: 1, author_id: 1, title: "Welcome to the weblog", body: "Such a lovely day", type: "Post", legacy_comments_count: 2, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 1, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 2, author_id: 1, title: "So I was thinking", body: "Like I hopefully always am", type: "SpecialPost", legacy_comments_count: 1, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 1, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 4, author_id: 1, title: "sti comments", body: "hello", type: "Post", legacy_comments_count: 5, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 0, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 6, author_id: 1, title: "habtm sti test", body: "hello", type: "Post", legacy_comments_count: 0, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 0, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>, #<DATS::Post id: 8, author_id: 3, title: "misc post by bob", body: "hello", type: "Post", legacy_comments_count: 0, taggings_with_delete_all_count: 0, taggings_with_destroy_count: 0, tags_count: 1, indestructible_tags_count: 0, tags_with_destroy_count: 0, tags_with_nullify_count: 0>]> ``` - SQL statement executed with this fix: ``` DATS::Post Load (0.2ms) SELECT "posts".* FROM "posts" INNER JOIN "categories_posts" ON "posts"."id" = "categories_posts"."post_id" WHERE "categories_posts"."category_id" = $1 ORDER BY "posts"."id" ASC [["category_id", 1]] ``` - SQL statement executed without this fix: ```sql DATS::Post Load (0.3ms) SELECT "posts".* FROM "posts" INNER JOIN "categories_posts" ON "posts"."id" = "categories_posts"."post_id" WHERE "categories_posts"."category_id" = $1 [["category_id", 1]] ``` Related to rails#55285
1 parent cea7cae commit 05f8809

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ class DeprecatedHasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
10141014
end
10151015

10161016
assert_deprecated_association(:deprecated_posts, context: context_for_method(:deprecated_posts)) do
1017-
assert_equal @category.posts, @category.deprecated_posts
1017+
assert_equal @category.posts.order(:id), @category.deprecated_posts.order(:id)
10181018
end
10191019
end
10201020

0 commit comments

Comments
 (0)