-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - Add call! method to halt the execution of the current ser…
…vice
- Loading branch information
1 parent
ff1c535
commit e3a10af
Showing
5 changed files
with
137 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ def call | |
# Test enforcing the interface of the service | ||
###### | ||
|
||
context "when the configuration is set to enforce the interface" do | ||
context 'when the configuration is set to enforce the interface' do | ||
before do | ||
SeaFood.configure do |config| | ||
config.enforce_interface = true | ||
|
@@ -79,8 +79,7 @@ def call | |
|
||
it 'rasies an error when the #initialize method is not implemented' do | ||
TestService = Class.new(SeaFood::Service) do | ||
def call | ||
end | ||
def call; end | ||
end | ||
|
||
expect { TestService.call }.to raise_error( | ||
|
@@ -148,9 +147,9 @@ def call; end | |
expect(result.email).to be_nil | ||
end | ||
|
||
###### | ||
# Test the difference behavior of #success #fail #fail! | ||
###### | ||
###### | ||
# Test the difference behavior of #success #fail #fail! | ||
###### | ||
|
||
it 'call #success twice' do | ||
TestSuccessService = Class.new(SeaFood::Service) do | ||
|
@@ -208,11 +207,10 @@ def call | |
|
||
it '#fail then #success' do | ||
TestFailService = Class.new(SeaFood::Service) do | ||
|
||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
fail(email: '[email protected]') | ||
success(email: @email) | ||
|
@@ -230,10 +228,10 @@ def call | |
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
fail!(email: '[email protected]') | ||
success!(email: @email) | ||
success(email: @email) | ||
end | ||
end | ||
|
||
|
@@ -242,5 +240,104 @@ def call | |
expect(result).to be_fail | ||
expect(result.email).to eq('[email protected]') | ||
end | ||
|
||
context 'testing nested services with call' do | ||
it 'it fails on the first service but not on the second one' do | ||
TestInnerFailService = Class.new(SeaFood::Service) do | ||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
fail!(email: @email) | ||
end | ||
end | ||
|
||
TestParentFailService = Class.new(SeaFood::Service) do | ||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
TestInnerFailService.call(email: '[email protected]') | ||
success(email: @email) | ||
end | ||
end | ||
|
||
result = TestParentFailService.call(email: '[email protected]') | ||
|
||
expect(result).to be_success | ||
expect(result.email).to eq('[email protected]') | ||
end | ||
end | ||
|
||
context 'testing nested services with call!' do | ||
it 'it fails on the first service so it fails the second one' do | ||
TestInnerFailService = Class.new(SeaFood::Service) do | ||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
fail!(email: @email) | ||
end | ||
end | ||
|
||
TestParentFailService = Class.new(SeaFood::Service) do | ||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
TestInnerFailService.call!(email: '[email protected]') | ||
success(email: @email) | ||
end | ||
end | ||
|
||
result = TestParentFailService.call(email: '[email protected]') | ||
expect(result).to be_fail | ||
expect(result.email).to eq('[email protected]') | ||
end | ||
end | ||
|
||
context 'testing three levels nested services with call!' do | ||
it 'it fails on the third level service but does not cascade' do | ||
TestThirdFailService = Class.new(SeaFood::Service) do | ||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
fail!(email: @email) | ||
end | ||
end | ||
|
||
TestSecondFailService = Class.new(SeaFood::Service) do | ||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
TestInnerFailService.call!(email: '[email protected]') | ||
success(email: @email) | ||
end | ||
end | ||
|
||
TestFirstService = Class.new(SeaFood::Service) do | ||
def initialize(email:) | ||
@email = email | ||
end | ||
|
||
def call | ||
TestInnerFailService.call(email: 'a') | ||
success(email: @email) | ||
end | ||
end | ||
|
||
result = TestFirstService.call(email: '[email protected]') | ||
expect(result).to be_success | ||
expect(result.email).to eq('[email protected]') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters