-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added custom outputs binary state methods
- Loading branch information
1 parent
a9f357e
commit 3e527c5
Showing
6 changed files
with
61 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
c | ||
success | ||
c | ||
event | ||
Result.new(Create, {"x" => String}, event) | ||
success.inspect | ||
success | ||
c | ||
success.inspect | ||
quit | ||
success.inspect |
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 |
---|---|---|
|
@@ -16,3 +16,4 @@ test/version_tmp | |
tmp | ||
/**/*.log | ||
.rubocop-*yml | ||
.idea |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "test_helper" | ||
|
||
class CustomOutputTest < Minitest::Spec | ||
# #success passes fast. | ||
class Execute < Trailblazer::Operation | ||
UsePaypal = Class.new(Trailblazer::Activity::Signal) | ||
|
||
step :find_provider, Output(UsePaypal, :paypal) => End(:paypal) | ||
step :charge_creditcard | ||
|
||
def find_provider(ctx, params:, **) | ||
return true unless params[:provider] == :paypal | ||
UsePaypal | ||
end | ||
|
||
def charge_creditcard(ctx, **) | ||
ctx[:charged] = true | ||
end | ||
end | ||
|
||
describe "if a custom output is used in an operation" do | ||
it "adds `<custom_output>?` method to the result object which returns true if the operation takes the correspondent track" do | ||
result = Execute.(params: {provider: :paypal}) | ||
assert result.paypal? | ||
assert !result.success? | ||
assert !result.failure? | ||
refute_respond_to result, :papa_johns? | ||
|
||
result = Execute.(params: {provider: :not_paypal}) | ||
assert !result.paypal? | ||
assert result.success? | ||
assert !result.failure? | ||
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