# frozen_string_literal: true # This file attempts to reproduce issue #1720 of the enhanced adapter # (https://github.com/rsim/oracle-enhanced). See issue comments for instructions # on how to use this file. # CONFIGURATION DB_CONFIG = { adapter: :mysql2, host: 'REPLACE_ME' || ENV['DB_HOST'], port: REPLACE_ME || ENV['DB_PORT'], database: 'REPLACE_ME' || ENV['DB_NAME'], username: 'REPLACE_ME' || ENV['DB_USERNAME'], password: 'REPLACE_ME' || ENV['DB_PASSWORD'] }.freeze # END OF CONFIGURATION begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' gem 'activerecord', ENV['NEW'] ? '5.2.0' : '5.1.6' gem 'activerecord-jdbcmysql-adapter' gem 'pry' end require 'active_record' require 'minitest/autorun' require 'active_record/connection_adapters/jdbcmysql_adapter' require "logger" # Ensure backward compatibility with Minitest 4 Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) # This connection will do for database-independent bug reports. ActiveRecord::Base.establish_connection(DB_CONFIG) ActiveRecord::Base.logger = Logger.new(STDOUT) TABLE_COUNT = 20 COLUMN_COUNT_PER_TYPE = 10 ActiveRecord::Schema.define do TABLE_COUNT.times do |i| create_table :"table_#{i}", force: true do |t| COLUMN_COUNT_PER_TYPE.times do |j| t.string :"string_column_#{j}" t.integer :"integer_column_#{j}" end end end end class BugTest < Minitest::Test # Tries to reproduce #1070. Works as expected. def test_performance benchmark = Benchmark.measure { TABLE_COUNT.times do |i| c = Class.new(ActiveRecord::Base) do self.table_name = "table_#{i}" end c.first end } puts "BENCHMARK:" puts benchmark end end