From 20aa48814d05c14d88feb0869612fb3c29a69c66 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Tue, 4 Jun 2024 11:49:14 +0200 Subject: [PATCH] add docs test to show merging flow_options and setting an alias in `ctx`. --- test/docs/public_call_monkeypatching_test.rb | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/docs/public_call_monkeypatching_test.rb b/test/docs/public_call_monkeypatching_test.rb index 4caa31c..2373121 100644 --- a/test/docs/public_call_monkeypatching_test.rb +++ b/test/docs/public_call_monkeypatching_test.rb @@ -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