Skip to content

Commit

Permalink
Merge pull request #151 from osyo-manga/add-support_rails7_1
Browse files Browse the repository at this point in the history
Add support Rails 7.1
  • Loading branch information
osyo-manga authored Jan 25, 2024
2 parents 7e4b37f + 2875d7c commit 21420ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ workflows:
gemfile:
- rails_6.1
- rails_7.0
- rails_7.1
- rails_main
exclude:
- ruby-version: '3.2'
Expand Down
4 changes: 4 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal"
gem "rails", "~> 7.1.0"

gemspec path: "../"
12 changes: 12 additions & 0 deletions lib/activerecord-bitemporal/bitemporal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21420ef

Please sign in to comment.