actioninteractor 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8b35b3d38ae5c8911e6dccf49d062eef893661c475b5acd93c687b2f8164902
4
- data.tar.gz: 32e4a9882568935c1d0f49af3370dad63640c6c2a556a580fb432b81cffcefdc
3
+ metadata.gz: 3abdd934a8609ef4c3d040807ce20d6d93e39413d2976f160bd1ba9ba3c6657e
4
+ data.tar.gz: d772e562956ef64cc2268612e24e8cff3f869ade10812591f609703c99330fe1
5
5
  SHA512:
6
- metadata.gz: af473f7d25ab12d582488f9c89a03c9cdb2494b0f17ad2831364dfd47e6828f822f669abbf6afc620a74a5da225cecb372500b66b74e79bb62dd376e2559869c
7
- data.tar.gz: 58adf66d5986157ca18f2a61d7bbf3be1fbe1ed3216b5345ac87c03abd5624a983b50b34adb54a9cb9208e573a61f27a4cb54a56fde12047992211ff70b9fa80
6
+ metadata.gz: a6d881147238cccb70ebf235aa5e14952ca73d3b745cfafd03a77fa9f188a6f7778c1f79271d1f858ebd652053ad66b8a4eab315391cde7e804be64bd4d5afdc
7
+ data.tar.gz: 38be37a4641949355534368100432b315b866fdcb81e63696286a386b135ab5c22cf55245aaf5ac347dbae0333aaf7d79063d52017a1a86c166d3e59a7e62c7f
@@ -65,6 +65,10 @@ module ActionInteractor
65
65
  @result[key] = value
66
66
  end
67
67
 
68
+ def results(items = {})
69
+ @result = items
70
+ end
71
+
68
72
  class << self
69
73
  def execute(params)
70
74
  new(params).tap(&:execute)
@@ -25,10 +25,10 @@ class BaseTest < Test::Unit::TestCase
25
25
  assert interactor.success?
26
26
  end
27
27
 
28
- test "#completed? is true" do
28
+ test "#finished? is true" do
29
29
  params = {}
30
30
  interactor = ActionInteractor::Base.execute(params)
31
- assert interactor.completed?
31
+ assert interactor.finished?
32
32
  end
33
33
 
34
34
  test "#aborted? is true after #abort!" do
@@ -1,5 +1,5 @@
1
1
  require "test/unit"
2
- require "actioninteractor"
2
+ require_relative "../lib/action_interactor/base.rb"
3
3
 
4
4
  class User
5
5
  attr_accessor :name
@@ -11,12 +11,21 @@ end
11
11
 
12
12
  class RegistrationInteractor < ActionInteractor::Base
13
13
  def execute
14
- return failed! unless params[:name]
14
+ return fail! unless params[:name]
15
15
  add_result(:user, User.new(name: params[:name]))
16
16
  finish!
17
17
  end
18
18
  end
19
19
 
20
+ class NotificationInteractor < ActionInteractor::Base
21
+ def execute
22
+ return fail! unless params[:name] || params[:email]
23
+ results(name: params[:name], email: params[:email])
24
+ finish!
25
+ end
26
+ end
27
+
28
+
20
29
  class InheritanceTest < Test::Unit::TestCase
21
30
  test ".execute does not raise error" do
22
31
  params = { name: 'John'}
@@ -48,10 +57,10 @@ class InheritanceTest < Test::Unit::TestCase
48
57
  assert interactor.success?
49
58
  end
50
59
 
51
- test "#completed? is true" do
60
+ test "#finished? is true" do
52
61
  params = { name: 'John'}
53
62
  interactor = RegistrationInteractor.execute(params)
54
- assert interactor.completed?
63
+ assert interactor.finished?
55
64
  end
56
65
 
57
66
  test "if params is empty, #failure? is true" do
@@ -60,9 +69,18 @@ class InheritanceTest < Test::Unit::TestCase
60
69
  assert interactor.failure?
61
70
  end
62
71
 
63
- test "if params is empty, #completed? is true" do
72
+ test "if params is empty, #finished? is true" do
64
73
  params = {}
65
74
  interactor = RegistrationInteractor.execute(params)
66
- assert interactor.completed?
75
+ assert interactor.finished?
76
+ end
77
+
78
+ test "the result user name is Taro and email is taro@example.com" do
79
+ params = { name: 'Taro', email: 'taro@example.com'}
80
+ interactor = NotificationInteractor.execute(params)
81
+ name = interactor.result[:name]
82
+ assert_equal(name, 'Taro')
83
+ email = interactor.result[:email]
84
+ assert_equal(email, 'taro@example.com')
67
85
  end
68
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actioninteractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Hashimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-20 00:00:00.000000000 Z
11
+ date: 2018-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler