From 1869678a549fb5e58bd5ac5b28bfd6a6e6b737d3 Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 15 Jul 2024 17:37:56 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fail=20actor=20play=20when=20an=20Interacto?= =?UTF-8?q?r=20fails=20=F0=9F=99=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #163 --- lib/service_actor/playable.rb | 5 ++++- spec/actor_spec.rb | 9 +++++++++ spec/examples/fail_with_interactor.rb | 11 +++++++++++ spec/examples/play_interactor_failure.rb | 10 ++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 spec/examples/fail_with_interactor.rb create mode 100644 spec/examples/play_interactor_failure.rb diff --git a/lib/service_actor/playable.rb b/lib/service_actor/playable.rb index 7a7004f..10a9489 100644 --- a/lib/service_actor/playable.rb +++ b/lib/service_actor/playable.rb @@ -116,7 +116,10 @@ def play_method(actor) end def play_interactor(actor) - result.merge!(actor.call(result.to_h).to_h) + interactor = actor.call(result.to_h) + result.merge!(interactor.to_h) + fail! if interactor.failure? + result end end end diff --git a/spec/actor_spec.rb b/spec/actor_spec.rb index 5e05d46..d4c01c8 100644 --- a/spec/actor_spec.rb +++ b/spec/actor_spec.rb @@ -673,6 +673,15 @@ end end + context "when playing a failing interactor" do + it "fails" do + actor = PlayInteractorFailure.result(value: 5) + expect(actor).to be_a_failure + expect(actor.error).to eq("Failed with Interactor") + expect(actor.value).to eq(5 + 1) + end + end + context "when using advanced mode with checks and not adding message key" do context "when using inclusion check" do let(:expected_alert) do diff --git a/spec/examples/fail_with_interactor.rb b/spec/examples/fail_with_interactor.rb new file mode 100644 index 0000000..2cfdba2 --- /dev/null +++ b/spec/examples/fail_with_interactor.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "interactor" + +class FailWithInteractor + include Interactor + + def call + context.fail!(error: "Failed with Interactor") + end +end diff --git a/spec/examples/play_interactor_failure.rb b/spec/examples/play_interactor_failure.rb new file mode 100644 index 0000000..b064905 --- /dev/null +++ b/spec/examples/play_interactor_failure.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class PlayInteractorFailure < Actor + input :value, default: 1 + output :value + + play IncrementValueWithInteractor, + FailWithInteractor, + IncrementValueWithInteractor +end From b6a3321727912c2ff57c991135ff5e8cf83fdc1d Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Mon, 15 Jul 2024 17:44:21 +0200 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afd3397..b2c1590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## unreleased +Fixes: +- Fail actor when playing a failing Interactor (#164) + ## v3.9.2 Fixes: