ENV['CRYPT_KEEPER_IGNORE_LEGACY_DEPRECATION'] = "true"
require 'coveralls'
Coveralls.wear!
require 'crypt_keeper'

SPEC_ROOT           = Pathname.new File.expand_path File.dirname __FILE__
AR_LOG              = SPEC_ROOT.join('debug.log').to_s
ENCRYPTION_PASSWORD = "supermadsecretstring"

Dir[SPEC_ROOT.join('support/*.rb')].each{|f| require f }

RSpec.configure do |config|
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  config.after :each do
    ActiveRecord::Base.descendants.each do |model|
      model.method(:delete_all).call
    end
  end

  config.after :suite do
    if File.exist?(AR_LOG) && ENV['TRAVIS'].present?
      `grep \"#{ENCRYPTION_PASSWORD}\" #{AR_LOG}`

      if $?.exitstatus == 0
        raise StandardError, "\n\nERROR: The encryption password was found in the logs\n\n"
      end
    end
  end
end

ENV['CRYPT_KEEPER_IGNORE_LEGACY_DEPRECATION'] = "true"
require 'coveralls'
Coveralls.wear!
require 'crypt_keeper'

SPEC_ROOT           = Pathname.new File.expand_path File.dirname __FILE__
AR_LOG              = SPEC_ROOT.join('debug.log').to_s
ENCRYPTION_PASSWORD = "supermadsecretstring"

Dir[SPEC_ROOT.join('support/*.rb')].each{|f| require f }

RSpec.configure do |config|
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  config.after :each do
    descendants = ActiveRecord::Base.descendants.delete_if do |descendant|
      descendant.to_s.include?("SchemaMigration")
    end

    descendants.each do |model|
      model.method(:delete_all).call
    end
  end

  config.after :suite do
    if File.exist?(AR_LOG) && ENV['TRAVIS'].present?
      `grep \"#{ENCRYPTION_PASSWORD}\" #{AR_LOG}`

      if $?.exitstatus == 0
        raise StandardError, "\n\nERROR: The encryption password was found in the logs\n\n"
      end
    end
  end
end

Remove SchemaMigration descendents from spec deletion
Remove SchemaMigration descendents from spec deletion

The `spec_helper.rb` file includes an after hook that runs on each spec
which takes every descendant of `ActiveRecord::Base` and calls
`delete_all` on it.

In ActiveRecord 6, there are two classes that are returned as
descendants that were not previously:

* ActiveRecord::SchemaMigration
* primary::SchemaMigration

Calling `delete_all` on these models causes issues with the test suite
because those tables do not exist when running this test suite. As such,
this removes those classes from descendants that we should delete all
the records from after each test is run.

As such, this modifies that after hook to exclude any descendant whose
class name includes `SchemaMigration`.

This may be a bit of a cat-and-mouse game with activerecord internals,
but as long as we want to have the spec_helper delete every record from
every class that exists in the test system in this manner, I think we
need to have this list of excluded classes.

This should not have an impact on prior versions of activerecord, as
these classes were not previously descendants, so removing a thing that
doesn't exist won't have a functional impact. It does have a negative
performance affect on the test suite, as it needs to run through the
descendants with every spec run and see if any of them are a
`SchemaMigration` and remove them.
