interaktor 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +25 -93
- data/Gemfile +5 -4
- data/README.md +154 -298
- data/interaktor.gemspec +2 -2
- data/lib/interaktor.rb +54 -15
- data/lib/interaktor/context.rb +10 -0
- data/lib/interaktor/organizer.rb +1 -1
- data/spec/integration_spec.rb +238 -228
- data/spec/interactor/context_spec.rb +21 -21
- data/spec/interactor/hooks_spec.rb +4 -0
- data/spec/interactor/organizer_spec.rb +13 -14
- data/spec/{interactor_spec.rb → interaktor_spec.rb} +0 -0
- data/spec/support/lint.rb +31 -20
- metadata +9 -9
@@ -2,36 +2,36 @@ module Interaktor
|
|
2
2
|
describe Context do
|
3
3
|
describe ".build" do
|
4
4
|
it "converts the given hash to a context" do
|
5
|
-
context =
|
5
|
+
context = described_class.build(foo: "bar")
|
6
6
|
|
7
|
-
expect(context).to be_a(
|
7
|
+
expect(context).to be_a(described_class)
|
8
8
|
expect(context.foo).to eq("bar")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "builds an empty context if no hash is given" do
|
12
|
-
context =
|
12
|
+
context = described_class.build
|
13
13
|
|
14
|
-
expect(context).to be_a(
|
14
|
+
expect(context).to be_a(described_class)
|
15
15
|
expect(context.send(:table)).to eq({})
|
16
16
|
end
|
17
17
|
|
18
18
|
it "doesn't affect the original hash" do
|
19
19
|
hash = { foo: "bar" }
|
20
|
-
context =
|
20
|
+
context = described_class.build(hash)
|
21
21
|
|
22
|
-
expect(context).to be_a(
|
22
|
+
expect(context).to be_a(described_class)
|
23
23
|
expect {
|
24
24
|
context.foo = "baz"
|
25
|
-
}.not_to
|
25
|
+
}.not_to(change {
|
26
26
|
hash[:foo]
|
27
|
-
}
|
27
|
+
})
|
28
28
|
end
|
29
29
|
|
30
30
|
it "preserves an already built context" do
|
31
|
-
context1 =
|
32
|
-
context2 =
|
31
|
+
context1 = described_class.build(foo: "bar")
|
32
|
+
context2 = described_class.build(context1)
|
33
33
|
|
34
|
-
expect(context2).to be_a(
|
34
|
+
expect(context2).to be_a(described_class)
|
35
35
|
expect {
|
36
36
|
context2.foo = "baz"
|
37
37
|
}.to change {
|
@@ -41,7 +41,7 @@ module Interaktor
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "#success?" do
|
44
|
-
let(:context) {
|
44
|
+
let(:context) { described_class.build }
|
45
45
|
|
46
46
|
it "is true by default" do
|
47
47
|
expect(context.success?).to eq(true)
|
@@ -49,7 +49,7 @@ module Interaktor
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe "#failure?" do
|
52
|
-
let(:context) {
|
52
|
+
let(:context) { described_class.build }
|
53
53
|
|
54
54
|
it "is false by default" do
|
55
55
|
expect(context.failure?).to eq(false)
|
@@ -57,7 +57,7 @@ module Interaktor
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "#fail!" do
|
60
|
-
let(:context) {
|
60
|
+
let(:context) { described_class.build(foo: "bar") }
|
61
61
|
|
62
62
|
it "sets success to false" do
|
63
63
|
expect {
|
@@ -139,9 +139,9 @@ module Interaktor
|
|
139
139
|
end
|
140
140
|
|
141
141
|
describe "#called!" do
|
142
|
-
let(:context) {
|
143
|
-
let(:instance1) {
|
144
|
-
let(:instance2) {
|
142
|
+
let(:context) { described_class.build }
|
143
|
+
let(:instance1) { instance_double(Interaktor) }
|
144
|
+
let(:instance2) { instance_double(Interaktor) }
|
145
145
|
|
146
146
|
it "appends to the internal list of called instances" do
|
147
147
|
expect {
|
@@ -152,9 +152,9 @@ module Interaktor
|
|
152
152
|
end
|
153
153
|
|
154
154
|
describe "#rollback!" do
|
155
|
-
let(:context) {
|
156
|
-
let(:instance1) {
|
157
|
-
let(:instance2) {
|
155
|
+
let(:context) { described_class.build }
|
156
|
+
let(:instance1) { instance_double(Interaktor) }
|
157
|
+
let(:instance2) { instance_double(Interaktor) }
|
158
158
|
|
159
159
|
before do
|
160
160
|
allow(context).to receive(:_called) { [instance1, instance2] }
|
@@ -177,7 +177,7 @@ module Interaktor
|
|
177
177
|
end
|
178
178
|
|
179
179
|
describe "#_called" do
|
180
|
-
let(:context) {
|
180
|
+
let(:context) { described_class.build }
|
181
181
|
|
182
182
|
it "is empty by default" do
|
183
183
|
expect(context._called).to eq([])
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Interaktor
|
2
2
|
describe Organizer do
|
3
|
-
let(:organizer) { Class.new.
|
3
|
+
let(:organizer) { Class.new.include(described_class) }
|
4
4
|
|
5
5
|
include_examples "lint"
|
6
6
|
|
7
7
|
describe ".organize" do
|
8
|
-
let(:interaktor2) {
|
9
|
-
let(:interaktor3) {
|
8
|
+
let(:interaktor2) { instance_double(Interaktor) }
|
9
|
+
let(:interaktor3) { instance_double(Interaktor) }
|
10
10
|
|
11
11
|
it "sets interaktors given class arguments" do
|
12
12
|
expect {
|
@@ -21,7 +21,7 @@ module Interaktor
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "allows multiple organize calls" do
|
24
|
-
interaktor4 =
|
24
|
+
interaktor4 = instance_double(Interaktor)
|
25
25
|
expect {
|
26
26
|
organizer.organize(interaktor2, interaktor3)
|
27
27
|
organizer.organize(interaktor4)
|
@@ -36,20 +36,19 @@ module Interaktor
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "#call" do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
allow(instance).to receive(:context)
|
39
|
+
it "calls each interaktor in order with the context" do
|
40
|
+
instance = organizer.new
|
41
|
+
context = instance_double(Interaktor::Context)
|
42
|
+
interaktor2 = class_double(Class.new.include(Interaktor))
|
43
|
+
interaktor3 = class_double(Class.new.include(Interaktor))
|
44
|
+
interaktor4 = class_double(Class.new.include(Interaktor))
|
45
|
+
|
46
|
+
allow(instance).to receive(:context).and_return(context)
|
47
|
+
instance.instance_variable_set(:@context, context)
|
47
48
|
allow(organizer).to receive(:organized) {
|
48
49
|
[interaktor2, interaktor3, interaktor4]
|
49
50
|
}
|
50
|
-
end
|
51
51
|
|
52
|
-
it "calls each interaktor in order with the context" do
|
53
52
|
expect(interaktor2).to receive(:call!).once.with(context).ordered
|
54
53
|
expect(interaktor3).to receive(:call!).once.with(context).ordered
|
55
54
|
expect(interaktor4).to receive(:call!).once.with(context).ordered
|
File without changes
|
data/spec/support/lint.rb
CHANGED
@@ -1,64 +1,75 @@
|
|
1
1
|
shared_examples "lint" do
|
2
|
-
let(:interaktor) { Class.new.
|
2
|
+
let(:interaktor) { Class.new.include(described_class) }
|
3
3
|
|
4
4
|
describe ".call" do
|
5
|
-
let(:context) {
|
6
|
-
let(:instance) {
|
5
|
+
let(:context) { instance_double(Interaktor::Context) }
|
6
|
+
let(:instance) { instance_double(interaktor) }
|
7
7
|
|
8
8
|
it "calls an instance with the given context" do
|
9
|
-
|
9
|
+
instance.instance_variable_set(:@context, context)
|
10
|
+
expect(interaktor).to receive(:new).once.with(foo: "bar").and_return(instance)
|
10
11
|
expect(instance).to receive(:run).once.with(no_args)
|
11
12
|
|
12
|
-
|
13
|
+
resulting_context = interaktor.call(foo: "bar")
|
14
|
+
|
15
|
+
expect(resulting_context).to eq(context)
|
13
16
|
end
|
14
17
|
|
15
18
|
it "provides a blank context if none is given" do
|
16
|
-
|
19
|
+
instance.instance_variable_set(:@context, context)
|
20
|
+
expect(interaktor).to receive(:new).once.with({}).and_return(instance)
|
17
21
|
expect(instance).to receive(:run).once.with(no_args)
|
18
22
|
|
19
|
-
|
23
|
+
resulting_context = interaktor.call({})
|
24
|
+
|
25
|
+
expect(resulting_context).to eq(context)
|
20
26
|
end
|
21
27
|
end
|
22
28
|
|
23
29
|
describe ".call!" do
|
24
|
-
let(:context) {
|
25
|
-
let(:instance) {
|
30
|
+
let(:context) { instance_double(Interaktor::Context) }
|
31
|
+
let(:instance) { instance_double(interaktor) }
|
26
32
|
|
27
33
|
it "calls an instance with the given context" do
|
28
|
-
|
34
|
+
instance.instance_variable_set(:@context, context)
|
35
|
+
expect(interaktor).to receive(:new).once.with(foo: "bar").and_return(instance)
|
29
36
|
expect(instance).to receive(:run!).once.with(no_args)
|
30
37
|
|
31
|
-
|
38
|
+
resulting_context = interaktor.call!(foo: "bar")
|
39
|
+
|
40
|
+
expect(resulting_context).to eq(context)
|
32
41
|
end
|
33
42
|
|
34
43
|
it "provides a blank context if none is given" do
|
35
|
-
|
44
|
+
instance.instance_variable_set(:@context, context)
|
45
|
+
expect(interaktor).to receive(:new).once.with({}).and_return(instance)
|
36
46
|
expect(instance).to receive(:run!).once.with(no_args)
|
37
47
|
|
38
|
-
|
48
|
+
resulting_context = interaktor.call!({})
|
49
|
+
|
50
|
+
expect(resulting_context).to eq(context)
|
39
51
|
end
|
40
52
|
end
|
41
53
|
|
42
54
|
describe ".new" do
|
43
|
-
let(:context) {
|
55
|
+
let(:context) { instance_double(Interaktor::Context) }
|
44
56
|
|
45
57
|
it "initializes a context" do
|
46
|
-
expect(Interaktor::Context).to receive(:build)
|
47
|
-
.once.with(foo: "bar") { context }
|
58
|
+
expect(Interaktor::Context).to receive(:build).once.with(foo: "bar").and_return(context)
|
48
59
|
|
49
60
|
instance = interaktor.new(foo: "bar")
|
50
61
|
|
51
|
-
expect(instance).to
|
52
|
-
expect(instance.context).to eq(context)
|
62
|
+
expect(instance).to be_an(interaktor)
|
63
|
+
expect(instance.instance_variable_get(:@context)).to eq(context)
|
53
64
|
end
|
54
65
|
|
55
66
|
it "initializes a blank context if none is given" do
|
56
|
-
expect(Interaktor::Context).to receive(:build).once.with({})
|
67
|
+
expect(Interaktor::Context).to receive(:build).once.with({}).and_return(context)
|
57
68
|
|
58
69
|
instance = interaktor.new
|
59
70
|
|
60
71
|
expect(instance).to be_a(interaktor)
|
61
|
-
expect(instance.context).to eq(context)
|
72
|
+
expect(instance.instance_variable_get(:@context)).to eq(context)
|
62
73
|
end
|
63
74
|
end
|
64
75
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interaktor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Thurlow
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,14 +61,14 @@ files:
|
|
61
61
|
- spec/interactor/context_spec.rb
|
62
62
|
- spec/interactor/hooks_spec.rb
|
63
63
|
- spec/interactor/organizer_spec.rb
|
64
|
-
- spec/
|
64
|
+
- spec/interaktor_spec.rb
|
65
65
|
- spec/spec_helper.rb
|
66
66
|
- spec/support/lint.rb
|
67
67
|
homepage: https://github.com/taylorthurlow/interaktor
|
68
68
|
licenses:
|
69
69
|
- MIT
|
70
70
|
metadata: {}
|
71
|
-
post_install_message:
|
71
|
+
post_install_message:
|
72
72
|
rdoc_options: []
|
73
73
|
require_paths:
|
74
74
|
- lib
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubygems_version: 3.1.2
|
87
|
-
signing_key:
|
87
|
+
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Simple service object implementation
|
90
90
|
test_files:
|
@@ -92,6 +92,6 @@ test_files:
|
|
92
92
|
- spec/interactor/context_spec.rb
|
93
93
|
- spec/interactor/hooks_spec.rb
|
94
94
|
- spec/interactor/organizer_spec.rb
|
95
|
-
- spec/
|
95
|
+
- spec/interaktor_spec.rb
|
96
96
|
- spec/spec_helper.rb
|
97
97
|
- spec/support/lint.rb
|