Skip to content

Commit 67dfa6e

Browse files
committed
Add support for Trilogy database adapter
1 parent 489bf8f commit 67dfa6e

File tree

7 files changed

+24
-9
lines changed

7 files changed

+24
-9
lines changed

CHANGELOG.md

+2
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/1501
6+
57
## 4.1.0 - 2023-10-23
68

79
### 🚀 Features

CONTRIBUTING.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,18 @@ Here's a quick guide:
7373
bundle exec rake spec
7474
```
7575

76-
The test suite runs by default with SQLite3. To run the test suite with PostgreSQL or MySQL, use:
76+
The test suite runs by default with SQLite3. To run the test suite with PostgreSQL, MySQL (Mysql2 adapter), or MySQL (Trilogy adapter), use:
7777

7878
```sh
7979
DB=pg bundle exec rake spec
8080
DB=mysql bundle exec rake spec
81+
DB=trilogy bundle exec rake spec
8182
```
82-
83+
8384
A one-liner to run all three
8485

8586
```sh
86-
bundle exec rake spec && DB=pg bundle exec rake spec && DB=mysql bundle exec rake spec
87+
bundle exec rake spec && DB=pg bundle exec rake spec && DB=mysql bundle exec rake spec && DB=trilogy bundle exec rake spec
8788
```
8889

8990
For Postgres and MySQL, databases are expected to exist, called 'ransack'. To create use these commands (assuming OS X and Homebrew):

Gemfile

+1
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

+1-1
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

+1-1
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

+4-4
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

+11
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)