rest_my_case 1.9.1 → 1.9.2
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/context/errors/base.rb +13 -3
- data/lib/rest_my_case/context/errors/status.rb +3 -1
- data/lib/rest_my_case/version.rb +1 -1
- data/spec/rest_my_case/accusation_attorneys/base_spec.rb +2 -2
- data/spec/rest_my_case/accusation_attorneys/each_spec.rb +2 -2
- data/spec/rest_my_case/base_spec.rb +5 -0
- data/spec/rest_my_case/status_spec.rb +72 -6
- 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: 088ea74126da74d24cd42b6ca1bd23838cf16f74
|
4
|
+
data.tar.gz: a5c583155c12293f7e23e23213bab13c74cf3544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d48c0464b9ea66217c168963ebbef24542273a55336486e0c0dcbfb0a7bf5ae8bbdf38cbdfb7d4dbf646f401a7d9ff62196e9885c13493a1e8af19c418c39057
|
7
|
+
data.tar.gz: 6c8546d1508b909c58e19287d7e8e8dc826f311a4e52387d7aeaf49b72d693e3d40816fba6da3c90d9253d4d3f5cdfed6fed21dc88c450cc613b6ffb5f73a69e
|
@@ -10,10 +10,20 @@ module RestMyCase
|
|
10
10
|
@context = context
|
11
11
|
end
|
12
12
|
|
13
|
-
def add(
|
14
|
-
self[
|
13
|
+
def add(class_name, message)
|
14
|
+
self[class_name] ||= []
|
15
15
|
|
16
|
-
self[
|
16
|
+
self[class_name].push(message.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def messages
|
20
|
+
self.values.flatten
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_messages
|
24
|
+
self.map do |class_name, messages|
|
25
|
+
"#{class_name}: #{messages.join(', ')}"
|
26
|
+
end
|
17
27
|
end
|
18
28
|
|
19
29
|
end
|
data/lib/rest_my_case/version.rb
CHANGED
@@ -4,9 +4,9 @@ describe RestMyCase::AccusationAttorneys::Base do
|
|
4
4
|
|
5
5
|
describe '#validate' do
|
6
6
|
context "given that the child class hasn't implemented the validate method" do
|
7
|
-
|
7
|
+
AccusationAttorneysTestCase1 = Class.new(described_class)
|
8
8
|
|
9
|
-
before { @instance =
|
9
|
+
before { @instance = AccusationAttorneysTestCase1.new({ attributes: { id: '1' } }) }
|
10
10
|
|
11
11
|
it 'should raise an error' do
|
12
12
|
expect { @instance.validate(nil) }.to raise_error
|
@@ -4,9 +4,9 @@ describe RestMyCase::AccusationAttorneys::Each do
|
|
4
4
|
|
5
5
|
describe '#validate_each' do
|
6
6
|
context "given that the child class hasn't implemented the validate_each method" do
|
7
|
-
|
7
|
+
AccusationAttorneysTestCase2 = Class.new(described_class)
|
8
8
|
|
9
|
-
before { @instance =
|
9
|
+
before { @instance = AccusationAttorneysTestCase2.new({ attributes: { id: '1' } }) }
|
10
10
|
|
11
11
|
it 'should raise an error' do
|
12
12
|
expect { @instance.validate_each(nil, nil, nil) }.to raise_error
|
@@ -108,6 +108,7 @@ describe RestMyCase::Base do
|
|
108
108
|
|
109
109
|
it "context should contain only one error" do
|
110
110
|
expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""]})
|
111
|
+
expect(@context.errors.full_messages).to eq ["Perform::ValidateName: "]
|
111
112
|
end
|
112
113
|
|
113
114
|
it "context prove that only the correct method have ran" do
|
@@ -130,6 +131,7 @@ describe RestMyCase::Base do
|
|
130
131
|
|
131
132
|
it "context should contain only one error" do
|
132
133
|
expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""]})
|
134
|
+
expect(@context.errors.full_messages).to eq ["Perform::ValidateName: "]
|
133
135
|
end
|
134
136
|
|
135
137
|
it "context prove that only the correct method have ran" do
|
@@ -231,6 +233,7 @@ describe RestMyCase::Base do
|
|
231
233
|
|
232
234
|
it "context should contain only 2 errors" do
|
233
235
|
expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""], "Perform::ValidateBody"=>[""]})
|
236
|
+
expect(@context.errors.full_messages).to eq ["Perform::ValidateName: ", "Perform::ValidateBody: "]
|
234
237
|
end
|
235
238
|
|
236
239
|
it "context prove that only the correct method have ran" do
|
@@ -255,6 +258,7 @@ describe RestMyCase::Base do
|
|
255
258
|
|
256
259
|
it "context should contain only 2 errors" do
|
257
260
|
expect(@context.errors).to match a_hash_including({"Perform::ValidateName"=>[""], "Perform::ValidateBody"=>[""]})
|
261
|
+
expect(@context.errors.full_messages).to eq ["Perform::ValidateName: ", "Perform::ValidateBody: "]
|
258
262
|
end
|
259
263
|
|
260
264
|
it "context prove that only the correct method have ran" do
|
@@ -290,6 +294,7 @@ describe RestMyCase::Base do
|
|
290
294
|
|
291
295
|
it "context should contain only 4 errors" do
|
292
296
|
expect(@context.errors).to match a_hash_including({"Perform::BuildPost"=>[""], "Perform::ValidateName"=>[""], "Perform::ValidateBody"=>[""], "Perform::SavePost"=>[""]})
|
297
|
+
expect(@context.errors.full_messages).to eq ["Perform::BuildPost: ", "Perform::ValidateName: ", "Perform::ValidateBody: ", "Perform::SavePost: "]
|
293
298
|
end
|
294
299
|
|
295
300
|
it "context prove that only the correct method have ran" do
|
@@ -18,10 +18,10 @@ describe RestMyCase::Status do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
context "when
|
21
|
+
context "when error(:unprocessable_entity) is used" do
|
22
22
|
TestCase2 = Class.new(described_class) do
|
23
23
|
def perform
|
24
|
-
|
24
|
+
error(:unprocessable_entity)
|
25
25
|
context.next_line = true
|
26
26
|
end
|
27
27
|
end
|
@@ -41,14 +41,17 @@ describe RestMyCase::Status do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "context's errors should have a proper message" do
|
44
|
-
|
44
|
+
message = "unprocessable_entity"
|
45
|
+
|
46
|
+
expect(@context.errors["TestCase2"]).to eq [message]
|
47
|
+
expect(@context.errors.messages).to eq [message]
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
|
-
context "when
|
51
|
+
context "when error!(:internal_server_error) is used" do
|
49
52
|
TestCase3 = Class.new(described_class) do
|
50
53
|
def perform
|
51
|
-
|
54
|
+
error!(:internal_server_error)
|
52
55
|
context.next_line = true
|
53
56
|
end
|
54
57
|
end
|
@@ -68,7 +71,70 @@ describe RestMyCase::Status do
|
|
68
71
|
end
|
69
72
|
|
70
73
|
it "context's errors should have a proper message" do
|
71
|
-
|
74
|
+
message = "internal_server_error"
|
75
|
+
|
76
|
+
expect(@context.errors["TestCase3"]).to eq [message]
|
77
|
+
expect(@context.errors.messages).to eq [message]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when failure(:unprocessable_entity) is used" do
|
82
|
+
TestCase4 = Class.new(described_class) do
|
83
|
+
def perform
|
84
|
+
failure(:unprocessable_entity, 'invalid id')
|
85
|
+
context.next_line = true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
before { @context = TestCase4.perform }
|
90
|
+
|
91
|
+
it "@context.status.unprocessable_entity? should be true" do
|
92
|
+
expect(@context.status.unprocessable_entity?).to be true
|
93
|
+
end
|
94
|
+
|
95
|
+
it "@context.next_line should be true" do
|
96
|
+
expect(@context.next_line).to be true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "@context.status.ok? should be false" do
|
100
|
+
expect(@context.status.ok?).to be false
|
101
|
+
end
|
102
|
+
|
103
|
+
it "context's errors should have a proper message" do
|
104
|
+
message = "unprocessable_entity - invalid id"
|
105
|
+
|
106
|
+
expect(@context.errors["TestCase4"]).to eq [message]
|
107
|
+
expect(@context.errors.messages).to eq [message]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "when failure!(:internal_server_error) is used" do
|
112
|
+
TestCase5 = Class.new(described_class) do
|
113
|
+
def perform
|
114
|
+
failure!(:internal_server_error, 'while saving the resource')
|
115
|
+
context.next_line = true
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
before { @context = TestCase5.perform }
|
120
|
+
|
121
|
+
it "@context.status.internal_server_error? should be true" do
|
122
|
+
expect(@context.status.internal_server_error?).to be true
|
123
|
+
end
|
124
|
+
|
125
|
+
it "@context.next_line should be true" do
|
126
|
+
expect { context.next_line }.to raise_error
|
127
|
+
end
|
128
|
+
|
129
|
+
it "@context.status.ok? should be false" do
|
130
|
+
expect(@context.status.ok?).to be false
|
131
|
+
end
|
132
|
+
|
133
|
+
it "context's errors should have a proper message" do
|
134
|
+
message = "internal_server_error - while saving the resource"
|
135
|
+
|
136
|
+
expect(@context.errors["TestCase5"]).to eq [message]
|
137
|
+
expect(@context.errors.messages).to eq [message]
|
72
138
|
end
|
73
139
|
end
|
74
140
|
|