Skip to content

Commit

Permalink
Merge pull request #1152 from JesseChavez/rails_71_support_mysql
Browse files Browse the repository at this point in the history
Fix some arjdbc mysql tests to support AR 7.1
  • Loading branch information
enebo authored Jul 26, 2024
2 parents d8ec034 + d3872dd commit 8029660
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/arjdbc/mysql/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def initialize(...)
@connection_parameters ||= @config
end

# NOTE: redefines constant defined in abstract class however this time
# will use methods defined in the mysql abstract class and map properly
# mysql types.
TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }

def self.database_exists?(config)
conn = ActiveRecord::Base.mysql2_connection(config)
conn && conn.really_valid?
Expand Down Expand Up @@ -239,6 +244,8 @@ def translate_exception(exception, message:, sql:, binds:)
case message
when /Table .* doesn't exist/i
StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
when /BLOB, TEXT, GEOMETRY or JSON column .* can't have a default value/i
StatementInvalid.new(message, sql: sql, binds: binds, connection_pool: @pool)
else
super
end
Expand Down
1 change: 1 addition & 0 deletions test/db/mysql/change_column_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MySQLChangeColumnTest < Test::Unit::TestCase
ActiveRecord::Migration.add_column :people, :about, :string, :default => 'x'
# NOTE: even in non strict mode MySQL does not allow us add or change
# text/binary with a default ...
# Message: BLOB, TEXT, GEOMETRY or JSON column '%s' can't have a default value
if mariadb_server? && db_version >= '10.2'
ActiveRecord::Migration.change_column :people, :about, :text
else
Expand Down
3 changes: 2 additions & 1 deletion test/db/mysql/schema_dump_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def test_schema_dump_should_not_have_limits_on_date

def test_should_include_limit
text_column = connection.columns('memos').find { |c| c.name == 'text' }
assert_equal 4294967295, text_column.limit

assert_equal 4_294_967_295, text_column.limit
end

def test_should_set_sqltype_to_longtext
Expand Down
4 changes: 2 additions & 2 deletions test/db/mysql/simple_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ def test_execute_after_disconnect

# active record change of behaviour 7.1, reconnects on query execution.
result = assert_nothing_raised do
connection.execute('SELECT 1 + 2')
connection.execute('SELECT 1 + 2 as total')
end

assert_equal 3, result.rows.flatten.first
assert_equal 3, result.first['total']
ensure
connection.reconnect!
end
Expand Down

0 comments on commit 8029660

Please sign in to comment.