From 0dfe2e4d1301cc353f972b28ab19554a53cad482 Mon Sep 17 00:00:00 2001 From: "M.Shibuya" Date: Sun, 6 Feb 2022 19:13:02 +0900 Subject: [PATCH] Fix failing to detect encoding with JDBC MySQL adapter Also switching JRuby CI to use MySQL instead of SQLite, because of frequent '[SQLITE_BUSY]' error --- .github/workflows/test.yml | 2 +- lib/rails_admin/adapters/active_record.rb | 6 +++++- spec/rails_admin/abstract_model_spec.rb | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98f4675cf8..8eb594659d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,7 +52,7 @@ jobs: - ruby: jruby gemfile: gemfiles/rails_6.1.gemfile orm: active_record - adapter: sqlite3 + adapter: mysql2 asset: sprockets - ruby: jruby gemfile: gemfiles/rails_6.1.gemfile diff --git a/lib/rails_admin/adapters/active_record.rb b/lib/rails_admin/adapters/active_record.rb index a707ee8d44..14c069d7f5 100644 --- a/lib/rails_admin/adapters/active_record.rb +++ b/lib/rails_admin/adapters/active_record.rb @@ -80,7 +80,11 @@ def encoding when 'postgresql' ::ActiveRecord::Base.connection.select_one("SELECT ''::text AS str;").values.first.encoding when 'mysql2' - ::ActiveRecord::Base.connection.raw_connection.encoding + if RUBY_ENGINE == 'jruby' + ::ActiveRecord::Base.connection.select_one("SELECT '' AS str;").values.first.encoding + else + ::ActiveRecord::Base.connection.raw_connection.encoding + end when 'oracle_enhanced' ::ActiveRecord::Base.connection.select_one('SELECT dummy FROM DUAL').values.first.encoding else diff --git a/spec/rails_admin/abstract_model_spec.rb b/spec/rails_admin/abstract_model_spec.rb index f1090a802e..d649f9c95b 100644 --- a/spec/rails_admin/abstract_model_spec.rb +++ b/spec/rails_admin/abstract_model_spec.rb @@ -112,7 +112,6 @@ end it 'lists elements within outbound limits' do - pending('Due to the JRuby SQLite3 datetime boundary issue') if RUBY_ENGINE == 'jruby' && CI_ORM == :active_record expect(@abstract_model.all(filters: {'datetime_field' => {'1' => {v: ['', '2012-01-02T00:00:00', '2012-01-03T23:59:59'], o: 'between'}}}).count).to eq(2) expect(@abstract_model.all(filters: {'datetime_field' => {'1' => {v: ['', '2012-01-02T00:00:00', '2012-01-03T12:00:00'], o: 'between'}}}).count).to eq(1) expect(@abstract_model.all(filters: {'datetime_field' => {'1' => {v: ['', '2012-01-03T12:00:00', ''], o: 'between'}}}).count).to eq(2)