Ensure ActiveRecord::Base has descendants before checking triggers (#14732)

HairTrigger uses the ActiveRecord::Base.descendants to find triggers
in the db (from `models`). WithModel (used in the Settings::Base spec)
clears this during its descendants cleanup, causing this test to
ocassionally fail.

Before checking hairtrigger, if AR::Base descendents is empty, add
ApplicationRecord (there's an assumption here that all of our
application models inherit from application record - this may or may
not be true if we use engine generated models that do not follow this
convention and need to validate triggers there.
This commit is contained in:
Daniel Uber 2021-09-15 09:29:44 -05:00 committed by GitHub
parent 84d931136e
commit 14e95e6713
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,12 @@ require "rails_helper"
RSpec.describe HairTrigger, type: :model do
describe ".migrations_current?" do
it "is always true" do
# work-around empty AR::Base descendants array caused by with_model cleanup
# HairTrigger uses AR::Base to get database triggers (and compare against the schema)
if ActiveRecord::Base.descendants.blank?
ActiveSupport::DescendantsTracker.store_inherited(ActiveRecord::Base, ApplicationRecord)
end
expect(described_class.migrations_current?).to be(true)
end
end