Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support usage alongside dry-auto_inject #101

Open
timriley opened this issue Apr 9, 2018 · 3 comments
Open

Support usage alongside dry-auto_inject #101

timriley opened this issue Apr 9, 2018 · 3 comments

Comments

@timriley
Copy link
Member

timriley commented Apr 9, 2018

Something like this should work:

require "dry-monads"
require "dry-auto_inject"

RSpec.describe "Using dry-auto_inject" do
  let(:transaction) {
    Class.new do
      include Dry::Transaction(container: Test::Container)
      include Test::Inject[:extract_email]

      step :symbolize

      def call(input)
        super(input).bind(extract_email)
      end
    end.new
  }

  before do
    module Test
      Container = {
        symbolize: -> input { Dry::Monads::Right(name: input["name"], email: input["email"]) },
        extract_email: -> input { Dry::Monads::Right(email: input[:email]) },
      }

      Inject = Dry::AutoInject(container: Container)
    end
  end

  it "support auto-injection of dependencies alongside step operations" do
    expect(transaction.("name" => "Jane", "email" => "jane@example.com").value).to eq(email: "jane@example.com")
  end
end

But right now, it doesn't:

  1) Using dry-auto_inject support auto-injection of dependencies alongside step operations
     Failure/Error: end.new
     ArgumentError:
       wrong number of arguments (given 1, expected 0)
     # ./lib/dry/transaction/instance_methods.rb:47:in `initialize'
     # ./lib/dry/transaction/instance_methods.rb:47:in `initialize'
     # ./lib/dry/transaction/operation_resolver.rb:19:in `block (2 levels) in initialize'
     # ./spec/integration/auto_injection_spec.rb:15:in `block (2 levels) in <top (required)>'
     # ./spec/integration/auto_injection_spec.rb:30:in `block (2 levels) in <top (required)>'
@GustavoCaso
Copy link
Member

I will try having a look at it! 💎

@johnvoon
Copy link

Has this issue been resolved? If no one's working on it at the moment, I'm happy to look into it.

@timriley
Copy link
Member Author

@johnvoon Would love you to look into it, thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants