Skip to content

Fix some arjdbc mysql tests to support AR 7.1 #1152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading