From 18529657f0732d303f8c24987e17ead625bfe3cb Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Tue, 4 Jun 2024 11:26:26 +0200 Subject: [PATCH] move taskwrap test to docs. --- test/call_test.rb | 51 ------------------ test/docs/public_call_monkeypatching_test.rb | 54 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 51 deletions(-) create mode 100644 test/docs/public_call_monkeypatching_test.rb diff --git a/test/call_test.rb b/test/call_test.rb index 4813f3b..2c6475c 100644 --- a/test/call_test.rb +++ b/test/call_test.rb @@ -93,55 +93,4 @@ def self.add_1(wrap_ctx, original_args) assert_equal signal.to_h[:semantic], :success assert_equal ctx[:seq], [1, :a, 1, 1] end - - #@ test overriding {Operation.call_with_public_interface} - #@ - module AfterCall - def self.add_task_name(wrap_ctx, original_args) - (ctx, _flow_options), circuit_options = original_args - - activity = circuit_options[:activity] # currently running Activity. - task = wrap_ctx[:task] # the current "step". - task_id = Trailblazer::Activity::Introspect.Nodes(activity, task: task).id - - ctx[:seq] << task_id - - return wrap_ctx, original_args # yay to mutable state. not. - end - end - - it "overrides {call_with_public_interface} and allows injecting {circuit_options} and {flow_options} from the override" do - mod = Module.new do - def call_with_public_interface(ctx, flow_options, **circuit_options) - my_extension = Trailblazer::Activity::TaskWrap::Extension( - [AfterCall.method(:add_task_name), id: "my.add_1", append: "task_wrap.call_task"] - ) - - super( - ctx, - flow_options.merge({}), - **circuit_options.merge( - wrap_runtime: Hash.new(my_extension), - runner: Trailblazer::Activity::TaskWrap::Runner - ) - ) - end - end - - operation = Class.new(Trailblazer::Operation) do - step :a - - include Trailblazer::Activity::Testing.def_steps(:a) - end - operation.extend mod # monkey-patch the "global" Operation. - - - # circuit interface invocation using call - result = operation.call( - seq: [] - ) - - assert_equal result.success?, true - 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 diff --git a/test/docs/public_call_monkeypatching_test.rb b/test/docs/public_call_monkeypatching_test.rb new file mode 100644 index 0000000..4caa31c --- /dev/null +++ b/test/docs/public_call_monkeypatching_test.rb @@ -0,0 +1,54 @@ +require "test_helper" + +class PublicCallMonkeypatchingTest < Minitest::Spec + #@ test overriding {Operation.call_with_public_interface} + #@ + module AfterCall + def self.add_task_name(wrap_ctx, original_args) + (ctx, _flow_options), circuit_options = original_args + + activity = circuit_options[:activity] # currently running Activity. + task = wrap_ctx[:task] # the current "step". + task_id = Trailblazer::Activity::Introspect.Nodes(activity, task: task).id + + ctx[:seq] << task_id + + return wrap_ctx, original_args # yay to mutable state. not. + end + end + + it "overrides {call_with_public_interface} and allows injecting {circuit_options} and {flow_options} from the override" do + TaskWrapExtension = Trailblazer::Activity::TaskWrap::Extension( + [AfterCall.method(:add_task_name), id: "my.add_1", append: "task_wrap.call_task"] + ) + + module OperationExtensions + def call_with_public_interface(ctx, flow_options, **circuit_options) + super( + ctx, + flow_options.merge({}), + **circuit_options.merge( + wrap_runtime: Hash.new(TaskWrapExtension), + runner: Trailblazer::Activity::TaskWrap::Runner + ) + ) + end + end + + operation = Class.new(Trailblazer::Operation) do + step :a + + include Trailblazer::Activity::Testing.def_steps(:a) + end + operation.extend OperationExtensions # monkey-patch the "global" Operation. + + + # circuit interface invocation using call + result = operation.call( + seq: [] + ) + + assert_equal result.success?, true + 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