Skip to content

Commit 6c01d9f

Browse files
committed
avoid context inner logic duplicating
1 parent 8909470 commit 6c01d9f

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
@@ -77,7 +77,7 @@ module InstanceMethods
7777
# Returns nothing.
7878
def call
7979
self.class.organized.each do |interactor|
80-
throw(:early_return) if context.failure?
80+
context.signal_early_return! if context.failure?
8181
interactor.call(context)
8282
end
8383
end

spec/interactor/organizer_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ module Interactor
6565
instance.call
6666
end
6767

68-
it "throws :early_return on failure of one of organizers" do
68+
it "signals about early_return on failure of one of organizers" do
6969
allow(context).to receive(:failure?).and_return(false, true)
70+
expect(context).to receive(:signal_early_return!).and_throw(:foo)
7071
expect {
7172
instance.call
72-
}.to throw_symbol(:early_return)
73+
}.to throw_symbol
7374
end
7475
end
7576
end

0 commit comments

Comments
 (0)