Skip to content

Commit

Permalink
Merge pull request #55 from k2nr/fix-for-activerecord-7.0.5
Browse files Browse the repository at this point in the history
Make ulid-rails work with ActiveRecord v7.0.5
  • Loading branch information
bquorning authored May 25, 2023
2 parents f7f53f9 + 4f70db0 commit 4e92e0c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RUBY_VERSION=2.6
RUBY_VERSION=2.7
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
push:
branches:
- master
workflow_dispatch:

jobs:
standardrb:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ on:
push:
branches:
- master
workflow_dispatch:

jobs:
tests:
name: ActiveRecord ${{ matrix.activerecord-version }} / Ruby ${{ matrix.ruby-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
activerecord-version: ["5.0", "5.1", "5.2", "6.0", "6.1", "7.0"]
activerecord-version: ["5.0", "5.1", "5.2", "6.0", "6.1", "7.0", "7.0.5"]
ruby-version: ["2.7", "3.0", "3.1", "3.2"]
exclude:
- {activerecord-version: "5.0", ruby-version: "3.0"}
Expand All @@ -28,5 +30,7 @@ jobs:
- {activerecord-version: "6.0", ruby-version: "3.1"}
steps:
- uses: actions/checkout@v3
- name: Test ActiveRecord ${{ matrix.activerecord-version }} and Ruby ${{ matrix.ruby-version }}
run: RUBY_VERSION=${{ matrix.ruby-version }} docker-compose run -e AR_VERSION=${{ matrix.activerecord-version }} test
- run: docker-compose run test
env:
RUBY_VERSION: ${{ matrix.ruby-version }}
AR_VERSION: ${{ matrix.activerecord-version }}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## Unreleased

## 1.1.1

- Drop support for ruby 2.6.
- Fix compatibility with ActiveRecord 7.0.5+.

## 1.1.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ You need to specicfy `type` option

Please note that this library doesn't work properly with `has_and_belongs_to_many` associations.

Our recommendation is to be explicit and instead use the `has_many, through: join_class` association.
Our recommendation is to be explicit and instead use the `has_many, through: join_class` association.
Notice that for it to work properly you must specify the `has_many` to the join class in the main classes of the association,
and your join class must have `belongs_to` main classes defined as shown in the example below:

Expand Down
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: '3.6'
services:
test:
image: "ruby:${RUBY_VERSION}"
image: "ruby:${RUBY_VERSION}"
command: sh -c "rm -f Gemfile.lock && bundle install && bin/run_tests"
environment:
- AR_VERSION=${AR_VERSION}
depends_on:
pg12:
condition: service_healthy
Expand All @@ -23,20 +25,20 @@ services:
MYSQL_ROOT_PASSWORD: password
command: --innodb-large-prefix --innodb-file-format=barracuda
healthcheck:
test: mysql --password=password -e "show databases;"
test: mysql --password=password -e "show databases;"
mysql57:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
healthcheck:
test: mysql --password=password -e "show databases;"
test: mysql --password=password -e "show databases;"
mysql80:
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: password
healthcheck:
test: mysql --password=password -e "show databases;"
test: mysql --password=password -e "show databases;"
pg12:
image: postgres:12
environment:
Expand Down
10 changes: 10 additions & 0 deletions gemfiles/7.0.5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source "https://rubygems.org"

gemspec path: ".."

gem "activesupport", "~> 7.0.5"
gem "activemodel", "~> 7.0.5"
gem "activerecord", "~> 7.0.5"
gem "sqlite3", "~> 1.4"
gem "mysql2", "~> 0.5"
gem "pg", "~> 1.1"
6 changes: 3 additions & 3 deletions gemfiles/7.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ source "https://rubygems.org"

gemspec path: ".."

gem "activesupport", "~> 7.0.0"
gem "activemodel", "~> 7.0.0"
gem "activerecord", "~> 7.0.0"
gem "activesupport", "~> 7.0.0", "< 7.0.5"
gem "activemodel", "~> 7.0.0", "< 7.0.5"
gem "activerecord", "~> 7.0.0", "< 7.0.5"
gem "sqlite3", "~> 1.4"
gem "mysql2", "~> 0.5"
gem "pg", "~> 1.1"
21 changes: 18 additions & 3 deletions lib/ulid/rails/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,24 @@ def assert_valid_value(value)
def deserialize(value)
return nil if value.nil?

value = value.to_s if value.is_a?(Data)
value = value.unpack1("H*") if value.encoding == Encoding::ASCII_8BIT
value = value[2..-1] if value.start_with?("\\x")
case adapter
when "mysql2"
if value.is_a?(Data)
value = value.to_s
elsif value.is_a?(String)
value = value.unpack1("H*")
end
when "postgresql"
if value.is_a?(Data)
value = value.to_s
value = value.unpack1("H*")
end
value = value[2..-1] if value.start_with?("\\x")
when "sqlite3"
if value.is_a?(Data)
value = value.to_s
end
end

value.length == 32 ? @formatter.format(value) : super
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ulid/rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ULID
module Rails
VERSION = "1.1.0"
VERSION = "1.1.1"
end
end

0 comments on commit 4e92e0c

Please sign in to comment.