From 0bd3a341e55ee677fa2839218eb540de8b0f2f44 Mon Sep 17 00:00:00 2001 From: manga_osyo Date: Fri, 12 Jan 2024 15:00:35 +0900 Subject: [PATCH 1/2] Add support Rails 7.1 --- Appraisals | 4 ++++ gemfiles/rails_7.1.gemfile | 8 ++++++++ lib/activerecord-bitemporal/bitemporal.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 gemfiles/rails_7.1.gemfile diff --git a/Appraisals b/Appraisals index 2b628c0..2b26630 100644 --- a/Appraisals +++ b/Appraisals @@ -11,3 +11,7 @@ end appraise "rails-7.0" do gem "rails", "~> 7.0.1" end + +appraise "rails-7.1" do + gem "rails", "~> 7.1.0" +end diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..c6f841a --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "rails", "~> 7.1.0" + +gemspec path: "../" diff --git a/lib/activerecord-bitemporal/bitemporal.rb b/lib/activerecord-bitemporal/bitemporal.rb index 641eaa7..35778ff 100644 --- a/lib/activerecord-bitemporal/bitemporal.rb +++ b/lib/activerecord-bitemporal/bitemporal.rb @@ -383,6 +383,18 @@ def destroy(force_delete: false, operated_at: Time.current) false end + if Gem::Version.new("7.1.0") <= ActiveRecord.version + # MEMO: Since Rails 7.1 #_find_record refers to a record with find_by!(@primary_key => id) + # But if @primary_key is "id", it can't refer to the intended record, so we hack it to refer to the record based on self.class.bitemporal_id_key + # see: https://github.com/rails/rails/blob/v7.1.0/activerecord/lib/active_record/persistence.rb#L1152-#L1171 + def _find_record(*) + tmp_primary_key, @primary_key = @primary_key, self.class.bitemporal_id_key + super + ensure + @primary_key = tmp_primary_key + end + end + module ::ActiveRecord::Persistence # MEMO: Must be override ActiveRecord::Persistence#reload alias_method :active_record_bitemporal_original_reload, :reload unless method_defined? :active_record_bitemporal_original_reload From 2875d7c7f379ee9e4e8d137c715f2f10fc844d63 Mon Sep 17 00:00:00 2001 From: manga_osyo Date: Fri, 12 Jan 2024 15:12:14 +0900 Subject: [PATCH 2/2] Add CI support. --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index cb71ef2..cdccc59 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -32,6 +32,7 @@ workflows: gemfile: - rails_6.1 - rails_7.0 + - rails_7.1 - rails_main exclude: - ruby-version: '3.2'