Skip to content

Commit d9d10fd

Browse files
committed
fix: make Trilogy optional for TruffleRuby and remove Rails 8.1
- Remove Rails 8.1 from CI matrix (not stable yet) - Skip Trilogy tests on TruffleRuby (trilogy gem not supported) - Make DATABASE_URL_TRILOGY conditional in CI - Add Zeitwerk configuration to ignore trilogy models when not needed - Wrap all Trilogy test classes in GemTestCase.trilogy_available? check - Update database.yml with conditional trilogy config
1 parent 9868528 commit d9d10fd

File tree

18 files changed

+226
-162
lines changed

18 files changed

+226
-162
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ jobs:
6262
rails:
6363
- 7.2
6464
- "8.0"
65-
- "8.1"
6665
env:
6766
ACTIVERECORD_VERSION: ${{ matrix.rails }}
6867
RAILS_ENV: test
@@ -83,7 +82,8 @@ jobs:
8382
env:
8483
DATABASE_URL_PG: postgres://with_advisory:with_advisory_pass@localhost:${{ job.services.postgres.ports[5432] }}/with_advisory_lock_test
8584
DATABASE_URL_MYSQL: mysql2://with_advisory:with_advisory_pass@127.0.0.1:${{ job.services.mysql.ports[3306] }}/with_advisory_lock_test
86-
DATABASE_URL_TRILOGY: trilogy://with_advisory:with_advisory_pass@127.0.0.1:${{ job.services.mariadb.ports[3306] }}/with_advisory_lock_trilogy_test
85+
# Trilogy doesn't support TruffleRuby
86+
DATABASE_URL_TRILOGY: ${{ matrix.ruby != 'truffleruby' && format('trilogy://with_advisory:with_advisory_pass@127.0.0.1:{0}/with_advisory_lock_trilogy_test', job.services.mariadb.ports[3306]) || '' }}
8787
run: |
8888
cd test/dummy
8989
bundle exec rake db:test:prepare
@@ -92,6 +92,7 @@ jobs:
9292
env:
9393
DATABASE_URL_PG: postgres://with_advisory:with_advisory_pass@localhost:${{ job.services.postgres.ports[5432] }}/with_advisory_lock_test
9494
DATABASE_URL_MYSQL: mysql2://with_advisory:with_advisory_pass@127.0.0.1:${{ job.services.mysql.ports[3306] }}/with_advisory_lock_test
95-
DATABASE_URL_TRILOGY: trilogy://with_advisory:with_advisory_pass@127.0.0.1:${{ job.services.mariadb.ports[3306] }}/with_advisory_lock_trilogy_test
95+
# Trilogy doesn't support TruffleRuby
96+
DATABASE_URL_TRILOGY: ${{ matrix.ruby != 'truffleruby' && format('trilogy://with_advisory:with_advisory_pass@127.0.0.1:{0}/with_advisory_lock_trilogy_test', job.services.mariadb.ports[3306]) || '' }}
9697
WITH_ADVISORY_LOCK_PREFIX: ${{ github.run_id }}
9798
run: bin/rails test

test/dummy/app/models/trilogy_label.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
class TrilogyLabel < TrilogyRecord
44
self.table_name = 'trilogy_labels'
5-
end
5+
end

test/dummy/app/models/trilogy_record.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
class TrilogyRecord < ActiveRecord::Base
44
self.abstract_class = true
55
establish_connection :trilogy
6-
end
6+
end

test/dummy/app/models/trilogy_tag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ class TrilogyTag < TrilogyRecord
77
TrilogyTagAudit.create(tag_name: name)
88
TrilogyLabel.create(name: name)
99
end
10-
end
10+
end

test/dummy/app/models/trilogy_tag_audit.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
class TrilogyTagAudit < TrilogyRecord
44
self.table_name = 'trilogy_tag_audits'
5-
end
5+
end

test/dummy/config/application.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ module TestSystemApp
1414
class Application < Rails::Application
1515
config.load_defaults [Rails::VERSION::MAJOR, Rails::VERSION::MINOR].join('.')
1616
config.eager_load = true
17+
18+
# Ignore trilogy models when DATABASE_URL_TRILOGY is not set (e.g., TruffleRuby)
19+
unless ENV['DATABASE_URL_TRILOGY'] && !ENV['DATABASE_URL_TRILOGY'].empty?
20+
config.autoload_lib(ignore: %w[])
21+
initializer 'ignore_trilogy_models', before: :set_autoload_paths do |app|
22+
trilogy_models = %w[trilogy_record trilogy_tag trilogy_tag_audit trilogy_label]
23+
trilogy_models.each do |model|
24+
Rails.autoloaders.main.ignore(Rails.root.join('app', 'models', "#{model}.rb"))
25+
end
26+
end
27+
end
1728
config.serve_static_files = false
1829
config.public_file_server.enabled = false
1930
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }

test/dummy/config/database.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ test:
1111
url: "<%= ENV['DATABASE_URL_MYSQL'] %>"
1212
properties:
1313
allowPublicKeyRetrieval: true
14+
<% if ENV['DATABASE_URL_TRILOGY'] && !ENV['DATABASE_URL_TRILOGY'].empty? %>
1415
trilogy:
1516
<<: *default
1617
url: "<%= ENV['DATABASE_URL_TRILOGY'] %>"
1718
adapter: trilogy
1819
properties:
1920
allowPublicKeyRetrieval: true
21+
<% end %>

test/dummy/lib/tasks/db.rake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ namespace :db do
1414
load Rails.root.join('db', 'secondary_schema.rb')
1515
puts 'MySQL database schema loaded'
1616

17-
# Setup Trilogy database (MariaDB)
18-
ActiveRecord::Base.establish_connection(:trilogy)
19-
load Rails.root.join('db', 'trilogy_schema.rb')
20-
puts 'Trilogy database schema loaded'
17+
# Setup Trilogy database (MariaDB) - optional, not supported on TruffleRuby
18+
if ENV['DATABASE_URL_TRILOGY'] && !ENV['DATABASE_URL_TRILOGY'].empty?
19+
ActiveRecord::Base.establish_connection(:trilogy)
20+
load Rails.root.join('db', 'trilogy_schema.rb')
21+
puts 'Trilogy database schema loaded'
22+
else
23+
puts 'Skipping Trilogy database (DATABASE_URL_TRILOGY not set)'
24+
end
2125

2226
puts 'All test databases prepared successfully'
2327
rescue StandardError => e

test/sanity_check_test.rb

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'test_helper'
44

55
class SanityCheckTest < GemTestCase
6-
test 'PostgreSQL, MySQL, and Trilogy databases are properly isolated' do
6+
test 'PostgreSQL and MySQL databases are properly isolated' do
77
# Create a tag in PostgreSQL database
88
pg_tag = Tag.create!(name: 'postgresql-only-tag')
99

@@ -26,31 +26,9 @@ class SanityCheckTest < GemTestCase
2626
assert_not Tag.exists?(name: 'mysql-only-tag')
2727
assert_equal 0, Tag.where(name: 'mysql-only-tag').count
2828

29-
# Create a tag in Trilogy database
30-
trilogy_tag = TrilogyTag.create!(name: 'trilogy-only-tag')
31-
32-
# Verify it exists in Trilogy
33-
assert TrilogyTag.exists?(name: 'trilogy-only-tag')
34-
assert_equal 1, TrilogyTag.where(name: 'trilogy-only-tag').count
35-
36-
# Verify it does NOT exist in PostgreSQL or MySQL databases
37-
assert_not Tag.exists?(name: 'trilogy-only-tag')
38-
assert_equal 0, Tag.where(name: 'trilogy-only-tag').count
39-
assert_not MysqlTag.exists?(name: 'trilogy-only-tag')
40-
assert_equal 0, MysqlTag.where(name: 'trilogy-only-tag').count
41-
42-
# Verify PostgreSQL tag does NOT exist in Trilogy
43-
assert_not TrilogyTag.exists?(name: 'postgresql-only-tag')
44-
assert_equal 0, TrilogyTag.where(name: 'postgresql-only-tag').count
45-
46-
# Verify MySQL tag does NOT exist in Trilogy
47-
assert_not TrilogyTag.exists?(name: 'mysql-only-tag')
48-
assert_equal 0, TrilogyTag.where(name: 'mysql-only-tag').count
49-
5029
# Clean up
5130
pg_tag.destroy
5231
mysql_tag.destroy
53-
trilogy_tag.destroy
5432
end
5533

5634
test 'PostgreSQL models use PostgreSQL adapter' do
@@ -65,31 +43,68 @@ class SanityCheckTest < GemTestCase
6543
assert_equal 'Mysql2', MysqlLabel.connection.adapter_name
6644
end
6745

68-
test 'Trilogy models use Trilogy adapter' do
69-
assert_equal 'Trilogy', TrilogyTag.connection.adapter_name
70-
assert_equal 'Trilogy', TrilogyTagAudit.connection.adapter_name
71-
assert_equal 'Trilogy', TrilogyLabel.connection.adapter_name
72-
end
73-
74-
test 'can write to all three databases in same test' do
75-
# Create records in all three databases
46+
test 'can write to PostgreSQL and MySQL databases in same test' do
47+
# Create records in both databases
7648
pg_tag = Tag.create!(name: 'test-pg')
7749
mysql_tag = MysqlTag.create!(name: 'test-mysql')
78-
trilogy_tag = TrilogyTag.create!(name: 'test-trilogy')
7950

80-
# All should have IDs
51+
# Both should have IDs
8152
assert pg_tag.persisted?
8253
assert mysql_tag.persisted?
83-
assert trilogy_tag.persisted?
8454

85-
# IDs should be independent (all could be 1 if tables are empty)
55+
# IDs should be independent (both could be 1 if tables are empty)
8656
assert_kind_of Integer, pg_tag.id
8757
assert_kind_of Integer, mysql_tag.id
88-
assert_kind_of Integer, trilogy_tag.id
8958

9059
# Clean up
9160
pg_tag.destroy
9261
mysql_tag.destroy
93-
trilogy_tag.destroy
62+
end
63+
end
64+
65+
if GemTestCase.trilogy_available?
66+
class TrilogySanityCheckTest < GemTestCase
67+
test 'Trilogy database is isolated from PostgreSQL and MySQL' do
68+
# Create tags in all databases
69+
pg_tag = Tag.create!(name: 'pg-isolation-test')
70+
mysql_tag = MysqlTag.create!(name: 'mysql-isolation-test')
71+
trilogy_tag = TrilogyTag.create!(name: 'trilogy-isolation-test')
72+
73+
# Verify Trilogy tag exists only in Trilogy
74+
assert TrilogyTag.exists?(name: 'trilogy-isolation-test')
75+
assert_not Tag.exists?(name: 'trilogy-isolation-test')
76+
assert_not MysqlTag.exists?(name: 'trilogy-isolation-test')
77+
78+
# Verify PostgreSQL tag doesn't exist in Trilogy
79+
assert_not TrilogyTag.exists?(name: 'pg-isolation-test')
80+
81+
# Verify MySQL tag doesn't exist in Trilogy
82+
assert_not TrilogyTag.exists?(name: 'mysql-isolation-test')
83+
84+
# Clean up
85+
pg_tag.destroy
86+
mysql_tag.destroy
87+
trilogy_tag.destroy
88+
end
89+
90+
test 'Trilogy models use Trilogy adapter' do
91+
assert_equal 'Trilogy', TrilogyTag.connection.adapter_name
92+
assert_equal 'Trilogy', TrilogyTagAudit.connection.adapter_name
93+
assert_equal 'Trilogy', TrilogyLabel.connection.adapter_name
94+
end
95+
96+
test 'can write to all three databases in same test' do
97+
pg_tag = Tag.create!(name: 'test-pg')
98+
mysql_tag = MysqlTag.create!(name: 'test-mysql')
99+
trilogy_tag = TrilogyTag.create!(name: 'test-trilogy')
100+
101+
assert pg_tag.persisted?
102+
assert mysql_tag.persisted?
103+
assert trilogy_tag.persisted?
104+
105+
pg_tag.destroy
106+
mysql_tag.destroy
107+
trilogy_tag.destroy
108+
end
94109
end
95110
end

test/test_helper.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@ class GemTestCase < ActiveSupport::TestCase
1919
parallelize(workers: 1)
2020

2121
def self.startup
22-
# Validate environment variables when tests actually start running
23-
%w[DATABASE_URL_PG DATABASE_URL_MYSQL DATABASE_URL_TRILOGY].each do |var|
22+
# Validate required environment variables
23+
%w[DATABASE_URL_PG DATABASE_URL_MYSQL].each do |var|
2424
abort "Missing required environment variable: #{var}" if ENV[var].nil? || ENV[var].empty?
2525
end
26+
27+
# Trilogy is optional (not supported on TruffleRuby)
28+
if ENV['DATABASE_URL_TRILOGY'].nil? || ENV['DATABASE_URL_TRILOGY'].empty?
29+
puts 'DATABASE_URL_TRILOGY not set, skipping Trilogy tests'
30+
end
31+
end
32+
33+
def self.trilogy_available?
34+
ENV['DATABASE_URL_TRILOGY'] && !ENV['DATABASE_URL_TRILOGY'].empty?
2635
end
2736

2837
# Override in test classes to clean only the tables you need

0 commit comments

Comments
 (0)