Permalink
Browse files

Modify new interactor's argument list to handle some cases (#242)

  • Loading branch information...
tokichie authored and jodosha committed Nov 20, 2017
1 parent b22b40f commit 6a3bc0d3e93ef2949752c4dd79a7623b74478a05
Showing with 33 additions and 7 deletions.
  1. +6 −6 lib/hanami/interactor.rb
  2. +27 −1 spec/unit/hanami/interactor_spec.rb
View
@@ -351,27 +351,27 @@ module Interface
# end
#
# Signup.new.call # => NoMethodError
def call(*args, **kwargs)
def call(*args)
@__result = ::Hanami::Interactor::Result.new
_call(*args, **kwargs) { super }
_call(*args) { super }
end
private
# @api private
# @since 1.1.0
def _call(*args, **kwargs)
def _call(*args)
catch :fail do
validate!(*args, **kwargs)
validate!(*args)
yield
end
_prepare!
end
# @since 1.1.0
def validate!(*args, **kwargs)
fail! unless valid?(*args, **kwargs)
def validate!(*args)
fail! unless valid?(*args)
end
end
@@ -88,7 +88,7 @@ def initialize(force_failure: false)
@force_failure = force_failure
end
def call(params)
def call(**params)
@params = params
@user = User.new(params)
@user.persist!
@@ -113,6 +113,15 @@ def call(*args, **kwargs)
end
end
class CallWithoutKwargs
include Hanami::Interactor
expose :args
def call(*args)
@args = args
end
end
class LegacyErrorInteractor
include Hanami::Interactor
expose :operations
@@ -497,6 +506,23 @@ def build_user(user:, **params)
expect(result.kwargs).to eql(Hash[baz: 'baz', buzz: 'buzz'])
end
it 'handles args without kwargs' do
result = CallWithoutKwargs.new.call('foo', 'bar')
expect(result.args).to eql(%w[foo bar])
end
it 'handles kwargs without args' do
result = ComplexCall.new.call(baz: 'baz', buzz: 'buzz')
expect(result.args).to eql(Array[])
expect(result.kwargs).to eql(Hash[baz: 'baz', buzz: 'buzz'])
end
it 'handles args with to_hash method' do
user = User.new(name: 'Luca')
result = CallWithoutKwargs.new.call(user)
expect(result.args).to eql(Array[user])
end
describe 'inheritance' do
it 'is successful for super class' do
result = CreateUser.new.call(name: 'L')

0 comments on commit 6a3bc0d

Please sign in to comment.