-
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.
- Loading branch information
Showing
10 changed files
with
1,663 additions
and
5 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,72 @@ | ||
# THIS FILE IS AUTOGENERATED FROM trailblazer-activity-dsl-linear/test/docs/activity_basics_test.rb | ||
require "test_helper" | ||
|
||
module X | ||
class DocsActivityTest < Minitest::Spec | ||
it "basic activity" do | ||
Memo = Struct.new(:options) do | ||
def save | ||
true | ||
end | ||
end | ||
|
||
#:memo-create | ||
module Memo::Operation | ||
class Create < Trailblazer::Operation | ||
step :validate | ||
#~body | ||
step :save | ||
left :handle_errors | ||
step :notify | ||
#~meths | ||
include T.def_steps(:validate, :save, :handle_errors, :notify) | ||
|
||
#:save | ||
def save(ctx, params:, **) | ||
memo = Memo.new(params[:memo]) | ||
memo.save | ||
|
||
ctx[:model] = memo # you can write to the {ctx}. | ||
end | ||
#:save end | ||
|
||
def notify(ctx, **) | ||
true | ||
end | ||
|
||
#~body end | ||
def validate(ctx, params:, **) # home-made validation | ||
params.key?(:memo) && | ||
params[:memo].key?(:text) && | ||
params[:memo][:text].size > 9 | ||
# return value matters! | ||
end | ||
#~meths end | ||
end | ||
end | ||
#:memo-create end | ||
|
||
#:memo-call | ||
result = Memo::Operation::Create.( | ||
params: {memo: {text: "Do not forget!"}} | ||
) | ||
|
||
result.success? # => true | ||
puts result.terminus.to_h[:semantic] #=> :success | ||
#:memo-call end | ||
|
||
#:memo-call-model | ||
result = Memo::Operation::Create.( | ||
params: {memo: {text: "Do not forget!"}} | ||
) | ||
|
||
#~ctx_to_result | ||
puts result[:model] #=> #<Memo id: 1 text: "Do not forget!"> | ||
#:memo-call-model end | ||
#~ctx_to_result end | ||
|
||
assert_equal result.terminus.inspect, %(#<Trailblazer::Activity::Railway::End::Success semantic=:success>) | ||
#~ignore end | ||
end | ||
end | ||
end |
Oops, something went wrong.