From 4baa1bfdbc97a5d05655f16320cb47b75bff4feb Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Wed, 8 Nov 2023 14:05:34 +0900 Subject: [PATCH 1/4] Remove unused travis ci --- .travis.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b7cb72b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -sudo: false -language: ruby -services: - - mysql -rvm: - - 3.0.6 - - 3.1.4 - - 3.2.2 -before_install: gem install bundler -gemfile: - - gemfiles/6.1_stable.gemfile - - gemfiles/7.0_stable.gemfile -script: - - bundle exec rspec - - bundle exec rubocop -script: bundle exec rspec From fbc34c94bf5f1b7482ca11541e9d6ebc335a7418 Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Wed, 8 Nov 2023 14:05:52 +0900 Subject: [PATCH 2/4] Add rails 7.1 for test --- .github/workflows/ci.yml | 4 ++-- Appraisals | 4 ++++ gemfiles/7.1_stable.gemfile | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 gemfiles/7.1_stable.gemfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d472aec..0feb302 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,8 +30,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - gemfile: ['6.1_stable', '7.0_stable'] - ruby-version: ['3.0', '3.1'] + gemfile: ['6.1_stable', '7.0_stable', '7.1_stable'] + ruby-version: ['3.0', '3.1', '3.2'] services: mysql: image: mysql:5.7 diff --git a/Appraisals b/Appraisals index cfb9567..bd9efd6 100644 --- a/Appraisals +++ b/Appraisals @@ -7,3 +7,7 @@ end appraise '7.0-stable' do gem 'activerecord', '~> 7.0.0' end + +appraise '7.1-stable' do + gem 'activerecord', '~> 7.1.0' +end diff --git a/gemfiles/7.1_stable.gemfile b/gemfiles/7.1_stable.gemfile new file mode 100644 index 0000000..69bc38a --- /dev/null +++ b/gemfiles/7.1_stable.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 7.1.0" + +gemspec path: "../" From 3e25dca4a4363616354157caa573700cd921f5ff Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Wed, 8 Nov 2023 14:19:04 +0900 Subject: [PATCH 3/4] Fix specs for 7.1 --- lib/active_record_encryption/quoter.rb | 5 +++++ lib/active_record_encryption/type/binary.rb | 13 +++++++++++++ spec/active_record_encryption/quoter_spec.rb | 14 +++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/active_record_encryption/quoter.rb b/lib/active_record_encryption/quoter.rb index 365b15e..a62486f 100644 --- a/lib/active_record_encryption/quoter.rb +++ b/lib/active_record_encryption/quoter.rb @@ -26,6 +26,11 @@ def type_cast(value) end end + # @return [Symbol] + def default_timezone + ActiveRecord::Base.connection.default_timezone + end + private if ActiveRecord::VERSION::MAJOR < 7 diff --git a/lib/active_record_encryption/type/binary.rb b/lib/active_record_encryption/type/binary.rb index 98794d4..d1cdbd9 100644 --- a/lib/active_record_encryption/type/binary.rb +++ b/lib/active_record_encryption/type/binary.rb @@ -1,6 +1,19 @@ module ActiveRecordEncryption class Type class Binary < ActiveModel::Type::Binary + def cast(value) + return super if ActiveRecord::VERSION::STRING <= '7.1.0' + + if value.is_a?(Data) + value.to_s + else + value = cast_value(value) unless value.nil? + # NOTE: Don't convert string to binary for backward compatibility. + # value = value.b if ::String === value && value.encoding != Encoding::BINARY + value + end + end + def serialize(value) return if value.nil? Data.new(value) diff --git a/spec/active_record_encryption/quoter_spec.rb b/spec/active_record_encryption/quoter_spec.rb index da67789..7ad1c0e 100644 --- a/spec/active_record_encryption/quoter_spec.rb +++ b/spec/active_record_encryption/quoter_spec.rb @@ -4,6 +4,14 @@ describe '#type_cast' do subject { described_class.instance.type_cast(value) } + def to_s(value, *args) + if ActiveRecord::VERSION::MAJOR >= 7 + value.to_fs(*args) + else + value.to_s(*args) + end + end + context 'given string' do let(:value) { 'hello world' } it { is_expected.to eq(value) } @@ -31,17 +39,17 @@ context 'given ActiveRecord::Type::Time::Value' do let(:value) { ActiveRecord::Type.lookup(:time).serialize(Time.now).change(usec: 0) } - it { is_expected.to eq(value.to_s(:db)) } + it { is_expected.to eq(to_s(value, :db)) } end context 'given Date' do let(:value) { Date.today } - it { is_expected.to eq value.to_s(:db) } + it { is_expected.to eq to_s(value, :db) } end context 'given Time' do let(:value) { Time.now.change(usec: 0) } - it { is_expected.to eq value.utc.to_s(:db) } + it { is_expected.to eq to_s(value.utc, :db) } end context 'given Integer' do From b6c06b4900ae8602df43b5d363486894d7d2e924 Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Wed, 8 Nov 2023 14:39:47 +0900 Subject: [PATCH 4/4] Don't convert string to binary in Rails 7.0 --- lib/active_record_encryption/type/binary.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_record_encryption/type/binary.rb b/lib/active_record_encryption/type/binary.rb index d1cdbd9..ac6ff5c 100644 --- a/lib/active_record_encryption/type/binary.rb +++ b/lib/active_record_encryption/type/binary.rb @@ -2,7 +2,7 @@ module ActiveRecordEncryption class Type class Binary < ActiveModel::Type::Binary def cast(value) - return super if ActiveRecord::VERSION::STRING <= '7.1.0' + return super if ActiveRecord::VERSION::STRING < '7.0.0' if value.is_a?(Data) value.to_s