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

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

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