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:
parent
84d931136e
commit
14e95e6713
1 changed files with 6 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue