Sha256: b3e36b455604d2a8b3940da7e3f92e6c4bd8bbf9c239ae97842cf077c738781b

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

$:.unshift(File.dirname(__FILE__) + '/../lib')
require "bundler/setup"
require "minitest/autorun"

require "active_record"
require "assertions"
require "database_cleaner"

require "acts_as_archival"

def prepare_for_tests
  setup_logging# if ENV["LOGGING_ENABLED"]
  setup_active_record
  setup_database_cleaner
  create_test_tables
  require_test_classes
end

def setup_logging
  require "logger"
  logfile = File.dirname(__FILE__) + "/debug.log"
  ActiveRecord::Base.logger = Logger.new(logfile)
end

def setup_active_record
  dbconfig_file = File.dirname(__FILE__) + "/database.yml"
  $dbconfig = YAML.load(File.read(dbconfig_file))
end

def setup_database_cleaner
  DatabaseCleaner.strategy = :truncation
  ActiveSupport::TestCase.send(:setup) do
    DatabaseCleaner.clean
  end
end

def create_test_tables
  schema_file = File.dirname(__FILE__) + "/schema.rb"
  ["pg", "mysql", "sqlite"].each do |db|
    puts "** Loading schema for #{db}"
    ActiveRecord::Base.establish_connection($dbconfig[db])
    load(schema_file) if File.exist?(schema_file)
  end
end

def require_test_classes
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.irregular "poly", "polys"
  end

  fixtures = [:archival,
   :archival_kid,
   :archival_grandkid,
   :archival_table_name,
   :exploder,
   :independent_archival,
   :plain,
   :missing_archived_at,
   :missing_archive_number,
   :mysql_archival,
   :mysql_exploder,
   :plain,
   :poly,
   :pg_archival,
   :pg_exploder,
   :readonly_when_archived]
  $require_mass_protection = ActiveModel.constants.include?(:MassAssignmentSecurity)
  fixtures << :mass_attribute_protected if $require_mass_protection
  fixtures.each {|test_class_file| require_relative "fixtures/#{test_class_file}"}
end

prepare_for_tests

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acts_as_archival-1.0.0 test/test_helper.rb
acts_as_archival-0.6.1 test/test_helper.rb
acts_as_archival-0.6.0 test/test_helper.rb