rest_my_case 1.3.2 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rest_my_case/base.rb +9 -9
- data/lib/rest_my_case/judge/base.rb +2 -2
- data/lib/rest_my_case/version.rb +1 -1
- data/spec/rest_my_case/base_spec.rb +90 -18
- data/spec/support/perform.rb +0 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: befb7a3cb43ce0e61ec02c2fc33afe9e1d9f734b
|
4
|
+
data.tar.gz: 18ac6c5fcf8ddb9a3d8534e7697fd1ae7995d299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74deb7063872d6ce4f3a0ed098238b70c27f671f6611ccf291c8facfbe31d5f33f4b18fb368ec04de1b818453c514332422b4e4720fd06d20fa33f90ad6e6529
|
7
|
+
data.tar.gz: 57cce6814654046a2a9700952aff2dace3fceb10abb4d804d788facd9263bd9c17a294b802e255c6341e0426085c01efa47f55d21e015c54311de0c62d5357ad
|
data/lib/rest_my_case/base.rb
CHANGED
@@ -45,7 +45,7 @@ module RestMyCase
|
|
45
45
|
|
46
46
|
def initialize(context, options = {})
|
47
47
|
@context = context
|
48
|
-
@options = options
|
48
|
+
@options = options.dup
|
49
49
|
end
|
50
50
|
|
51
51
|
def setup; end
|
@@ -56,14 +56,6 @@ module RestMyCase
|
|
56
56
|
|
57
57
|
def final; end
|
58
58
|
|
59
|
-
def fail(message = '')
|
60
|
-
abort && @context.errors[self.class.name].push(message)
|
61
|
-
end
|
62
|
-
|
63
|
-
def fail!(message = '')
|
64
|
-
fail(message) && raise(Errors::Abort)
|
65
|
-
end
|
66
|
-
|
67
59
|
def abort
|
68
60
|
options[:should_abort] = true
|
69
61
|
end
|
@@ -72,6 +64,14 @@ module RestMyCase
|
|
72
64
|
abort && raise(Errors::Abort)
|
73
65
|
end
|
74
66
|
|
67
|
+
def fail(message = '')
|
68
|
+
abort && context.errors[self.class.name].push(message)
|
69
|
+
end
|
70
|
+
|
71
|
+
def fail!(message = '')
|
72
|
+
fail(message) && raise(Errors::Abort)
|
73
|
+
end
|
74
|
+
|
75
75
|
def skip
|
76
76
|
options[:should_skip] = true
|
77
77
|
end
|
@@ -35,7 +35,7 @@ module RestMyCase
|
|
35
35
|
def run_rollback_methods
|
36
36
|
return nil unless @use_case_that_aborted
|
37
37
|
|
38
|
-
@performed_use_cases.
|
38
|
+
@performed_use_cases.reverse.each do |use_case|
|
39
39
|
run_method(:rollback, use_case)
|
40
40
|
end
|
41
41
|
end
|
@@ -62,7 +62,7 @@ module RestMyCase
|
|
62
62
|
begin
|
63
63
|
run_method(method_name, use_case)
|
64
64
|
|
65
|
-
use_case.options[:should_abort]
|
65
|
+
use_case.options[:should_abort] && @use_case_that_aborted = use_case
|
66
66
|
rescue Errors::Skip => exception
|
67
67
|
false
|
68
68
|
rescue Errors::Abort => exception
|
data/lib/rest_my_case/version.rb
CHANGED
@@ -3,15 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe RestMyCase::Base do
|
4
4
|
|
5
5
|
describe ".dependencies" do
|
6
|
-
it "
|
6
|
+
it "should only list the class's dependencies" do
|
7
7
|
expect(RestMyCaseBase::CreatePostWithComments.dependencies).to \
|
8
8
|
eq [RestMyCaseBase::BuildComments, RestMyCaseBase::CreateComments]
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe ".context_accessor" do
|
13
|
-
let(:context)
|
14
|
-
let(:use_case)
|
13
|
+
let(:context) { RestMyCase::TrialCase::Context.new(id: 1, comment: 'my comment', session: -1) }
|
14
|
+
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
15
15
|
|
16
16
|
it "Should create getters targeting to context" do
|
17
17
|
expect(use_case.respond_to?(:comment)).to be true
|
@@ -22,7 +22,7 @@ describe RestMyCase::Base do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "Getter should delegate to context" do
|
25
|
-
expect(use_case.comment).to eq
|
25
|
+
expect(use_case.comment).to eq 'my comment'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "Setter should delegate to context" do
|
@@ -32,7 +32,8 @@ describe RestMyCase::Base do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe ".context_writer" do
|
35
|
-
let(:
|
35
|
+
let(:context) { RestMyCase::TrialCase::Context.new }
|
36
|
+
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
36
37
|
|
37
38
|
it "Should create setters targeting to context" do
|
38
39
|
expect(use_case.respond_to?(:id)).to be false
|
@@ -47,8 +48,8 @@ describe RestMyCase::Base do
|
|
47
48
|
end
|
48
49
|
|
49
50
|
describe ".context_reader" do
|
50
|
-
let(:context)
|
51
|
-
let(:use_case)
|
51
|
+
let(:context) { RestMyCase::TrialCase::Context.new(id: 1, comment: 'my comment', session: -1) }
|
52
|
+
let(:use_case) { RestMyCaseBase::CreatePostWithComments.new(context) }
|
52
53
|
|
53
54
|
it "Should create getters targeting to context" do
|
54
55
|
expect(use_case.respond_to?(:session)).to be true
|
@@ -56,21 +57,29 @@ describe RestMyCase::Base do
|
|
56
57
|
end
|
57
58
|
|
58
59
|
it "Getter should delegate to context" do
|
59
|
-
expect(use_case.session).to eq
|
60
|
+
expect(use_case.session).to eq -1
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
64
|
describe ".perform" do
|
64
65
|
|
65
|
-
context "When
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
context "When a use case #fail during the setup process" do
|
67
|
+
before do
|
68
|
+
class Perform::ValidateName < RestMyCase::Base
|
69
|
+
def setup
|
70
|
+
fail('no name!')
|
71
|
+
context.setup << self.class.name
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
@context = Perform::CreatePost.perform
|
69
76
|
end
|
70
|
-
end
|
71
77
|
|
72
|
-
|
73
|
-
|
78
|
+
after do
|
79
|
+
class Perform::ValidateName < RestMyCase::Base
|
80
|
+
def setup; context.setup << self.class.name; end
|
81
|
+
end
|
82
|
+
end
|
74
83
|
|
75
84
|
it "context should reflect an invalid state" do
|
76
85
|
expect(@context.valid?).to be false
|
@@ -80,11 +89,74 @@ describe RestMyCase::Base do
|
|
80
89
|
expect(@context.errors.keys.length).to be 1
|
81
90
|
end
|
82
91
|
|
83
|
-
it "context
|
84
|
-
# binding.pry
|
92
|
+
it "context prove that only the correct method have ran" do
|
85
93
|
expect(@context.setup.length).to be 2
|
86
94
|
expect(@context.perform.length).to be 0
|
87
|
-
expect(@context.rollback.length).to be
|
95
|
+
expect(@context.rollback.length).to be 0
|
96
|
+
expect(@context.final.length).to be 6
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "When a use case #fail! during the setup process" do
|
101
|
+
before do
|
102
|
+
class Perform::ValidateName < RestMyCase::Base
|
103
|
+
def setup
|
104
|
+
fail!('no name!')
|
105
|
+
context.setup << self.class.name
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
@context = Perform::CreatePost.perform
|
110
|
+
end
|
111
|
+
|
112
|
+
after do
|
113
|
+
class Perform::ValidateName < RestMyCase::Base
|
114
|
+
def setup; context.setup << self.class.name; end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "context should reflect an invalid state" do
|
119
|
+
expect(@context.valid?).to be false
|
120
|
+
end
|
121
|
+
|
122
|
+
it "context should contain only one error" do
|
123
|
+
expect(@context.errors.keys.length).to be 1
|
124
|
+
end
|
125
|
+
|
126
|
+
it "context prove that only the correct method have ran" do
|
127
|
+
expect(@context.setup.length).to be 1
|
128
|
+
expect(@context.perform.length).to be 0
|
129
|
+
expect(@context.rollback.length).to be 0
|
130
|
+
expect(@context.final.length).to be 6
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "When a use case #skip during the setup process" do
|
135
|
+
before do
|
136
|
+
class Perform::ValidateBody < RestMyCase::Base
|
137
|
+
def setup
|
138
|
+
skip
|
139
|
+
context.setup << self.class.name
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
@context = Perform::CreatePost.perform
|
144
|
+
end
|
145
|
+
|
146
|
+
after do
|
147
|
+
class Perform::ValidateName < RestMyCase::Base
|
148
|
+
def setup; context.setup << self.class.name; end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it "context should reflect an valid state" do
|
153
|
+
expect(@context.valid?).to be true
|
154
|
+
end
|
155
|
+
|
156
|
+
it "context prove that only the correct method have ran" do
|
157
|
+
expect(@context.setup.length).to be 6
|
158
|
+
expect(@context.perform.length).to be 5
|
159
|
+
expect(@context.rollback.length).to be 0
|
88
160
|
expect(@context.final.length).to be 6
|
89
161
|
end
|
90
162
|
end
|
data/spec/support/perform.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
module Perform
|
2
2
|
|
3
3
|
class ValidateName < RestMyCase::Base
|
4
|
-
context_reader :name
|
5
|
-
|
6
4
|
def setup
|
7
|
-
fail('no name present!') if name.nil?
|
8
|
-
|
9
5
|
context.setup << self.class.name
|
10
6
|
end
|
11
7
|
|
@@ -23,11 +19,7 @@ module Perform
|
|
23
19
|
end
|
24
20
|
|
25
21
|
class ValidateBody < RestMyCase::Base
|
26
|
-
context_reader :body
|
27
|
-
|
28
22
|
def setup
|
29
|
-
fail('no body present!') if body.nil?
|
30
|
-
|
31
23
|
context.setup << self.class.name
|
32
24
|
end
|
33
25
|
|