Skip to content

Instantly share code, notes, and snippets.

@sudoremo
Created March 22, 2018 13:19
Show Gist options
  • Save sudoremo/76f84c68f5545fbb46e50f6d3b633884 to your computer and use it in GitHub Desktop.
Save sudoremo/76f84c68f5545fbb46e50f6d3b633884 to your computer and use it in GitHub Desktop.
This file attempts to reproduce the issues #920, #1070 and #1678 of the oracle enhanced adapter (https://github.com/rsim/oracle-enhanced)
# frozen_string_literal: true
# This file attempts to reproduce the issues #920, #1070 and #1678 of the oracle
# enhanced adapter (https://github.com/rsim/oracle-enhanced). To use it:
#
# 1) Make sure that ojdbc(6|7|9).jar is in your $PATH
# 2) Set the constant DB_CONFIG to your database credentials
# (use a fresh database as it may delete some tables)
# 3) Run this script via "jruby oracle_enhanced_1678.rb"
# CONFIGURATION
DB_CONFIG = {
adapter: :oracle_enhanced,
host: 'CHANGE_THIS',
port: 1521,
database: 'CHANGE_THIS',
username: 'CHANGE_THIS',
password: 'CHANGE_THIS'
}.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'
# Activate the gem you are reporting the issue against.
gem 'activerecord', '5.2.0.rc2'
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0.rc1'
gem 'pry'
end
require 'active_record'
require 'minitest/autorun'
require 'active_record/connection_adapters/oracle_enhanced_adapter'
require "logger"
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
# See https://github.com/rsim/oracle-enhanced/issues/920 and
# https://github.com/rsim/oracle-enhanced/issues/1066
self.use_old_oracle_visitor = true
end
end
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(DB_CONFIG)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name
t.integer :group_id
end
create_table :groups, force: true do |t|
t.string :name
end
end
class User < ActiveRecord::Base
belongs_to :group
end
class Group < ActiveRecord::Base
has_one :user
end
class BugTest < Minitest::Test
# Enforce alphabetical test order as 4 needs to run after 3.
def self.test_order
:alpha
end
# Tries to reproduce #1070. Works as expected.
def test_1_limit_offset
User.limit(5).offset(1).to_a
end
# Tries to reproduce #920. Works as expected.
def test_2_lock_first
User.create!(name: 'Test')
User.first.lock!
end
# Reproduces #1678. Fails with:
# ActiveRecord::StatementInvalid: Java::JavaSql::SQLException:
# Missing IN or OUT parameter at index:: 1:
# select us.sequence_name from all_sequences us where
# us.sequence_owner = :owner and us.sequence_name = :sequence_name
def test_3_join_error
User.joins(:group).to_sql
end
# Tries to reproduce #1678 as well but since we're calling `Group.first`
# first, it works as expected.
def test_4_join_success
# Force adapter to load structural information for groups table
Group.first
# Now the same statement that failed works as expected
User.joins(:group).to_sql
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment