Skip to content

Commit 45a1cb9

Browse files
committed
Add support for Trilogy database adapter
1 parent 489bf8f commit 45a1cb9

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
* Add support for Trilogy database adapter by @navels in https://github.com/activerecord-hackery/ransack/pull/1500
6+
57
## 4.1.0 - 2023-10-23
68

79
### 🚀 Features

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ else
4343
end
4444
end
4545
gem 'mysql2'
46+
gem 'trilogy'
4647

4748
group :test do
4849
gem 'machinist', '~> 1.0.6'

lib/ransack/constants.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ module Constants
162162
# replace % \ to \% \\
163163
def escape_wildcards(unescaped)
164164
case ActiveRecord::Base.connection.adapter_name
165-
when "Mysql2".freeze
165+
when "Mysql2".freeze, "Trilogy".freeze
166166
# Necessary for MySQL
167167
unescaped.to_s.gsub(/([\\%_])/, '\\\\\\1')
168168
when "PostgreSQL".freeze

spec/ransack/adapters/active_record/base_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def without_application_record_method(method)
794794
end
795795

796796
def rails7_and_mysql
797-
::ActiveRecord::VERSION::MAJOR >= 7 && ENV['DB'] == 'mysql'
797+
::ActiveRecord::VERSION::MAJOR >= 7 && ['mysql', 'trilogy'].include?(ENV['DB'])
798798
end
799799
end
800800
end

spec/ransack/predicate_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module Ransack
160160
it_has_behavior 'wildcard escaping', :name_cont,
161161
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
162162
/"people"."name" ILIKE '%\\%\\.\\_\\\\%'/
163-
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
163+
elsif ["Mysql2", "Trilogy"].include?(ActiveRecord::Base.connection.adapter_name)
164164
/`people`.`name` LIKE '%\\\\%.\\\\_\\\\\\\\%'/
165165
else
166166
/"people"."name" LIKE '%%._\\%'/
@@ -179,7 +179,7 @@ module Ransack
179179
it_has_behavior 'wildcard escaping', :name_not_cont,
180180
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
181181
/"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/
182-
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
182+
elsif ["Mysql2", "Trilogy"].include?(ActiveRecord::Base.connection.adapter_name)
183183
/`people`.`name` NOT LIKE '%\\\\%.\\\\_\\\\\\\\%'/
184184
else
185185
/"people"."name" NOT LIKE '%%._\\%'/
@@ -198,7 +198,7 @@ module Ransack
198198
it_has_behavior 'wildcard escaping', :name_i_cont,
199199
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
200200
/"people"."name" ILIKE '%\\%\\.\\_\\\\%'/
201-
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
201+
elsif ["Mysql2", "Trilogy"].include?(ActiveRecord::Base.connection.adapter_name)
202202
/LOWER\(`people`.`name`\) LIKE '%\\\\%.\\\\_\\\\\\\\%'/
203203
else
204204
/LOWER\("people"."name"\) LIKE '%%._\\%'/
@@ -217,7 +217,7 @@ module Ransack
217217
it_has_behavior 'wildcard escaping', :name_not_i_cont,
218218
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
219219
/"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/
220-
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
220+
elsif ["Mysql2", "Trilogy"].include?(ActiveRecord::Base.connection.adapter_name)
221221
/LOWER\(`people`.`name`\) NOT LIKE '%\\\\%.\\\\_\\\\\\\\%'/
222222
else
223223
/LOWER\("people"."name"\) NOT LIKE '%%._\\%'/

spec/support/schema.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
database: 'ransack',
99
username: ENV.fetch("MYSQL_USERNAME") { "root" },
1010
password: ENV.fetch("MYSQL_PASSWORD") { "" },
11+
host: ENV.fetch("MYSQL_HOST") { "localhost" },
12+
encoding: 'utf8'
13+
)
14+
when 'trilogy'
15+
# To test with trilogy: `DB=trilogy bundle exec rake spec`
16+
ActiveRecord::Base.establish_connection(
17+
adapter: 'trilogy',
18+
database: 'ransack',
19+
username: ENV.fetch("MYSQL_USERNAME") { "root" },
20+
password: ENV.fetch("MYSQL_PASSWORD") { "" },
21+
host: ENV.fetch("MYSQL_HOST") { "localhost" },
1122
encoding: 'utf8'
1223
)
1324
when 'pg', 'postgres', 'postgresql'

0 commit comments

Comments
 (0)