Skip to content

Commit

Permalink
add autogenerated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Nov 21, 2023
1 parent decd562 commit 444f6b0
Show file tree
Hide file tree
Showing 10 changed files with 1,663 additions and 5 deletions.
72 changes: 72 additions & 0 deletions test/docs/autogenerated/activity_basics_test.rb
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
Loading

0 comments on commit 444f6b0

Please sign in to comment.