Skip to content

Commit

Permalink
Merge pull request #43131 from yahonda/bin_test_handles_adaptes
Browse files Browse the repository at this point in the history
Active Record `bin/test` to execute its own adapter specific tests
  • Loading branch information
rafaelfranca committed Sep 21, 2021
2 parents badf915 + 6d10aaf commit 1a240cf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
2 changes: 1 addition & 1 deletion activerecord/bin/test
Expand Up @@ -8,7 +8,7 @@ if adapter_index
end

COMPONENT_ROOT = File.expand_path("..", __dir__)
require_relative "../../tools/test"
require_relative "../test/support/tools"

module Minitest
def self.plugin_active_record_options(opts, options)
Expand Down
Expand Up @@ -7,7 +7,7 @@ class PostgresqlTime < ActiveRecord::Base
# Declare attributes to get rid from deprecation warnings on ActiveRecord 6.1
attribute :time_interval, :string
attribute :scaled_time_interval, :interval
end if current_adapter?(:PostgreSQLAdapter)
end

class PostgresqlOid < ActiveRecord::Base
end
Expand Down
Expand Up @@ -16,7 +16,7 @@ class PostgresqlPoint < ActiveRecord::Base
attribute :legacy_x, :legacy_point
attribute :legacy_y, :legacy_point
attribute :legacy_z, :legacy_point
end if current_adapter?(:PostgreSQLAdapter)
end

def setup
@connection = ActiveRecord::Base.connection
Expand Down
Expand Up @@ -12,7 +12,7 @@ class IntervalDataType < ActiveRecord::Base
attribute :default_term, :interval
attribute :all_terms, :interval, array: true
attribute :legacy_term, :string
end if current_adapter?(:PostgreSQLAdapter)
end

class DeprecatedIntervalDataType < ActiveRecord::Base; end

Expand Down
35 changes: 35 additions & 0 deletions activerecord/test/support/tools.rb
@@ -0,0 +1,35 @@
# frozen_string_literal: true

$: << File.expand_path("test", COMPONENT_ROOT)

require "bundler/setup"

require "rails/test_unit/runner"
require "rails/test_unit/reporter"
require "rails/test_unit/line_filtering"
require "active_support"
require "active_support/test_case"

require "rake/testtask"
Rails::TestUnit::Runner.singleton_class.prepend Module.new {
private
def list_tests(argv)
tests = super
tests.concat FileList["test/cases/adapters/#{adapter_name}/**/*_test.rb"]
end

def default_test_exclude_glob
ENV["DEFAULT_TEST_EXCLUDE"] || "test/cases/adapters/*/*_test.rb"
end

def adapter_name
ENV["ARCONN"] || "sqlite3"
end
}

ActiveSupport::TestCase.extend Rails::LineFiltering
Rails::TestUnitReporter.app_root = COMPONENT_ROOT
Rails::TestUnitReporter.executable = "bin/test"

Rails::TestUnit::Runner.parse_options(ARGV)
Rails::TestUnit::Runner.run(ARGV)
13 changes: 9 additions & 4 deletions railties/lib/rails/test_unit/runner.rb
Expand Up @@ -43,10 +43,7 @@ def run(argv = [])
end

def load_tests(argv)
patterns = extract_filters(argv)

tests = Rake::FileList[patterns.any? ? patterns : default_test_glob]
tests.exclude(default_test_exclude_glob) if patterns.empty?
tests = list_tests(argv)
tests.to_a.each { |path| require File.expand_path(path) }
end

Expand Down Expand Up @@ -94,6 +91,14 @@ def regexp_filter?(arg)
def path_argument?(arg)
%r"^[/\\]?\w+[/\\]".match?(arg)
end

def list_tests(argv)
patterns = extract_filters(argv)

tests = Rake::FileList[patterns.any? ? patterns : default_test_glob]
tests.exclude(default_test_exclude_glob) if patterns.empty?
tests
end
end
end

Expand Down

0 comments on commit 1a240cf

Please sign in to comment.