1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# frozen_string_literal: true
# $DEBUG = true
require "active_record"
require "minitest/autorun"
require "mocha/minitest"
require "acts_as_list"
if defined?(ActiveRecord::VERSION) &&
ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2
# Was removed in Rails 5 and is effectively true.
ActiveRecord::Base.raise_in_transactional_callbacks = true
end
db_config = YAML.load_file(File.expand_path("../database.yml", __FILE__)).fetch(ENV["DB"] || "sqlite")
ActiveRecord::Base.establish_connection(db_config)
ActiveRecord::Schema.verbose = false
def teardown_db
if ActiveRecord::VERSION::MAJOR >= 5
tables = ActiveRecord::Base.connection.data_sources
else
tables = ActiveRecord::Base.connection.tables
end
tables.each do |table|
ActiveRecord::Base.connection.drop_table(table)
end
end
require "shared"
# require 'logger'
# ActiveRecord::Base.logger = Logger.new(STDOUT)
def assert_equal_or_nil(a, b)
if a.nil?
assert_nil b
else
assert_equal a, b
end
end
def assert_no_deprecation_warning_raised_by(failure_message = 'ActiveRecord deprecation warning raised when we didn\'t expect it', pass_message = 'No ActiveRecord deprecation raised')
original_behavior = ActiveSupport::Deprecation.behavior
ActiveSupport::Deprecation.behavior = :raise
begin
yield
rescue ActiveSupport::DeprecationException => e
flunk "#{failure_message}: #{e}"
rescue
raise
else
pass pass_message
end
ensure
ActiveSupport::Deprecation.behavior = original_behavior
end
|