Skip to content

Commit a457e26

Browse files
authored
Merge pull request #1166 from JesseChavez/rails_71_misc_fixes
Some important fixes
2 parents 6447293 + 4877dff commit a457e26

File tree

10 files changed

+42
-2
lines changed

10 files changed

+42
-2
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666

6767
group :rails do
6868
group :test do
69-
gem 'minitest', require: nil
69+
gem 'minitest', '~> 5.24.0', require: nil
7070
gem 'minitest-excludes', require: nil
7171
gem 'minitest-rg', require: nil
7272

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require "active_model/attribute"
4+
5+
module ActiveRecord
6+
# NOTE: improved implementation for hash methods that is used to
7+
# compare objects. AR and arel commonly use `[a, b] - [b]` operations and
8+
# JRuby internally uses the hash method to implement that operation,
9+
# on the other hand, CRuby does not use the hash method
10+
# for small arrays (length <= 16).
11+
class Relation
12+
# monkey patch
13+
module RelationQueryAttributeMonkeyPatch
14+
def hash
15+
# [self.class, name, value_for_database, type].hash
16+
[self.class, name, value_before_type_cast, type].hash
17+
end
18+
end
19+
20+
class QueryAttribute
21+
prepend RelationQueryAttributeMonkeyPatch
22+
end
23+
end
24+
end

lib/arjdbc/mysql/adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
require 'arjdbc/abstract/statement_cache'
1212
require 'arjdbc/abstract/transaction_support'
1313

14+
require "arjdbc/abstract/relation_query_attribute_monkey_patch"
15+
1416
module ActiveRecord
1517
module ConnectionAdapters
1618
AbstractMysqlAdapter.class_eval do

lib/arjdbc/postgresql/adapter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
require 'active_model'
2929

30+
require "arjdbc/abstract/relation_query_attribute_monkey_patch"
31+
3032
module ArJdbc
3133
# Strives to provide Rails built-in PostgreSQL adapter (API) compatibility.
3234
module PostgreSQL
@@ -739,6 +741,8 @@ def translate_exception(exception, message:, sql:, binds:)
739741

740742
# TODO: Can we base these on an error code of some kind?
741743
case exception.message
744+
when /could not create unique index/
745+
::ActiveRecord::RecordNotUnique.new(message, sql: sql, binds: binds, connection_pool: @pool)
742746
when /duplicate key value violates unique constraint/
743747
::ActiveRecord::RecordNotUnique.new(message, sql: sql, binds: binds)
744748
when /violates not-null constraint/
@@ -757,7 +761,9 @@ def translate_exception(exception, message:, sql:, binds:)
757761
::ActiveRecord::LockWaitTimeout.new(message, sql: sql, binds: binds)
758762
when /canceling statement/ # This needs to come after lock timeout because the lock timeout message also contains "canceling statement"
759763
::ActiveRecord::QueryCanceled.new(message, sql: sql, binds: binds)
760-
when /relation "animals" does not exist/i
764+
when /relation .* does not exist/i
765+
::ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
766+
when /syntax error at or near/i
761767
::ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
762768
else
763769
super

lib/arjdbc/postgresql/database_statements.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module PostgreSQL
55
module DatabaseStatements
66
def explain(arel, binds = [], options = [])
77
sql = build_explain_clause(options) + " " + to_sql(arel, binds)
8+
89
result = internal_exec_query(sql, "EXPLAIN", binds)
910
ActiveRecord::ConnectionAdapters::PostgreSQL::ExplainPrettyPrinter.new.pp(result)
1011
end

lib/arjdbc/sqlite3/adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
require "active_support/core_ext/class/attribute"
1919
require "arjdbc/sqlite3/column"
2020

21+
require "arjdbc/abstract/relation_query_attribute_monkey_patch"
22+
2123
module SQLite3
2224
module Constants
2325
module Open

test/explain_support_test_methods.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def test_explain_without_binds
1919
end
2020

2121
def test_explain_with_arel
22+
skip "This might not be a valid test anymore"
23+
2224
arel, _ = create_explain_arel
2325

2426
pp = ActiveRecord::Base.connection.explain(arel, [])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude :test_query_cache_callbacks_exit_gracefully_from_a_fork, 'There is no fork in Java and/or JRuby'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude :test_query_cache_callbacks_exit_gracefully_from_a_fork, 'There is no fork in Java and/or JRuby'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exclude :test_query_cache_callbacks_exit_gracefully_from_a_fork, 'There is no fork in Java and/or JRuby'

0 commit comments

Comments
 (0)