diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /gems/activerecord-gitlab | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'gems/activerecord-gitlab')
-rw-r--r-- | gems/activerecord-gitlab/lib/active_record/gitlab_patches/rescue_from.rb | 6 | ||||
-rw-r--r-- | gems/activerecord-gitlab/spec/active_record/gitlab_patches/rescue_from_spec.rb | 26 |
2 files changed, 16 insertions, 16 deletions
diff --git a/gems/activerecord-gitlab/lib/active_record/gitlab_patches/rescue_from.rb b/gems/activerecord-gitlab/lib/active_record/gitlab_patches/rescue_from.rb index eaa42d1523d..faabddd2686 100644 --- a/gems/activerecord-gitlab/lib/active_record/gitlab_patches/rescue_from.rb +++ b/gems/activerecord-gitlab/lib/active_record/gitlab_patches/rescue_from.rb @@ -3,8 +3,10 @@ module ActiveRecord module GitlabPatches # This adds `rescue_from` to ActiveRecord::Base. - # Currently, only errors called from `ActiveRecord::Relation#exec_queries` - # will be handled by `rescue_from`. + # Currently only the following places will be handled by `rescue_from`: + # + # - `ActiveRecord::Relation#load`, and other methods that call + # `ActiveRecord::Relation#exec_queries`. # # class ApplicationRecord < ActiveRecord::Base # rescue_from MyException, with: :my_handler diff --git a/gems/activerecord-gitlab/spec/active_record/gitlab_patches/rescue_from_spec.rb b/gems/activerecord-gitlab/spec/active_record/gitlab_patches/rescue_from_spec.rb index c1537c3bd90..22729edb014 100644 --- a/gems/activerecord-gitlab/spec/active_record/gitlab_patches/rescue_from_spec.rb +++ b/gems/activerecord-gitlab/spec/active_record/gitlab_patches/rescue_from_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -RSpec.describe ActiveRecord::GitlabPatches::RescueFrom, :without_sqlite3 do +RSpec.describe ActiveRecord::GitlabPatches::RescueFrom do let(:model_with_rescue_from) do - Class.new(ActiveRecord::Base) do - rescue_from ActiveRecord::ConnectionNotEstablished, with: :handle_exception + Class.new(Project) do + rescue_from ActiveRecord::StatementInvalid, with: :handle_exception class << self def handle_exception(exception); end @@ -12,20 +12,18 @@ RSpec.describe ActiveRecord::GitlabPatches::RescueFrom, :without_sqlite3 do end let(:model_without_rescue_from) do - Class.new(ActiveRecord::Base) + Class.new(Project) end - it 'triggers rescue_from' do - stub_const('ModelWithRescueFrom', model_with_rescue_from) + context 'for errors from ActiveRelation.load' do + it 'triggers rescue_from' do + expect(model_with_rescue_from).to receive(:handle_exception) - expect(model_with_rescue_from).to receive(:handle_exception) - - expect { model_with_rescue_from.all.load }.not_to raise_error - end - - it 'does not trigger rescue_from' do - stub_const('ModelWithoutRescueFrom', model_without_rescue_from) + expect { model_with_rescue_from.where('BADQUERY').load }.not_to raise_error + end - expect { model_without_rescue_from.all.load }.to raise_error(ActiveRecord::ConnectionNotEstablished) + it 'does not trigger rescue_from' do + expect { model_without_rescue_from.where('BADQUERY').load }.to raise_error(ActiveRecord::StatementInvalid) + end end end |