From 834f5414c3b879a3a50c5cac128c9d9b007fa569 Mon Sep 17 00:00:00 2001 From: alimi Date: Mon, 6 Apr 2020 21:14:17 -0400 Subject: [PATCH] Fix EagerLoadPolyAssocsTest setup (#38883) * Fix EagerLoadPolyAssocsTest setup * EagerLoadPolyAssocsTest includes a Remembered module in multiple test ActiveRecord classes. The module is supposed to keep track of records created for each of the included classes individually, but it collects all records for every class. This happens because @@remembered is defined on the Remembered module and shared between the ActiveRecord classes. This only becomes an issue for databases (like CockroachDB) that use random primary keys instead of sequential ones by default. * To fix the bug, we can make the remembered collection name unique per ActiveRecord class. * Update EagerLoadPolyAssocsTest test setup * Instead of defining remembered as a class variable, we can define it as an instance variable that will be unique to every class that includes the Remembered module. --- .../test/cases/associations/eager_load_nested_include_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/associations/eager_load_nested_include_test.rb b/activerecord/test/cases/associations/eager_load_nested_include_test.rb index 9be21b23db2..f81bb2e425e 100644 --- a/activerecord/test/cases/associations/eager_load_nested_include_test.rb +++ b/activerecord/test/cases/associations/eager_load_nested_include_test.rb @@ -20,8 +20,8 @@ module Remembered end module ClassMethods - def remembered; @@remembered ||= []; end - def sample; @@remembered.sample; end + def remembered; @remembered ||= []; end + def sample; remembered.sample; end end end