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.
This commit is contained in:
alimi 2020-04-06 21:14:17 -04:00 committed by GitHub
parent 41139f6ba2
commit 834f5414c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -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