Sha256: aa92d3863c8086fc4a345c02cbaf951f03cd4c6ce1dfd8b3a39deddf047d3a3c
Contents?: true
Size: 1.06 KB
Versions: 3
Compression:
Stored size: 1.06 KB
Contents
RSpec.describe "Custom step adapters" do let(:transaction) { Class.new do include Dry::Transaction(container: Test::Container, step_adapters: Test::CustomStepAdapters) map :process, with: :process tee :persist, with: :persist enqueue :deliver, with: :deliver end.new } before do Test::DB = [] Test::QUEUE = [] module Test Container = { process: -> input { {name: input["name"], email: input["email"]} }, persist: -> input { Test::DB << input and true }, deliver: -> input { "Delivered email to #{input[:email]}" }, } 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
3 entries across 3 versions & 1 rubygems