summaryrefslogtreecommitdiff
path: root/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
diff options
context:
space:
mode:
authorAlberto Vena <kennyadsl@gmail.com>2021-07-12 15:29:53 +0200
committerAlberto Vena <kennyadsl@gmail.com>2021-07-13 16:22:59 +0200
commitc9e26197b0abbe50b029c368017243314d572884 (patch)
tree751072edbfae746e21045bdc027606c48c2670d2 /spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
parent662719693c9f369cd9176e432ab3d4a554822751 (diff)
Logs an error in the Rails logs when installment processing fails
At the moment, by default, all installment prceissing errors are swallowed and there's no way for a developer to understand what's happening. Of course they can create a custom handler with the processing_error_handler configuration provided but usually, when the first errors happen, it's too late and those errors are lost. We are not raising errors of this job because if there's a retry mechanism in place for Active Job, the installment will be reprocessed twice. Once by Active Job and once by the installment retry mechanism already provided by the extension. Logging to Rails.error is a middle-ground that allows to intercept the message of the exception. Still, creating a custom handler based on the bug tracker/exception handler used is the suggested option here.
Diffstat (limited to 'spec/jobs/solidus_subscriptions/process_installment_job_spec.rb')
-rw-r--r--spec/jobs/solidus_subscriptions/process_installment_job_spec.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
index bc33d0e..7211cfe 100644
--- a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
+++ b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
@@ -12,7 +12,22 @@ RSpec.describe SolidusSubscriptions::ProcessInstallmentJob do
end
context 'when handling #perform errors' do
+ it 'by default logs exception data without raising exceptions' do
+ checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
+ allow(c).to receive(:process).and_raise('test error')
+ end
+ allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout)
+ allow(Rails.logger).to receive(:error)
+
+ expect {
+ described_class.perform_now(build_stubbed(:installment))
+ }.not_to raise_error
+
+ expect(Rails.logger).to have_received(:error).with("test error").ordered
+ end
+
it 'swallows error when a proc is not configured' do
+ stub_config(processing_error_handler: nil )
checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
allow(c).to receive(:process).and_raise('test error')
end