rest_my_case 1.10.9 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +330 -2
- data/lib/rest_my_case/base.rb +46 -21
- data/lib/rest_my_case/context/base.rb +11 -0
- data/lib/rest_my_case/context/schema_validator/base.rb +27 -0
- data/lib/rest_my_case/context/schema_validator/compel.rb +36 -0
- data/lib/rest_my_case/context/status.rb +2 -0
- data/lib/rest_my_case/defense_attorney/base.rb +1 -1
- data/lib/rest_my_case/http_status.rb +5 -8
- data/lib/rest_my_case/judge/base.rb +19 -14
- data/lib/rest_my_case/status.rb +13 -12
- data/lib/rest_my_case/trial/case.rb +3 -3
- data/lib/rest_my_case/validator.rb +3 -8
- data/lib/rest_my_case/version.rb +1 -1
- data/lib/rest_my_case.rb +0 -4
- data/rest_my_case.gemspec +1 -1
- data/spec/rest_my_case/accusation_attorneys/base_spec.rb +1 -1
- data/spec/rest_my_case/accusation_attorneys/each_spec.rb +1 -1
- data/spec/rest_my_case/accusation_attorneys/format_spec.rb +2 -2
- data/spec/rest_my_case/base/context_accessor_spec.rb +29 -0
- data/spec/rest_my_case/base/context_reader_spec.rb +21 -0
- data/spec/rest_my_case/base/context_writer_spec.rb +23 -0
- data/spec/rest_my_case/base/dependencies_spec.rb +14 -0
- data/spec/rest_my_case/base/invoke!_spec.rb +140 -0
- data/spec/rest_my_case/base/invoke_spec.rb +29 -0
- data/spec/rest_my_case/{base_spec.rb → base/perform_spec.rb} +0 -226
- data/spec/rest_my_case/base/required_context_spec.rb +33 -0
- data/spec/rest_my_case/context/status_spec.rb +2 -2
- data/spec/rest_my_case/status_spec.rb +6 -6
- data/spec/support/required_context.rb +49 -0
- metadata +42 -24
data/lib/rest_my_case/status.rb
CHANGED
@@ -1,28 +1,29 @@
|
|
1
|
+
require 'rest_my_case/context/status'
|
2
|
+
|
1
3
|
module RestMyCase
|
2
4
|
|
3
5
|
module Status
|
4
6
|
|
5
|
-
module ClassMethods
|
6
|
-
def trial_court
|
7
|
-
@trial_court ||= Trial::Court.new \
|
8
|
-
Judge::Base, DefenseAttorney::Base, Base, Context::Status
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
7
|
def self.included(parent_class)
|
13
|
-
parent_class.
|
8
|
+
return unless parent_class.respond_to? :trial_court
|
9
|
+
|
10
|
+
parent_class.trial_court.context_class = Context::Status
|
14
11
|
end
|
15
12
|
|
16
13
|
def status
|
17
14
|
context.status
|
18
15
|
end
|
19
16
|
|
20
|
-
def failure(status,
|
21
|
-
|
17
|
+
def failure(status, error_message = nil)
|
18
|
+
if error_message.is_a?(Hash)
|
19
|
+
error_data = error_message
|
20
|
+
else
|
21
|
+
error_data = { message: error_message }
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
+
error_data[:status] = status
|
24
25
|
|
25
|
-
error(
|
26
|
+
error(error_data)
|
26
27
|
end
|
27
28
|
|
28
29
|
def failure!(status, error = nil)
|
@@ -12,10 +12,10 @@ module RestMyCase
|
|
12
12
|
:defendant_class
|
13
13
|
|
14
14
|
def initialize(last_ancestor, context_class, use_case_classes, attributes)
|
15
|
-
@context
|
16
|
-
@last_ancestor
|
15
|
+
@context = build_context attributes, context_class
|
16
|
+
@last_ancestor = last_ancestor
|
17
17
|
@defendant_class = build_defendant(last_ancestor, use_case_classes)
|
18
|
-
@defendant
|
18
|
+
@defendant = @defendant_class.new @context
|
19
19
|
end
|
20
20
|
|
21
21
|
def aborted
|
@@ -6,11 +6,6 @@ module RestMyCase
|
|
6
6
|
|
7
7
|
attr_writer :validators
|
8
8
|
|
9
|
-
def trial_court
|
10
|
-
@trial_court ||= Trial::Court.new \
|
11
|
-
Judge::Base, DefenseAttorney::Base, Validator, Context::Base
|
12
|
-
end
|
13
|
-
|
14
9
|
def target_options
|
15
10
|
@target_options || Helpers.super_method(self, :target_options)
|
16
11
|
end
|
@@ -59,6 +54,8 @@ module RestMyCase
|
|
59
54
|
|
60
55
|
extend ClassMethods
|
61
56
|
|
57
|
+
trial_court.last_ancestor = Validator
|
58
|
+
|
62
59
|
self.silence_dependencies_abort = true
|
63
60
|
|
64
61
|
extend AccusationAttorneys::HelperMethods
|
@@ -91,9 +88,7 @@ module RestMyCase
|
|
91
88
|
|
92
89
|
return if Helpers.blank?(targets) || all_validations_green?(targets)
|
93
90
|
|
94
|
-
if parent_target
|
95
|
-
parent_target.errors.add(target_options[:name], :invalid)
|
96
|
-
end
|
91
|
+
parent_target.errors.add(target_options[:name], :invalid) if parent_target
|
97
92
|
|
98
93
|
error('unprocessable_entity')
|
99
94
|
end
|
data/lib/rest_my_case/version.rb
CHANGED
data/lib/rest_my_case.rb
CHANGED
@@ -6,11 +6,7 @@ require 'rest_my_case/errors/base'
|
|
6
6
|
require 'rest_my_case/config/base'
|
7
7
|
require 'rest_my_case/config/general'
|
8
8
|
require 'rest_my_case/defense_attorney/base'
|
9
|
-
require 'rest_my_case/context/errors/base'
|
10
|
-
require 'rest_my_case/context/errors/status'
|
11
9
|
require 'rest_my_case/context/base'
|
12
|
-
require 'rest_my_case/context/status'
|
13
|
-
require 'rest_my_case/context/http_status'
|
14
10
|
require 'rest_my_case/judge/base'
|
15
11
|
require 'rest_my_case/trial/case'
|
16
12
|
require 'rest_my_case/trial/court'
|
data/rest_my_case.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.authors = ['goncalvesjoao']
|
10
10
|
gem.email = ['goncalves.joao@gmail.com']
|
11
11
|
gem.summary = %q{Quick and light "The Clean Architecture" use case implementation.}
|
12
|
-
gem.description = %q{
|
12
|
+
gem.description = %q{Light Ruby gem with everything you need in a "The Clean Architecture" use case scenario}
|
13
13
|
gem.homepage = 'https://github.com/goncalvesjoao/rest_my_case'
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
@@ -9,7 +9,7 @@ describe RestMyCase::AccusationAttorneys::Base do
|
|
9
9
|
before { @instance = AccusationAttorneysTestCase1.new({ attributes: { id: '1' } }) }
|
10
10
|
|
11
11
|
it 'should raise an error' do
|
12
|
-
expect { @instance.validate(nil) }.to raise_error
|
12
|
+
expect { @instance.validate(nil) }.to raise_error NotImplementedError
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -9,7 +9,7 @@ describe RestMyCase::AccusationAttorneys::Each do
|
|
9
9
|
before { @instance = AccusationAttorneysTestCase2.new({ attributes: { id: '1' } }) }
|
10
10
|
|
11
11
|
it 'should raise an error' do
|
12
|
-
expect { @instance.validate_each(nil, nil, nil) }.to raise_error
|
12
|
+
expect { @instance.validate_each(nil, nil, nil) }.to raise_error NotImplementedError
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -64,8 +64,8 @@ describe RestMyCase::AccusationAttorneys::Format do
|
|
64
64
|
|
65
65
|
describe "without options" do
|
66
66
|
it 'should raise an error' do
|
67
|
-
expect { Class.new(RestMyCase::Validator) { validates_format_of :body } }.to raise_error
|
67
|
+
expect { Class.new(RestMyCase::Validator) { validates_format_of :body } }.to raise_error ArgumentError
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
end
|
71
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Base do
|
4
|
+
|
5
|
+
describe ".context_accessor" do
|
6
|
+
|
7
|
+
let(:context) { RestMyCase::Context::Base.new(id: 1, comment: 'my comment', session: -1) }
|
8
|
+
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
9
|
+
|
10
|
+
it "Should create getters targeting to context" do
|
11
|
+
expect(use_case.respond_to?(:comment)).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "Should create setters targeting to context" do
|
15
|
+
expect(use_case.respond_to?(:comment=)).to be true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "Getter should delegate to context" do
|
19
|
+
expect(use_case.comment).to eq 'my comment'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Setter should delegate to context" do
|
23
|
+
use_case.comment = 'your comment'
|
24
|
+
expect(use_case.context.comment).to eq 'your comment'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Base do
|
4
|
+
|
5
|
+
describe ".context_reader" do
|
6
|
+
|
7
|
+
let(:context) { RestMyCase::Context::Base.new(id: 1, comment: 'my comment', session: -1) }
|
8
|
+
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
9
|
+
|
10
|
+
it "Should create getters targeting to context" do
|
11
|
+
expect(use_case.respond_to?(:session)).to be true
|
12
|
+
expect(use_case.respond_to?(:session=)).to be false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Getter should delegate to context" do
|
16
|
+
expect(use_case.session).to eq -1
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Base do
|
4
|
+
|
5
|
+
describe ".context_writer" do
|
6
|
+
|
7
|
+
let(:context) { RestMyCase::Context::Base.new }
|
8
|
+
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
9
|
+
|
10
|
+
it "Should create setters targeting to context" do
|
11
|
+
expect(use_case.respond_to?(:id)).to be false
|
12
|
+
expect(use_case.respond_to?(:id=)).to be true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Setter should delegate to context" do
|
16
|
+
use_case.id = 2
|
17
|
+
|
18
|
+
expect(use_case.context.id).to eq 2
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Base do
|
4
|
+
|
5
|
+
describe ".dependencies" do
|
6
|
+
|
7
|
+
it "should only list the class's dependencies" do
|
8
|
+
expect(RestMyCaseBase::CreatePostWithComments.dependencies).to \
|
9
|
+
eq [RestMyCaseBase::BuildComments, RestMyCaseBase::CreateComments]
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Base do
|
4
|
+
|
5
|
+
describe "#invoke!" do
|
6
|
+
|
7
|
+
context "when the invokees don't abort" do
|
8
|
+
|
9
|
+
class Perform::ScreammingInvoker < Perform::UseCaseWrapper
|
10
|
+
def perform
|
11
|
+
super
|
12
|
+
invoke! Perform::BuildPost, Perform::Validations, Perform::SavePost
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should invoke other use cases with the invoker's context and actually alter it" do
|
17
|
+
@context = Perform::ScreammingInvoker.perform
|
18
|
+
|
19
|
+
expect(@context.setup).to eq [
|
20
|
+
"Perform::Logger",
|
21
|
+
"Perform::ScreammingInvoker",
|
22
|
+
"Perform::Logger",
|
23
|
+
"Perform::BuildPost",
|
24
|
+
"Perform::Logger",
|
25
|
+
"Perform::ValidateName",
|
26
|
+
"Perform::Logger",
|
27
|
+
"Perform::ValidateBody",
|
28
|
+
"Perform::Logger",
|
29
|
+
"Perform::Validations",
|
30
|
+
"Perform::Logger",
|
31
|
+
"Perform::SavePost"
|
32
|
+
]
|
33
|
+
expect(@context.perform).to eq [
|
34
|
+
"Perform::Logger",
|
35
|
+
"Perform::ScreammingInvoker",
|
36
|
+
"Perform::Logger",
|
37
|
+
"Perform::BuildPost",
|
38
|
+
"Perform::Logger",
|
39
|
+
"Perform::ValidateName",
|
40
|
+
"Perform::Logger",
|
41
|
+
"Perform::ValidateBody",
|
42
|
+
"Perform::Logger",
|
43
|
+
"Perform::Validations",
|
44
|
+
"Perform::Logger",
|
45
|
+
"Perform::SavePost"
|
46
|
+
]
|
47
|
+
expect(@context.rollback).to eq []
|
48
|
+
expect(@context.final).to eq [
|
49
|
+
"Perform::Logger",
|
50
|
+
"Perform::BuildPost",
|
51
|
+
"Perform::Logger",
|
52
|
+
"Perform::ValidateName",
|
53
|
+
"Perform::Logger",
|
54
|
+
"Perform::ValidateBody",
|
55
|
+
"Perform::Logger",
|
56
|
+
"Perform::Validations",
|
57
|
+
"Perform::Logger",
|
58
|
+
"Perform::SavePost",
|
59
|
+
"Perform::Logger",
|
60
|
+
"Perform::ScreammingInvoker"
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when the invokees abort" do
|
67
|
+
|
68
|
+
class Perform::Validations2 < Perform::UseCaseWrapper
|
69
|
+
def perform
|
70
|
+
super
|
71
|
+
|
72
|
+
invoke! Perform::ValidateName, Perform::ValidateBody
|
73
|
+
|
74
|
+
context.should_not_be_true = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Perform::CreatePost2 < Perform::UseCaseWrapper
|
79
|
+
depends Perform::BuildPost, Perform::Validations2, Perform::SavePost
|
80
|
+
end
|
81
|
+
|
82
|
+
before do
|
83
|
+
@context = Perform::CreatePost2.perform \
|
84
|
+
error: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform']
|
85
|
+
end
|
86
|
+
|
87
|
+
it "invoker should abort the process it his invokees have also aborted" do
|
88
|
+
expect(@context.setup).to eq [
|
89
|
+
"Perform::Logger",
|
90
|
+
"Perform::BuildPost",
|
91
|
+
"Perform::Logger",
|
92
|
+
"Perform::Validations2",
|
93
|
+
"Perform::Logger",
|
94
|
+
"Perform::SavePost",
|
95
|
+
"Perform::Logger",
|
96
|
+
"Perform::CreatePost2",
|
97
|
+
"Perform::Logger",
|
98
|
+
"Perform::ValidateName",
|
99
|
+
"Perform::Logger",
|
100
|
+
"Perform::ValidateBody"
|
101
|
+
]
|
102
|
+
expect(@context.perform).to eq [
|
103
|
+
"Perform::Logger",
|
104
|
+
"Perform::BuildPost",
|
105
|
+
"Perform::Logger",
|
106
|
+
"Perform::Validations2",
|
107
|
+
"Perform::Logger",
|
108
|
+
"Perform::ValidateName"
|
109
|
+
]
|
110
|
+
expect(@context.rollback).to eq [
|
111
|
+
"Perform::ValidateName",
|
112
|
+
"Perform::Logger",
|
113
|
+
"Perform::Validations2",
|
114
|
+
"Perform::Logger",
|
115
|
+
"Perform::BuildPost",
|
116
|
+
"Perform::Logger"
|
117
|
+
]
|
118
|
+
expect(@context.final).to eq [
|
119
|
+
"Perform::Logger",
|
120
|
+
"Perform::ValidateName",
|
121
|
+
"Perform::Logger",
|
122
|
+
"Perform::ValidateBody",
|
123
|
+
"Perform::Logger",
|
124
|
+
"Perform::BuildPost",
|
125
|
+
"Perform::Logger",
|
126
|
+
"Perform::Validations2",
|
127
|
+
"Perform::Logger",
|
128
|
+
"Perform::SavePost",
|
129
|
+
"Perform::Logger",
|
130
|
+
"Perform::CreatePost2"
|
131
|
+
]
|
132
|
+
|
133
|
+
expect(@context.should_not_be_true).to be_falsey
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Base do
|
4
|
+
|
5
|
+
describe "#invoke" do
|
6
|
+
|
7
|
+
class Perform::Invoker < Perform::UseCaseWrapper
|
8
|
+
def perform
|
9
|
+
super
|
10
|
+
invoke Perform::BuildPost, Perform::Validations, Perform::SavePost
|
11
|
+
|
12
|
+
context.should_be_true = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should invoke other use cases with the invoker's cloned context and they can't alter the invoker's context" do
|
17
|
+
context = Perform::Invoker.perform
|
18
|
+
|
19
|
+
expect(context.setup.length).to be 2
|
20
|
+
expect(context.perform.length).to be 2
|
21
|
+
expect(context.rollback.length).to be 0
|
22
|
+
expect(context.final.length).to be 2
|
23
|
+
|
24
|
+
expect(context.should_be_true).to be true
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -2,73 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe RestMyCase::Base do
|
4
4
|
|
5
|
-
describe ".dependencies" do
|
6
|
-
|
7
|
-
it "should only list the class's dependencies" do
|
8
|
-
expect(RestMyCaseBase::CreatePostWithComments.dependencies).to \
|
9
|
-
eq [RestMyCaseBase::BuildComments, RestMyCaseBase::CreateComments]
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe ".context_accessor" do
|
15
|
-
|
16
|
-
let(:context) { RestMyCase::Context::Base.new(id: 1, comment: 'my comment', session: -1) }
|
17
|
-
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
18
|
-
|
19
|
-
it "Should create getters targeting to context" do
|
20
|
-
expect(use_case.respond_to?(:comment)).to be true
|
21
|
-
end
|
22
|
-
|
23
|
-
it "Should create setters targeting to context" do
|
24
|
-
expect(use_case.respond_to?(:comment=)).to be true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "Getter should delegate to context" do
|
28
|
-
expect(use_case.comment).to eq 'my comment'
|
29
|
-
end
|
30
|
-
|
31
|
-
it "Setter should delegate to context" do
|
32
|
-
use_case.comment = 'your comment'
|
33
|
-
expect(use_case.context.comment).to eq 'your comment'
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
describe ".context_writer" do
|
39
|
-
|
40
|
-
let(:context) { RestMyCase::Context::Base.new }
|
41
|
-
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
42
|
-
|
43
|
-
it "Should create setters targeting to context" do
|
44
|
-
expect(use_case.respond_to?(:id)).to be false
|
45
|
-
expect(use_case.respond_to?(:id=)).to be true
|
46
|
-
end
|
47
|
-
|
48
|
-
it "Setter should delegate to context" do
|
49
|
-
use_case.id = 2
|
50
|
-
|
51
|
-
expect(use_case.context.id).to eq 2
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
describe ".context_reader" do
|
57
|
-
|
58
|
-
let(:context) { RestMyCase::Context::Base.new(id: 1, comment: 'my comment', session: -1) }
|
59
|
-
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
60
|
-
|
61
|
-
it "Should create getters targeting to context" do
|
62
|
-
expect(use_case.respond_to?(:session)).to be true
|
63
|
-
expect(use_case.respond_to?(:session=)).to be false
|
64
|
-
end
|
65
|
-
|
66
|
-
it "Getter should delegate to context" do
|
67
|
-
expect(use_case.session).to eq -1
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
5
|
describe ".perform" do
|
73
6
|
|
74
7
|
context "When something that doesn't responds to #to_hash is passed down" do
|
@@ -305,163 +238,4 @@ describe RestMyCase::Base do
|
|
305
238
|
|
306
239
|
end
|
307
240
|
|
308
|
-
describe "#invoke" do
|
309
|
-
|
310
|
-
class Perform::Invoker < Perform::UseCaseWrapper
|
311
|
-
def perform
|
312
|
-
super
|
313
|
-
invoke Perform::BuildPost, Perform::Validations, Perform::SavePost
|
314
|
-
|
315
|
-
context.should_be_true = true
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
it "should invoke other use cases with the invoker's cloned context and they can't alter the invoker's context" do
|
320
|
-
context = Perform::Invoker.perform
|
321
|
-
|
322
|
-
expect(context.setup.length).to be 2
|
323
|
-
expect(context.perform.length).to be 2
|
324
|
-
expect(context.rollback.length).to be 0
|
325
|
-
expect(context.final.length).to be 2
|
326
|
-
|
327
|
-
expect(context.should_be_true).to be true
|
328
|
-
end
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
describe "#invoke!" do
|
333
|
-
|
334
|
-
context "when the invokees don't abort" do
|
335
|
-
|
336
|
-
class Perform::ScreammingInvoker < Perform::UseCaseWrapper
|
337
|
-
def perform
|
338
|
-
super
|
339
|
-
invoke! Perform::BuildPost, Perform::Validations, Perform::SavePost
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
it "should invoke other use cases with the invoker's context and actually alter it" do
|
344
|
-
@context = Perform::ScreammingInvoker.perform
|
345
|
-
|
346
|
-
expect(@context.setup).to eq [
|
347
|
-
"Perform::Logger",
|
348
|
-
"Perform::ScreammingInvoker",
|
349
|
-
"Perform::Logger",
|
350
|
-
"Perform::BuildPost",
|
351
|
-
"Perform::Logger",
|
352
|
-
"Perform::ValidateName",
|
353
|
-
"Perform::Logger",
|
354
|
-
"Perform::ValidateBody",
|
355
|
-
"Perform::Logger",
|
356
|
-
"Perform::Validations",
|
357
|
-
"Perform::Logger",
|
358
|
-
"Perform::SavePost"
|
359
|
-
]
|
360
|
-
expect(@context.perform).to eq [
|
361
|
-
"Perform::Logger",
|
362
|
-
"Perform::ScreammingInvoker",
|
363
|
-
"Perform::Logger",
|
364
|
-
"Perform::BuildPost",
|
365
|
-
"Perform::Logger",
|
366
|
-
"Perform::ValidateName",
|
367
|
-
"Perform::Logger",
|
368
|
-
"Perform::ValidateBody",
|
369
|
-
"Perform::Logger",
|
370
|
-
"Perform::Validations",
|
371
|
-
"Perform::Logger",
|
372
|
-
"Perform::SavePost"
|
373
|
-
]
|
374
|
-
expect(@context.rollback).to eq []
|
375
|
-
expect(@context.final).to eq [
|
376
|
-
"Perform::Logger",
|
377
|
-
"Perform::BuildPost",
|
378
|
-
"Perform::Logger",
|
379
|
-
"Perform::ValidateName",
|
380
|
-
"Perform::Logger",
|
381
|
-
"Perform::ValidateBody",
|
382
|
-
"Perform::Logger",
|
383
|
-
"Perform::Validations",
|
384
|
-
"Perform::Logger",
|
385
|
-
"Perform::SavePost",
|
386
|
-
"Perform::Logger",
|
387
|
-
"Perform::ScreammingInvoker"
|
388
|
-
]
|
389
|
-
end
|
390
|
-
|
391
|
-
end
|
392
|
-
|
393
|
-
context "when the invokees abort" do
|
394
|
-
|
395
|
-
class Perform::Validations2 < Perform::UseCaseWrapper
|
396
|
-
def perform
|
397
|
-
super
|
398
|
-
|
399
|
-
invoke! Perform::ValidateName, Perform::ValidateBody
|
400
|
-
|
401
|
-
context.should_not_be_true = true
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
class Perform::CreatePost2 < Perform::UseCaseWrapper
|
406
|
-
depends Perform::BuildPost, Perform::Validations2, Perform::SavePost
|
407
|
-
end
|
408
|
-
|
409
|
-
before do
|
410
|
-
@context = Perform::CreatePost2.perform \
|
411
|
-
error: ['Perform::ValidateName_perform', 'Perform::ValidateBody_perform']
|
412
|
-
end
|
413
|
-
|
414
|
-
it "invoker should abort the process it his invokees have also aborted" do
|
415
|
-
expect(@context.setup).to eq [
|
416
|
-
"Perform::Logger",
|
417
|
-
"Perform::BuildPost",
|
418
|
-
"Perform::Logger",
|
419
|
-
"Perform::Validations2",
|
420
|
-
"Perform::Logger",
|
421
|
-
"Perform::SavePost",
|
422
|
-
"Perform::Logger",
|
423
|
-
"Perform::CreatePost2",
|
424
|
-
"Perform::Logger",
|
425
|
-
"Perform::ValidateName",
|
426
|
-
"Perform::Logger",
|
427
|
-
"Perform::ValidateBody"
|
428
|
-
]
|
429
|
-
expect(@context.perform).to eq [
|
430
|
-
"Perform::Logger",
|
431
|
-
"Perform::BuildPost",
|
432
|
-
"Perform::Logger",
|
433
|
-
"Perform::Validations2",
|
434
|
-
"Perform::Logger",
|
435
|
-
"Perform::ValidateName"
|
436
|
-
]
|
437
|
-
expect(@context.rollback).to eq [
|
438
|
-
"Perform::ValidateName",
|
439
|
-
"Perform::Logger",
|
440
|
-
"Perform::Validations2",
|
441
|
-
"Perform::Logger",
|
442
|
-
"Perform::BuildPost",
|
443
|
-
"Perform::Logger"
|
444
|
-
]
|
445
|
-
expect(@context.final).to eq [
|
446
|
-
"Perform::Logger",
|
447
|
-
"Perform::ValidateName",
|
448
|
-
"Perform::Logger",
|
449
|
-
"Perform::ValidateBody",
|
450
|
-
"Perform::Logger",
|
451
|
-
"Perform::BuildPost",
|
452
|
-
"Perform::Logger",
|
453
|
-
"Perform::Validations2",
|
454
|
-
"Perform::Logger",
|
455
|
-
"Perform::SavePost",
|
456
|
-
"Perform::Logger",
|
457
|
-
"Perform::CreatePost2"
|
458
|
-
]
|
459
|
-
|
460
|
-
expect(@context.should_not_be_true).to be_falsey
|
461
|
-
end
|
462
|
-
|
463
|
-
end
|
464
|
-
|
465
|
-
end
|
466
|
-
|
467
241
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Base do
|
4
|
+
|
5
|
+
describe ".required_context" do
|
6
|
+
|
7
|
+
context "When #setup odly populates the required field" do
|
8
|
+
before { @context = RequiredContext::Users::GetCurrentUser.perform }
|
9
|
+
|
10
|
+
it "context should be ok" do
|
11
|
+
expect(@context.ok?).to be true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "When dependencies also have a required_context" do
|
16
|
+
before { @context = RequiredContext::Posts::Update.perform }
|
17
|
+
|
18
|
+
it "context should NOT be ok" do
|
19
|
+
expect(@context.ok?).to be false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "context errors should include 3 context_errors" do
|
23
|
+
expect(@context.errors.length).to be 3
|
24
|
+
expect(@context.errors[0][:context_errors][:id]).to be_truthy
|
25
|
+
expect(@context.errors[1][:context_errors][:post]).to be_truthy
|
26
|
+
expect(@context.errors[1][:context_errors][:post_attributes]).to be_truthy
|
27
|
+
expect(@context.errors[2][:context_errors][:post]).to be_truthy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|