Skip to content

Commit

Permalink
Merge pull request #31 from alpaca-tc/support-rails-7-1
Browse files Browse the repository at this point in the history
Support rails 7.1
  • Loading branch information
alpaca-tc authored Nov 8, 2023
2 parents 4b245cb + b6c06b4 commit 8f54f28
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions gemfiles/7.1_stable.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 7.1.0"

gemspec path: "../"
5 changes: 5 additions & 0 deletions lib/active_record_encryption/quoter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/active_record_encryption/type/binary.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
module ActiveRecordEncryption
class Type
class Binary < ActiveModel::Type::Binary
def cast(value)
return super if ActiveRecord::VERSION::STRING < '7.0.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)
Expand Down
14 changes: 11 additions & 3 deletions spec/active_record_encryption/quoter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f54f28

Please sign in to comment.