Skip to content

Commit

Permalink
add docs test to show merging flow_options and setting an alias in `c…
Browse files Browse the repository at this point in the history
…tx`.
  • Loading branch information
apotonick committed Jun 4, 2024
1 parent 1852965 commit 20aa488
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/docs/public_call_monkeypatching_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,45 @@ def call_with_public_interface(ctx, flow_options, **circuit_options)
assert_equal result[:seq], ["Start.default", :a, :a, "End.success", nil] # {nil} because we don't have an ID for the actual operation.
end
end

class FlowOptionsMonekypatching < Minitest::Spec
module App
FLOW_OPTIONS = {
context_options: {
aliases: { "contract.default": :contract },
container_class: Trailblazer::Context::Container::WithAliases,
}
}

module OperationExtensions
def call_with_public_interface(ctx, flow_options, **circuit_options)
super(
ctx,
flow_options.merge(App::FLOW_OPTIONS),
**circuit_options
)
end
end
end

it do
operation = Class.new(Trailblazer::Operation) do
step :a

def a(ctx, contract:, **)
ctx[:seq] << contract
end
end
operation.extend App::OperationExtensions # monkey-patch the "global" Operation.


# circuit interface invocation using call
result = operation.call(
seq: [],
:"contract.default" => Object,
)

assert_equal result.success?, true
assert_equal result[:seq].inspect, %([Object])
end
end

0 comments on commit 20aa488

Please sign in to comment.