From 5e08c274eb69973e4bddd956218c83237412ae83 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Thu, 25 May 2023 12:53:17 +0200 Subject: [PATCH 1/2] Change the test scripts a little bit I hope this is easier to read and understand. --- .env | 2 +- .github/workflows/lint.yml | 1 + .github/workflows/test.yml | 8 ++++++-- README.md | 2 +- docker-compose.yml | 10 ++++++---- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.env b/.env index c04414b..73b8208 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -RUBY_VERSION=2.6 +RUBY_VERSION=2.7 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 08be5e9..72101f1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,6 +6,7 @@ on: push: branches: - master + workflow_dispatch: jobs: standardrb: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 482ac16..50d17a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,9 +6,11 @@ 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 @@ -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 }} diff --git a/README.md b/README.md index 680c0fb..27fc1e5 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/docker-compose.yml b/docker-compose.yml index ce26971..af52220 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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: From 4f70db0c55227eb8b5a1141b41ea35c999420930 Mon Sep 17 00:00:00 2001 From: Benjamin Quorning Date: Thu, 25 May 2023 11:25:10 +0200 Subject: [PATCH 2/2] Make ulid-rails work with ActiveRecord v7.0.5 After https://github.com/rails/rails/pull/48274 the value of binary columns started being return in the ASCII_8BIT encoding. Having our logic depend on a string's encoding was probably a mistake in hindsight. It seems more future proof to have a different implementation per adapter instead. Co-authored-by: Nony Dutton --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 3 +++ gemfiles/7.0.5.gemfile | 10 ++++++++++ gemfiles/7.0.gemfile | 6 +++--- lib/ulid/rails/type.rb | 21 ++++++++++++++++++--- lib/ulid/rails/version.rb | 2 +- 6 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 gemfiles/7.0.5.gemfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 50d17a6..bc8581d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: 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"} diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6ab30..2e468f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ ## Unreleased +## 1.1.1 + - Drop support for ruby 2.6. +- Fix compatibility with ActiveRecord 7.0.5+. ## 1.1.0 diff --git a/gemfiles/7.0.5.gemfile b/gemfiles/7.0.5.gemfile new file mode 100644 index 0000000..0b3a000 --- /dev/null +++ b/gemfiles/7.0.5.gemfile @@ -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" diff --git a/gemfiles/7.0.gemfile b/gemfiles/7.0.gemfile index ad3f42a..961cff0 100644 --- a/gemfiles/7.0.gemfile +++ b/gemfiles/7.0.gemfile @@ -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" diff --git a/lib/ulid/rails/type.rb b/lib/ulid/rails/type.rb index e02b852..c327c2b 100644 --- a/lib/ulid/rails/type.rb +++ b/lib/ulid/rails/type.rb @@ -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 diff --git a/lib/ulid/rails/version.rb b/lib/ulid/rails/version.rb index 5b7e24e..6328c7b 100644 --- a/lib/ulid/rails/version.rb +++ b/lib/ulid/rails/version.rb @@ -1,5 +1,5 @@ module ULID module Rails - VERSION = "1.1.0" + VERSION = "1.1.1" end end