Sha256: 731fc8f43091a89c107f6fb63f18926c4560c1be011d184800e12e4d52df602a

Contents?: true

Size: 1006 Bytes

Versions: 1

Compression:

Stored size: 1006 Bytes

Contents

RSpec.describe "Custom step adapters" do
  let(:transaction) {
    Dry.Transaction(container: container, step_adapters: Test::CustomStepAdapters) do
      map :process
      tee :persist
      enqueue :deliver
    end
  }

  let(:container) {
    {
      process: -> input { {name: input["name"], email: input["email"]} },
      persist: -> input { Test::DB << input and true },
      deliver: -> input { "Delivered email to #{input[:email]}" },
    }
  }

  before do
    Test::DB = []
    Test::QUEUE = []

    module Test
      class CustomStepAdapters < Dry::Transaction::StepAdapters
        extend Dry::Monads::Either::Mixin

        register :enqueue, -> step, input, *args {
          Test::QUEUE << step.operation.call(input, *args)
          Right(input)
        }
      end
    end
  end

  it "supports custom step adapters" do
    input = {"name" => "Jane", "email" => "jane@doe.com"}
    transaction.call(input)
    expect(Test::QUEUE).to include("Delivered email to jane@doe.com")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-transaction-0.9.0 spec/integration/custom_step_adapters_spec.rb