Skip to content

Commit 661413b

Browse files
committed
avoid context inner logic duplicating
1 parent 7326e77 commit 661413b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/interactor/context.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ def failure?
123123
def fail!(context = {})
124124
context.each { |key, value| modifiable[key.to_sym] = value }
125125
@failure = true
126+
signal_early_return!
127+
end
128+
129+
def signal_early_return!
126130
throw :early_return
127131
end
128132

lib/interactor/organizer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module InstanceMethods
7676
# Returns nothing.
7777
def call
7878
self.class.organized.each do |interactor|
79-
throw(:early_return) if context.failure?
79+
context.signal_early_return! if context.failure?
8080
interactor.call(context)
8181
end
8282
end

spec/interactor/organizer_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ module Interactor
5555
instance.call
5656
end
5757

58-
it "throws :early_return on failure of one of organizers" do
58+
it "signals about early_return on failure of one of organizers" do
5959
allow(context).to receive(:failure?).and_return(false, true)
60+
expect(context).to receive(:signal_early_return!).and_throw(:foo)
6061
expect {
6162
instance.call
62-
}.to throw_symbol(:early_return)
63+
}.to throw_symbol
6364
end
6465
end
6566
end

0 commit comments

Comments
 (0)