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.
17 lines
684 B
Ruby
17 lines
684 B
Ruby
require "rails_helper"
|
|
|
|
# HairTrigger suggests adding this test to make sure the schema and triggers are aligned
|
|
# See https://github.com/jenseng/hair_trigger#testing
|
|
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
|
|
end
|