Skip to content

Commit

Permalink
Merge pull request #60 from k2nr/test-with-trilogy-adapter
Browse files Browse the repository at this point in the history
Test with the Trilogy database adapter
  • Loading branch information
bquorning authored Sep 29, 2023
2 parents 72e7e3c + 945773e commit 99f5006
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Ensure compatibility with the Trilogy database adapter.

## 2.0.0.pre.2

- Drop support for Rails 5.0 and Rails 5.1.
Expand Down
2 changes: 2 additions & 0 deletions bin/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ test_with_db "sqlite3"
test_with_db "mysql56"

test_with_db "mysql57"
test_with_db "mysql57-trilogy"

test_with_db "mysql80"
test_with_db "mysql80-trilogy"

test_with_db "pg12"
1 change: 1 addition & 0 deletions gemfiles/6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gem "activerecord", "~> 6.0.0"
gem "sqlite3", "~> 1.4"
gem "mysql2", ">= 0.4.4"
gem "pg", ">= 0.18", "< 2.0"
gem "activerecord-trilogy-adapter"
1 change: 1 addition & 0 deletions gemfiles/6.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gem "activerecord", "~> 6.1.0"
gem "sqlite3", "~> 1.4"
gem "mysql2", "~> 0.5"
gem "pg", "~> 1.1"
gem "activerecord-trilogy-adapter"
1 change: 1 addition & 0 deletions gemfiles/7.0.5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gem "activerecord", "~> 7.0.5"
gem "sqlite3", "~> 1.4"
gem "mysql2", "~> 0.5"
gem "pg", "~> 1.1"
gem "activerecord-trilogy-adapter"
1 change: 1 addition & 0 deletions gemfiles/7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ gem "activerecord", "~> 7.0.0", "< 7.0.5"
gem "sqlite3", "~> 1.4"
gem "mysql2", "~> 0.5"
gem "pg", "~> 1.1"
gem "activerecord-trilogy-adapter"
24 changes: 24 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,27 @@
password: "password",
database: "test"
},
"mysql57-trilogy" => {
host: "mysql57",
adapter: "trilogy",
username: "root",
password: "password",
database: "test"
},
"mysql80" => {
host: "mysql80",
adapter: "mysql2",
username: "root",
password: "password",
database: "test"
},
"mysql80-trilogy" => {
host: "mysql80",
adapter: "trilogy",
username: "root",
password: "password",
database: "test"
},
"pg12" => {
host: "pg12",
adapter: "postgresql",
Expand All @@ -46,6 +60,16 @@
db_sets.fetch("sqlite3")
end

if db[:adapter] == "trilogy"
if ActiveRecord.gem_version < Gem::Version.new("6.0")
warn "Skipping tests for ActiveRecord v#{ActiveRecord.gem_version} using the #{db[:adapter]} database adapter."
exit
else
require "trilogy_adapter/connection"
ActiveRecord::Base.extend(TrilogyAdapter::Connection)
end
end

unless db[:adapter] == "sqlite3"
ActiveRecord::Base.establish_connection(db.except(:database))
begin
Expand Down
8 changes: 7 additions & 1 deletion test/ulid/rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def setup

def type
case database_adapter
when "mysql2"
when "mysql2", "trilogy"
ULID::Rails::Type.new
when "sqlite3"
ULID::Rails::SqliteType.new
Expand All @@ -21,6 +21,7 @@ def type
def test_serialize_to_s
expected_string = {
"mysql2" => "01ARZ3NDEKTSV4RRFFQ69G5FAV",
"trilogy" => "01ARZ3NDEKTSV4RRFFQ69G5FAV",
"sqlite3" => "01563e3ab5d3d6764c61efb99302bd5b",
"postgresql" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b
}.fetch(database_adapter)
Expand All @@ -31,6 +32,7 @@ def test_serialize_to_s
def test_serialize_hex
expected_hex = {
"mysql2" => "01563e3ab5d3d6764c61efb99302bd5b",
"trilogy" => "01563e3ab5d3d6764c61efb99302bd5b",
"sqlite3" => "01563e3ab5d3d6764c61efb99302bd5b",
"postgresql" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b
}.fetch(database_adapter)
Expand All @@ -41,6 +43,7 @@ def test_serialize_hex
def test_deserialize
serialized_value = {
"mysql2" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b,
"trilogy" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b,
"sqlite3" => "01563e3ab5d3d6764c61efb99302bd5b".b,
"postgresql" => "\\x01563e3ab5d3d6764c61efb99302bd5b".b
}.fetch(database_adapter)
Expand All @@ -60,6 +63,7 @@ def test_stores_the_ulid_as_binary_value_in_the_database
raw_id = user.read_attribute_before_type_cast(:id).hex
expected_raw_id = {
"mysql2" => "01563e3ab5d3d6764c61efb99302bd5b",
"trilogy" => "01563e3ab5d3d6764c61efb99302bd5b",
"sqlite3" => "01563e3ab5d3d6764c61efb99302bd5b",
"postgresql" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b
}.fetch(database_adapter)
Expand All @@ -69,6 +73,7 @@ def test_stores_the_ulid_as_binary_value_in_the_database
binary_stored_id = User.last.read_attribute_before_type_cast(:id)
expected_binary_stored_id = {
"mysql2" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b,
"trilogy" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b,
"sqlite3" => "01563e3ab5d3d6764c61efb99302bd5b".b,
"postgresql" => "\\x01563e3ab5d3d6764c61efb99302bd5b".b
}.fetch(database_adapter)
Expand Down Expand Up @@ -208,6 +213,7 @@ def test_type_casting
raw_id = user.read_attribute_before_type_cast(:id)
expected_raw_id = {
"mysql2" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b,
"trilogy" => "\x01V>:\xB5\xD3\xD6vLa\xEF\xB9\x93\x02\xBD[".b,
"sqlite3" => "01563e3ab5d3d6764c61efb99302bd5b".b,
"postgresql" => "\\x01563e3ab5d3d6764c61efb99302bd5b".b
}.fetch(database_adapter)
Expand Down

0 comments on commit 99f5006

Please sign in to comment.