1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix flakey test due to non-deterministic order

Example failure: https://buildkite.com/rails/rails/builds/70840#d213df74-a2e6-45e5-8302-d75a6c31f700/1021-1033

The test's assertion expects the authors to be ordered by ID, but that
order is not guaranteed without an explicit sort.
This commit is contained in:
Jonathan Hefner 2020-07-27 10:53:12 -05:00
parent a9336a67b0
commit 5e2d3db4b5

View file

@ -587,7 +587,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_preloading_has_many_through_with_implicit_source
authors = Author.includes(:very_special_comments).to_a
authors = Author.includes(:very_special_comments).to_a.sort_by(&:id)
assert_no_queries do
special_comment_authors = authors.map { |author| [author.name, author.very_special_comments.size] }
assert_equal [["David", 1], ["Mary", 0], ["Bob", 0]], special_comment_authors