diff --git a/test/docs/path_layout_test.rb b/test/docs/path_layout_test.rb new file mode 100644 index 0000000..784f37f --- /dev/null +++ b/test/docs/path_layout_test.rb @@ -0,0 +1,71 @@ + it do + module A + Memo = DocsStrategyTest::Memo + + #:step + module Memo::Activity + class Create < Trailblazer::Activity::Path + step :validate + step :create + #~mod + def validate(ctx, params:, **) + ctx[:input] = Form.validate(params) + end + + def create(ctx, input:, **) + Memo.create(input) + end + #~mod end + end + end + #:step end + end + + ctx = {params: {text: "Hydrate!"}} + + signal, (ctx, flow_options) = A::Memo::Activity::Create.([ctx, {}]) + + _(signal.inspect).must_equal %{#} + _(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}} + end + + it do + module B + #:validate + class Create < Trailblazer::Activity::Path + #~flow + step :validate, Output(Trailblazer::Activity::Left, :failure) => End(:invalid) + step :create + #~flow end + #~mod + def validate(ctx, params:, **) + ctx[:input] = Form.validate(params) # true/false + end + + def create(ctx, input:, **) + Memo.create(input) + end + #~mod end + end + #:validate end + end + + ctx = {params: {text: "Hydrate!"}} + signal, (ctx, _flow_options) = B::Create.([ctx, {}]) + + _(signal.inspect).must_equal %{#} + _(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}} + + ctx = {params: nil} + signal, (ctx, _flow_options) = B::Create.([ctx, {}]) + _(signal.inspect).must_equal %{#} + _(ctx.inspect).must_equal %{{:params=>nil, :input=>nil}} +=begin + #:validate-call + ctx = {params: nil} + signal, (ctx, flow_options) = Memo::Create.([ctx, {}]) + + puts signal #=> # + #:validate-call end +=end + end diff --git a/test/docs/strategy_test.rb b/test/docs/strategy_test.rb index 7d30d07..a27eac6 100644 --- a/test/docs/strategy_test.rb +++ b/test/docs/strategy_test.rb @@ -15,78 +15,6 @@ def self.create(options) end end - it do - module A - Memo = DocsStrategyTest::Memo - - #:step - module Memo::Activity - class Create < Trailblazer::Activity::Path - step :validate - step :create - #~mod - def validate(ctx, params:, **) - ctx[:input] = Form.validate(params) - end - - def create(ctx, input:, **) - Memo.create(input) - end - #~mod end - end - end - #:step end - end - - ctx = {params: {text: "Hydrate!"}} - - signal, (ctx, flow_options) = A::Memo::Activity::Create.([ctx, {}]) - - _(signal.inspect).must_equal %{#} - _(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}} - end - - it do - module B - #:validate - class Create < Trailblazer::Activity::Path - #~flow - step :validate, Output(Trailblazer::Activity::Left, :failure) => End(:invalid) - step :create - #~flow end - #~mod - def validate(ctx, params:, **) - ctx[:input] = Form.validate(params) # true/false - end - - def create(ctx, input:, **) - Memo.create(input) - end - #~mod end - end - #:validate end - end - - ctx = {params: {text: "Hydrate!"}} - signal, (ctx, _flow_options) = B::Create.([ctx, {}]) - - _(signal.inspect).must_equal %{#} - _(ctx.inspect).must_equal %{{:params=>{:text=>\"Hydrate!\"}, :input=>{:text=>\"Hydrate!\"}}} - - ctx = {params: nil} - signal, (ctx, _flow_options) = B::Create.([ctx, {}]) - _(signal.inspect).must_equal %{#} - _(ctx.inspect).must_equal %{{:params=>nil, :input=>nil}} -=begin - #:validate-call - ctx = {params: nil} - signal, (ctx, flow_options) = Memo::Create.([ctx, {}]) - - puts signal #=> # - #:validate-call end -=end - end - it do module C #:double-end